码迷,mamicode.com
首页 > 其他好文 > 详细

odoo在底部显示指定字段合计和汇总时显示合计

时间:2017-06-27 11:02:12      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:strong   text   -o   erb   ons   tac   分组   ret   sum   

1.odoo的tree视图底部显示合计

tree 视图,底部显示指定字段合计数 ,视图中字段定义上在sum,取自sale.view_order_tree 销售订单 tree 视图

<field name="amount_total" sum="Total Tax Included"/>

 

2. odoo使用group by分组时显示字段合计  方法是重写read_group方法

 

https://stackoverflow.com/questions/27536186/how-to-sum-other-columns-when-using-group-by-in-a-tree-view

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):

 

odoo在底部显示指定字段合计和汇总时显示合计

标签:strong   text   -o   erb   ons   tac   分组   ret   sum   

原文地址:http://www.cnblogs.com/crazyguo/p/7083798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!