1.I have two fields like "employee name" and "department".If i change the employee name in the first field,then the second filed("department") should be auto populate.please provide .py and .xml Thanx in advance
Asked
Active
Viewed 352 times
1 Answers
0
Please try this code for reference :
.py
class HR(models.Model):
_name = 'hr.hr'
employee = fields.Many2one('emp.emp', string="Employee")
department = fields.Many2one('emp.dept',related='employee.department',string="Department")
#related attribute will automatically change as you change employee and fill the department field
# Master of Employee
class Employee(models.Model):
_name = 'emp.emp'
name = fields.Char('Employee Name')
department = fields.Many2one('emp.dept',string="Department")
# Master of Department
class Department(models.Model):
_name = 'emp.dept'
name = fields.Char('Department Name')
.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="employee_form_view" model="ir.ui.view">
<field name="name">hr.hr.form</field>
<field name="model">hr.hr</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="HR">
<sheet>
<group>
<group>
<field name="employee"/>
</group>
<group>
<field name="department"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
<!-- Write Tree View, Action, and Menu Code on your own -->
<!-- Also create view xml file for Employee Master and Department Master to enter Data -->

Bhoomi Vaishnani
- 718
- 4
- 19
-
Thank you so much.Its's working.I have wasted 2 days of time using onchange. – Raj725 Feb 23 '18 at 07:44
-