[英]create domain from header to detail in odoo 10 using python
i dunno what's wrong with my code. 我不知道我的代码有什么问题。 I have two model, one is payroll.adjustment that i used model in my xml and one is payroll.adjustment.lines.
我有两个模型,一个是我在xml中使用模型的payroll.adjustment,另一个是payroll.adjustment.lines。 All i need to do is to create a domain in a field on payroll.adjustment.lines which is employee_id and here what i do.
我需要做的就是在payroll.adjustment.lines上的一个字段中创建一个域,该域是employee_id,在这里我要做什么。
<field name="employee_id" options="{'no_create': True}" domain="
[('address_id','=',company_id)]"/>
but it shows an error "Uncaught Error: NameError: name 'company_id' is not defined" 但显示错误“未捕获的错误:NameError:未定义名称'company_id'”
My code in .py 我在.py中的代码
from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError
class PayrollAdjustment(models.Model):
_name = 'payroll.adjustment'
_description ='Payroll Adjustment'
name = fields.Char(string="Name", related='doc_num')
doc_num = fields.Char(string="Document No.")
state = fields.Selection([('draft', 'Draft'),
('confirm', 'Waiting for Approval'),
('approved','Approved'),
('void', 'Void')],default='draft')
company_id = fields.Many2one('res.partner',string="Company",domain="
[('is_company','=',True)]")
date_from = fields.Date(string="Date From", required= True)
date_to = fields.Date(string="Date To", required= True)
adjustment_lines =
fields.One2many('payroll.adjustment.lines','adj_id',string="Adjustment
lines")
color = fields.Integer()
sample = fields.Many2one ('hr.employee')
@api.multi
def action_draft(self):
self.state = 'draft'
@api.multi
def action_confirm(self):
self.state = 'confirm'
@api.multi
def action_approve(self):
self.state = 'approved'
@api.multi
def action_void(self):
self.state = 'void'
@api.model
def create(self, vals):
vals['name'] = self.env['ir.sequence'].get('payroll.adj.seq')
return super(PayrollAdjustment, self).create(vals)
class PayrollAdjustmentLines(models.Model):
_name = 'payroll.adjustment.lines'
_description = 'Payroll Adjustment Lines'
_inherit = ['mail.thread']
employee_id = fields.Many2one('hr.employee',
string="Employee",required=True)
adjustment_for = fields.Many2one('hr.salary.rule', string="Adjustment
for",domain=[('appears_on_adj', '=', True)], required=True)
remarks = fields.Char(string="Remarks")
amount = fields.Float(string="Amount", default = 0.00)
adj_id = fields.Many2one('payroll.adjustment',string="Payroll
Adjustment",ondelete='cascade')
my code .xml 我的代码.xml
<record id="payroll_adjustment_form_view" model="ir.ui.view">
<field name="name">payroll_adjustment.form</field>
<field name="model">payroll.adjustment</field>
<field name="arch" type="xml">
<form>
<header>
<button name="action_draft" type="object" string="Set
back to draft" states="confirm"/>
<button name="action_confirm" type="object"
string="Confirm" states="draft" class="oe_highlight"/>
<button name="action_approve" type="object"
string="Approve" states="confirm" class="oe_highlight"
groups="hr_payroll.group_hr_payroll_manager"/>
<button name="action_void" type="object" string="Void"
states="confirm,approved" class="oe_highlight"
groups="hr_payroll.group_hr_payroll_manager"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="pull-left">
<label for="doc_num" class="oe_edit_only oe_inline"/>
<h1>
<field name="doc_num" readonly="1"/>
</h1>
</div>
<group>
<label for="company_id"/>
<div>
<field name="company_id" class="oe_inline"
attrs="{'readonly': [('state','not in',('draft'))]}"/>
</div>
<label for="date_from" string="Period"/>
<div>
<field name="date_from" class="oe_inline"
attrs="{'readonly': [('state','not in',('draft'))]}"/> -
<field name="date_to" class="oe_inline" attrs="
{'readonly': [('state','not in',('draft'))]}"/>
<field name="sample" domain="
[('address_id','=',company_id)]"/>
</div>
</group>
<field name="adjustment_lines" attrs="{'readonly':
[('state','not in',('draft'))]}" context="{'company': company_id }">
<tree editable="1">
<field name="employee_id" options="{'no_create':
True}" domain="[('address_id','=',company_id)]"/>
<field name="adjustment_for" options="
{'no_create': True}"/>
<field name="amount"/>
<field name="remarks"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
please help me. 请帮我。 Thanks in advance
提前致谢
You are adding domain in field employee_id of 'payroll.adjustment.lines' model, but 'company_id' field is not in that model but it is in parent model 'payroll.adjustment'. 您要在“ payroll.adjustment.lines”模型的字段employee_id中添加域,但“ company_id”字段不在该模型中,而是在父模型“ payroll.adjustment”中。
So you should write as following : 所以你应该这样写:
<field name="employee_id" options="{'no_create': True}" domain="
[('address_id','=',parent.company_id)]"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.