我有一个 TreeView ,其中列出了费用和收入记录。 xml中有一个金额列与SUM函数一起应用。我的要求是在 -ve 中计算所有金额,其中 type=Revenues 在树形 View 中,这样当汇总时结果将是费用减去收入。以下是我的 TreeView ,请帮忙。提前致谢!
<record id="view_program_activity_tree" model="ir.ui.view">
<field name="name">program.activity.tree</field>
<field name="model">program.activity</field>
<field name="arch" type="xml">
<tree string="Program Activity" colors="green:type_id[1] == 'REVENUE'">
<field name="department_id"/>
<field name="sector_id"/>
<field name="name"/>
<field name="code"/>
<field name="type_id"/>
<field name="total_planned" sum="Total Planned"/>
</tree>
</field>
</record>
最佳答案
您可以实现一个新的计算字段total_planned_signed
,它依赖于total_planned
和type_id
,并在 ListView 中显示这个新字段:
total_planned_signed = fields.Float(
string="Total Planned", compute="_compute_total_planned_signed",
store=True)
@api.depends('total_planned', 'type_id')
def _compute_total_planned_signed(self):
for activity in self:
if activity.type_id.name == 'REVENUE':
activity.total_planned_signed = activity.total_planned
else:
activity.total_planned_signed = -activity.total_planned
现在只需将 ListView 中的 total_planned
替换为 total_planned_signed
即可。
或者,如果可能的话,始终计算或设置 total_planned
作为有符号值。
关于xml - 如何在Odoo中自定义 TreeView 的求和函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54069392/