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.

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