我在'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)
2 回答
您必须在Python字段声明中添加
inverse
参数,如:参见文档:https://www.odoo.com/documentation/11.0/reference/orm.html#computed-fields
只需在Python中添加xml force_save =“1”和store = True:例如: