jt93
July 15, 2024, 1:26pm
1
Hi,
I want to be able to create variants with different initial list_prices e.g.
Product = Model.get('product.product')
p1 = Product(template=tmpl, list_price=Decimal('10.00'))
p1.save()
p2 = Product(template=tmpl, list_price=Decimal('20.00'))
p2.save()
How could I extend the product module to do something like this without using any custom price lists?
Thanks for your help
ced
(Cédric Krier)
July 15, 2024, 2:28pm
2
You will have to extend product.product
to store the new list price field and override list_price_used
property to use it.
jt93
July 15, 2024, 2:43pm
3
I tried to apply the change but still get a KeyError: 'product.product.list_price'
in pool.py.
This is what I did:
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
@classmethod
def __setup__(cls):
super(Product, cls).__setup__()
field = getattr(cls, 'list_price')
if isinstance(field, TemplateFunction):
field = deepcopy(field._field)
field.readonly = False
setattr(cls, 'list_price', field)
@property
def list_price_used(self):
transaction = Transaction()
with transaction.reset_context(), \
transaction.set_context(self._context):
return self.get_multivalue('list_price')
jt93
July 15, 2024, 3:05pm
4
Do I have to extend product.list_price
as well such that it has a product field and not only a template field and/or modify the multivalue_model()
class method?
Sorry, I probably haven’t fully understood how the Multivalue fields work yet. Thanks for your help anyways.
ced
(Cédric Krier)
July 15, 2024, 9:53pm
5
Yes if you want to make it a MultiValue field.
Maybe you should start simple by just using a new field name and progressively convert it to a MultiValue and override of template field.
system
(system)
Closed
November 21, 2024, 8:12am
6
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.