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

i added a computed field to odoo product.template to concatenate some field's strings to make a name of product because of the computed field isn't stored and non searchable i need to add a button with a method to copy this field content into name field so i can search on it

i added a button and do a method just in self product i need the method to go all over the products in each product get name2 content and copy it to Name

class autopart(models.Model):
_inherit = 'product.template'

@api.multi
@api.depends('item', 'car', 'model', 'dsc', 'drc', 'year', 'org')
def compute_amount(self):
    for rec in self:
        rec.name2 = " ".join(
            [rec.item and rec.item.name or "", rec.car and rec.car.name or "", rec.model and rec.model.name or "",
             rec.dsc and rec.dsc.name or "", rec.drc and rec.drc.name or "", rec.org and rec.org.name or "",rec.manf and rec.manf.name or "",
             rec.year and rec.year.name or "" ])

@api.multi
def button_name(self):
    for rec in self:
        rec.name = rec.name2
name = fields.Char(string="Name", required=False )
name2 = fields.Char(string="", required=False, compute=compute_amount, )
الصورة الرمزية
إهمال

Have a look into odoo customization tips: https://www.scoop.it/t/learn-openerp

أفضل إجابة

you can store computed field values using store = True in python end and force_save="1" in XML end.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 19
4481
1
أكتوبر 16
6551
1
فبراير 21
4739
1
أبريل 20
7220
0
مارس 15
3942