Chaban33
Chaban33

Reputation: 1382

one create method 2 separate models

class SunOrder(models.Model):

    _name = 'sun.order'
    manufacture_id = fields.Many2one(
    'product.product',

     @api.model
     def create(self, vals):
        Sequence = self.env['ir.sequence']
        vals['name'] = Sequence.next_by_code('sun.order')
        return super(SunOrder, self).create(vals)

here is simple create method that i use when creating data in my module. the goal is to create quotation with same CREATE method with same name and samemanufacture_id.I mean when i creat sun.order i need that the same time quotation would be created. So maybe some 1 can give me example or general idea how it can be done. because i have no clue.

class pos_quotation(models.Model):
    _name = "pos.quotation"
    name = fields.Char('Name')
    manufacture_id = fields.Many2one(
        'product.product',

Upvotes: 1

Views: 53

Answers (1)

Dayana
Dayana

Reputation: 1548

You can rewrite your create method as follows:

@api.model
def create(self, vals):
    Sequence = self.env['ir.sequence']
    vals['name'] = Sequence.next_by_code('sun.order')
    #set your pos_quotation dictionary
    vals_quot = {'manufacture_id': vals['manufacture_id'],
                #... other fields for pos.quotation model
                } 
    self.env['pos.quotation'].create(vals_quot)
    return super(SunOrder, self).create(vals)

I hope this help you.

Upvotes: 1

Related Questions