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

odoo 分组视图下显示同一批次记录的总数

时间:2019-04-17 16:46:11      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:javascrip   span   mod   div   his   options   fun   UNC   extend   

修改前:

技术图片

 

修改后:

技术图片

 

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
    <data>
        <template id="assets_backend" name="rhwl_gene_inherit assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/rhwl_gene_inherit/static/js/rhwl_gene_inherit.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

js文件:

openerp.rhwl_gene_inherit = function (instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;

instance.web.rhwl_gene_inherit = instance.web.rhwl_gene_inherit || {};

instance.web.rhwl_gene_inherit.SearchView = instance.web.ListView.Groups.extend({
init: function (view, options) {
this._super.apply(this, arguments);
// all_batch_str :全局变量用于保存批次名和该批次对应的数量
this.all_batch_str = {};
var self = this;
var Mod = new instance.web.Model(‘rhwl.easy.genes.new‘);
Mod.call("get_all_batch_num").then(function(all_batch_num) {
self.all_batch_str = all_batch_num;
});
},

render_groups: function (datagroups) {
var self = this;
for ( var i = 0; i < datagroups.length; i++) {
if (datagroups[i].grouped_on === "batch_no"){
var batch_no_name = datagroups[i].value;
var current_num = datagroups[i].length;
for (batch_str in self.all_batch_str) {
if (batch_str === batch_no_name){
datagroups[i].length = current_num+"/"+self.all_batch_str[batch_str];
}
}
}
}
placeholder = this._super.apply(this, arguments);
return placeholder;
}
});

instance.web.views.add(‘rhwl_gene_inherit_ListView‘, ‘instance.web.rhwl_gene_inherit.ListView‘);
instance.web.rhwl_gene_inherit.ListView = instance.web.ListView.extend({
init: function (parent, dataset, view_id, options) {
this._super(parent, dataset, view_id, _.extend(options || {}, {
GroupsType: instance.web.rhwl_gene_inherit.SearchView
}));
}
});
};

py文件:

    def get_all_batch_num(self, cr, uid, context=None):
        res = {}
        sql_str = "SELECT batch_no, count(*) as batch_count from rhwl_easy_genes_new WHERE  batch_no is not NULL GROUP BY batch_no "
        cr.execute(sql_str)
        for i in cr.fetchall():
            res.update({i[0]: i[1]})
        return res

 

odoo 分组视图下显示同一批次记录的总数

标签:javascrip   span   mod   div   his   options   fun   UNC   extend   

原文地址:https://www.cnblogs.com/dancesir/p/10724350.html

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