You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1109 lines
40 KiB

/*
© 2020 Le Filament (<http://www.le-filament.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) {
"use strict";
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 popups = require('point_of_sale.popups');
var container = require('pos_container.container');
var models_and_db = require('pos_container.models_and_db');
var core = require('web.core');
var rpc = require('web.rpc');
var utils = require('web.utils');
var QWeb = core.qweb;
var _t = core._t;
var round_pr = utils.round_precision;
var action_button_classes = [];
screens.ScreenWidget.include({
show: function(){
var self = this;
if (this.pos.config.is_balance_free) {
var queue = this.pos.proxy_queue;
var container = this.gui.get_current_screen_param('container');
// format price
var scale_screen = this.gui.screen_instances['balancescale'];
var price = scale_screen.format_price(scale_screen.get_product_price());
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.set_weight(0);
}
});
}, {duration: 500, repeat: true});
// }
}
this._super();
},
format_tare: function (container) {
var tare = (Math.abs(container.weight) * 1000).toString();
tare = ("0000" + tare).slice(-4);
return tare;
},
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());
scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
scale_screen.$('.weight-brut').text('0.000 kg');
var container_text = '0.000 kg'
scale_screen.$('.tare-container').text(container_text);
},
set_price: function (price) {
var scale_screen = this.gui.screen_instances['balancescale'];
scale_screen.price = price;
scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
},
barcode_container_action: function(code){
var self = this;
if (this.pos.config.is_balance_free){
if (self.pos.scan_container(code)) {
var order = this.pos.get_order();
var selected_orderline = order.get_selected_orderline();
var container = selected_orderline.get_container();
// 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-balance', {container: container});
},
});
} else {
self.gui.show_screen('products-balance', {container: container});
}
} else {
self.gui.show_screen('balancecontainerscale', {barcode: code.base_code});
}
}
else {
this._super(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 BalanceScaleScreenWidget = screens.ScaleScreenWidget.extend({
template: 'BalanceScaleScreenWidget',
next_screen: 'confirmation',
previous_screen: 'products-balance',
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: function(){
var product = this.get_product();
var defaultstr = (this.weight || 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 || 0, unit.rounding);
var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) ));
weightstr += ' ' + unit.name;
return weightstr;
},
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']).toFixed(2);
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,
'condition': function(){
return this.pos.config.is_balance_free;
},
});
/* -------- The Product Screen BALANCE -------- */
var ProductBalanceScreenWidget = screens.ScreenWidget.extend({
template:'ProductBalanceScreenWidget',
previous_screen: 'presentation',
start: function(){
var self = this;
var queue = this.pos.proxy_queue;
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 scale_screen = this.gui.screen_instances['balancescale'];
var price = scale_screen.format_price(scale_screen.get_product_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.set_weight(0);
}
});
}, {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.set_weight(0);
}
});
}, {duration: 500, repeat: true});
}
// this._super();
this.actionpad = new screens.ActionpadWidget(this,{});
this.actionpad.replace(this.$('.placeholder-ActionpadWidget'));
this.numpad = new screens.NumpadWidget(this,{});
this.numpad.replace(this.$('.placeholder-NumpadWidget'));
this.order_widget = new screens.OrderWidget(this,{
numpad_state: this.numpad.state,
});
this.order_widget.replace(this.$('.placeholder-OrderWidget'));
this.product_list_widget = new screens.ProductListWidget(this,{
click_product_action: function(product){ self.click_product(product); },
product_list: this.pos.db.get_product_by_category(0)
});
this.product_list_widget.replace(this.$('.placeholder-ProductListWidget'));
this.product_categories_widget = new screens.ProductCategoriesWidget(this,{
product_list_widget: this.product_list_widget,
});
this.product_categories_widget.replace(this.$('.placeholder-ProductCategoriesWidget'));
this.action_buttons = {};
var classes = action_button_classes;
for (var i = 0; i < classes.length; i++) {
var classe = classes[i];
if ( !classe.condition || classe.condition.call(this) ) {
var widget = new classe.widget(this,{});
widget.appendTo(this.$('.control-buttons'));
this.action_buttons[classe.name] = widget;
}
}
if (_.size(this.action_buttons)) {
this.$('.control-buttons').removeClass('oe_hidden');
}
var self = this;
var scale_screen = this.gui.screen_instances['balancescale'];
scale_screen.$el.removeClass('oe_hidden');
this.product_categories_widget.reset_category();
this.numpad.state.reset();
// Ajout de la fonctionnalité Pesée sans contenant
if (this.pos.config.allow_without_container){
$("#add-new-container").removeClass('oe_hidden');
}
else {
$("#add-new-container").addClass('oe_hidden');
}
this.$('.add-new-container').click(function(){
self.gui.show_screen('balancecontainerscale', {barcode: 'CONTAINER'});
});
this.$('.back').click(function(){
self.gui.show_screen('presentation');
});
// Ajout pour le pb de tare
var container = this.gui.get_current_screen_param('container');
if (container) {
this.pos.proxy.reset_tare();
}
// Ajout pour le pb de tare
$("#pos-header-text-prod").removeClass('oe_hidden');
},
hide: function(){
this._super();
$("#pos-header-text-prod").addClass('oe_hidden');
$("#add-new-container").addClass('oe_hidden');
var screen = this.gui.screen_instances['products-balance'];
},
set_weight: function(weight){
this.weight = weight;
var scale_screen = this.gui.screen_instances['balancescale'];
var container = this.gui.get_current_screen_param('container');
if (container) {
scale_screen.weight_container = container.weight;
scale_screen.weight_brut = container.weight + scale_screen.weight;
}
scale_screen.weight = weight;
scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
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);
},
set_price: function (price) {
var scale_screen = this.gui.screen_instances['balancescale'];
scale_screen.price = price;
scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
},
click_product: function(product) {
var scale_screen = this.gui.screen_instances['balancescale'];
if (scale_screen.weight != 0) {
this.create_transaction(product);
}
},
order_product: function(product, container){
// Replace the orderline if the product is the placeholder
// container product.
if (container){
var order = this.pos.get_order();
order.add_product(product,{ quantity: this.weight, price: 0.0 });
var orderline = order.get_selected_orderline();
orderline.set_container(container);
var old_orderline = this.gui.get_current_screen_param(
'old_orderline');
if (old_orderline){
order.remove_orderline(old_orderline);
}
orderline.set_quantity(this.weight);
orderline.set_gross_weight(this.weight + container.weight);
orderline.set_tare_mode('AUTO');
orderline.trigger('change', orderline);
} else {
this.pos.get_order().add_product(product,{ quantity: this.weight });
}
},
show: function(reset){
this._super();
if (reset) {
this.product_categories_widget.reset_category();
this.numpad.state.reset();
}
if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) {
this.chrome.widget.keyboard.connect($(this.el.querySelector('.searchbox input')));
}
},
create_transaction: function(product){
var self = this;
var fields = {};
var container = this.gui.get_current_screen_param('container');
var scale_screen = this.gui.screen_instances['balancescale'];
var qrcode = '';
var ean13 = '';
var ean13_verif = '';
if (container){
fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
fields['container_ean13'] = container.barcode;
}
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 = (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 = (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);
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'] = scale_screen.weight;
if(container){
fields['weight_tare'] = container.weight;
}
else{
fields['weight_tare'] = 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']).toFixed(2);
fields.name = product.display_name;
this.pos.push_transaction(fields).then(
this.pushed_transaction(fields["ean13"], product, container, fields)
);
},
pushed_transaction: function(barcode, product, container, transaction){
var self = this;
// Add product on order
this.order_product(product, container);
// Push order
var order = this.pos.get_order();
order.initialize_validation_date();
order.finalized = true;
this.pos.push_order(order);
this.pos.add_new_order();
this.gui.show_screen(
'confirmation',
{product: product, container: container, transaction: transaction});
},
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':'products-balance',
'widget': ProductBalanceScreenWidget,
'condition': function(){
return this.pos.config.is_balance_free;
},
});
/*--------------------------------------*\
| 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);
if (self.pos.config.is_comptoir) {
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(){
if (this.weight != 0) {
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;
if (this.pos.config.is_comptoir) {
self.gui.show_screen(self.next_screen);
}
else{
self.gui.show_popup('confirm-pesee',{
'title': _t('Merci'),
'body': _t('Contenant ajouté, vous pouvez vous servir'),
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,
'condition': function(){
return this.pos.config.is_balance_free;
},
});
var ConfirmPopupWidgetPesee = popups.extend({
template: 'ConfirmPopupWidgetPesee',
});
gui.define_popup({name:'confirm-pesee', widget: ConfirmPopupWidgetPesee});
// The initial screen that allows you to scan container
var PresentationScreenWidget = screens.ScreenWidget.extend({
template: 'PresentationScreenWidget',
next_screen: 'products-balance',
// Ignore products, discounts, and client barcodes
barcode_product_action: function(code){},
barcode_discount_action: function(code){},
barcode_client_action: function(code){},
init: function(parent, options) {
this._super(parent, options);
this.transactions = [];
this.editing = false;
},
// this method shows the screen and sets up all the widget related to this screen. Extend this method
// if you want to alter the behavior of the screen.
show: function(){
this._super();
var self = this;
var scale_screen = this.gui.screen_instances['balancescale'];
scale_screen.$el.removeClass('oe_hidden');
var screen = this.gui.screen_instances['products-balance'];
screen.$el.removeClass('oe_hidden');
$("#pos-header-text-selec").removeClass('oe_hidden');
$("#pos-header-text-confirm").addClass('oe_hidden');
$("#add-new-container").addClass('oe_hidden');
// Ajout de la fonctionnalité Pesée sans contenant
if (this.pos.config.allow_without_container){
this.$('.bypass-container').removeClass('oe_hidden');
}
else {
this.$('.bypass-container').addClass('oe_hidden');
}
this.$('.bypass-container').click(function(){
self.gui.show_screen('products-balance');
});
},
// this methods hides the screen. It's not a good place to put your cleanup stuff as it is called on the
// POS initialization.
hide: function(){
this._super();
var screen = this.gui.screen_instances['products-balance'];
screen.$el.addClass('oe_hidden');
$("#pos-header-text-selec").addClass('oe_hidden');
if (this.pos.config.allow_without_container){
$("#add-new-container").removeClass('oe_hidden');
}
},
});
gui.define_screen({
'name': 'presentation',
'widget': PresentationScreenWidget,
'condition': function(){
return this.pos.config.is_balance_free;
},
});
// Screen confirmation de la pesée
var ConfirmationScreen = screens.ScreenWidget.extend({
template: 'ConfirmationScreen',
next_screen: 'presentation',
// previous_screen: 'presentation',
show: function(){
this._super();
var self = this;
this.renderElement();
var scale_screen = this.gui.screen_instances['balancescale'];
scale_screen.$el.removeClass('oe_hidden');
this.$('.next,.back-presentation').click(function(){
// self.set_weight(0);
self.set_price(0);
self.pos.proxy.reset_tare();
self.gui.show_screen('presentation');
});
$("#pos-header-text-confirm").removeClass('oe_hidden');
var container = this.gui.get_current_screen_param('container');
if (container) {
this.pos.proxy.reset_tare();
}
// A remettre
// setTimeout(function(){
// self.set_price(0);
// self.pos.proxy.reset_tare();
// self.gui.show_screen('presentation');
// }, 5000);
// A remettre
},
set_weight: function(weight){
var scale_screen = this.gui.screen_instances['balancescale'];
var container = this.gui.get_current_screen_param('container');
if (container){
var container_weight = container.weight;
}
else{
var container_weight = 0.0
}
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);
},
set_price: function (price) {
var scale_screen = this.gui.screen_instances['balancescale'];
scale_screen.price = price;
scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
},
_get_active_pricelist: function(){
var current_order = this.pos.get_order();
var current_pricelist = this.pos.default_pricelist;
if (current_order) {
current_pricelist = current_order.pricelist;
}
return current_pricelist;
},
get_product_name: function(){
var product = this.gui.get_current_screen_param('product');
return (product ? product.display_name : undefined) || 'Unnamed Product';
},
get_product_price: function(){
var product = this.gui.get_current_screen_param('product');
var pricelist = this._get_active_pricelist();
return (product ? product.get_price(pricelist, 1) : 0) || 0;
},
get_product_uom: function(){
var product = this.gui.get_current_screen_param('product');
if(product){
return this.pos.units_by_id[product.uom_id[0]].name;
}else{
return '';
}
},
});
gui.define_screen({
'name': 'confirmation',
'widget': ConfirmationScreen,
'condition': function(){
return this.pos.config.is_balance_free;
},
});
// Add the Presentation to the GUI, and set it as the default screen
chrome.Chrome.include({
build_widgets: function(){
this._super();
if (this.pos.config.is_balance_free) {
this.gui.set_startup_screen('presentation');
}
},
build_chrome: function() {
this._super();
var self = this;
if (this.pos.config.is_balance_free) {
this.$('.pos-topheader').addClass('oe_hidden');
this.$('.close-button-bls').click(function(){
self.click_close();
});
}
else {
this.$('.pos-topheader-title').addClass('oe_hidden');
}
},
click_close: function() {
var self = this;
clearTimeout(this.confirmed);
this.gui.close();
},
});
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.is_balance_free) {
if (this.pos.get_order()) {
this.$el.removeClass('oe_invisible');
} else {
this.$el.addClass('oe_invisible');
}
}
},
});
var CheckBarcodePopupDoublon = popups.extend({
template:'CheckBarcodePopupDoublon',
show: function(options){
var self = this;
options = options || {};
this.name = options.transaction.name ;
this.weight_net = options.transaction.weight_net.toFixed(3) ;
this.price_product = options.transaction.price_product.toFixed(2);
this.price_net = options.transaction.price_net;
this._super(options);
this.renderElement();
},
});
gui.define_popup({name:'doublon-barcode', widget: CheckBarcodePopupDoublon});
return {
ProductBalanceScreenWidget: ProductBalanceScreenWidget,
BalanceContainerScaleScreenWidget: BalanceContainerScaleScreenWidget,
PresentationScreenWidget: PresentationScreenWidget,
BalanceScaleScreenWidget: BalanceScaleScreenWidget,
CheckBarcodePopupDoublon: CheckBarcodePopupDoublon,
ConfirmPopupWidgetPesee: ConfirmPopupWidgetPesee,
ConfirmationScreen: ConfirmationScreen,
};
});