تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
5141 أدوات العرض

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
يناير 16
35533
1
أغسطس 20
4631
1
سبتمبر 19
8780
3
فبراير 19
8952
3
يوليو 17
11585