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

Posted dancesir

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了odoo 分组视图下显示同一批次记录的总数相关的知识,希望对你有一定的参考价值。

修改前:

技术图片

 

修改后:

技术图片

 

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 分组视图下显示同一批次记录的总数的主要内容,如果未能解决你的问题,请参考以下文章

Odoo 看板视图

Odoo10学习笔记三:模型(结构化的应用数据)视图(用户界面设计)

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

如何在 Odoo 8 的 fom 视图中对树/列表视图进行分组?

odoo-开发笔记 列表视图 增加记录弹出窗口效果

odoo 权限问题