跳至内容
菜单
此问题已终结
1 回复
5158 查看

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

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
1月 16
35548
1
8月 20
4639
1
9月 19
8793
3
2月 19
8967
3
7月 17
11595