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.

1125 lines
40 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. © 2020 Le Filament (<http://www.le-filament.com>)
  3. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. */
  5. odoo.define('vracoop_pos_free_balance_v2.container_balance', function (require) {
  6. "use strict";
  7. var chrome = require('point_of_sale.chrome');
  8. var gui = require('point_of_sale.gui');
  9. var models = require('point_of_sale.models');
  10. var screens = require('point_of_sale.screens');
  11. var popups = require('point_of_sale.popups');
  12. var container = require('pos_container.container');
  13. var models_and_db = require('pos_container.models_and_db');
  14. var core = require('web.core');
  15. var rpc = require('web.rpc');
  16. var utils = require('web.utils');
  17. var QWeb = core.qweb;
  18. var _t = core._t;
  19. var round_pr = utils.round_precision;
  20. var action_button_classes = [];
  21. screens.ScreenWidget.include({
  22. show: function(){
  23. var self = this;
  24. if (this.pos.config.is_balance_free) {
  25. var queue = this.pos.proxy_queue;
  26. var container = this.gui.get_current_screen_param('container');
  27. // format price
  28. var scale_screen = this.gui.screen_instances['balancescale'];
  29. var price = scale_screen.format_price(scale_screen.get_product_price());
  30. // Problème de tare
  31. if (container) {
  32. // format tare
  33. var tare = this.format_tare(container);
  34. queue.schedule(function () {
  35. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  36. self.set_weight(scale_answer.weight);
  37. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  38. self.set_weight(0);
  39. self.pos.proxy.reset_tare();
  40. }
  41. });
  42. }, {duration: 500, repeat: true});
  43. } else {
  44. queue.schedule(function () {
  45. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  46. self.set_weight(scale_answer.weight);
  47. // self.set_price(scale_answer.price);
  48. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  49. self.set_weight(0);
  50. }
  51. });
  52. }, {duration: 500, repeat: true});
  53. }
  54. }
  55. this._super();
  56. },
  57. format_tare: function (container) {
  58. var tare = (Math.abs(container.weight) * 1000).toString();
  59. tare = ("0000" + tare).slice(-4);
  60. return tare;
  61. },
  62. set_weight: function(weight){
  63. var scale_screen = this.gui.screen_instances['balancescale'];
  64. scale_screen.weight = weight;
  65. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  66. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  67. scale_screen.$('.weight-brut').text('0.000 kg');
  68. var container_text = '0.000 kg'
  69. scale_screen.$('.tare-container').text(container_text);
  70. },
  71. set_price: function (price) {
  72. var scale_screen = this.gui.screen_instances['balancescale'];
  73. scale_screen.price = price;
  74. scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
  75. },
  76. barcode_container_action: function(code){
  77. var self = this;
  78. if (this.pos.config.is_balance_free){
  79. if (self.pos.scan_container(code)) {
  80. var order = this.pos.get_order();
  81. var selected_orderline = order.get_selected_orderline();
  82. var container = selected_orderline.get_container();
  83. // Vérfification: est-ce qu'un container vient d'être utilisé dans l'heure
  84. if (self.pos.scan_container_check(code)){
  85. var transaction = self.pos.scan_container_check(code);
  86. this.gui.show_popup('doublon-barcode',{
  87. title: _t('Contenu déjà enregistré récemment:'),
  88. transaction: transaction,
  89. confirm: function(){
  90. var transaction = self.pos.scan_container_check(code)
  91. self.delete_selected_transaction(transaction, code);
  92. self.gui.show_screen('products-balance', {container: container});
  93. },
  94. });
  95. } else {
  96. self.gui.show_screen('products-balance', {container: container});
  97. }
  98. } else {
  99. self.gui.show_screen('balancecontainerscale', {barcode: code.base_code});
  100. }
  101. }
  102. else {
  103. this._super(code);
  104. }
  105. },
  106. delete_selected_transaction: function(transaction, barcode){
  107. var self = this;
  108. if (!transaction.id){
  109. self.deleted_transaction(transaction.container_ean13)
  110. }
  111. else {
  112. rpc.query({
  113. model: 'pos.transaction',
  114. method: 'unlink',
  115. args: [transaction.id],
  116. }).then(function(){
  117. self.deleted_transaction(transaction.container_ean13);
  118. },function(err,ev){
  119. ev.preventDefault();
  120. var error_body = _t('Your Internet connection is probably down.');
  121. if (err.data) {
  122. var except = err.data;
  123. error_body = except.arguments && except.arguments[0] || except.message || error_body;
  124. }
  125. self.gui.show_popup('error',{
  126. 'title': _t('Error: Could not Save Changes'),
  127. 'body': error_body,
  128. });
  129. }
  130. );
  131. }
  132. },
  133. deleted_transaction: function(barcode){
  134. var self = this;
  135. this.pos.db.remove_transactions([barcode]);
  136. },
  137. close: function(){
  138. this._super();
  139. this.pos.proxy_queue.clear();
  140. },
  141. });
  142. var BalanceScaleScreenWidget = screens.ScaleScreenWidget.extend({
  143. template: 'BalanceScaleScreenWidget',
  144. next_screen: 'confirmation',
  145. previous_screen: 'products-balance',
  146. init: function(parent, options){
  147. this._super(parent, options);
  148. this.weight_container = 0;
  149. this.weight_brut = 0;
  150. this.weight = 0;
  151. },
  152. set_weight: function(weight){
  153. var container = this.get_container();
  154. this.weight = weight;
  155. this.weight_container = container.weight;
  156. this.weight_brut = container.weight + this.weight;
  157. this.$('.weight').text(this.get_product_weight_string());
  158. this.$('.computed-price').text(this.get_computed_price_string());
  159. this.$('.weight-brut').text(this.get_product_weight_string_brut());
  160. },
  161. show: function(){
  162. var self = this;
  163. var queue = this.pos.proxy_queue;
  164. this.set_weight(0);
  165. this.renderElement();
  166. var container = this.gui.get_current_screen_param('container');
  167. queue.schedule(function () {
  168. return self.pos.proxy.reset_weight().then(function () {
  169. self.set_weight(0);
  170. self.set_price(0);
  171. });
  172. }, {duration: 500});
  173. // format price
  174. var price = this.format_price(this.get_product_price());
  175. if (container) {
  176. // format tare
  177. var tare = this.format_tare(container);
  178. queue.schedule(function () {
  179. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  180. self.set_weight(scale_answer.weight);
  181. self.set_price(scale_answer.price);
  182. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  183. self.gui.show_screen(self.next_screen);
  184. // add product *after* switching screen to scroll properly
  185. self.order_product();
  186. self.pos.proxy.reset_tare();
  187. }
  188. });
  189. }, {duration: 500, repeat: true});
  190. } else {
  191. queue.schedule(function () {
  192. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  193. self.set_weight(scale_answer.weight);
  194. self.set_price(scale_answer.price);
  195. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  196. self.gui.show_screen(self.next_screen);
  197. self.create_transaction();
  198. self.order_product();
  199. }
  200. });
  201. }, {duration: 500, repeat: true});
  202. }
  203. // this._super();
  204. var self = this;
  205. this.$('.next,.add-transaction').click(function(){
  206. self.create_transaction();
  207. });
  208. $("#pos-header-text-peser").removeClass('oe_hidden');
  209. },
  210. get_container: function(){
  211. return this.gui.get_current_screen_param('container');
  212. },
  213. //////////////////////////////
  214. // Ajout fonction Toledo?
  215. set_price: function (price) {
  216. if (!price) {
  217. this.$('.computed-price').text(this.get_computed_price_string());
  218. } else {
  219. this.price = price;
  220. //this.$('.price').text(this.format_currency(price));
  221. this.$('.computed-price').text(this.format_currency(price));
  222. }
  223. },
  224. get_price: function () {
  225. return this.price;
  226. },
  227. format_tare: function (container) {
  228. var tare = (Math.abs(container.weight) * 1000).toString();
  229. tare = ("0000" + tare).slice(-4);
  230. return tare;
  231. },
  232. format_price: function (product_price) {
  233. var price = (product_price * 1000).toString();
  234. price = ("000000" + price).slice(-6);
  235. return price;
  236. },
  237. // FIN
  238. //////////////////////////////
  239. get_current_container_weight: function(){
  240. var container = this.get_container();
  241. if (container){
  242. return (this.weight_container || 0).toFixed(3) + ' kg';
  243. }
  244. else{
  245. ''
  246. }
  247. },
  248. get_current_container_name: function(){
  249. var container = this.get_container();
  250. if (container){
  251. return container.name;
  252. }
  253. else{
  254. ''
  255. }
  256. },
  257. get_product_weight_string: function(){
  258. var product = this.get_product();
  259. var defaultstr = (this.weight || 0).toFixed(3) + ' kg';
  260. if(!product || !this.pos){
  261. return defaultstr;
  262. }
  263. var unit_id = product.uom_id;
  264. if(!unit_id){
  265. return defaultstr;
  266. }
  267. var unit = this.pos.units_by_id[unit_id[0]];
  268. var weight = round_pr(this.weight || 0, unit.rounding);
  269. var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) ));
  270. weightstr += ' ' + unit.name;
  271. return weightstr;
  272. },
  273. get_product_weight_string_brut: function(){
  274. var product = this.get_product();
  275. var defaultstr = (this.weight + this.weight_container || 0).toFixed(3) + ' kg';
  276. if(!product || !this.pos){
  277. return defaultstr;
  278. }
  279. var unit_id = product.uom_id;
  280. if(!unit_id){
  281. return defaultstr;
  282. }
  283. var unit = this.pos.units_by_id[unit_id[0]];
  284. var weight = round_pr(this.weight + this.weight_container || 0, unit.rounding);
  285. var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) ));
  286. weightstr += ' ' + unit.name;
  287. return weightstr;
  288. },
  289. hide: function(){
  290. this._super();
  291. $("#pos-header-text-peser").addClass('oe_hidden');
  292. },
  293. create_transaction: function(){
  294. var self = this;
  295. var fields = {};
  296. var container = this.get_container();
  297. var product = this.get_product();
  298. var qrcode = '';
  299. var ean13 = '';
  300. var ean13_verif = '';
  301. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  302. fields['container_ean13'] = container.barcode;
  303. fields['product_id'] = this.get_product().id;
  304. // var product_id = (this.get_product().id).toString();
  305. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  306. var weight_str = (this.weight * 1000).toString();
  307. weight_str = ("00000" + weight_str).slice(-5);
  308. ean13 = ean13.concat(26,product_id,weight_str,4);
  309. var weight_brut_str = (this.weight_brut * 1000).toString();
  310. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  311. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  312. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  313. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  314. fields['ean13'] = ean13_digit;
  315. fields['ean13_verif'] = ean13_verif_digit;
  316. fields['balance_id'] = this.pos.get_balance_id();
  317. var today = new Date();
  318. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  319. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  320. var date_time = date + ' ' + time;
  321. fields['write_date'] = date_time;
  322. fields['weight_net'] = this.weight;
  323. var pricelist = this._get_active_pricelist();
  324. fields['price_product'] = (product ? product.get_price(pricelist, this.weight) : 0) || 0;
  325. fields['price_net'] = (fields['weight_net'] * fields['price_product']).toFixed(2);
  326. fields.name = product.display_name;
  327. this.pos.push_transaction(fields).then(
  328. this.pushed_transaction(fields["ean13"])
  329. );
  330. },
  331. pushed_transaction: function(barcode){
  332. var self = this;
  333. // Remise à zero du poids à l'écran
  334. // this.set_weight(0);
  335. // this.renderElement();
  336. var product = this.get_product();
  337. this.gui.show_screen('confirmation',{product: product});
  338. },
  339. });
  340. gui.define_screen({
  341. 'name':'balancescale',
  342. 'widget': BalanceScaleScreenWidget,
  343. 'condition': function(){
  344. return this.pos.config.is_balance_free;
  345. },
  346. });
  347. /* -------- The Product Screen BALANCE -------- */
  348. var ProductBalanceScreenWidget = screens.ScreenWidget.extend({
  349. template:'ProductBalanceScreenWidget',
  350. previous_screen: 'presentation',
  351. start: function(){
  352. var self = this;
  353. var queue = this.pos.proxy_queue;
  354. var container = this.gui.get_current_screen_param('container');
  355. queue.schedule(function () {
  356. return self.pos.proxy.reset_weight().then(function () {
  357. self.set_weight(0);
  358. self.set_price(0);
  359. });
  360. }, {duration: 500});
  361. // format price
  362. var scale_screen = this.gui.screen_instances['balancescale'];
  363. var price = scale_screen.format_price(scale_screen.get_product_price());
  364. // var price = this.format_price(this.get_product_price());
  365. if (container) {
  366. // format tare
  367. var tare = this.format_tare(container);
  368. queue.schedule(function () {
  369. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  370. self.set_weight(scale_answer.weight);
  371. self.set_price(scale_answer.price);
  372. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  373. self.set_weight(0);
  374. }
  375. });
  376. }, {duration: 500, repeat: true});
  377. } else {
  378. queue.schedule(function () {
  379. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  380. self.set_weight(scale_answer.weight);
  381. self.set_price(scale_answer.price);
  382. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  383. self.set_weight(0);
  384. }
  385. });
  386. }, {duration: 500, repeat: true});
  387. }
  388. // this._super();
  389. this.actionpad = new screens.ActionpadWidget(this,{});
  390. this.actionpad.replace(this.$('.placeholder-ActionpadWidget'));
  391. this.numpad = new screens.NumpadWidget(this,{});
  392. this.numpad.replace(this.$('.placeholder-NumpadWidget'));
  393. this.order_widget = new screens.OrderWidget(this,{
  394. numpad_state: this.numpad.state,
  395. });
  396. this.order_widget.replace(this.$('.placeholder-OrderWidget'));
  397. this.product_list_widget = new screens.ProductListWidget(this,{
  398. click_product_action: function(product){ self.click_product(product); },
  399. product_list: this.pos.db.get_product_by_category(0)
  400. });
  401. this.product_list_widget.replace(this.$('.placeholder-ProductListWidget'));
  402. this.product_categories_widget = new screens.ProductCategoriesWidget(this,{
  403. product_list_widget: this.product_list_widget,
  404. });
  405. this.product_categories_widget.replace(this.$('.placeholder-ProductCategoriesWidget'));
  406. this.action_buttons = {};
  407. var classes = action_button_classes;
  408. for (var i = 0; i < classes.length; i++) {
  409. var classe = classes[i];
  410. if ( !classe.condition || classe.condition.call(this) ) {
  411. var widget = new classe.widget(this,{});
  412. widget.appendTo(this.$('.control-buttons'));
  413. this.action_buttons[classe.name] = widget;
  414. }
  415. }
  416. if (_.size(this.action_buttons)) {
  417. this.$('.control-buttons').removeClass('oe_hidden');
  418. }
  419. var self = this;
  420. var scale_screen = this.gui.screen_instances['balancescale'];
  421. scale_screen.$el.removeClass('oe_hidden');
  422. this.product_categories_widget.reset_category();
  423. this.numpad.state.reset();
  424. // Ajout de la fonctionnalité Pesée sans contenant
  425. if (this.pos.config.allow_without_container){
  426. $("#add-new-container").removeClass('oe_hidden');
  427. }
  428. else {
  429. $("#add-new-container").addClass('oe_hidden');
  430. }
  431. this.$('.add-new-container').click(function(){
  432. self.gui.show_screen('balancecontainerscale', {barcode: 'CONTAINER'});
  433. });
  434. this.$('.back').click(function(){
  435. self.gui.show_screen('presentation', {container: null});
  436. });
  437. // Ajout pour le pb de tare
  438. var container = this.gui.get_current_screen_param('container');
  439. if (container) {
  440. this.pos.proxy.reset_tare();
  441. }
  442. // Ajout pour le pb de tare
  443. $("#pos-header-text-prod").removeClass('oe_hidden');
  444. },
  445. hide: function(){
  446. this._super();
  447. $("#pos-header-text-prod").addClass('oe_hidden');
  448. $("#add-new-container").addClass('oe_hidden');
  449. var screen = this.gui.screen_instances['products-balance'];
  450. },
  451. set_weight: function(weight){
  452. this.weight = weight;
  453. var scale_screen = this.gui.screen_instances['balancescale'];
  454. var container = this.gui.get_current_screen_param('container');
  455. if (container) {
  456. scale_screen.weight_container = container.weight;
  457. scale_screen.weight_brut = container.weight + scale_screen.weight;
  458. }
  459. scale_screen.weight = weight;
  460. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  461. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  462. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  463. if (container){
  464. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  465. }
  466. else{
  467. var container_text = ''
  468. }
  469. scale_screen.$('.tare-container').text(container_text);
  470. },
  471. set_price: function (price) {
  472. var scale_screen = this.gui.screen_instances['balancescale'];
  473. scale_screen.price = price;
  474. scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
  475. },
  476. click_product: function(product) {
  477. var scale_screen = this.gui.screen_instances['balancescale'];
  478. if (scale_screen.weight != 0) {
  479. this.create_transaction(product);
  480. }
  481. },
  482. order_product: function(product, container){
  483. // Replace the orderline if the product is the placeholder
  484. // container product.
  485. if (container){
  486. var order = this.pos.get_order();
  487. order.add_product(product,{ quantity: this.weight, price: 0.0 });
  488. var orderline = order.get_selected_orderline();
  489. orderline.set_container(container);
  490. var old_orderline = this.gui.get_current_screen_param(
  491. 'old_orderline');
  492. if (old_orderline){
  493. order.remove_orderline(old_orderline);
  494. }
  495. orderline.set_quantity(this.weight);
  496. orderline.set_gross_weight(this.weight + container.weight);
  497. orderline.set_tare_mode('AUTO');
  498. orderline.trigger('change', orderline);
  499. } else {
  500. this.pos.get_order().add_product(product,{ quantity: this.weight });
  501. }
  502. },
  503. show: function(reset){
  504. this._super();
  505. if (reset) {
  506. this.product_categories_widget.reset_category();
  507. this.numpad.state.reset();
  508. }
  509. if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) {
  510. this.chrome.widget.keyboard.connect($(this.el.querySelector('.searchbox input')));
  511. }
  512. },
  513. create_transaction: function(product){
  514. var self = this;
  515. var fields = {};
  516. var container = this.gui.get_current_screen_param('container');
  517. var scale_screen = this.gui.screen_instances['balancescale'];
  518. var qrcode = '';
  519. var ean13 = '';
  520. var ean13_verif = '';
  521. if (container){
  522. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  523. fields['container_ean13'] = container.barcode;
  524. }
  525. fields['product_id'] = product.id;
  526. // var product_id = (this.get_product().id).toString();
  527. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  528. var weight_str = (scale_screen.weight * 1000).toString();
  529. weight_str = ("00000" + weight_str).slice(-5);
  530. ean13 = ean13.concat(26,product_id,weight_str,4);
  531. var weight_brut_str = (scale_screen.weight_brut * 1000).toString();
  532. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  533. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  534. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  535. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  536. fields['ean13'] = ean13_digit;
  537. fields['ean13_verif'] = ean13_verif_digit;
  538. fields['balance_id'] = this.pos.get_balance_id();
  539. var today = new Date();
  540. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  541. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  542. var date_time = date + ' ' + time;
  543. fields['write_date'] = date_time;
  544. fields['weight_net'] = scale_screen.weight;
  545. if(container){
  546. fields['weight_tare'] = container.weight;
  547. }
  548. else{
  549. fields['weight_tare'] = 0.0;
  550. }
  551. var pricelist = scale_screen._get_active_pricelist();
  552. fields['price_product'] = (product ? product.get_price(pricelist, scale_screen.weight) : 0) || 0;
  553. fields['price_net'] = (fields['weight_net'] * fields['price_product']).toFixed(2);
  554. fields.name = product.display_name;
  555. this.pos.push_transaction(fields).then(
  556. this.pushed_transaction(fields["ean13"], product, container, fields)
  557. );
  558. },
  559. pushed_transaction: function(barcode, product, container, transaction){
  560. var self = this;
  561. // Add product on order
  562. this.order_product(product, container);
  563. // Push order
  564. var order = this.pos.get_order();
  565. order.initialize_validation_date();
  566. order.finalized = true;
  567. this.pos.push_order(order);
  568. this.pos.add_new_order();
  569. this.gui.show_screen(
  570. 'confirmation',
  571. {product: product, container: container, transaction: transaction});
  572. },
  573. close: function(){
  574. this._super();
  575. if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){
  576. this.chrome.widget.keyboard.hide();
  577. }
  578. this.pos.proxy_queue.clear();
  579. },
  580. });
  581. gui.define_screen({
  582. 'name':'products-balance',
  583. 'widget': ProductBalanceScreenWidget,
  584. 'condition': function(){
  585. return this.pos.config.is_balance_free;
  586. },
  587. });
  588. /*--------------------------------------*\
  589. | THE SCALE SCREEN FREE |
  590. | BALANCE CONTAINER |
  591. \*======================================*/
  592. // The free balance container scale screen
  593. // displays the weight of
  594. // a new container on the electronic scale.
  595. var BalanceContainerScaleScreenWidget = screens.ScaleScreenWidget.extend({
  596. template: 'BalanceContainerScaleScreenWidget',
  597. next_screen: 'presentation',
  598. previous_screen: 'presentation',
  599. init: function(parent, options){
  600. this._super(parent, options);
  601. },
  602. show: function(){
  603. var self = this;
  604. var queue = this.pos.proxy_queue;
  605. var priceStr = '001000'; // bizerba doesn't accept '000000' as unit price
  606. this.renderElement();
  607. queue.schedule(function () {
  608. return self.pos.proxy.reset_weight().then(function () {
  609. self.set_weight(0);
  610. });
  611. }, {duration: 500});
  612. queue.schedule(function () {
  613. return self.pos.proxy.scale_read_data_price(priceStr).then(function (scale_answer) {
  614. self.set_weight(scale_answer.weight);
  615. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  616. self.gui.show_screen(self.next_screen);
  617. if (self.pos.config.is_comptoir) {
  618. self.create_container();
  619. }
  620. }
  621. });
  622. }, {duration: 500, repeat: true});
  623. this._super();
  624. var self = this;
  625. this.$('.next,.add-container').click(function(){
  626. self.create_container();
  627. });
  628. if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){
  629. this.chrome.widget.keyboard.connect($(this.el.querySelector('.container-name input')));
  630. }
  631. $("#pos-header-text-peser").removeClass('oe_hidden');
  632. $("#pos-topheader-scale-cont").removeClass('oe_hidden');
  633. },
  634. hide: function(){
  635. this._super();
  636. $("#pos-header-text-peser").addClass('oe_hidden');
  637. $("#pos-topheader-scale-cont").addClass('oe_hidden');
  638. },
  639. get_product: function(){
  640. return this.pos.get_container_product();
  641. },
  642. create_container: function(){
  643. if (this.weight != 0) {
  644. var self = this;
  645. var fields = {};
  646. fields['weight'] = this.weight;
  647. fields.barcode = this.gui.get_current_screen_param('barcode') || false;
  648. fields.name = fields.name || _t('Container');
  649. this.pos.push_container(fields).then(
  650. this.pushed_container(fields["barcode"],fields)
  651. );
  652. }
  653. },
  654. pushed_container: function(barcode,container){
  655. var self = this;
  656. if (this.pos.config.is_comptoir) {
  657. self.gui.show_screen(self.next_screen);
  658. }
  659. else{
  660. self.gui.show_popup('confirm-pesee',{
  661. 'title': _t('Merci'),
  662. 'body': _t('Contenant ajouté, vous pouvez vous servir'),
  663. confirm: function(){
  664. self.gui.show_screen(self.next_screen);
  665. },
  666. });
  667. }
  668. },
  669. close: function(){
  670. this._super();
  671. if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) {
  672. this.chrome.widget.keyboard.hide();
  673. }
  674. },
  675. });
  676. gui.define_screen({
  677. 'name':'balancecontainerscale',
  678. 'widget': BalanceContainerScaleScreenWidget,
  679. 'condition': function(){
  680. return this.pos.config.is_balance_free;
  681. },
  682. });
  683. var ConfirmPopupWidgetPesee = popups.extend({
  684. template: 'ConfirmPopupWidgetPesee',
  685. });
  686. gui.define_popup({name:'confirm-pesee', widget: ConfirmPopupWidgetPesee});
  687. // The initial screen that allows you to scan container
  688. var PresentationScreenWidget = screens.ScreenWidget.extend({
  689. template: 'PresentationScreenWidget',
  690. next_screen: 'products-balance',
  691. // Ignore products, discounts, and client barcodes
  692. barcode_product_action: function(code){},
  693. barcode_discount_action: function(code){},
  694. barcode_client_action: function(code){},
  695. init: function(parent, options) {
  696. this._super(parent, options);
  697. this.transactions = [];
  698. this.editing = false;
  699. },
  700. // this method shows the screen and sets up all the widget related to this screen. Extend this method
  701. // if you want to alter the behavior of the screen.
  702. show: function(){
  703. this._super();
  704. var self = this;
  705. var scale_screen = this.gui.screen_instances['balancescale'];
  706. scale_screen.$el.removeClass('oe_hidden');
  707. var screen = this.gui.screen_instances['products-balance'];
  708. screen.$el.removeClass('oe_hidden');
  709. $("#pos-header-text-selec").removeClass('oe_hidden');
  710. $("#pos-header-text-confirm").addClass('oe_hidden');
  711. $("#add-new-container").addClass('oe_hidden');
  712. // Ajout de la fonctionnalité Pesée sans contenant
  713. if (this.pos.config.allow_without_container){
  714. this.$('.bypass-container').removeClass('oe_hidden');
  715. }
  716. else {
  717. this.$('.bypass-container').addClass('oe_hidden');
  718. }
  719. this.$('.bypass-container').click(function(){
  720. self.gui.show_screen('products-balance');
  721. });
  722. },
  723. // this methods hides the screen. It's not a good place to put your cleanup stuff as it is called on the
  724. // POS initialization.
  725. hide: function(){
  726. this._super();
  727. var screen = this.gui.screen_instances['products-balance'];
  728. screen.$el.addClass('oe_hidden');
  729. $("#pos-header-text-selec").addClass('oe_hidden');
  730. if (this.pos.config.allow_without_container){
  731. $("#add-new-container").removeClass('oe_hidden');
  732. }
  733. },
  734. });
  735. gui.define_screen({
  736. 'name': 'presentation',
  737. 'widget': PresentationScreenWidget,
  738. 'condition': function(){
  739. return this.pos.config.is_balance_free;
  740. },
  741. });
  742. // Screen confirmation de la pesée
  743. var ConfirmationScreen = screens.ScreenWidget.extend({
  744. template: 'ConfirmationScreen',
  745. next_screen: 'presentation',
  746. // previous_screen: 'presentation',
  747. show: function(){
  748. this._super();
  749. var self = this;
  750. this.renderElement();
  751. var scale_screen = this.gui.screen_instances['balancescale'];
  752. scale_screen.$el.removeClass('oe_hidden');
  753. this.$('.next,.back-presentation').click(function(){
  754. // self.set_weight(0);
  755. self.set_price(0);
  756. self.pos.proxy.reset_tare();
  757. self.gui.show_screen('presentation', {container: null});
  758. });
  759. $("#pos-header-text-confirm").removeClass('oe_hidden');
  760. var container = this.gui.get_current_screen_param('container');
  761. if (container) {
  762. this.pos.proxy.reset_tare();
  763. }
  764. // A remettre
  765. // setTimeout(function(){
  766. // self.set_price(0);
  767. // self.pos.proxy.reset_tare();
  768. // self.gui.show_screen('presentation');
  769. // }, 5000);
  770. // A remettre
  771. },
  772. set_weight: function(weight){
  773. var scale_screen = this.gui.screen_instances['balancescale'];
  774. var container = this.gui.get_current_screen_param('container');
  775. if (container){
  776. var container_weight = container.weight;
  777. }
  778. else{
  779. var container_weight = 0.0
  780. }
  781. scale_screen.weight_container = container_weight;
  782. scale_screen.weight = weight;
  783. scale_screen.weight_brut = container_weight + scale_screen.weight;
  784. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  785. scale_screen.$('.computed-price').text(scale_screen.get_computed_price_string());
  786. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  787. if (container){
  788. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  789. }
  790. else{
  791. var container_text = ''
  792. }
  793. scale_screen.$('.tare-container').text(container_text);
  794. },
  795. set_price: function (price) {
  796. var scale_screen = this.gui.screen_instances['balancescale'];
  797. scale_screen.price = price;
  798. scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
  799. },
  800. _get_active_pricelist: function(){
  801. var current_order = this.pos.get_order();
  802. var current_pricelist = this.pos.default_pricelist;
  803. if (current_order) {
  804. current_pricelist = current_order.pricelist;
  805. }
  806. return current_pricelist;
  807. },
  808. get_product_name: function(){
  809. var product = this.gui.get_current_screen_param('product');
  810. return (product ? product.display_name : undefined) || 'Unnamed Product';
  811. },
  812. get_product_price: function(){
  813. var product = this.gui.get_current_screen_param('product');
  814. var pricelist = this._get_active_pricelist();
  815. return (product ? product.get_price(pricelist, 1) : 0) || 0;
  816. },
  817. get_product_uom: function(){
  818. var product = this.gui.get_current_screen_param('product');
  819. if(product){
  820. return this.pos.units_by_id[product.uom_id[0]].name;
  821. }else{
  822. return '';
  823. }
  824. },
  825. });
  826. gui.define_screen({
  827. 'name': 'confirmation',
  828. 'widget': ConfirmationScreen,
  829. 'condition': function(){
  830. return this.pos.config.is_balance_free;
  831. },
  832. });
  833. // Add the Presentation to the GUI, and set it as the default screen
  834. chrome.Chrome.include({
  835. build_widgets: function(){
  836. this._super();
  837. if (this.pos.config.is_balance_free) {
  838. this.gui.set_startup_screen('presentation');
  839. }
  840. },
  841. build_chrome: function() {
  842. this._super();
  843. var self = this;
  844. if (this.pos.config.is_balance_free) {
  845. this.$('.pos-topheader').addClass('oe_hidden');
  846. this.$('.close-button-bls').click(function(){
  847. self.click_close();
  848. });
  849. }
  850. else {
  851. this.$('.pos-topheader-title').addClass('oe_hidden');
  852. }
  853. },
  854. click_close: function() {
  855. var self = this;
  856. clearTimeout(this.confirmed);
  857. this.gui.close();
  858. },
  859. });
  860. gui.Gui.include({
  861. show_saved_screen: function(order,options) {
  862. this._super();
  863. options = options || {};
  864. this.close_popup();
  865. this.show_screen(this.startup_screen);
  866. },
  867. });
  868. // We need to modify the OrderSelector to hide itself when we're on
  869. // the floor plan ?
  870. chrome.OrderSelectorWidget.include({
  871. hide: function(){
  872. this.$el.addClass('oe_invisible');
  873. },
  874. show: function(){
  875. this.$el.removeClass('oe_invisible');
  876. },
  877. renderElement: function(){
  878. var self = this;
  879. this._super();
  880. if (this.pos.config.is_balance_free) {
  881. if (this.pos.get_order()) {
  882. this.$el.removeClass('oe_invisible');
  883. } else {
  884. this.$el.addClass('oe_invisible');
  885. }
  886. }
  887. },
  888. });
  889. var CheckBarcodePopupDoublon = popups.extend({
  890. template:'CheckBarcodePopupDoublon',
  891. show: function(options){
  892. var self = this;
  893. options = options || {};
  894. this.name = options.transaction.name ;
  895. this.weight_net = options.transaction.weight_net.toFixed(3) ;
  896. this.price_product = options.transaction.price_product.toFixed(2);
  897. this.price_net = options.transaction.price_net;
  898. this._super(options);
  899. this.renderElement();
  900. },
  901. });
  902. gui.define_popup({name:'doublon-barcode', widget: CheckBarcodePopupDoublon});
  903. return {
  904. ProductBalanceScreenWidget: ProductBalanceScreenWidget,
  905. BalanceContainerScaleScreenWidget: BalanceContainerScaleScreenWidget,
  906. PresentationScreenWidget: PresentationScreenWidget,
  907. BalanceScaleScreenWidget: BalanceScaleScreenWidget,
  908. CheckBarcodePopupDoublon: CheckBarcodePopupDoublon,
  909. ConfirmPopupWidgetPesee: ConfirmPopupWidgetPesee,
  910. ConfirmationScreen: ConfirmationScreen,
  911. };
  912. });