2017-10-16 44 views
1
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) 

這裏是我在模塊中創建數據時使用的簡單創建方法。 我們的目標是創建具有相同名稱和samemanufacture_id的CREATE方法的引用。我的意思是當我創建sun.order時,我需要同一時間引用將被創建。所以也許有些人可以給我一個例子或者一般的想法。因爲我不知道。一種創建方法2個獨立模型

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

回答

1

你可以重寫創建方法如下:

@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) 

我希望這可以幫助您。