标签: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
标签:javascrip span mod div his options fun UNC extend
原文地址:https://www.cnblogs.com/dancesir/p/10724350.html