Home > Mobile >  How to create sequence number Odoo 15
How to create sequence number Odoo 15

Time:12-25

I create sequence in customer module sale, and _inherit to res.partner but I get fill 'New' in my sequence field when I create new customer

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

CodePudding user response:

That is a wrong way to inherit create function. Here is the correct one:

@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
  • Related