Unique list prices for variants

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

You will have to extend product.product to store the new list price field and override list_price_used property to use it.

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')

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.

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.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.