如何从odoo中的上一行获取计算值

问题描述

我正在尝试根据上一行的值来计算当前值

  1. 行:收据-费用=余额

  2. 行:“此行的余额” =收据-费用+“上一行的余额”

  3. 行:“此行的余额” =收据-费用+“上一行的余额”

    enter image description here

    余额是计算字段,未存储在数据库中,仅在视图中可见

这是我的课程和查看代码

class cashflow(models.Model):
_name = 'singleentrybookkeeping.cashflow'
_description = "Knjiga blagajne"
_order = 'date'

date = fields.Date(string="Datum",default=fields.Date.today)
accounting_doc = fields.Char("broj i oznaka knjigovodstvene isprave")
description = fields.Char("Opis")
currency_id = fields.Many2one("res.currency",string="Valuta",default=29)
receipt = fields.Monetary(string="Primitak")
expense = fields.Monetary(string="Izdatak")
balance = fields.Monetary(store='False',compute='_compute_balance',string="Saldo")

@api.depends('receipt','expense')
def _compute_balance(self):
    balance = 0
    for record in self:
        res = record.receipt - record.expense
        record.balance = res - balance
        balance = res

<record model="ir.ui.view" id="cashflow_tree_view">
<field name="name">cashflow.tree</field>
<field name="model">singleentrybookkeeping.cashflow</field>
<field name="arch" type="xml">
    <tree string="Cashflow Tree" editable="top">
        <field name="date"/>
        <field name="accounting_doc"/>
        <field name="description"/>
        <field name="currency_id" attrs="{'column_invisible': [('parent.field_name','=',False)]}"/>
        <field name="receipt" widget="monetary"/>
        <field name="expense" widget="monetary"/>
        <field name="balance" widget="monetary"/>
    </tree>
</field>

搜索了类似的解决方案并尝试实现这些解决方案,但我缺少了一些东西:

How to get the previous data or the latest data by id in Odoo?

https://www.odoo.com/es_ES/forum/ayuda-1/question/how-to-get-the-last-record-id-from-existing-table-40446

https://www.odoo.com/es_ES/forum/ayuda-1/question/how-to-get-the-value-of-the-previous-row-and-store-it-in-the-next-row-one2many-140982

difference between curent record and previous record odoo 11

https://www.odoo.com/es_ES/forum/ayuda-1/question/how-can-i-get-the-previous-record-in-a-table-38261

https://www.odoo.com/es_ES/forum/ayuda-1/question/get-data-from-previous-entry-in-tree-view-170889

https://www.odoo.com/fr_FR/forum/aide-1/question/get-value-of-field-from-previous-record-136171

我需要动态解决方案,当有人按日期或任何现有列对视图进行排序时,计算必须是实时的: 我认为我需要先获取prevIoUs_balance = sum_of_the_all_prevIoUs_receipts-sum_of_the_all_prevIoUs_expenses

在那之后,我应该计算current_balance =(current_receipts-当前费用)+ prevIoUs_balance

应该怎么做?

谢谢

Ivica

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)