我正在尝试在odoo 10中实现忠诚的程序。 这个功能在odoo 8中起作用,同样试图在10中开发 尝试使用以下代码
我有3个模型类。我从model.load_models获取所有数据 虽然我没有在添加到购物车屏幕下的pos屏幕中获取按钮
loyal.xml
<templates id="template" xml:space="preserve">
<t t-name="LoyaltyPoints">
<div class='loyalty-points'>
<div class='loyalty-points-title'>Points</div>
<t t-if='points_won'>
<div class="loyalty-points-won">
<span class='value'>+<t t-esc='widget.format_pr(points_won,1)'/></span>
</div>
</t>
<t t-if='points_spent'>
<div class="loyalty-points-spent">
<span class='value'>-<t t-esc='widget.format_pr(points_spent,1)'/></span>
</div>
</t>
<div class='loyalty-points-total'>
<span class='value'><t t-esc='widget.format_pr(points_total,1)' /></span>
</div>
</div>
</t>
<t t-name="LoyaltyButton">
<div class='control-button'>
<i class='fa fa-tag' /> Rewards
</div>
</t>
</templates>
loyal.js
odoo.define('pos_loyalty_program.pos_loyalty_program', function (require) {
"use strict";
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var core = require('web.core');
var utils = require('web.utils');
var gui = require('point_of_sale.gui');
var _t = core._t;
var round_pr = utils.round_precision;
var QWeb = core.qweb;
models.load_fields('res.partner','loyalty_points');
models.load_models([
{
model: 'loyal.program',
condition: function(self){ return !!self.config; },
fields: ['name'],
domain: function(self){
return [['id','=',self.config.related_loyal_program_id[0]]]; },
loaded: function(self,loyalties){
self.loyalty = loyalties[0];
},
{
model: 'loyal.rule',}
{
model: 'loyal.award',}
},
],{'after': 'product.product'});
var LoyaltyButton = screens.ActionButtonWidget.extend({
template: 'LoyaltyButton',
button_click: function(){
var order = this.pos.get_order();
var client = order.get_client();
if (!client) {
this.gui.show_screen('clientlist');
return;
}
var rewards = order.get_available_rewards();
if (rewards.length === 0) {
this.gui.show_popup('alert',{
'title': 'No Rewards Available',
'body': 'There are no rewards available for this customer as part of the loyalty program',
});
return;
} else if (rewards.length === 1 && this.pos.loyalty.rewards.length === 1) {
order.apply_reward(rewards[0]);
return;
} else {
var list = [];
for (var i = 0; i < rewards.length; i++) {
list.push({
label: rewards[i].name,
item: rewards[i],
});
}
this.gui.show_popup('selection',{
'title': 'Please select a reward',
'list': list,
'confirm': function(reward){
order.apply_reward(reward);
},
});
}
},
});
screens.define_action_button({
'name': 'loyalty',
'widget': LoyaltyButton,
'condition': function(){
return this.pos.loyalty && this.pos.loyalty.rewards.length;
},
});
有谁可以帮我解决这个问题。
答案 0 :(得分:0)
只需构建小部件。例如:
module.PosWidget.include({
build_widgets: function(){
var self = this;
this._super();
// -------- Button screen and his selector ---------
this.button_screen = new module.LoyaltyButton(this,{});
this.button_screen.appendTo(this.$('.screens'));
this.screen_selector.add_screen('loyalty',this.button_screen);
}