Python 如何在odoo(正式openerp)中使用onchange和ManyOne

Python 如何在odoo(正式openerp)中使用onchange和ManyOne,python,odoo,erp,Python,Odoo,Erp,1.我有两个字段,如员工姓名和部门。如果我在第一个字段中更改员工姓名,则第二个fileddepartment应自动填充。请提供.py和.xml Thanx提前请尝试此代码以供参考: 白痴 .xml 因此,这里不是解决作业和给出现成答案的地方。请付出一些努力,并提及您需要帮助的地方。非常感谢。它正在发挥作用。我已经浪费了两天的时间使用onchange。我认为您是初学者。 class HR(models.Model): _name = 'hr.hr' employee = fiel

1.我有两个字段,如员工姓名和部门。如果我在第一个字段中更改员工姓名,则第二个fileddepartment应自动填充。请提供.py和.xml
Thanx提前

请尝试此代码以供参考:

白痴

.xml


因此,这里不是解决作业和给出现成答案的地方。请付出一些努力,并提及您需要帮助的地方。非常感谢。它正在发挥作用。我已经浪费了两天的时间使用onchange。我认为您是初学者。
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 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 -->