我在“ hr.payslip”模型中有一个计算字段。
cumulative_income_tax_base_previous = fields.Float(string="Kümülatif
Gelir Vergisi Matrahı"
compute='_get_previous_payslip_fields',store=True)
我想根据同一模型中的另一个字段(类型为布尔值)来编辑此字段。
first_access = fields.Boolean(string="İlk bordro girişi mi ?",
default=False)
如果此字段设置为true,我想编辑手动计算的字段。 在表单视图中,我将readonly:True属性设置为我的计算字段。
<xpath expr="//group[@name='accounting']" position="after">
<group name="other_calculation" string="Dİğer Hesaplamalar">
<field name="first_access"/>
<field name="cumulative_income_tax_base_previous"
attrs="{'readonly':[('first_access', '!=', True)],
'required': [('first_access', '=', True)]}"/>
</group>
</xpath>
但是,我没有在python类中学习。当我手动编辑它时,它被分配为零。我该如何解决这个问题
@api.one
@api.depends('employee_id', 'date_from', 'date_to', 'first_access')
def _get_previous_payslip_fields(self):
for record in self:
if record.employee_id and record.date_from and record.date_to
and not record.line_ids:
.... (some codes)
payslip_object = self.env['hr.payslip'].search(domain,
order='id desc', limit=1)
if payslip_object and not record.first_access:
record.gv_rate_init_previous=payslip_object['gv_rate_init']
record.cumulative_income_tax_base_previous =
payslip_object['cumulative_income_tax_base']
else:
... ? ( When the first access field is set True)
答案 0 :(得分:0)
您必须在Python字段声明中添加inverse
参数,例如:
cumulative_income_tax_base_previous = fields.Float(string="Kümülatif
Gelir Vergisi Matrahı"
compute='_get_previous_payslip_fields',
inveres='_set_previous_payslip_fields',
store=True)
请参阅文档:https://www.odoo.com/documentation/11.0/reference/orm.html#computed-fields
答案 1 :(得分:0)
只需添加xml force_save =“ 1”,并在Python中存储= True: 例如:
XML:
<field name="your_field" force_save="1"/>
Python:
your_fields = fields.Float("Your field", compute=compute_method, store=True)