您需要将函数调用添加到 widgets.js 文件中。
module.VisitorWidget = module.PosBaseWidget.extend({
template: 'VisitorWidget',
init: function(parent, options){
options = options || {};
this._super(parent, options);
this.label = options.label;
},
renderElement: function(){
var self = this;
var pos = self.pos;
var shop = this.pos.get('shop');
var counter = self.pos.get('visitorcounter');
var visitors = self.pos.get('visitors',[])
this.label = counter.toString();
this._super();
this.$el.click(function(){
self.pos.set('visitorcounter', counter + 1);
var date = new Date();
obj = { 'visitdate' : date,
'count' : 1 ,
'shop_id' : shop.id,
}
self.pos.get('visitors',[]).push(obj);
self.renderElement();
});
},
sync_visitors:function(){
var visitors = self.pos.get('visitors',[]);
(new instance.web.Model('shop.visitor.history')).get_func('sync_visitors')(visitors)
.fail(function(unused, event){
event.preventDefault();
return;
})
.done(function(){
self.pos.set('visitors',[])
});
},
});
这是我的python函数
def sync_visitors(self, cr, uid, visitor, context=None):如果不是访客:返回 False
for visitor in visitors:
shop = visitor.get('shop_id',False)
visitdate = visitor['visitdate']
count = visitor['count']
vals = {
'visitdate' : visitdate,
'count' : count,
'shop_id' : shop,
}
self.create(cr, uid, vals, context=context)
return True
同样,您需要在 models.js 中创建模型。