如何创建序列号 Odoo 15

How to create sequence number Odoo 15

我在客户模块 sale 中创建了序列,并且 _inherit 到 res.partner 但我在创建新客户时在我的序列字段中填充了 'New'

group_id = fields.Many2one(
    'group.customer', 
    string="Group"
)

@api.model
def create(self, value):
    if self.group_id.name == 'Dealer':
        if value.get('code_customer', _('New')) == _('New'):
            value['code_customer'] = self.env['ir.sequence'].next_by_code('code.customer.dealer') or _('New')
    result = super(res_partner, self).create(value)
    return result

这是继承create函数的错误方式。这是正确的:

@api.model
def create(self, value):
    group_id = value.get('group_id')
    if group_id:
        group = self.env['group.customer'].browse(group_id)
        if group.name=='Dealer' and value.get('code_customer', _('New')) == _('New'):
            value['code_customer'] = self.env['ir.sequence'].next_by_code('code.customer.dealer') or _('New')
    result = super(res_partner, self).create(value)
    return result