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.

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