Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
4800 Visualizzazioni

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
Abbandona

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

Risposta migliore

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
Abbandona