How to do it...

Follow these steps to display the last five orders for the selected customer:

  1. Import the RPC utility in the /static/src/js/pos_demo.js file by adding the following code
var rpc = require('web.rpc');
  1. Add the following code to the /static/src/js/pos_demo.js file; this will add a new action button to fetch and display the information about the last five orders when a user clicks on the button:
var lastOrders = screens.ActionButtonWidget.extend({
template: 'LastOrders',
// Add step 3 and 4 here
});

screens.define_action_button({
'name': 'last_orders',
'widget': lastOrders
});
  1. Add the button_click function in the lastOrders widget to manage button clicks:
button_click: function () {
var self = this;
var order = this.pos.get_order();
if (order.attributes.client) {
var domain = [['partner_id', '=', order.attributes.client.id]];
rpc.query({
model: 'pos.order',
method: 'search_read',
args: [domain, ['name', 'amount_total', 'cu']],
kwargs: { limit: 5 },
}).then(function (orders) {
if(orders.length > 0){
var order_list = _.map(orders, function (o) {
return { 'label': _.str.sprintf("%s - TOTAL: %s", o.name, o.amount_total) };
});
self.show_order_list(order_list);
} else {
self.show_error('No previous order found for the customer');
}
});
} else {
this.show_error('Please select the customer');
}
},
  1. Add methods to show the order list and errors:
show_order_list: function(list) {
this.gui.show_popup('selection', {
'title': 'Please select a reward',
'list': list,
'confirm': function (reward) {
order.apply_reward(reward);
},
});
},
show_error: function (message){
this.gui.show_popup('error', {
title: "Warning",
body: message,
});
}
  1. Add the QWeb template for the button in the /static/src/xml/pos_demo.xml file:
<t t-name="LastOrders">
<div class='control-button'>
<i class='fa fa-shopping-cart' /> Last orders
</div>
</t>

Update the pos_demo module to apply the changes. After that, you will be able to see the Last Orders button above the keyboard panel. When this button is clicked, a popup will be displayed with the order information:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset