python - Odoo V10 - 检索相同模型的先前记录的值
问题描述
这是我的计算字段函数:
# Fonction qui récupère la valeur du champs booléen inscription de l'année précédente
@api.depends('half_pension')
def _retrieve_halfpension_previous(self):
for record in self:
if record.half_pension:
record.half_pension_previous = record.half_pension
这是我的领域:
half_pension = fields.Boolean(string='Catering', copy=False)
half_pension_previous = fields.Boolean(string='previously registered', copy=False, store=False,
compute='_retrieve_halfpension_previous')
这是我的观点:
<!-- Vue Tree enfants scolarisés cantine-->
<record model="ir.ui.view" id="halfpension_view_tree">
<field name="name">halfpension.view.tree</field>
<field name="model">ecole.partner.school</field>
<field name="arch" type="xml">
<tree editable="bottom" default_order="half_pension_id" string="school_halfpension_tree">
<field name="partner_id" readonly="1" />
<field name="half_pension" />
<field name="half_pension_id" />
<field name="school_name_id" />
<field name="half_pension_begin_date" />
<field name="half_pension_end_date" />
<field name="half_pension_text" />
<field name="half_pension_previous" />
<field name="default_school_year" invisible="1" />
</tree>
</field>
</record>
目前,我在我的字段“”中获得了相同的“”值。但是,我想检索同一合作伙伴的前一条记录的值,而不是当前记录。怎么做 ?谢谢
解决方案
您可以将记录保存到合作伙伴字段中,以便能够跟踪该合作伙伴的最后一条记录。您将需要根据您想要的事件更改合作伙伴中的记录。例如,在通过覆盖ecole.partner.school
模型的 create 方法创建的新记录上,将创建的记录附加为合作伙伴的最后一条记录。
half_pension_previous
之后根据合作伙伴附加记录half_pension
字段解析该字段的值
推荐阅读
- google-vr - Google Elements 包中的演示/脚本错误
- javascript - lua中同时定义和调用函数
- spring - Facebook Messenger webhook POST 重复发送相同的文本
- python-3.x - 用python3进行文件转换和替换
- python-3.x - Python:如何使变量等于消息,并将消息放在控制台的同一行
- java - Java n 线程更新值
- python - 将 Python 数据发送到 PHP 脚本
- listbox - 使用文件中每一行的文本文件第一个索引填充列表框
- android - RecyclerView 和 ArrayList - 如何从数据库中添加用户图像?
- cobol - COBOL-85 源文件的未知确切格式