Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
4726 Zobrazení

Good day everyone.  I'm trying to override write in product class to replace the value of a field when user saves.

class ProductProduct(models.Model):
   _inherit = 'product.product'

   def write(self, vals):
       res = super(ProductProduct, self).write(vals)
       self.description_sale = res.part_number

       return res

Could anyone please point me the proper sintax?  thanks in advance.
Avatar
Zrušit

Hello Avash,

The write method returns a Boolean and not a recordset/object. If you are trying to achieve set the description_sale value the sale as the part_number field. You can try:

self.description_sale = self.part_number

Could you provide more info on what you are trying to do, please.

Your code looks ok in terms of overriding.

Thanks,

Autor Nejlepší odpověď

Hello Jack, thanks for reply.   For some reason the forum does not allow me to reply to your message. 

What I'm doing is storing the value of part_number to description_sale anytime user changes part_number and this code seems to do the job.

class ProductTemplate(models.Model):
    _inherit = 'product.template'
    def write(self, vals):
        desc = ''
        if vals.get('part_number'):
            desc = vals.get('part_number')
        if desc:     
            vals.update({'description_sale': desc})
        res = super(ProductTemplate, self).write(vals)
       return res

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
zář 18
2748
0
kvě 16
3321
2
pro 15
3482
1
bře 15
5200
2
dub 19
2669