Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5050 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
ian. 16
35390
1
aug. 20
4521
1
sept. 19
8666
3
feb. 19
8843
3
iul. 17
11467