diff --git a/pos_order_load/__openerp__.py b/pos_order_load/__manifest__.py similarity index 98% rename from pos_order_load/__openerp__.py rename to pos_order_load/__manifest__.py index 4309e777..b07fa01c 100644 --- a/pos_order_load/__openerp__.py +++ b/pos_order_load/__manifest__.py @@ -22,7 +22,7 @@ { 'name': 'POS Order Load and Save', - 'version': '8.0.1.0.0', + 'version': '10.0.1.0.0', 'author': 'Akretion,GRAP,Odoo Community Association (OCA)', 'category': 'Point Of Sale', 'license': 'AGPL-3', diff --git a/pos_order_load/models/pos_order.py b/pos_order_load/models/pos_order.py index 2b0b777a..fa7a1455 100644 --- a/pos_order_load/models/pos_order.py +++ b/pos_order_load/models/pos_order.py @@ -21,7 +21,7 @@ # ############################################################################## -from openerp import models, api +from odoo import models, api class PosOrder(models.Model): diff --git a/pos_order_load/static/src/js/pos_order_load.js b/pos_order_load/static/src/js/pos_order_load.js index 5cff51d9..f8931326 100644 --- a/pos_order_load/static/src/js/pos_order_load.js +++ b/pos_order_load/static/src/js/pos_order_load.js @@ -15,17 +15,32 @@ * along with this program. If not, see . *****************************************************************************/ -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({ + * Add getter and setter function for field 'order_id'; + */ + + var _super_order = models.Order.prototype; + models.Order = models.Order.extend({ + set_order_id: function(id) { this.set({ @@ -41,33 +56,32 @@ 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({ + * On click, display a new screen to select draft orders; + */ + 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'); }); }, }); /************************************************************************* New Widget SaveButtonWidget: - * On click, save the current draft order; - */ - module.SaveButtonWidget = module.PosBaseWidget.extend({ + * On click, save the current draft order; + */ + 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(){ @@ -83,57 +97,52 @@ openerp.pos_order_load = function(instance, local) { /************************************************************************* Extend PosWidget: - * Create new screen; - * Add load and save button; - */ - module.PosWidget = module.PosWidget.extend({ + * Create new screen; + * Add load and save button; + */ + 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.load_button = new LoadButtonWidget(this, {}); + this.load_button.appendTo(this.$('div.order-empty')); - this.screen_selector.screen_set.orderlist = this.orderlist_screen; - - // 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: - */ - module.OrderWidget = module.OrderWidget.extend({ + * Extend OrderWidget: + */ + 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: - * 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({ + * 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; + */ + // + 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,35 +163,33 @@ 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'); - }).fail(function (error, event){ - if (parseInt(error.code) === 200) { - // Business Logic Error, not a connection problem - self.pos_widget.screen_selector.show_popup( - 'error-traceback', { - message: error.data.message, - comment: error.data.debug + .then(function (result) { + self.gui.show_screen('products'); + }).fail(function (error, event){ + if (parseInt(error.code) === 200) { + // Business Logic Error, not a connection problem + self.gui.show_popup( + 'error-traceback', { + message: error.data.message, + comment: error.data.debug + }); + } + else{ + self.gui.show_popup('error',{ + message: _t('Connection error'), + comment: _t('Can not load the Selected Order because the POS is currently offline'), }); - } - else{ - self.pos_widget.screen_selector.show_popup('error',{ - message: _t('Connection error'), - comment: _t('Can not load the Selected Order because the POS is currently offline'), - }); - } - event.preventDefault(); - }); + } + event.preventDefault(); + }); }); var search_timeout = null; @@ -227,109 +234,110 @@ 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(); - var orderlines = result.orderlines || []; - var unknown_products = []; - for (var i=0, len=orderlines.length; i 0){ - self.pos_widget.screen_selector.show_popup( - 'error-traceback', { - message: _t('Unknown Products'), - comment: _t('Unable to load some order lines because the ' + + order.add_product(product, + self.prepare_orderline_options(orderline) + ); + 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.gui.show_popup( + 'error-traceback', { + message: _t('Unknown Products'), + comment: _t('Unable to load some order lines because the ' + 'products are not available in the POS cache.\n\n' + 'Please check that lines :\n\n * ') + unknown_products.join("; \n *") - }); - self.$el.find('span.button.validate').hide(); - } - else{ - self.$el.find('span.button.validate').show(); - } + }); + self.$el.find('span.button.validate').hide(); + } + else{ + self.$el.find('span.button.validate').show(); + } - }).fail(function (error, event){ - if (parseInt(error.code) === 200) { - // Business Logic Error, not a connection problem - self.pos_widget.screen_selector.show_popup( - 'error-traceback', { - message: error.data.message, - comment: error.data.debug + }).fail(function (error, event){ + if (parseInt(error.code) === 200) { + // Business Logic Error, not a connection problem + self.gui.show_popup( + 'error-traceback', { + message: error.data.message, + comment: error.data.debug + }); + } + else{ + self.gui.show_popup('error',{ + message: _t('Connection error'), + comment: _t('Can not execute this action because the POS is currently offline'), }); - } - else{ - self.pos_widget.screen_selector.show_popup('error',{ - message: _t('Connection error'), - comment: _t('Can not execute this action because the POS is currently offline'), - }); - } - event.preventDefault(); - }); + } + event.preventDefault(); + }); }, 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( - 'error-traceback', { - message: error.data.message, - comment: error.data.debug - } - ); - } - else{ - self.pos_widget.screen_selector.show_popup('error',{ - message: _t('Connection error'), - comment: _t('Can not execute this action because the POS is currently offline'), - }); - } - event.preventDefault(); - }); + .then(function (result) { + self.render_list(result); + }).fail(function (error, event){ + if (parseInt(error.code) === 200) { + // Business Logic Error, not a connection problem + self.gui.show_popup( + 'error-traceback', { + message: error.data.message, + comment: error.data.debug + } + ); + } + else{ + self.gui.show_popup('error',{ + message: _t('Connection error'), + comment: _t('Can not execute this action because the POS is currently offline'), + }); + } + event.preventDefault(); + }); }, 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, }; +}); diff --git a/pos_order_load/static/src/xml/pos_order_load.xml b/pos_order_load/static/src/xml/pos_order_load.xml index 220e221e..87808478 100644 --- a/pos_order_load/static/src/xml/pos_order_load.xml +++ b/pos_order_load/static/src/xml/pos_order_load.xml @@ -44,12 +44,6 @@
-
diff --git a/pos_order_load/view/pos_order_load.xml b/pos_order_load/view/pos_order_load.xml index f4d0c506..e630bb60 100644 --- a/pos_order_load/view/pos_order_load.xml +++ b/pos_order_load/view/pos_order_load.xml @@ -1,18 +1,14 @@ - - - - - - - + + + +