关于不同产品类型,生成不同的产品序号的问题?
未解决
Odoo 新手求助
-
请问一下根据不同的产品类别生成不同的产品编号,有什么简单的方法实现,我想到的方法是给一个新字段,然后根据该字段的内容匹配不同的产品序号,但是获取不到该字段的内容,有什么方法解决,或者有什么更好的实现方法?
class ProductTemplateInherit(models.Model):
_inherit = 'product.template'
x_category_ordinal = fields.Char(related='categ_id.x_ordinal', string='产品类型序号', required=True)
default_code = fields.Char(default=lambda self: _(' '))@api.model def create(self, vals): if vals.get("x_category_ordinal") is None: # 获取记录中的实际数据值 record = self.env['product.template'].browse(vals['categ_id']) x_category_ordinal = record.x_category_ordinal vals['x_category_ordinal'] = x_category_ordinal if vals.get('default_code', _(' ')) == _(' '): if vals['x_category_ordinal'] == 'value1': vals['default_code'] = self.env['ir.sequence'].next_by_code('sequence_code_1') or _(' ') elif vals['x_category_ordinal'] == 'value2': vals['default_code'] = self.env['ir.sequence'].next_by_code('sequence_code_2') or _(' ') elif vals['x_category_ordinal'] == 'value3': vals['default_code'] = self.env['ir.sequence'].next_by_code('sequence_code_3') or _(' ') elif vals['x_category_ordinal'] == 'value4': vals['default_code'] = self.env['ir.sequence'].next_by_code('sequence_code_4') or _(' ') else: vals['default_code'] = self.env['ir.sequence'].next_by_code('default_sequence') or _(' ') res = super(ProductTemplateInherit, self).create(vals) return res