0
私のコードに何が間違っているのかわからない。私は2つのモデルを持っています、1つはpayroll.adjustmentです。私はxmlでモデルを使用し、1つはpayroll.adjustment.linesです。私がする必要があるのは、employee_idであるpayroll.adjustment.linesのフィールドにドメインを作成することです。odoo 10でヘッダから詳細までドメインを作成する
<field name="employee_id" options="{'no_create': True}" domain="
[('address_id','=',company_id)]"/>
が、それは誤り示した.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')
私のコードの.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>
で
私のコードを "不明なエラー:NameError名 'のcompany_id' が定義されていません"
私を助けてください。ありがとうございます。
それが動作します。ありがとうございました –
hello sir/ma'am。 payroll.adjustmentのツリービューにemployee_idを表示したいのですが可能ですか?私は何を追加できますか?それが正しいか? ? –