首页 > 解决方案 > 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>

目前,我在我的字段“”中获得了相同的“”值。但是,我想检索同一合作伙伴的前一条记录的值,而不是当前记录。怎么做 ?谢谢

标签: pythonodoo

解决方案


您可以将记录保存到合作伙伴字段中,以便能够跟踪该合作伙伴的最后一条记录。您将需要根据您想要的事件更改合作伙伴中的记录。例如,在通过覆盖ecole.partner.school模型的 create 方法创建的新记录上,将创建的记录附加为合作伙伴的最后一条记录。

half_pension_previous之后根据合作伙伴附加记录half_pension字段解析该字段的值


推荐阅读