Skip to Content
Menu
This question has been flagged

Hello,

Let say I have a list with 4 records with having field name is A, B, C, D in model_a.py . 

model_a.py :

name_a = fields.Many2one('hr.employee', 'Employee')

time_a = fields.Date('Time A', default=fields.Date.today)


In model_b.py I have two one2many fields that connect to model_c.py and model_d.py

model_b.py :

time_b = fields.Date('Time B', default=fields.Date.today)

o_2_m_c = fields.One2many('model.c', 'connect_c')

o_2_m_d = fields.One2many('model.d', 'connect_d')


In model_c.py , I have already a list with 2 records having field name is A, E

model_c.py :

name_c = fields.Many2one('hr.employee', 'Employee')

connect_c = fields.Many2one('model.b')


model_d.py:

name_d = fields.Many2one('hr.employee', 'Employee')

connect_d = fields.Many2one('model.b')


In the model_b.py , I create a wizard button with a function to compare the name of model_a.py and in o_2_m_c in the form view of model_b.py at the same time.

If their name matches together (==) then the name should be written in o_2_m_d. 

I'd done to do it.

The code of button in model_b.py like this:

def compare(self):

   for rec in self:

      list_a = self.env['model.a'].search([('time_a', '=', rec.time_b)])

      for a in list_a:

          list_vals_a = []

          for c in rec.o_2_m_c:

              if a.name_a == c.name_c:

                   name_match = {

                        'name_d': c.name_c.id,

                        }

                   list_vals_a.append([0, 0, name_match])

                   rec.write({'o_2_m_d': list_vals_a})


With this, the name: A has done to write into o_2_m_d.


So with the remaining name E in model_c.py , and the name B, C, D in model_a.py. I also want to show all of it out in o_2_m_d field with the message state like:

Message state for these name of model_a.py : "This name is not matched with name in o_2_m_c field"

Message state for these name in o_2_m_c of model_b.py : "This name is not matched with these name of model A"

I'd tried to use the ELSE condition but I got the wrong results with duplicated records in o_2_m_d field.

I think I got the problem with FOR loop.

So how to show (write) all the remaining records which do not satisfy the condition in o_2_m_d without duplicated?

Please help!

Thank you!

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 19
5862
1
Jul 19
5545
2
Jun 21
1828
1
Aug 20
3735
3
Dec 23
23103