我正在尝试在 odoo 10 中实现忠诚程序。此功能在 odoo 8 中与尝试在 odoo 10 中开发相同尝试使用以下代码
我有 3 个模型班。我从 model.load_models 获取所有数据,尽管我没有在添加到购物车屏幕下的 pos 屏幕中获得按钮
忠诚的.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>
忠诚的.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;
},
});
谁能帮我解决这个问题。