xml - 如何在Odoo中自定义 TreeView 的求和函数?

标签 xml sum treeview odoo odoo-10

我有一个 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_plannedtype_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/

相关文章:

c# - 根级别的数据无效。第 1 行,位置 1。读取 xml 时

c++ - 使用给定的行 vector 和查找以最大形式排列的二进制矩阵的列 vector 和

python - 类型错误 : unsupported operand type(s) for + when using sum

mysql - 如何对mysql中已经求和的别名列进行求和

delphi - 第二次分配 TPngImageCollectionItem 对象 TreeView 仍然绘制第一个分配的图像(Delphi XE 7)

c# - WPF TreeView 绑定(bind)

c# - 在 ScrollView 中滚动到选定的 Treeviewitem

java - 如何在不带扩展名的 XSL 中将 ASCII 字符串转换为 base64?

python - 在 Python 中解析带有未声明前缀的 XML

php - 用PHP获取嵌套的XML元素