|
|
@ -15,17 +15,32 @@ |
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/ |
|
|
|
|
|
|
|
openerp.pos_order_load = function(instance, local) { |
|
|
|
module = instance.point_of_sale; |
|
|
|
var QWeb = instance.web.qweb; |
|
|
|
var _t = instance.web._t; |
|
|
|
var round_pr = instance.web.round_precision; |
|
|
|
odoo.define('pos_order_load', function (require) { |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
var PosBaseWidget = require('point_of_sale.BaseWidget'); |
|
|
|
var chrome = require('point_of_sale.chrome'); |
|
|
|
var gui = require('point_of_sale.gui'); |
|
|
|
var models = require('point_of_sale.models'); |
|
|
|
var screens = require('point_of_sale.screens'); |
|
|
|
var Model = require('web.DataModel'); |
|
|
|
|
|
|
|
var utils = require('web.utils'); |
|
|
|
var round_pr = utils.round_precision; |
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
|
var QWeb = core.qweb; |
|
|
|
var _t = core._t; |
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************* |
|
|
|
Extend Model Order: |
|
|
|
* Add getter and setter function for field 'order_id'; |
|
|
|
*/ |
|
|
|
module.Order = module.Order.extend({ |
|
|
|
|
|
|
|
var _super_order = models.Order.prototype; |
|
|
|
models.Order = models.Order.extend({ |
|
|
|
|
|
|
|
|
|
|
|
set_order_id: function(id) { |
|
|
|
this.set({ |
|
|
@ -43,15 +58,14 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
New Widget LoadButtonWidget: |
|
|
|
* On click, display a new screen to select draft orders; |
|
|
|
*/ |
|
|
|
module.LoadButtonWidget = module.PosBaseWidget.extend({ |
|
|
|
var LoadButtonWidget = PosBaseWidget.extend({ |
|
|
|
template: 'LoadButtonWidget', |
|
|
|
|
|
|
|
renderElement: function() { |
|
|
|
var self = this; |
|
|
|
this._super(); |
|
|
|
this.$el.click(function(){ |
|
|
|
var ss = self.pos.pos_widget.screen_selector; |
|
|
|
ss.set_current_screen('orderlist'); |
|
|
|
self.gui.show_screen('orderlist'); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}); |
|
|
@ -60,14 +74,14 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
New Widget SaveButtonWidget: |
|
|
|
* On click, save the current draft order; |
|
|
|
*/ |
|
|
|
module.SaveButtonWidget = module.PosBaseWidget.extend({ |
|
|
|
var SaveButtonWidget = PosBaseWidget.extend({ |
|
|
|
template: 'SaveButtonWidget', |
|
|
|
|
|
|
|
renderElement: function() { |
|
|
|
var self = this; |
|
|
|
this._super(); |
|
|
|
this.$el.click(function(){ |
|
|
|
self.pos.pos_widget.screen_selector.show_popup('confirm',{ |
|
|
|
self.gui.show_popup('confirm',{ |
|
|
|
message: _t('Save The current Order ?'), |
|
|
|
comment: _t('This operation will save the current order in a draft state. You\'ll have to mark it as paid after.'), |
|
|
|
confirm: function(){ |
|
|
@ -86,54 +100,49 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
* Create new screen; |
|
|
|
* Add load and save button; |
|
|
|
*/ |
|
|
|
module.PosWidget = module.PosWidget.extend({ |
|
|
|
chrome.Chrome.include({ |
|
|
|
build_widgets: function() { |
|
|
|
this._super(); |
|
|
|
|
|
|
|
// New Screen to select Draft Orders
|
|
|
|
this.orderlist_screen = new module.OrderListScreenWidget(this, {}); |
|
|
|
this.orderlist_screen.appendTo(this.$('.screens')); |
|
|
|
this.orderlist_screen.hide(); |
|
|
|
|
|
|
|
this.screen_selector.screen_set.orderlist = this.orderlist_screen; |
|
|
|
this.load_button = new LoadButtonWidget(this, {}); |
|
|
|
this.load_button.appendTo(this.$('div.order-empty')); |
|
|
|
|
|
|
|
// Add buttons
|
|
|
|
this.load_button = new module.LoadButtonWidget(this,{}); |
|
|
|
this.load_button.appendTo(this.pos_widget.$('li.orderline.empty')); |
|
|
|
|
|
|
|
this.save_button = new module.SaveButtonWidget(this,{}); |
|
|
|
this.save_button = new SaveButtonWidget(this, {}); |
|
|
|
|
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************* |
|
|
|
Extend OrderWidget: |
|
|
|
* Extend OrderWidget: |
|
|
|
*/ |
|
|
|
module.OrderWidget = module.OrderWidget.extend({ |
|
|
|
screens.OrderWidget.include({ |
|
|
|
renderElement: function(scrollbottom){ |
|
|
|
this._super(scrollbottom); |
|
|
|
if (this.pos_widget.load_button) { |
|
|
|
this.pos_widget.load_button.appendTo( |
|
|
|
this.pos_widget.$('li.orderline.empty') |
|
|
|
if (this.chrome.load_button) { |
|
|
|
this.chrome.load_button.appendTo( |
|
|
|
this.chrome.$('div.order-empty') |
|
|
|
); |
|
|
|
} |
|
|
|
if (this.pos_widget.save_button && (this.pos.get('selectedOrder').get('orderLines').length > 0)) { |
|
|
|
this.pos_widget.save_button.appendTo( |
|
|
|
this.pos_widget.$('div.summary') |
|
|
|
if (this.pos.get_order()) { |
|
|
|
if (this.chrome.save_button && (this.pos.get_order().get_orderlines().length > 0)) { |
|
|
|
this.chrome.save_button.appendTo( |
|
|
|
this.chrome.$('div.summary') |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
/************************************************************************* |
|
|
|
New ScreenWidget OrderListScreenWidget: |
|
|
|
* New ScreenWidget OrderListScreenWidget: |
|
|
|
* On show, display all draft orders; |
|
|
|
* on click on an order, display the content; |
|
|
|
* on click on 'validate', allow to use this POS Order; |
|
|
|
* on click on 'cancel', display the preview screen; |
|
|
|
*/ |
|
|
|
module.OrderListScreenWidget = module.ScreenWidget.extend({ |
|
|
|
//
|
|
|
|
var OrderListScreenWidget = screens.ScreenWidget.extend({ |
|
|
|
template: 'OrderListScreenWidget', |
|
|
|
show_leftpane: true, |
|
|
|
model: 'pos.order', |
|
|
@ -146,7 +155,7 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
reset_order: function(order) { |
|
|
|
order.set_client(undefined); |
|
|
|
order.set_order_id(undefined); |
|
|
|
order.get('orderLines').reset(); |
|
|
|
order.orderlines.reset(); |
|
|
|
return order; |
|
|
|
}, |
|
|
|
|
|
|
@ -154,29 +163,27 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
var self = this; |
|
|
|
this._super(); |
|
|
|
this.$el.find('span.button.back').click(function(){ |
|
|
|
order = self.pos.get('selectedOrder'); |
|
|
|
var order = self.pos.get('selectedOrder'); |
|
|
|
self.reset_order(order); |
|
|
|
self.pos_widget.order_widget.change_selected_order(); |
|
|
|
var ss = self.pos.pos_widget.screen_selector; |
|
|
|
ss.set_current_screen('products'); |
|
|
|
self.chrome.screens.products.order_widget.change_selected_order(); |
|
|
|
self.gui.show_screen('products'); |
|
|
|
}); |
|
|
|
this.$el.find('span.button.validate').click(function(){ |
|
|
|
var orderModel = new instance.web.Model('pos.order'); |
|
|
|
var orderModel = new Model('pos.order'); |
|
|
|
return orderModel.call('unlink', [[self.current_order_id]]) |
|
|
|
.then(function (result) { |
|
|
|
var ss = self.pos.pos_widget.screen_selector; |
|
|
|
ss.set_current_screen('products'); |
|
|
|
self.gui.show_screen('products'); |
|
|
|
}).fail(function (error, event){ |
|
|
|
if (parseInt(error.code) === 200) { |
|
|
|
// Business Logic Error, not a connection problem
|
|
|
|
self.pos_widget.screen_selector.show_popup( |
|
|
|
self.gui.show_popup( |
|
|
|
'error-traceback', { |
|
|
|
message: error.data.message, |
|
|
|
comment: error.data.debug |
|
|
|
}); |
|
|
|
} |
|
|
|
else{ |
|
|
|
self.pos_widget.screen_selector.show_popup('error',{ |
|
|
|
self.gui.show_popup('error',{ |
|
|
|
message: _t('Connection error'), |
|
|
|
comment: _t('Can not load the Selected Order because the POS is currently offline'), |
|
|
|
}); |
|
|
@ -227,12 +234,12 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
|
|
|
|
load_order: function(order_id) { |
|
|
|
var self = this; |
|
|
|
var orderModel = new instance.web.Model(this.model); |
|
|
|
var orderModel = new Model(this.model); |
|
|
|
return orderModel.call('load_order', [order_id]) |
|
|
|
.then(function (result) { |
|
|
|
var order = self.pos.get('selectedOrder'); |
|
|
|
order = self.load_order_fields(order, result); |
|
|
|
order.get('orderLines').reset(); |
|
|
|
order.orderlines.reset(); |
|
|
|
var orderlines = result.orderlines || []; |
|
|
|
var unknown_products = []; |
|
|
|
for (var i=0, len=orderlines.length; i<len; i++) { |
|
|
@ -253,15 +260,15 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
order.addProduct(product, |
|
|
|
order.add_product(product, |
|
|
|
self.prepare_orderline_options(orderline) |
|
|
|
); |
|
|
|
last_orderline = order.getLastOrderline(); |
|
|
|
var last_orderline = order.get_last_orderline(); |
|
|
|
last_orderline = jQuery.extend(last_orderline, orderline); |
|
|
|
} |
|
|
|
// Forbid POS Order loading if some products are unknown
|
|
|
|
if (unknown_products.length > 0){ |
|
|
|
self.pos_widget.screen_selector.show_popup( |
|
|
|
self.gui.show_popup( |
|
|
|
'error-traceback', { |
|
|
|
message: _t('Unknown Products'), |
|
|
|
comment: _t('Unable to load some order lines because the ' + |
|
|
@ -277,14 +284,14 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
}).fail(function (error, event){ |
|
|
|
if (parseInt(error.code) === 200) { |
|
|
|
// Business Logic Error, not a connection problem
|
|
|
|
self.pos_widget.screen_selector.show_popup( |
|
|
|
self.gui.show_popup( |
|
|
|
'error-traceback', { |
|
|
|
message: error.data.message, |
|
|
|
comment: error.data.debug |
|
|
|
}); |
|
|
|
} |
|
|
|
else{ |
|
|
|
self.pos_widget.screen_selector.show_popup('error',{ |
|
|
|
self.gui.show_popup('error',{ |
|
|
|
message: _t('Connection error'), |
|
|
|
comment: _t('Can not execute this action because the POS is currently offline'), |
|
|
|
}); |
|
|
@ -295,14 +302,14 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
|
|
|
|
load_orders: function(query) { |
|
|
|
var self = this; |
|
|
|
var orderModel = new instance.web.Model(this.model); |
|
|
|
var orderModel = new Model(this.model); |
|
|
|
return orderModel.call('search_read_orders', [query || '']) |
|
|
|
.then(function (result) { |
|
|
|
self.render_list(result); |
|
|
|
}).fail(function (error, event){ |
|
|
|
if (parseInt(error.code) === 200) { |
|
|
|
// Business Logic Error, not a connection problem
|
|
|
|
self.pos_widget.screen_selector.show_popup( |
|
|
|
self.gui.show_popup( |
|
|
|
'error-traceback', { |
|
|
|
message: error.data.message, |
|
|
|
comment: error.data.debug |
|
|
@ -310,7 +317,7 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
); |
|
|
|
} |
|
|
|
else{ |
|
|
|
self.pos_widget.screen_selector.show_popup('error',{ |
|
|
|
self.gui.show_popup('error',{ |
|
|
|
message: _t('Connection error'), |
|
|
|
comment: _t('Can not execute this action because the POS is currently offline'), |
|
|
|
}); |
|
|
@ -321,15 +328,16 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
|
|
|
|
show: function() { |
|
|
|
this._super(); |
|
|
|
var ss = this.pos.pos_widget.screen_selector; |
|
|
|
if (ss.get_current_screen() == 'orderlist') { |
|
|
|
if (this.gui.get_current_screen() == 'orderlist') { |
|
|
|
this.load_orders(); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
on_click_draft_order: function(event){ |
|
|
|
this.$('.order-list .highlight').removeClass('highlight'); |
|
|
|
this.current_order_id = parseInt(event.target.parentNode.dataset.orderId); |
|
|
|
this.load_order(this.current_order_id); |
|
|
|
$(event.target.parentNode).addClass('highlight'); |
|
|
|
}, |
|
|
|
|
|
|
|
render_list: function(orders){ |
|
|
@ -359,5 +367,10 @@ openerp.pos_order_load = function(instance, local) { |
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
gui.define_screen({'name': 'orderlist', 'widget': OrderListScreenWidget}); |
|
|
|
return { |
|
|
|
LoadButtonButton: LoadButtonWidget, |
|
|
|
SaveButtonButton: SaveButtonWidget, |
|
|
|
OrderListScreenWidget: OrderListScreenWidget, |
|
|
|
}; |
|
|
|
}); |