问题
I have two one2many field which is reffering to a single model, existing in different models.
ie,
class modelA(models.Model):
_name = 'modela'
fila = fields.One2many('main','refa')
class moddelB(models.Model):
_name = 'modelb'
filb = fields.One2many('main','refb')
class main(models.Model):
_name = 'main'
name = fields.Char('Name')
date = fields.Date('Date')
refa = fields.Many2one('modela')
refb = fields.Many2one('modelb')
I will create records in modela. In this model there is a button is there. On clicking on that button i need to copy all values of fila field to filb field of modelb . How can i do that.
回答1:
You need to use One2manu values filling
XML code
<button name="copy2b" type="object" string="COPY"/>
Python code:
@api.multi
def copy2b(self):
for record in self:
filb_values = [(0, 0, {'name': line.name, 'date': line.date}) for line in record.fila]
vals = {'filb': filb_values}
# Just pass these values to `create` or `write` method to save them on `modelb`
来源:https://stackoverflow.com/questions/39524632/how-to-automatically-fill-a-one2many-field-values-to-another-one2many-field-in-o