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.

882 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.pos.proxy.reset_tare();
  482. self.gui.show_screen('presentation');
  483. });
  484. $("#pos-header-text-confirm").removeClass('oe_hidden');
  485. var container = this.gui.get_current_screen_param('container');
  486. if (container) {
  487. this.pos.proxy.reset_tare();
  488. }
  489. setTimeout(function(){
  490. self.set_price(0);
  491. self.pos.proxy.reset_tare();
  492. self.gui.show_screen('presentation');
  493. }, 5000);
  494. },
  495. set_weight: function(weight){
  496. var scale_screen = this.gui.screen_instances['balancescale'];
  497. var container = this.gui.get_current_screen_param('container');
  498. scale_screen.weight_container = container.weight;
  499. scale_screen.weight = weight;
  500. scale_screen.weight_brut = container.weight + scale_screen.weight;
  501. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  502. scale_screen.$('.computed-price').text(scale_screen.get_computed_price_string());
  503. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  504. if (container){
  505. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  506. }
  507. else{
  508. var container_text = ''
  509. }
  510. scale_screen.$('.tare-container').text(container_text);
  511. },
  512. _get_active_pricelist: function(){
  513. var current_order = this.pos.get_order();
  514. var current_pricelist = this.pos.default_pricelist;
  515. if (current_order) {
  516. current_pricelist = current_order.pricelist;
  517. }
  518. return current_pricelist;
  519. },
  520. get_product_name: function(){
  521. var product = this.gui.get_current_screen_param('product');
  522. return (product ? product.display_name : undefined) || 'Unnamed Product';
  523. },
  524. get_product_price: function(){
  525. var product = this.gui.get_current_screen_param('product');
  526. var pricelist = this._get_active_pricelist();
  527. return (product ? product.get_price(pricelist, 1) : 0) || 0;
  528. },
  529. get_product_uom: function(){
  530. var product = this.gui.get_current_screen_param('product');
  531. if(product){
  532. return this.pos.units_by_id[product.uom_id[0]].name;
  533. }else{
  534. return '';
  535. }
  536. },
  537. });
  538. gui.define_screen({
  539. 'name': 'confirmation',
  540. 'widget': ConfirmationScreen,
  541. });
  542. // Add the Presentation to the GUI, and set it as the default screen
  543. chrome.Chrome.include({
  544. build_widgets: function(){
  545. this._super();
  546. if (this.pos.config.balance_id) {
  547. this.gui.set_startup_screen('presentation');
  548. }
  549. },
  550. });
  551. gui.Gui.include({
  552. show_saved_screen: function(order,options) {
  553. this._super();
  554. options = options || {};
  555. this.close_popup();
  556. this.show_screen(this.startup_screen);
  557. },
  558. });
  559. // We need to modify the OrderSelector to hide itself when we're on
  560. // the floor plan ?
  561. chrome.OrderSelectorWidget.include({
  562. hide: function(){
  563. this.$el.addClass('oe_invisible');
  564. },
  565. show: function(){
  566. this.$el.removeClass('oe_invisible');
  567. },
  568. renderElement: function(){
  569. var self = this;
  570. this._super();
  571. if (this.pos.config.balance_id) {
  572. if (this.pos.get_order()) {
  573. this.$el.removeClass('oe_invisible');
  574. } else {
  575. this.$el.addClass('oe_invisible');
  576. }
  577. }
  578. },
  579. });
  580. screens.ProductScreenWidget.include({
  581. previous_screen: 'presentation',
  582. show: function(){
  583. this._super();
  584. var self = this;
  585. var scale_screen = this.gui.screen_instances['balancescale'];
  586. scale_screen.$el.removeClass('oe_hidden');
  587. this.product_categories_widget.reset_category();
  588. this.numpad.state.reset();
  589. this.$('.back').click(function(){
  590. self.gui.show_screen('presentation');
  591. });
  592. $("#pos-header-text-prod").removeClass('oe_hidden');
  593. },
  594. hide: function(){
  595. this._super();
  596. $("#pos-header-text-prod").addClass('oe_hidden');
  597. var screen = this.gui.screen_instances['products'];
  598. },
  599. // Ajout fonction scale
  600. set_weight: function(weight){
  601. var scale_screen = this.gui.screen_instances['balancescale'];
  602. var container = this.gui.get_current_screen_param('container');
  603. scale_screen.weight_container = container.weight;
  604. scale_screen.weight = weight;
  605. scale_screen.weight_brut = container.weight + scale_screen.weight;
  606. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  607. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  608. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  609. if (container){
  610. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  611. }
  612. else{
  613. var container_text = ''
  614. }
  615. scale_screen.$('.tare-container').text(container_text);
  616. },
  617. click_product: function(product) {
  618. var scale_screen = this.gui.screen_instances['balancescale'];
  619. if (scale_screen.weight != 0) {
  620. this.create_transaction(product);
  621. }
  622. },
  623. create_transaction: function(product){
  624. var self = this;
  625. var fields = {};
  626. var container = this.gui.get_current_screen_param('container');
  627. var scale_screen = this.gui.screen_instances['balancescale'];
  628. var qrcode = '';
  629. var ean13 = '';
  630. var ean13_verif = '';
  631. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  632. fields['container_ean13'] = container.barcode;
  633. fields['product_id'] = product.id;
  634. // var product_id = (this.get_product().id).toString();
  635. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  636. var weight_str = (scale_screen.weight * 1000).toString();
  637. weight_str = ("00000" + weight_str).slice(-5);
  638. ean13 = ean13.concat(26,product_id,weight_str,4);
  639. var weight_brut_str = (scale_screen.weight_brut * 1000).toString();
  640. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  641. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  642. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  643. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  644. fields['ean13'] = ean13_digit;
  645. fields['ean13_verif'] = ean13_verif_digit;
  646. fields['balance_id'] = this.pos.get_balance_id();
  647. var today = new Date();
  648. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  649. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  650. var date_time = date + ' ' + time;
  651. fields['write_date'] = date_time;
  652. fields['weight_net'] = scale_screen.weight;
  653. fields['weight_tare'] = container.weight;
  654. var pricelist = scale_screen._get_active_pricelist();
  655. fields['price_product'] = (product ? product.get_price(pricelist, scale_screen.weight) : 0) || 0;
  656. fields['price_net'] = fields['weight_net'] * fields['price_product'];
  657. fields.name = product.display_name;
  658. this.pos.push_transaction(fields).then(
  659. this.pushed_transaction(fields["ean13"], product, container)
  660. );
  661. },
  662. pushed_transaction: function(barcode, product, container){
  663. var self = this;
  664. this.gui.show_screen('confirmation',{product: product, container: container});
  665. },
  666. close: function(){
  667. this._super();
  668. this.pos.proxy_queue.clear();
  669. },
  670. });
  671. var CheckBarcodePopupDoublon = popups.extend({
  672. template:'CheckBarcodePopupDoublon',
  673. show: function(options){
  674. var self = this;
  675. options = options || {};
  676. this.name = options.transaction.name ;
  677. this.weight_net = options.transaction.weight_net.toFixed(3) ;
  678. this.price_product = options.transaction.price_product.toFixed(2);
  679. this.price_net = options.transaction.price_net.toFixed(2);
  680. this._super(options);
  681. this.renderElement();
  682. },
  683. });
  684. gui.define_popup({name:'doublon-barcode', widget: CheckBarcodePopupDoublon});
  685. return {
  686. BalanceContainerScaleScreenWidget: BalanceContainerScaleScreenWidget,
  687. PresentationScreenWidget: PresentationScreenWidget,
  688. BalanceScaleScreenWidget: BalanceScaleScreenWidget,
  689. CheckBarcodePopupDoublon: CheckBarcodePopupDoublon,
  690. ConfirmPopupWidgetPesee: ConfirmPopupWidgetPesee,
  691. ConfirmationScreen: ConfirmationScreen,
  692. };
  693. });