This question has been flagged
1 Reply
3561 Views

Hi

I'm trying  to create new product in product.template model using the following code

    def write(self, values):

        # list_price = self.env['product.template'].create(values)

        list_price = self.env['product.template'].create({'list_price': self.unit_cost, 'name': self.p_name})

        print(values)

        self.env['product.template'].clear_caches()

        return super(Offset, self).write(values)

this creates a new record but the values 'name:p_name' stores as product.product(id#) and list_price stores a previously/earlier stored value

Thank you for helping me out

Avatar
Discard
Best Answer

Hi,

Not clear about the issue that you are facing,

        list_price = self.env['product.template'].create({'list_price': self.unit_cost, 'name': self.p_name})


What above line do is that, it will create a record in model product.template with the values you have passed inside the dictionary. The name of product will be the value in the variable self.p_name and price will be self.unit_cost, you can add a print statement in the code and see what values are coming inside this variables and compare it with name and price of newly created product.

Creating Record From Code: Create Record From Code in Odoo

Thanks

Avatar
Discard