Skip to Content
Menu
This question has been flagged
2 Replies
4430 Views

I am using odoo community version 12

I tried creating two different Id's using two different create functions in a single model. But, it generates only one of them at a time.


bill_num=fields.Char(string='Bill Id',Translate=True, readonly=True)
   

class orders(models.Model):


    @api.model
    def create(self, vals):
        x = self.env['ir.sequence'].next_by_code('pickabite.orders') or '/'
        vals['bill_num'] = x
        return super(orders,self).create(vals)
   
   
    #order id generation
    order_id = fields.Char(string='Order Id', Translate= True ,
            readonly = True)
           
    @api.model
    def create(self, vals):
        x = self.env['ir.sequence'].next_by_code('pickabite.orders') or '/'
        vals['order_id'] = x
        return super(orders,self).create(vals)
   

Avatar
Discard

Why would you want to do that? You can do all your logic in one create function, no?

Best Answer

Hi,

Why can't you make them into one?

@api.model
def create(self, vals):
x = self.env['ir.sequence'].next_by_code('pickabite.orders') or '/'
vals['bill_num'] = x
vals['order_id'] = x

return super(orders, self).create(vals)

When you define a function twice inside a class, the last one will get executed.


Thanks

Avatar
Discard