odoo在底部显示制定字段合计and汇总时显示合计

  1. odoo的tree视图底部显示合计
tree 视图,底部显示指定字段合计数 ,视图中字段定义上在sum,
取自sale.view_order_tree 销售订单 tree 视图
   
<field name="amount_total" sum="Total Tax Included"/>



  1. odoo使用group by分组时显示字段合计
来自:http://stackoverflow.com/questions/27536186/how-to-sum-other-columns-when-using-group-by-in-a-tree-view

方法是重写read_group方法

The key is to overwrite the  read_group  method of the class:
class your_class(osv.osv):
    # ...        

    def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):
        res = super(your_class, self).read_group(cr, uid, domain, fields, groupby, offset, limit=limit, context=context, orderby=orderby, lazy=lazy)
        if 'amount_pending' in fields:
            for line in res:
                if '__domain' in line:
                    lines = self.search(cr, uid, line['__domain'], context=context)
                    pending_value = 0.0
                    for current_account in self.browse(cr, uid, lines, context=context):
                        pending_value += current_account.amount_pending
                    line['amount_pending'] = pending_value
        if 'amount_payed' in fields:
            for line in res:
                if '__domain' in line:
                    lines = self.search(cr, uid, line['__domain'], context=context)
                    payed_value = 0.0
                    for current_account in self.browse(cr, uid, lines, context=context):
                        payed_value += current_account.amount_payed
                    line['amount_payed'] = payed_value
        return res

If you want, for example, remove the sum of a column in the group by, you can do something like this:

class your_class(osv.osv):
    # ...     

    def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):
        if 'column' in fields:
            fields.remove('column')
        return super(your_class, self).read_group(cr, uid, domain, fields, groupby, offset, limit=limit, context=context, orderby=orderby, lazy=lazy):


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值