2017-01-20 11 views
0

私はodoo 10で忠実なプログラムを実装しようとしています。 この機能はodoo 8でも同じです10で開発しようとしています コードPOS Odoo 10のAddtocart画面に新しいボタンやテキストを追加したいのですが、

私は3つのモデルクラスを持っています。イムmodel.load_models からすべてのデータを取得もののイムないADDTOカート画面の下の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

可能な重複(http://stackoverflow.com/questions/41997252/odoo-10-add-button-to-posを)[Odoo 10は、POSにボタンを追加します] –

答えて

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); 
    } 
関連する問題