python - Odoo V11 - 如何强制手动编辑计算字段?
问题描述
我在“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)
解决方案
只需添加 xml force_save="1",并在 Python 中 store = True:例如:
XML:
<field name="your_field" force_save="1"/>
Python:
your_fields = fields.Float("Your field", compute=compute_method, store=True)
推荐阅读
- python - 学习如何转换数字输入
- javascript - 如何通过 id 更改 HTML 元素?
- python - Vtk 一次设置颜色,无需循环
- python - 尝试通过 MQTT 发送一条消息并休眠 5 秒
- batch-file - 用于检查 IP 地址并设置基于位置的八位字节的批处理文件
- python - 如何使用代理参数重新创建 pysftp.Connection?
- google-chrome - Chrome 浏览器显示来自两个不同按钮的两个不同打印预览
- matlab - 带线段的散点图
- javascript - 使用 css/javascript 更改背景颜色
- python - SSD(单发检测器)的默认盒子实现