diff --git a/static/src/css/style.css b/static/src/css/style.css index c7da931..5bb54aa 100644 --- a/static/src/css/style.css +++ b/static/src/css/style.css @@ -376,4 +376,8 @@ h1.product-name { .searchbox{ display: none; +} + +.pos .product-list-scroller{ + padding-bottom: 200px; } \ No newline at end of file diff --git a/static/src/js/container.js b/static/src/js/container.js index 94c1ea1..6672e16 100644 --- a/static/src/js/container.js +++ b/static/src/js/container.js @@ -25,6 +25,453 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) var round_pr = utils.round_precision; + var BalanceScaleScreenWidget = screens.ScaleScreenWidget.extend({ + template: 'BalanceScaleScreenWidget', + + next_screen: 'confirmation', + previous_screen: 'products', + + init: function(parent, options){ + this._super(parent, options); + this.weight_container = 0; + this.weight_brut = 0; + this.weight = 0; + }, + + set_weight: function(weight){ + var container = this.get_container(); + this.weight = weight; + this.weight_container = container.weight; + this.weight_brut = container.weight + this.weight; + this.$('.weight').text(this.get_product_weight_string()); + this.$('.computed-price').text(this.get_computed_price_string()); + this.$('.weight-brut').text(this.get_product_weight_string_brut()); + }, + + show: function(){ + var self = this; + var queue = this.pos.proxy_queue; + + this.set_weight(0); + this.renderElement(); + + var container = this.gui.get_current_screen_param('container'); + + queue.schedule(function () { + return self.pos.proxy.reset_weight().then(function () { + self.set_weight(0); + self.set_price(0); + }); + }, {duration: 500}); + + // format price + var price = this.format_price(this.get_product_price()); + + if (container) { + // format tare + var tare = this.format_tare(container); + queue.schedule(function () { + return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) { + self.set_weight(scale_answer.weight); + self.set_price(scale_answer.price); + if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) { + self.gui.show_screen(self.next_screen); + // add product *after* switching screen to scroll properly + self.order_product(); + self.pos.proxy.reset_tare(); + } + }); + }, {duration: 500, repeat: true}); + + } else { + queue.schedule(function () { + return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) { + self.set_weight(scale_answer.weight); + self.set_price(scale_answer.price); + if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) { + self.gui.show_screen(self.next_screen); + self.create_transaction(); + self.order_product(); + } + }); + }, {duration: 500, repeat: true}); + } + // this._super(); + + var self = this; + + this.$('.next,.add-transaction').click(function(){ + self.create_transaction(); + }); + + $("#pos-header-text-peser").removeClass('oe_hidden'); + + }, + + + get_container: function(){ + return this.gui.get_current_screen_param('container'); + }, + + ////////////////////////////// + // Ajout fonction Toledo? + set_price: function (price) { + if (!price) { + this.$('.computed-price').text(this.get_computed_price_string()); + } else { + this.price = price; + //this.$('.price').text(this.format_currency(price)); + this.$('.computed-price').text(this.format_currency(price)); + } + }, + + get_price: function () { + return this.price; + }, + + format_tare: function (container) { + var tare = (Math.abs(container.weight) * 1000).toString(); + tare = ("0000" + tare).slice(-4); + return tare; + }, + + format_price: function (product_price) { + var price = (product_price * 1000).toString(); + price = ("000000" + price).slice(-6); + return price; + }, + + // FIN + ////////////////////////////// + + + get_current_container_weight: function(){ + var container = this.get_container(); + if (container){ + return (this.weight_container || 0).toFixed(3) + ' kg'; + } + else{ + '' + } + }, + + get_current_container_name: function(){ + var container = this.get_container(); + if (container){ + return container.name; + } + else{ + '' + } + }, + + get_product_weight_string_brut: function(){ + var product = this.get_product(); + var defaultstr = (this.weight + this.weight_container || 0).toFixed(3) + ' Kg'; + if(!product || !this.pos){ + return defaultstr; + } + var unit_id = product.uom_id; + if(!unit_id){ + return defaultstr; + } + var unit = this.pos.units_by_id[unit_id[0]]; + var weight = round_pr(this.weight + this.weight_container || 0, unit.rounding); + var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) )); + weightstr += ' ' + unit.name; + return weightstr; + }, + + hide: function(){ + this._super(); + + $("#pos-header-text-peser").addClass('oe_hidden'); + }, + + create_transaction: function(){ + var self = this; + var fields = {}; + var container = this.get_container(); + var product = this.get_product(); + + var qrcode = ''; + var ean13 = ''; + var ean13_verif = ''; + fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode); + fields['container_ean13'] = container.barcode; + + fields['product_id'] = this.get_product().id; + // var product_id = (this.get_product().id).toString(); + var product_id = ("00000" + product.default_code.toString()).slice(-5); + + var weight_str = (this.weight * 1000).toString(); + weight_str = ("00000" + weight_str).slice(-5); + + ean13 = ean13.concat(26,product_id,weight_str,4); + + var weight_brut_str = (this.weight_brut * 1000).toString(); + weight_brut_str = ("00000" + weight_brut_str).slice(-5); + + ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4); + + var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13); + var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif); + + fields['ean13'] = ean13_digit; + fields['ean13_verif'] = ean13_verif_digit; + fields['balance_id'] = this.pos.get_balance_id(); + var today = new Date(); + var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate(); + var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); + var date_time = date + ' ' + time; + fields['write_date'] = date_time; + + fields['weight_net'] = this.weight; + + var pricelist = this._get_active_pricelist(); + fields['price_product'] = (product ? product.get_price(pricelist, this.weight) : 0) || 0; + + fields['price_net'] = fields['weight_net'] * fields['price_product']; + + fields.name = product.display_name; + + this.pos.push_transaction(fields).then( + this.pushed_transaction(fields["ean13"]) + ); + }, + + pushed_transaction: function(barcode){ + var self = this; + + // Remise à zero du poids à l'écran + + // this.set_weight(0); + // this.renderElement(); + var product = this.get_product(); + + this.gui.show_screen('confirmation',{product: product}); + }, + + }); + + gui.define_screen({ + name:'balancescale', + widget: BalanceScaleScreenWidget, + }); + + +/*--------------------------------------*\ + | THE SCALE SCREEN FREE | + | BALANCE CONTAINER | +\*======================================*/ + +// The free balance container scale screen +// displays the weight of +// a new container on the electronic scale. + + var BalanceContainerScaleScreenWidget = screens.ScaleScreenWidget.extend({ + template: 'BalanceContainerScaleScreenWidget', + + next_screen: 'presentation', + previous_screen: 'presentation', + + init: function(parent, options){ + this._super(parent, options); + }, + + show: function(){ + + var self = this; + var queue = this.pos.proxy_queue; + var priceStr = '001000'; // bizerba doesn't accept '000000' as unit price + this.renderElement(); + queue.schedule(function () { + return self.pos.proxy.reset_weight().then(function () { + self.set_weight(0); + }); + }, {duration: 500}); + + queue.schedule(function () { + return self.pos.proxy.scale_read_data_price(priceStr).then(function (scale_answer) { + self.set_weight(scale_answer.weight); + if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) { + self.gui.show_screen(self.next_screen); + self.create_container(); + } + }); + }, {duration: 500, repeat: true}); + this._super(); + + var self = this; + + this.$('.next,.add-container').click(function(){ + self.create_container(); + }); + + if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){ + this.chrome.widget.keyboard.connect($(this.el.querySelector('.container-name input'))); + } + + $("#pos-header-text-peser").removeClass('oe_hidden'); + $("#pos-topheader-scale-cont").removeClass('oe_hidden'); + + }, + + + hide: function(){ + this._super(); + $("#pos-header-text-peser").addClass('oe_hidden'); + $("#pos-topheader-scale-cont").addClass('oe_hidden'); + }, + + get_product: function(){ + return this.pos.get_container_product(); + }, + create_container: function(){ + var self = this; + var fields = {}; + + fields['weight'] = this.weight; + + fields.barcode = this.gui.get_current_screen_param('barcode') || false; + fields.name = fields.name || _t('Container'); + + this.pos.push_container(fields).then( + this.pushed_container(fields["barcode"],fields) + ); + }, + pushed_container: function(barcode,container){ + var self = this; + + var selected_order = this.pos.get_order(); + + selected_order.add_container(container); + + self.gui.show_popup('confirm-pesee',{ + 'title': _t('Merci'), + 'body': _t('La pesée est validée'), + confirm: function(){ + self.gui.show_screen(self.next_screen); + }, + }); + + }, + close: function(){ + this._super(); + if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) { + this.chrome.widget.keyboard.hide(); + } + }, + }); + + gui.define_screen({ + name:'balancecontainerscale', + widget: BalanceContainerScaleScreenWidget, + }); + + + screens.ScreenWidget.include({ + + show: function(){ + var self = this; + var queue = this.pos.proxy_queue; + + var scale_screen = this.gui.screen_instances['balancescale']; + this.set_weight(0); + scale_screen.renderElement(); + + queue.schedule(function(){ + return self.pos.proxy.scale_read().then(function(weight){ + self.set_weight(weight.weight); + }); + },{duration:500, repeat: true}); + + this._super(); + }, + + set_weight: function(weight){ + var scale_screen = this.gui.screen_instances['balancescale']; + scale_screen.weight = weight; + scale_screen.$('.weight').text(scale_screen.get_product_weight_string()); + }, + + set_price: function (price) { + var scale_screen = this.gui.screen_instances['balancescale']; + if (!price) { + scale_screen.$('.computed-price').text(scale_screen.get_computed_price_string()); + } else { + scale_screen.price = price; + scale_screen.$('.computed-price').text(scale_screen.format_currency(price)); + } + }, + + barcode_container_action: function(code){ + var self = this; + + if (self.pos.scan_container(code)) { + + // Vérfification: est-ce qu'un container vient d'être utilisé dans l'heure + if (self.pos.scan_container_check(code)){ + var transaction = self.pos.scan_container_check(code); + this.gui.show_popup('doublon-barcode',{ + title: _t('Contenu déjà enregistré récemment:'), + transaction: transaction, + confirm: function(){ + var transaction = self.pos.scan_container_check(code) + self.delete_selected_transaction(transaction, code); + self.gui.show_screen('products'); + }, + }); + + } else { + self.gui.show_screen('products'); + } + + } else { + self.gui.show_screen('balancecontainerscale', {barcode: code.base_code}); + } + }, + + delete_selected_transaction: function(transaction, barcode){ + var self = this; + + if (!transaction.id){ + self.deleted_transaction(transaction.container_ean13) + } + else { + rpc.query({ + model: 'pos.transaction', + method: 'unlink', + args: [transaction.id], + }).then(function(){ + self.deleted_transaction(transaction.container_ean13); + },function(err,ev){ + ev.preventDefault(); + var error_body = _t('Your Internet connection is probably down.'); + if (err.data) { + var except = err.data; + error_body = except.arguments && except.arguments[0] || except.message || error_body; + } + self.gui.show_popup('error',{ + 'title': _t('Error: Could not Save Changes'), + 'body': error_body, + }); + } + ); + } + }, + deleted_transaction: function(barcode){ + var self = this; + this.pos.db.remove_transactions([barcode]); + }, + + close: function(){ + this._super(); + + this.pos.proxy_queue.clear(); + }, + + }); var ConfirmPopupWidgetPesee = popups.extend({ template: 'ConfirmPopupWidgetPesee', @@ -34,6 +481,7 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) // The initial screen that allows you to scan container var PresentationScreenWidget = screens.ScreenWidget.extend({ template: 'PresentationScreenWidget', + next_screen: 'products', // Ignore products, discounts, and client barcodes // barcode_product_action: function(code){}, @@ -50,15 +498,16 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) // if you want to alter the behavior of the screen. show: function(){ this._super(); + var self = this; + + this.set_weight(0); + this.set_price(0); var scale_screen = this.gui.screen_instances['balancescale']; scale_screen.$el.removeClass('oe_hidden'); - var screen = this.gui.screen_instances['products']; screen.$el.removeClass('oe_hidden'); $("#pos-header-text-selec").removeClass('oe_hidden'); - $("#validation-bloc").addClass('oe_hidden'); - $("#pos-topheader-scale").addClass('oe_hidden'); $("#pos-header-text-confirm").addClass('oe_hidden'); }, @@ -69,7 +518,6 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) var screen = this.gui.screen_instances['products']; screen.$el.addClass('oe_hidden'); $("#pos-header-text-selec").addClass('oe_hidden'); - $("#pos-topheader-scale").addClass('oe_hidden'); }, }); @@ -87,14 +535,10 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) template: 'ConfirmationScreen', next_screen: 'presentation', - previous_screen: 'presentation', - - init: function(parent, options) { - this._super(parent, options); - - }, + // previous_screen: 'presentation', show: function(){ + this._super(); var self = this; @@ -103,17 +547,35 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) scale_screen.$el.removeClass('oe_hidden'); this.$('.next,.back-presentation').click(function(){ + self.set_weight(0); + self.set_price(0); self.gui.show_screen('presentation'); }); $("#pos-header-text-confirm").removeClass('oe_hidden'); - $("#validation-bloc").addClass('oe_hidden'); - $("#pos-topheader-scale").addClass('oe_hidden'); }, - hide: function(){ - this._super(); - $("#pos-topheader-scale").addClass('oe_hidden'); + set_weight: function(weight){ + var scale_screen = this.gui.screen_instances['balancescale']; + + var order = this.pos.get_order(); + var selected_orderline = order.get_selected_orderline(); + var container = selected_orderline.get_container(); + + scale_screen.weight_container = container.weight; + scale_screen.weight = weight; + scale_screen.weight_brut = container.weight + scale_screen.weight; + scale_screen.$('.weight').text(scale_screen.get_product_weight_string()); + scale_screen.$('.computed-price').text(scale_screen.get_computed_price_string()); + scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut()); + + if (container){ + var container_text = (container.weight || 0).toFixed(3) + ' kg'; + } + else{ + var container_text = '' + } + scale_screen.$('.tare-container').text(container_text); }, _get_active_pricelist: function(){ @@ -136,7 +598,6 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) get_product_price: function(){ var product = this.gui.get_current_screen_param('product'); var pricelist = this._get_active_pricelist(); - console.log(pricelist); return (product ? product.get_price(pricelist, 1) : 0) || 0; }, @@ -165,345 +626,111 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) this.gui.set_startup_screen('presentation'); } }, - }); - - gui.Gui.include({ - show_saved_screen: function(order,options) { - this._super(); - options = options || {}; - this.close_popup(); - this.show_screen(this.startup_screen); - }, - }); - - // We need to modify the OrderSelector to hide itself when we're on - // the floor plan ? - chrome.OrderSelectorWidget.include({ - - hide: function(){ - this.$el.addClass('oe_invisible'); - }, - show: function(){ - this.$el.removeClass('oe_invisible'); - }, - renderElement: function(){ - var self = this; - this._super(); - if (this.pos.config.balance_id) { - if (this.pos.get_order()) { - this.$el.removeClass('oe_invisible'); - } else { - this.$el.addClass('oe_invisible'); - } - } - }, - }); - - screens.ProductScreenWidget.include({ - - previous_screen: 'presentation', - - hide: function(){ - this._super(); - $("#pos-header-text-prod").addClass('oe_hidden'); - $("#pos-topheader-scale").addClass('oe_hidden'); - - var screen = this.gui.screen_instances['products']; - }, - - show: function(){ - this._super(); - var self = this; - - this.product_categories_widget.reset_category(); - this.numpad.state.reset(); - - this.$('.back').click(function(){ - self.gui.show_screen('presentation'); - }); - - $("#pos-header-text-prod").removeClass('oe_hidden'); - $("#pos-topheader-scale").addClass('oe_hidden'); - - var container = this.gui.get_current_screen_param('container'); - if (container) { - this.pos.proxy.reset_tare(); - } - }, - - renderElement: function(){ - this._super(); - - var self = this; - this.$('.back').click(function () { - self.gui.show_screen('presentation'); - }); - }, - - click_product: function(product) { - if (this.pos.config.is_balance_free){ - var order = this.pos.get_order(); - var selected_orderline = order.get_selected_orderline(); - if (product.to_weight && selected_orderline && - selected_orderline.product === this.pos.get_container_product()){ - var container = selected_orderline.get_container(); - this.gui.show_screen( - 'balancescale', - {product: product, - container: container, - old_orderline: selected_orderline}); - } else { - this._super(product); - } - } - else{ - this._super(product); - } - $("#validation-bloc").removeClass('oe_hidden'); - - }, - - close: function(){ - this._super(); - - this.pos.proxy_queue.clear(); - }, - - }); - - screens.ScreenWidget.include({ - - barcode_container_action: function(code){ - var self = this; - - if (self.pos.scan_container(code)) { - - // Vérfification: est-ce qu'un container vient d'être utilisé dans l'heure - if (self.pos.scan_container_check(code)){ - var transaction = self.pos.scan_container_check(code); - this.gui.show_popup('doublon-barcode',{ - title: _t('Contenu déjà enregistré récemment:'), - transaction: transaction, - confirm: function(){ - var transaction = self.pos.scan_container_check(code) - self.delete_selected_transaction(transaction, code); - self.gui.show_screen('products'); - }, - }); - - } else { - self.gui.show_screen('products'); - } - - } else { - self.gui.show_screen('balancecontainerscale', {barcode: code.base_code}); - } - }, - - delete_selected_transaction: function(transaction, barcode){ - var self = this; - - if (!transaction.id){ - self.deleted_transaction(transaction.container_ean13) - } - else { - rpc.query({ - model: 'pos.transaction', - method: 'unlink', - args: [transaction.id], - }).then(function(){ - self.deleted_transaction(transaction.container_ean13); - },function(err,ev){ - ev.preventDefault(); - var error_body = _t('Your Internet connection is probably down.'); - if (err.data) { - var except = err.data; - error_body = except.arguments && except.arguments[0] || except.message || error_body; - } - self.gui.show_popup('error',{ - 'title': _t('Error: Could not Save Changes'), - 'body': error_body, - }); - } - ); - } - }, - deleted_transaction: function(barcode){ - var self = this; - this.pos.db.remove_transactions([barcode]); - }, - - }); - - var BalanceScaleScreenWidget = screens.ScaleScreenWidget.extend({ - template: 'BalanceScaleScreenWidget', - - next_screen: 'confirmation', - previous_screen: 'products', - - init: function(parent, options){ - this._super(parent, options); - this.weight_container = 0; - this.weight_brut = 0; - this.weight = 0; - }, - - - show: function(){ - var self = this; - var queue = this.pos.proxy_queue; - - this.set_weight(0); - this.renderElement(); - - var container = this.gui.get_current_screen_param('container'); - - queue.schedule(function () { - return self.pos.proxy.reset_weight().then(function () { - self.set_weight(0); - self.set_price(0); - }); - }, {duration: 500}); - - // format price - var price = this.format_price(this.get_product_price()); - - if (container) { - // format tare - var tare = this.format_tare(container); - queue.schedule(function () { - return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) { - self.set_weight(scale_answer.weight); - self.set_price(scale_answer.price); - if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) { - self.gui.show_screen(self.next_screen); - // add product *after* switching screen to scroll properly - self.order_product(); - self.pos.proxy.reset_tare(); - } - }); - }, {duration: 500, repeat: true}); - - } else { - queue.schedule(function () { - return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) { - self.set_weight(scale_answer.weight); - self.set_price(scale_answer.price); - if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) { - self.gui.show_screen(self.next_screen); - self.create_transaction(); - self.order_product(); - } - }); - }, {duration: 500, repeat: true}); - } - this._super(); - - var self = this; - - this.$('.next,.add-transaction').click(function(){ - self.create_transaction(); - }); - $("#pos-topheader-scale").removeClass('oe_hidden'); - $("#pos-header-text-peser").removeClass('oe_hidden'); - - }, - + }); - get_container: function(){ - return this.gui.get_current_screen_param('container'); + gui.Gui.include({ + show_saved_screen: function(order,options) { + this._super(); + options = options || {}; + this.close_popup(); + this.show_screen(this.startup_screen); }, + }); - set_weight: function(weight){ - var container = this.get_container(); - this.weight = weight; - this.weight_container = container.weight; - this.weight_brut = container.weight + this.weight; - this.$('.weight').text(this.get_product_weight_string()); - this.$('.computed-price').text(this.get_computed_price_string()); - this.$('.weight-brut').text(this.get_product_weight_string_brut()); + // We need to modify the OrderSelector to hide itself when we're on + // the floor plan ? + chrome.OrderSelectorWidget.include({ + + hide: function(){ + this.$el.addClass('oe_invisible'); }, - - ////////////////////////////// - // Ajout fonction Toledo? - set_price: function (price) { - if (!price) { - this.$('.computed-price').text(this.get_computed_price_string()); - } else { - this.price = price; - //this.$('.price').text(this.format_currency(price)); - this.$('.computed-price').text(this.format_currency(price)); + show: function(){ + this.$el.removeClass('oe_invisible'); + }, + renderElement: function(){ + var self = this; + this._super(); + if (this.pos.config.balance_id) { + if (this.pos.get_order()) { + this.$el.removeClass('oe_invisible'); + } else { + this.$el.addClass('oe_invisible'); + } } }, + }); - get_price: function () { - return this.price; - }, + screens.ProductScreenWidget.include({ + + previous_screen: 'presentation', - format_tare: function (container) { - var tare = (Math.abs(container.weight) * 1000).toString(); - tare = ("0000" + tare).slice(-4); - return tare; - }, + show: function(){ - format_price: function (product_price) { - var price = (product_price * 1000).toString(); - price = ("000000" + price).slice(-6); - return price; - }, + this._super(); + var self = this; - // FIN - ////////////////////////////// + var scale_screen = this.gui.screen_instances['balancescale']; + scale_screen.$el.removeClass('oe_hidden'); - get_current_container_weight: function(){ - var container = this.get_container(); - if (container){ - return (this.weight_container || 0).toFixed(3) + ' kg'; - } - else{ - '' + this.product_categories_widget.reset_category(); + this.numpad.state.reset(); + + this.$('.back').click(function(){ + self.gui.show_screen('presentation'); + }); + + $("#pos-header-text-prod").removeClass('oe_hidden'); + + var container = this.gui.get_current_screen_param('container'); + if (container) { + this.pos.proxy.reset_tare(); } }, - get_current_container_name: function(){ - var container = this.get_container(); + hide: function(){ + this._super(); + $("#pos-header-text-prod").addClass('oe_hidden'); + + var screen = this.gui.screen_instances['products']; + }, + + // Ajout fonction scale + set_weight: function(weight){ + var scale_screen = this.gui.screen_instances['balancescale']; + + var order = this.pos.get_order(); + var selected_orderline = order.get_selected_orderline(); + var container = selected_orderline.get_container(); + + scale_screen.weight_container = container.weight; + scale_screen.weight = weight; + scale_screen.weight_brut = container.weight + scale_screen.weight; + scale_screen.$('.weight').text(scale_screen.get_product_weight_string()); + scale_screen.$('.computed-price').text(scale_screen.get_computed_price_string()); + scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut()); + if (container){ - return container.name; + var container_text = (container.weight || 0).toFixed(3) + ' kg'; } else{ - '' - } - }, - - get_product_weight_string_brut: function(){ - var product = this.get_product(); - var defaultstr = (this.weight + this.weight_container || 0).toFixed(3) + ' Kg'; - if(!product || !this.pos){ - return defaultstr; - } - var unit_id = product.uom_id; - if(!unit_id){ - return defaultstr; + var container_text = '' } - var unit = this.pos.units_by_id[unit_id[0]]; - var weight = round_pr(this.weight + this.weight_container || 0, unit.rounding); - var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) )); - weightstr += ' ' + unit.name; - return weightstr; + scale_screen.$('.tare-container').text(container_text); }, - hide: function(){ - this._super(); - $("#pos-topheader-scale").addClass('oe_hidden'); - $("#pos-header-text-peser").addClass('oe_hidden'); - }, + click_product: function(product) { + this.create_transaction(product); + }, - create_transaction: function(){ + create_transaction: function(product){ var self = this; var fields = {}; - var container = this.get_container(); - var product = this.get_product(); + var order = this.pos.get_order(); + var selected_orderline = order.get_selected_orderline(); + var container = selected_orderline.get_container(); + var scale_screen = this.gui.screen_instances['balancescale']; + // var product = this.get_product(); var qrcode = ''; var ean13 = ''; @@ -511,16 +738,16 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode); fields['container_ean13'] = container.barcode; - fields['product_id'] = this.get_product().id; + fields['product_id'] = product.id; // var product_id = (this.get_product().id).toString(); var product_id = ("00000" + product.default_code.toString()).slice(-5); - var weight_str = (this.weight * 1000).toString(); + var weight_str = (scale_screen.weight * 1000).toString(); weight_str = ("00000" + weight_str).slice(-5); ean13 = ean13.concat(26,product_id,weight_str,4); - var weight_brut_str = (this.weight_brut * 1000).toString(); + var weight_brut_str = (scale_screen.weight_brut * 1000).toString(); weight_brut_str = ("00000" + weight_brut_str).slice(-5); ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4); @@ -537,147 +764,32 @@ odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) var date_time = date + ' ' + time; fields['write_date'] = date_time; - fields['weight_net'] = this.weight; + fields['weight_net'] = scale_screen.weight; - var pricelist = this._get_active_pricelist(); - fields['price_product'] = (product ? product.get_price(pricelist, this.weight) : 0) || 0; + var pricelist = scale_screen._get_active_pricelist(); + fields['price_product'] = (product ? product.get_price(pricelist, scale_screen.weight) : 0) || 0; fields['price_net'] = fields['weight_net'] * fields['price_product']; fields.name = product.display_name; this.pos.push_transaction(fields).then( - this.pushed_transaction(fields["ean13"]) + this.pushed_transaction(fields["ean13"], product) ); }, - pushed_transaction: function(barcode){ + pushed_transaction: function(barcode, product){ var self = this; - - // Remise à zero du poids à l'écran - this.set_weight(0); - this.renderElement(); - var product = this.get_product(); this.gui.show_screen('confirmation',{product: product}); }, - - }); - - gui.define_screen({ - name:'balancescale', - widget: BalanceScaleScreenWidget, - }); - - - -/*--------------------------------------*\ - | THE SCALE SCREEN FREE | - | BALANCE CONTAINER | -\*======================================*/ - -// The free balance container scale screen -// displays the weight of -// a new container on the electronic scale. - - var BalanceContainerScaleScreenWidget = screens.ScaleScreenWidget.extend({ - template: 'BalanceContainerScaleScreenWidget', - - next_screen: 'presentation', - previous_screen: 'presentation', - - init: function(parent, options){ - this._super(parent, options); - }, - - show: function(){ - - var self = this; - var queue = this.pos.proxy_queue; - var priceStr = '001000'; // bizerba doesn't accept '000000' as unit price - - queue.schedule(function () { - return self.pos.proxy.reset_weight().then(function () { - self.set_weight(0); - }); - }, {duration: 500}); - - queue.schedule(function () { - return self.pos.proxy.scale_read_data_price(priceStr).then(function (scale_answer) { - self.set_weight(scale_answer.weight); - if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) { - self.gui.show_screen(self.next_screen); - self.create_container(); - } - }); - }, {duration: 500, repeat: true}); - this._super(); - - var self = this; - - this.$('.next,.add-container').click(function(){ - self.create_container(); - }); - - if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){ - this.chrome.widget.keyboard.connect($(this.el.querySelector('.container-name input'))); - } - - $("#pos-header-text-peser").removeClass('oe_hidden'); - $("#pos-topheader-scale-cont").removeClass('oe_hidden'); - - }, - - - hide: function(){ - this._super(); - $("#pos-header-text-peser").addClass('oe_hidden'); - $("#pos-topheader-scale-cont").addClass('oe_hidden'); - }, - - get_product: function(){ - return this.pos.get_container_product(); - }, - create_container: function(){ - var self = this; - var fields = {}; - - fields['weight'] = this.weight; - - fields.barcode = this.gui.get_current_screen_param('barcode') || false; - fields.name = fields.name || _t('Container'); - - this.pos.push_container(fields).then( - this.pushed_container(fields["barcode"],fields) - ); - }, - pushed_container: function(barcode,container){ - var self = this; - - var selected_order = this.pos.get_order(); - - selected_order.add_container(container); - - self.gui.show_popup('confirm-pesee',{ - 'title': _t('Merci'), - 'body': _t('La pesée est validée'), - confirm: function(){ - self.gui.show_screen(self.next_screen); - }, - }); - }, close: function(){ this._super(); - if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) { - this.chrome.widget.keyboard.hide(); - } + + this.pos.proxy_queue.clear(); }, - }); - gui.define_screen({ - name:'balancecontainerscale', - widget: BalanceContainerScaleScreenWidget, }); var CheckBarcodePopupDoublon = popups.extend({ diff --git a/static/src/xml/pos.xml b/static/src/xml/pos.xml index e1dd5e4..a742b97 100644 --- a/static/src/xml/pos.xml +++ b/static/src/xml/pos.xml @@ -114,7 +114,7 @@ -
+
-
+
Poids Net
@@ -155,7 +155,7 @@
Prix
-
+
0.00 €
@@ -164,14 +164,15 @@
Poids Brut total:
- 0.00 + 0.000
Tare contenant:
-
- +
+ 0.000 +