Skip to Content
Menu
This question has been flagged
1 Reply
4063 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
Related Posts Replies Views Activity
2
Jan 16
34004
1
Aug 20
3517
1
Sep 19
7706
3
Feb 19
7485
3
Jul 17
10370