How to automatically fill a one2many field values to another one2many field in odoo

一笑奈何 提交于 2019-12-11 00:43:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!