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.

871 lines
30 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
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 BalanceScaleScreenWidget = screens.ScaleScreenWidget.extend({
  21. template: 'BalanceScaleScreenWidget',
  22. next_screen: 'confirmation',
  23. previous_screen: 'products',
  24. init: function(parent, options){
  25. this._super(parent, options);
  26. this.weight_container = 0;
  27. this.weight_brut = 0;
  28. this.weight = 0;
  29. },
  30. set_weight: function(weight){
  31. var container = this.get_container();
  32. this.weight = weight;
  33. this.weight_container = container.weight;
  34. this.weight_brut = container.weight + this.weight;
  35. this.$('.weight').text(this.get_product_weight_string());
  36. this.$('.computed-price').text(this.get_computed_price_string());
  37. this.$('.weight-brut').text(this.get_product_weight_string_brut());
  38. },
  39. show: function(){
  40. var self = this;
  41. var queue = this.pos.proxy_queue;
  42. this.set_weight(0);
  43. this.renderElement();
  44. var container = this.gui.get_current_screen_param('container');
  45. queue.schedule(function () {
  46. return self.pos.proxy.reset_weight().then(function () {
  47. self.set_weight(0);
  48. self.set_price(0);
  49. });
  50. }, {duration: 500});
  51. // format price
  52. var price = this.format_price(this.get_product_price());
  53. if (container) {
  54. // format tare
  55. var tare = this.format_tare(container);
  56. queue.schedule(function () {
  57. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  58. self.set_weight(scale_answer.weight);
  59. self.set_price(scale_answer.price);
  60. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  61. self.gui.show_screen(self.next_screen);
  62. // add product *after* switching screen to scroll properly
  63. self.order_product();
  64. self.pos.proxy.reset_tare();
  65. }
  66. });
  67. }, {duration: 500, repeat: true});
  68. } else {
  69. queue.schedule(function () {
  70. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  71. self.set_weight(scale_answer.weight);
  72. self.set_price(scale_answer.price);
  73. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  74. self.gui.show_screen(self.next_screen);
  75. self.create_transaction();
  76. self.order_product();
  77. }
  78. });
  79. }, {duration: 500, repeat: true});
  80. }
  81. // this._super();
  82. var self = this;
  83. this.$('.next,.add-transaction').click(function(){
  84. self.create_transaction();
  85. });
  86. $("#pos-header-text-peser").removeClass('oe_hidden');
  87. },
  88. get_container: function(){
  89. return this.gui.get_current_screen_param('container');
  90. },
  91. //////////////////////////////
  92. // Ajout fonction Toledo?
  93. set_price: function (price) {
  94. if (!price) {
  95. this.$('.computed-price').text(this.get_computed_price_string());
  96. } else {
  97. this.price = price;
  98. //this.$('.price').text(this.format_currency(price));
  99. this.$('.computed-price').text(this.format_currency(price));
  100. }
  101. },
  102. get_price: function () {
  103. return this.price;
  104. },
  105. format_tare: function (container) {
  106. var tare = (Math.abs(container.weight) * 1000).toString();
  107. tare = ("0000" + tare).slice(-4);
  108. return tare;
  109. },
  110. format_price: function (product_price) {
  111. var price = (product_price * 1000).toString();
  112. price = ("000000" + price).slice(-6);
  113. return price;
  114. },
  115. // FIN
  116. //////////////////////////////
  117. get_current_container_weight: function(){
  118. var container = this.get_container();
  119. if (container){
  120. return (this.weight_container || 0).toFixed(3) + ' kg';
  121. }
  122. else{
  123. ''
  124. }
  125. },
  126. get_current_container_name: function(){
  127. var container = this.get_container();
  128. if (container){
  129. return container.name;
  130. }
  131. else{
  132. ''
  133. }
  134. },
  135. get_product_weight_string_brut: function(){
  136. var product = this.get_product();
  137. var defaultstr = (this.weight + this.weight_container || 0).toFixed(3) + ' Kg';
  138. if(!product || !this.pos){
  139. return defaultstr;
  140. }
  141. var unit_id = product.uom_id;
  142. if(!unit_id){
  143. return defaultstr;
  144. }
  145. var unit = this.pos.units_by_id[unit_id[0]];
  146. var weight = round_pr(this.weight + this.weight_container || 0, unit.rounding);
  147. var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) ));
  148. weightstr += ' ' + unit.name;
  149. return weightstr;
  150. },
  151. hide: function(){
  152. this._super();
  153. $("#pos-header-text-peser").addClass('oe_hidden');
  154. },
  155. create_transaction: function(){
  156. var self = this;
  157. var fields = {};
  158. var container = this.get_container();
  159. var product = this.get_product();
  160. var qrcode = '';
  161. var ean13 = '';
  162. var ean13_verif = '';
  163. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  164. fields['container_ean13'] = container.barcode;
  165. fields['product_id'] = this.get_product().id;
  166. // var product_id = (this.get_product().id).toString();
  167. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  168. var weight_str = (this.weight * 1000).toString();
  169. weight_str = ("00000" + weight_str).slice(-5);
  170. ean13 = ean13.concat(26,product_id,weight_str,4);
  171. var weight_brut_str = (this.weight_brut * 1000).toString();
  172. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  173. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  174. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  175. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  176. fields['ean13'] = ean13_digit;
  177. fields['ean13_verif'] = ean13_verif_digit;
  178. fields['balance_id'] = this.pos.get_balance_id();
  179. var today = new Date();
  180. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  181. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  182. var date_time = date + ' ' + time;
  183. fields['write_date'] = date_time;
  184. fields['weight_net'] = this.weight;
  185. var pricelist = this._get_active_pricelist();
  186. fields['price_product'] = (product ? product.get_price(pricelist, this.weight) : 0) || 0;
  187. fields['price_net'] = fields['weight_net'] * fields['price_product'];
  188. fields.name = product.display_name;
  189. this.pos.push_transaction(fields).then(
  190. this.pushed_transaction(fields["ean13"])
  191. );
  192. },
  193. pushed_transaction: function(barcode){
  194. var self = this;
  195. // Remise à zero du poids à l'écran
  196. // this.set_weight(0);
  197. // this.renderElement();
  198. var product = this.get_product();
  199. this.gui.show_screen('confirmation',{product: product});
  200. },
  201. });
  202. gui.define_screen({
  203. name:'balancescale',
  204. widget: BalanceScaleScreenWidget,
  205. });
  206. /*--------------------------------------*\
  207. | THE SCALE SCREEN FREE |
  208. | BALANCE CONTAINER |
  209. \*======================================*/
  210. // The free balance container scale screen
  211. // displays the weight of
  212. // a new container on the electronic scale.
  213. var BalanceContainerScaleScreenWidget = screens.ScaleScreenWidget.extend({
  214. template: 'BalanceContainerScaleScreenWidget',
  215. next_screen: 'presentation',
  216. previous_screen: 'presentation',
  217. init: function(parent, options){
  218. this._super(parent, options);
  219. },
  220. show: function(){
  221. var self = this;
  222. var queue = this.pos.proxy_queue;
  223. var priceStr = '001000'; // bizerba doesn't accept '000000' as unit price
  224. this.renderElement();
  225. queue.schedule(function () {
  226. return self.pos.proxy.reset_weight().then(function () {
  227. self.set_weight(0);
  228. });
  229. }, {duration: 500});
  230. queue.schedule(function () {
  231. return self.pos.proxy.scale_read_data_price(priceStr).then(function (scale_answer) {
  232. self.set_weight(scale_answer.weight);
  233. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  234. self.gui.show_screen(self.next_screen);
  235. self.create_container();
  236. }
  237. });
  238. }, {duration: 500, repeat: true});
  239. this._super();
  240. var self = this;
  241. this.$('.next,.add-container').click(function(){
  242. self.create_container();
  243. });
  244. if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){
  245. this.chrome.widget.keyboard.connect($(this.el.querySelector('.container-name input')));
  246. }
  247. $("#pos-header-text-peser").removeClass('oe_hidden');
  248. $("#pos-topheader-scale-cont").removeClass('oe_hidden');
  249. },
  250. hide: function(){
  251. this._super();
  252. $("#pos-header-text-peser").addClass('oe_hidden');
  253. $("#pos-topheader-scale-cont").addClass('oe_hidden');
  254. },
  255. get_product: function(){
  256. return this.pos.get_container_product();
  257. },
  258. create_container: function(){
  259. if (this.weight != 0) {
  260. var self = this;
  261. var fields = {};
  262. fields['weight'] = this.weight;
  263. fields.barcode = this.gui.get_current_screen_param('barcode') || false;
  264. fields.name = fields.name || _t('Container');
  265. this.pos.push_container(fields).then(
  266. this.pushed_container(fields["barcode"],fields)
  267. );
  268. }
  269. },
  270. pushed_container: function(barcode,container){
  271. var self = this;
  272. var selected_order = this.pos.get_order();
  273. selected_order.add_container(container);
  274. self.gui.show_popup('confirm-pesee',{
  275. 'title': _t('Merci'),
  276. 'body': _t('La pesée est validée'),
  277. confirm: function(){
  278. self.gui.show_screen(self.next_screen);
  279. },
  280. });
  281. },
  282. close: function(){
  283. this._super();
  284. if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) {
  285. this.chrome.widget.keyboard.hide();
  286. }
  287. },
  288. });
  289. gui.define_screen({
  290. name:'balancecontainerscale',
  291. widget: BalanceContainerScaleScreenWidget,
  292. });
  293. screens.ScreenWidget.include({
  294. show: function(){
  295. var self = this;
  296. var queue = this.pos.proxy_queue;
  297. var container = this.gui.get_current_screen_param('container');
  298. // queue.schedule(function () {
  299. // return self.pos.proxy.reset_weight().then(function () {
  300. // self.set_weight(0);
  301. // self.set_price(0);
  302. // });
  303. // }, {duration: 500});
  304. // format price
  305. var scale_screen = this.gui.screen_instances['balancescale'];
  306. var price = scale_screen.format_price(scale_screen.get_product_price());
  307. if (container) {
  308. // format tare
  309. var tare = this.format_tare(container);
  310. queue.schedule(function () {
  311. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  312. self.set_weight(scale_answer.weight);
  313. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  314. self.set_weight(0);
  315. self.pos.proxy.reset_tare();
  316. }
  317. });
  318. }, {duration: 500, repeat: true});
  319. } else {
  320. queue.schedule(function () {
  321. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  322. self.set_weight(scale_answer.weight);
  323. // self.set_price(scale_answer.price);
  324. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  325. self.set_weight(0);
  326. }
  327. });
  328. }, {duration: 500, repeat: true});
  329. }
  330. this._super();
  331. },
  332. format_tare: function (container) {
  333. var tare = (Math.abs(container.weight) * 1000).toString();
  334. tare = ("0000" + tare).slice(-4);
  335. return tare;
  336. },
  337. set_weight: function(weight){
  338. var scale_screen = this.gui.screen_instances['balancescale'];
  339. scale_screen.weight = weight;
  340. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  341. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  342. scale_screen.$('.weight-brut').text('');
  343. var container_text = ''
  344. scale_screen.$('.tare-container').text(container_text);
  345. },
  346. set_price: function (price) {
  347. var scale_screen = this.gui.screen_instances['balancescale'];
  348. scale_screen.price = price;
  349. scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
  350. },
  351. barcode_container_action: function(code){
  352. var self = this;
  353. if (self.pos.scan_container(code)) {
  354. var order = this.pos.get_order();
  355. var selected_orderline = order.get_selected_orderline();
  356. var container = selected_orderline.get_container();
  357. // Vérfification: est-ce qu'un container vient d'être utilisé dans l'heure
  358. if (self.pos.scan_container_check(code)){
  359. var transaction = self.pos.scan_container_check(code);
  360. this.gui.show_popup('doublon-barcode',{
  361. title: _t('Contenu déjà enregistré récemment:'),
  362. transaction: transaction,
  363. confirm: function(){
  364. var transaction = self.pos.scan_container_check(code)
  365. self.delete_selected_transaction(transaction, code);
  366. self.gui.show_screen('products', {container: container});
  367. },
  368. });
  369. } else {
  370. self.gui.show_screen('products', {container: container});
  371. }
  372. } else {
  373. self.gui.show_screen('balancecontainerscale', {barcode: code.base_code});
  374. }
  375. },
  376. delete_selected_transaction: function(transaction, barcode){
  377. var self = this;
  378. if (!transaction.id){
  379. self.deleted_transaction(transaction.container_ean13)
  380. }
  381. else {
  382. rpc.query({
  383. model: 'pos.transaction',
  384. method: 'unlink',
  385. args: [transaction.id],
  386. }).then(function(){
  387. self.deleted_transaction(transaction.container_ean13);
  388. },function(err,ev){
  389. ev.preventDefault();
  390. var error_body = _t('Your Internet connection is probably down.');
  391. if (err.data) {
  392. var except = err.data;
  393. error_body = except.arguments && except.arguments[0] || except.message || error_body;
  394. }
  395. self.gui.show_popup('error',{
  396. 'title': _t('Error: Could not Save Changes'),
  397. 'body': error_body,
  398. });
  399. }
  400. );
  401. }
  402. },
  403. deleted_transaction: function(barcode){
  404. var self = this;
  405. this.pos.db.remove_transactions([barcode]);
  406. },
  407. close: function(){
  408. this._super();
  409. this.pos.proxy_queue.clear();
  410. },
  411. });
  412. var ConfirmPopupWidgetPesee = popups.extend({
  413. template: 'ConfirmPopupWidgetPesee',
  414. });
  415. gui.define_popup({name:'confirm-pesee', widget: ConfirmPopupWidgetPesee});
  416. // The initial screen that allows you to scan container
  417. var PresentationScreenWidget = screens.ScreenWidget.extend({
  418. template: 'PresentationScreenWidget',
  419. next_screen: 'products',
  420. // Ignore products, discounts, and client barcodes
  421. // barcode_product_action: function(code){},
  422. barcode_discount_action: function(code){},
  423. barcode_client_action: function(code){},
  424. init: function(parent, options) {
  425. this._super(parent, options);
  426. this.transactions = [];
  427. this.editing = false;
  428. },
  429. // this method shows the screen and sets up all the widget related to this screen. Extend this method
  430. // if you want to alter the behavior of the screen.
  431. show: function(){
  432. this._super();
  433. var self = this;
  434. var scale_screen = this.gui.screen_instances['balancescale'];
  435. scale_screen.$el.removeClass('oe_hidden');
  436. var screen = this.gui.screen_instances['products'];
  437. screen.$el.removeClass('oe_hidden');
  438. $("#pos-header-text-selec").removeClass('oe_hidden');
  439. $("#pos-header-text-confirm").addClass('oe_hidden');
  440. },
  441. // this methods hides the screen. It's not a good place to put your cleanup stuff as it is called on the
  442. // POS initialization.
  443. hide: function(){
  444. this._super();
  445. var screen = this.gui.screen_instances['products'];
  446. screen.$el.addClass('oe_hidden');
  447. $("#pos-header-text-selec").addClass('oe_hidden');
  448. },
  449. });
  450. gui.define_screen({
  451. 'name': 'presentation',
  452. 'widget': PresentationScreenWidget,
  453. 'condition': function(){
  454. return this.pos.config.balance_id;
  455. },
  456. });
  457. // Screen confirmation de la pesée
  458. var ConfirmationScreen = screens.ScreenWidget.extend({
  459. template: 'ConfirmationScreen',
  460. next_screen: 'presentation',
  461. // previous_screen: 'presentation',
  462. show: function(){
  463. this._super();
  464. var self = this;
  465. this.renderElement();
  466. var scale_screen = this.gui.screen_instances['balancescale'];
  467. scale_screen.$el.removeClass('oe_hidden');
  468. this.$('.next,.back-presentation').click(function(){
  469. // self.set_weight(0);
  470. self.set_price(0);
  471. self.pos.proxy.reset_tare();
  472. self.gui.show_screen('presentation');
  473. });
  474. $("#pos-header-text-confirm").removeClass('oe_hidden');
  475. var container = this.gui.get_current_screen_param('container');
  476. if (container) {
  477. this.pos.proxy.reset_tare();
  478. }
  479. setTimeout(function(){
  480. self.set_price(0);
  481. self.pos.proxy.reset_tare();
  482. self.gui.show_screen('presentation');
  483. }, 5000);
  484. },
  485. set_weight: function(weight){
  486. var scale_screen = this.gui.screen_instances['balancescale'];
  487. var container = this.gui.get_current_screen_param('container');
  488. scale_screen.weight_container = container.weight;
  489. scale_screen.weight = weight;
  490. scale_screen.weight_brut = container.weight + scale_screen.weight;
  491. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  492. scale_screen.$('.computed-price').text(scale_screen.get_computed_price_string());
  493. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  494. if (container){
  495. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  496. }
  497. else{
  498. var container_text = ''
  499. }
  500. scale_screen.$('.tare-container').text(container_text);
  501. },
  502. _get_active_pricelist: function(){
  503. var current_order = this.pos.get_order();
  504. var current_pricelist = this.pos.default_pricelist;
  505. if (current_order) {
  506. current_pricelist = current_order.pricelist;
  507. }
  508. return current_pricelist;
  509. },
  510. get_product_name: function(){
  511. var product = this.gui.get_current_screen_param('product');
  512. return (product ? product.display_name : undefined) || 'Unnamed Product';
  513. },
  514. get_product_price: function(){
  515. var product = this.gui.get_current_screen_param('product');
  516. var pricelist = this._get_active_pricelist();
  517. return (product ? product.get_price(pricelist, 1) : 0) || 0;
  518. },
  519. get_product_uom: function(){
  520. var product = this.gui.get_current_screen_param('product');
  521. if(product){
  522. return this.pos.units_by_id[product.uom_id[0]].name;
  523. }else{
  524. return '';
  525. }
  526. },
  527. });
  528. gui.define_screen({
  529. 'name': 'confirmation',
  530. 'widget': ConfirmationScreen,
  531. });
  532. // Add the Presentation to the GUI, and set it as the default screen
  533. chrome.Chrome.include({
  534. build_widgets: function(){
  535. this._super();
  536. if (this.pos.config.balance_id) {
  537. this.gui.set_startup_screen('presentation');
  538. }
  539. },
  540. });
  541. gui.Gui.include({
  542. show_saved_screen: function(order,options) {
  543. this._super();
  544. options = options || {};
  545. this.close_popup();
  546. this.show_screen(this.startup_screen);
  547. },
  548. });
  549. // We need to modify the OrderSelector to hide itself when we're on
  550. // the floor plan ?
  551. chrome.OrderSelectorWidget.include({
  552. hide: function(){
  553. this.$el.addClass('oe_invisible');
  554. },
  555. show: function(){
  556. this.$el.removeClass('oe_invisible');
  557. },
  558. renderElement: function(){
  559. var self = this;
  560. this._super();
  561. if (this.pos.config.balance_id) {
  562. if (this.pos.get_order()) {
  563. this.$el.removeClass('oe_invisible');
  564. } else {
  565. this.$el.addClass('oe_invisible');
  566. }
  567. }
  568. },
  569. });
  570. screens.ProductScreenWidget.include({
  571. previous_screen: 'presentation',
  572. show: function(){
  573. this._super();
  574. var self = this;
  575. var scale_screen = this.gui.screen_instances['balancescale'];
  576. scale_screen.$el.removeClass('oe_hidden');
  577. this.product_categories_widget.reset_category();
  578. this.numpad.state.reset();
  579. this.$('.back').click(function(){
  580. self.gui.show_screen('presentation');
  581. });
  582. $("#pos-header-text-prod").removeClass('oe_hidden');
  583. },
  584. hide: function(){
  585. this._super();
  586. $("#pos-header-text-prod").addClass('oe_hidden');
  587. var screen = this.gui.screen_instances['products'];
  588. },
  589. // Ajout fonction scale
  590. set_weight: function(weight){
  591. var scale_screen = this.gui.screen_instances['balancescale'];
  592. var container = this.gui.get_current_screen_param('container');
  593. scale_screen.weight_container = container.weight;
  594. scale_screen.weight = weight;
  595. scale_screen.weight_brut = container.weight + scale_screen.weight;
  596. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  597. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  598. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  599. if (container){
  600. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  601. }
  602. else{
  603. var container_text = ''
  604. }
  605. scale_screen.$('.tare-container').text(container_text);
  606. },
  607. click_product: function(product) {
  608. var scale_screen = this.gui.screen_instances['balancescale'];
  609. if (scale_screen.weight != 0) {
  610. this.create_transaction(product);
  611. }
  612. },
  613. create_transaction: function(product){
  614. var self = this;
  615. var fields = {};
  616. var container = this.gui.get_current_screen_param('container');
  617. var scale_screen = this.gui.screen_instances['balancescale'];
  618. var qrcode = '';
  619. var ean13 = '';
  620. var ean13_verif = '';
  621. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  622. fields['container_ean13'] = container.barcode;
  623. fields['product_id'] = product.id;
  624. // var product_id = (this.get_product().id).toString();
  625. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  626. var weight_str = (scale_screen.weight * 1000).toString();
  627. weight_str = ("00000" + weight_str).slice(-5);
  628. ean13 = ean13.concat(26,product_id,weight_str,4);
  629. var weight_brut_str = (scale_screen.weight_brut * 1000).toString();
  630. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  631. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  632. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  633. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  634. fields['ean13'] = ean13_digit;
  635. fields['ean13_verif'] = ean13_verif_digit;
  636. fields['balance_id'] = this.pos.get_balance_id();
  637. var today = new Date();
  638. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  639. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  640. var date_time = date + ' ' + time;
  641. fields['write_date'] = date_time;
  642. fields['weight_net'] = scale_screen.weight;
  643. var pricelist = scale_screen._get_active_pricelist();
  644. fields['price_product'] = (product ? product.get_price(pricelist, scale_screen.weight) : 0) || 0;
  645. fields['price_net'] = fields['weight_net'] * fields['price_product'];
  646. fields.name = product.display_name;
  647. this.pos.push_transaction(fields).then(
  648. this.pushed_transaction(fields["ean13"], product, container)
  649. );
  650. },
  651. pushed_transaction: function(barcode, product, container){
  652. var self = this;
  653. this.gui.show_screen('confirmation',{product: product, container: container});
  654. },
  655. close: function(){
  656. this._super();
  657. this.pos.proxy_queue.clear();
  658. },
  659. });
  660. var CheckBarcodePopupDoublon = popups.extend({
  661. template:'CheckBarcodePopupDoublon',
  662. show: function(options){
  663. var self = this;
  664. options = options || {};
  665. this.name = options.transaction.name ;
  666. this.weight_net = options.transaction.weight_net ;
  667. this.price_product = options.transaction.price_product.toFixed(2); ;
  668. this.price_net = options.transaction.price_net.toFixed(2);
  669. this._super(options);
  670. this.renderElement();
  671. },
  672. });
  673. gui.define_popup({name:'doublon-barcode', widget: CheckBarcodePopupDoublon});
  674. return {
  675. BalanceContainerScaleScreenWidget: BalanceContainerScaleScreenWidget,
  676. PresentationScreenWidget: PresentationScreenWidget,
  677. BalanceScaleScreenWidget: BalanceScaleScreenWidget,
  678. CheckBarcodePopupDoublon: CheckBarcodePopupDoublon,
  679. ConfirmPopupWidgetPesee: ConfirmPopupWidgetPesee,
  680. ConfirmationScreen: ConfirmationScreen,
  681. };
  682. });