问题
from this picture here
when i click on the add new item, i want employee list that show up is only employees from the selected department, in the pict case is "IT" department. iam using odoo v8
ive tried this in my o2m field :
class overtime(models.Model):
_name = 'overtime.overtime'
department_id = fields.Many2one('hr.department', string='Department', readonly=True, states={'draft': [('readonly', False)]})
employee_ids = fields.One2many('overtime.overtime_details', 'overtime_id', string="Employee",
domain="[('hr.employee.department_id', '=', department_id)]")
class overtime_details(models.Model):
_name='overtime.overtime_details'
nik = fields.Char('NIK', size=250, required=True)
overtime_id = fields.Many2one('overtime.overtime', string="Overtime", ondelete='cascade')
job_id = fields.Many2one('hr.job', string="Position")
employee_id = fields.Many2one('hr.employee', "Employee", required=True, select=True)
and got error like this :
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 544, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 581, in dispatch
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 317, in _call_function
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 314, in checked_call
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 810, in __call__
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 410, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0\server\openerp\addons\web\controllers\main.py", line 944, in call_kw
File "C:\Program Files (x86)\Odoo 8.0\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 3148, in read
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 3183, in read
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 3370, in _read_from_database
File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\osv\fields.py", line 774, in get
TypeError: cannot concatenate 'str' and 'list' objects
here is the xml :
<record id="overtime_form1" model="ir.ui.view">
<field name="name">overtime_form1</field>
<field name="model">overtime.overtime</field>
<field name="arch" type="xml">
<form string="Overtime Request Form">
<sheet>
<div class="oe_title">
<label for="code" class="oe_edit_only"
string="Overtime Code" />
<h1>
<field name="code" />
</h1>
</div>
<group>
<field name="department_id"/>
<label string="Duration"/>
<div>
<group col="5">
<field name="start_date" class="oe_inline"/>
<label string="-" class="oe_inline"/>
<field name="end_date" class="oe_inline"/>
</group>
</div>
<field name="total_overtime"/>
<field name="overtime_bonus"/>
<field name="reason"/>
</group>
<notebook>
<page string="Employees">
<field name="employee_ids" >
<tree string="Employees" editable="bottom">
<field name="nik"/>
<field name="employee_id"/>
<field name="job_id"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
thanks before :)
回答1:
You can do it using parent.department_id.
<notebook>
<page string="Employees">
<field name="employee_ids" >
<tree string="Employees" editable="bottom">
<field name="nik"/>
<field name="employee_id" domain="[('department_id', '=',parent.department_id)]" />
<field name="job_id"/>
</tree>
</field>
</page>
This may help you.
回答2:
First, you need to add a related field to the overtime.overtime_details
model to identify the department_id
like this:
department_id = fields.Many2one(related="overtime_id.department_id", store=False)
Then, in the xml view now you can filter the employee_id
list by the department_id
in the tree of the employee_ids
field:
<notebook>
<page string="Employees">
<field name="employee_ids" >
<tree string="Employees" editable="bottom">
<field name="department_id" invisible="1"/>
<field name="nik"/>
<field name="employee_id" domain="[('department_id', '=', department_id)]" />
<field name="job_id"/>
</tree>
</field>
</page>
</notebook>
回答3:
You can filter the employees in employee_id
with domain
:
<notebook>
<page string="Employees">
<field name="employee_ids" >
<tree string="Employees" editable="bottom">
<field name="nik"/>
<field name="employee_id" domain="[('department_id', '=', department_id)]" />
<field name="job_id"/>
</tree>
</field>
</page>
</notebook>
来源:https://stackoverflow.com/questions/42666521/odoo-inputing-employee-based-on-department-id-one2many-domain