Skip to Content
Menu
This question has been flagged

Hello,

I have 3 models:

model_b.py :

time_b = fields.Datetime("Your time", default=fields.Date.today)

#get value from module planning

role_b = fields.Many2one("planning.role", "Your role")

o_2_m = fields.One2many('model.a', 'keya')

state = fields.Selection([

            ('draf', 'DRAF'),

            ('confirm', 'CONFIRMED'),

            (cancel', 'CANCEL'),

            ],default='draf')


model_a.py :

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

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


model_c.py:

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

time_c = fields.Datetime('Your time')

role_c = fields.Many2one('planning.role', 'Your role)


XML of model_c.py :

<record id="model_c_tree_view" model="ir.ui.view">

            <field name="name">model.c.tree.view</field>

            <field name="model">model.c</field>

            <field name="arch" type="xml">

                <tree>

                    <field name="name"/>

                    <field name="role_c"/>

                    <field name="time_c"/>

                </tree>

            </field>

        </record>

I want to pass all values selected of the field: 'employee_id' of model_a.py in the o_2_m field, and field 'role_b' and 'time_b' of model_b.py to the list view of model_c.py via the wizard button.

I created the method of model_b.py like this:

def confirm(self):

        for rec in self:

            if rec.o_2_m:

                for line in rec.o_2_m:

                    bc = self.env["model.c"].search([])

                    if bc:

                        bc['name'] = line.employee_id.id

                        bc['role_c'] = self.role_b

                        bc['time_c'] = self.time_b                    

            rec.state = "confirmed"                      

        return True 


After click on the "Add a line" link in the o_2_m tree view, and selected records of model_a.py and selected value for two fields of in the form view of model_b.py, and click the 'confirm' button...  It still not work! 


Please help!

Thank you!        



Avatar
Discard
Related Posts Replies Views Activity
1
Feb 24
395
2
Nov 24
12400
1
Oct 23
1378
0
Oct 22
1341
0
Feb 21
2914