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.

938 lines
33 KiB

4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 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. screens.ScreenWidget.include({
  21. show: function(){
  22. var self = this;
  23. var queue = this.pos.proxy_queue;
  24. var container = this.gui.get_current_screen_param('container');
  25. // format price
  26. var scale_screen = this.gui.screen_instances['balancescale'];
  27. var price = scale_screen.format_price(scale_screen.get_product_price());
  28. // if (container) {
  29. // // format tare
  30. // var tare = this.format_tare(container);
  31. // queue.schedule(function () {
  32. // return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  33. // self.set_weight(scale_answer.weight);
  34. // if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  35. // self.set_weight(0);
  36. // self.pos.proxy.reset_tare();
  37. // }
  38. // });
  39. // }, {duration: 500, repeat: true});
  40. // } else {
  41. queue.schedule(function () {
  42. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  43. self.set_weight(scale_answer.weight);
  44. // self.set_price(scale_answer.price);
  45. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  46. self.set_weight(0);
  47. }
  48. });
  49. }, {duration: 500, repeat: true});
  50. // }
  51. this._super();
  52. },
  53. format_tare: function (container) {
  54. var tare = (Math.abs(container.weight) * 1000).toString();
  55. tare = ("0000" + tare).slice(-4);
  56. return tare;
  57. },
  58. set_weight: function(weight){
  59. var scale_screen = this.gui.screen_instances['balancescale'];
  60. scale_screen.weight = weight;
  61. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  62. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  63. scale_screen.$('.weight-brut').text('0.000 kg');
  64. var container_text = '0.000 kg'
  65. scale_screen.$('.tare-container').text(container_text);
  66. },
  67. set_price: function (price) {
  68. var scale_screen = this.gui.screen_instances['balancescale'];
  69. scale_screen.price = price;
  70. scale_screen.$('.computed-price').text(scale_screen.format_currency(0));
  71. },
  72. barcode_container_action: function(code){
  73. var self = this;
  74. if (self.pos.scan_container(code)) {
  75. var order = this.pos.get_order();
  76. var selected_orderline = order.get_selected_orderline();
  77. var container = selected_orderline.get_container();
  78. // Vérfification: est-ce qu'un container vient d'être utilisé dans l'heure
  79. if (self.pos.scan_container_check(code)){
  80. var transaction = self.pos.scan_container_check(code);
  81. this.gui.show_popup('doublon-barcode',{
  82. title: _t('Contenu déjà enregistré récemment:'),
  83. transaction: transaction,
  84. confirm: function(){
  85. var transaction = self.pos.scan_container_check(code)
  86. self.delete_selected_transaction(transaction, code);
  87. self.gui.show_screen('products', {container: container});
  88. },
  89. });
  90. } else {
  91. self.gui.show_screen('products', {container: container});
  92. }
  93. } else {
  94. self.gui.show_screen('balancecontainerscale', {barcode: code.base_code});
  95. }
  96. },
  97. delete_selected_transaction: function(transaction, barcode){
  98. var self = this;
  99. if (!transaction.id){
  100. self.deleted_transaction(transaction.container_ean13)
  101. }
  102. else {
  103. rpc.query({
  104. model: 'pos.transaction',
  105. method: 'unlink',
  106. args: [transaction.id],
  107. }).then(function(){
  108. self.deleted_transaction(transaction.container_ean13);
  109. },function(err,ev){
  110. ev.preventDefault();
  111. var error_body = _t('Your Internet connection is probably down.');
  112. if (err.data) {
  113. var except = err.data;
  114. error_body = except.arguments && except.arguments[0] || except.message || error_body;
  115. }
  116. self.gui.show_popup('error',{
  117. 'title': _t('Error: Could not Save Changes'),
  118. 'body': error_body,
  119. });
  120. }
  121. );
  122. }
  123. },
  124. deleted_transaction: function(barcode){
  125. var self = this;
  126. this.pos.db.remove_transactions([barcode]);
  127. },
  128. close: function(){
  129. this._super();
  130. this.pos.proxy_queue.clear();
  131. },
  132. });
  133. var BalanceScaleScreenWidget = screens.ScaleScreenWidget.extend({
  134. template: 'BalanceScaleScreenWidget',
  135. next_screen: 'confirmation',
  136. previous_screen: 'products',
  137. init: function(parent, options){
  138. this._super(parent, options);
  139. this.weight_container = 0;
  140. this.weight_brut = 0;
  141. this.weight = 0;
  142. },
  143. set_weight: function(weight){
  144. var container = this.get_container();
  145. this.weight = weight;
  146. this.weight_container = container.weight;
  147. this.weight_brut = container.weight + this.weight;
  148. this.$('.weight').text(this.get_product_weight_string());
  149. this.$('.computed-price').text(this.get_computed_price_string());
  150. this.$('.weight-brut').text(this.get_product_weight_string_brut());
  151. },
  152. show: function(){
  153. var self = this;
  154. var queue = this.pos.proxy_queue;
  155. this.set_weight(0);
  156. this.renderElement();
  157. var container = this.gui.get_current_screen_param('container');
  158. queue.schedule(function () {
  159. return self.pos.proxy.reset_weight().then(function () {
  160. self.set_weight(0);
  161. self.set_price(0);
  162. });
  163. }, {duration: 500});
  164. // format price
  165. var price = this.format_price(this.get_product_price());
  166. if (container) {
  167. // format tare
  168. var tare = this.format_tare(container);
  169. queue.schedule(function () {
  170. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  171. self.set_weight(scale_answer.weight);
  172. self.set_price(scale_answer.price);
  173. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  174. self.gui.show_screen(self.next_screen);
  175. // add product *after* switching screen to scroll properly
  176. self.order_product();
  177. self.pos.proxy.reset_tare();
  178. }
  179. });
  180. }, {duration: 500, repeat: true});
  181. } else {
  182. queue.schedule(function () {
  183. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  184. self.set_weight(scale_answer.weight);
  185. self.set_price(scale_answer.price);
  186. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  187. self.gui.show_screen(self.next_screen);
  188. self.create_transaction();
  189. self.order_product();
  190. }
  191. });
  192. }, {duration: 500, repeat: true});
  193. }
  194. // this._super();
  195. var self = this;
  196. this.$('.next,.add-transaction').click(function(){
  197. self.create_transaction();
  198. });
  199. $("#pos-header-text-peser").removeClass('oe_hidden');
  200. },
  201. get_container: function(){
  202. return this.gui.get_current_screen_param('container');
  203. },
  204. //////////////////////////////
  205. // Ajout fonction Toledo?
  206. set_price: function (price) {
  207. if (!price) {
  208. this.$('.computed-price').text(this.get_computed_price_string());
  209. } else {
  210. this.price = price;
  211. //this.$('.price').text(this.format_currency(price));
  212. this.$('.computed-price').text(this.format_currency(price));
  213. }
  214. },
  215. get_price: function () {
  216. return this.price;
  217. },
  218. format_tare: function (container) {
  219. var tare = (Math.abs(container.weight) * 1000).toString();
  220. tare = ("0000" + tare).slice(-4);
  221. return tare;
  222. },
  223. format_price: function (product_price) {
  224. var price = (product_price * 1000).toString();
  225. price = ("000000" + price).slice(-6);
  226. return price;
  227. },
  228. // FIN
  229. //////////////////////////////
  230. get_current_container_weight: function(){
  231. var container = this.get_container();
  232. if (container){
  233. return (this.weight_container || 0).toFixed(3) + ' kg';
  234. }
  235. else{
  236. ''
  237. }
  238. },
  239. get_current_container_name: function(){
  240. var container = this.get_container();
  241. if (container){
  242. return container.name;
  243. }
  244. else{
  245. ''
  246. }
  247. },
  248. get_product_weight_string: function(){
  249. var product = this.get_product();
  250. var defaultstr = (this.weight || 0).toFixed(3) + ' kg';
  251. if(!product || !this.pos){
  252. return defaultstr;
  253. }
  254. var unit_id = product.uom_id;
  255. if(!unit_id){
  256. return defaultstr;
  257. }
  258. var unit = this.pos.units_by_id[unit_id[0]];
  259. var weight = round_pr(this.weight || 0, unit.rounding);
  260. var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) ));
  261. weightstr += ' ' + unit.name;
  262. return weightstr;
  263. },
  264. get_product_weight_string_brut: function(){
  265. var product = this.get_product();
  266. var defaultstr = (this.weight + this.weight_container || 0).toFixed(3) + ' kg';
  267. if(!product || !this.pos){
  268. return defaultstr;
  269. }
  270. var unit_id = product.uom_id;
  271. if(!unit_id){
  272. return defaultstr;
  273. }
  274. var unit = this.pos.units_by_id[unit_id[0]];
  275. var weight = round_pr(this.weight + this.weight_container || 0, unit.rounding);
  276. var weightstr = weight.toFixed(Math.ceil(Math.log(1.0/unit.rounding) / Math.log(10) ));
  277. weightstr += ' ' + unit.name;
  278. return weightstr;
  279. },
  280. hide: function(){
  281. this._super();
  282. $("#pos-header-text-peser").addClass('oe_hidden');
  283. },
  284. create_transaction: function(){
  285. var self = this;
  286. var fields = {};
  287. var container = this.get_container();
  288. var product = this.get_product();
  289. var qrcode = '';
  290. var ean13 = '';
  291. var ean13_verif = '';
  292. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  293. fields['container_ean13'] = container.barcode;
  294. fields['product_id'] = this.get_product().id;
  295. // var product_id = (this.get_product().id).toString();
  296. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  297. var weight_str = (this.weight * 1000).toString();
  298. weight_str = ("00000" + weight_str).slice(-5);
  299. ean13 = ean13.concat(26,product_id,weight_str,4);
  300. var weight_brut_str = (this.weight_brut * 1000).toString();
  301. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  302. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  303. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  304. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  305. fields['ean13'] = ean13_digit;
  306. fields['ean13_verif'] = ean13_verif_digit;
  307. fields['balance_id'] = this.pos.get_balance_id();
  308. var today = new Date();
  309. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  310. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  311. var date_time = date + ' ' + time;
  312. fields['write_date'] = date_time;
  313. fields['weight_net'] = this.weight;
  314. var pricelist = this._get_active_pricelist();
  315. fields['price_product'] = (product ? product.get_price(pricelist, this.weight) : 0) || 0;
  316. fields['price_net'] = fields['weight_net'] * fields['price_product'];
  317. fields.name = product.display_name;
  318. this.pos.push_transaction(fields).then(
  319. this.pushed_transaction(fields["ean13"])
  320. );
  321. },
  322. pushed_transaction: function(barcode){
  323. var self = this;
  324. // Remise à zero du poids à l'écran
  325. // this.set_weight(0);
  326. // this.renderElement();
  327. var product = this.get_product();
  328. this.gui.show_screen('confirmation',{product: product});
  329. },
  330. });
  331. gui.define_screen({
  332. name:'balancescale',
  333. widget: BalanceScaleScreenWidget,
  334. });
  335. /*--------------------------------------*\
  336. | THE SCALE SCREEN FREE |
  337. | BALANCE CONTAINER |
  338. \*======================================*/
  339. // The free balance container scale screen
  340. // displays the weight of
  341. // a new container on the electronic scale.
  342. var BalanceContainerScaleScreenWidget = screens.ScaleScreenWidget.extend({
  343. template: 'BalanceContainerScaleScreenWidget',
  344. next_screen: 'presentation',
  345. previous_screen: 'presentation',
  346. init: function(parent, options){
  347. this._super(parent, options);
  348. },
  349. show: function(){
  350. var self = this;
  351. var queue = this.pos.proxy_queue;
  352. var priceStr = '001000'; // bizerba doesn't accept '000000' as unit price
  353. this.renderElement();
  354. queue.schedule(function () {
  355. return self.pos.proxy.reset_weight().then(function () {
  356. self.set_weight(0);
  357. });
  358. }, {duration: 500});
  359. queue.schedule(function () {
  360. return self.pos.proxy.scale_read_data_price(priceStr).then(function (scale_answer) {
  361. self.set_weight(scale_answer.weight);
  362. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  363. self.gui.show_screen(self.next_screen);
  364. if (self.pos.config.is_comptoir) {
  365. self.create_container();
  366. }
  367. }
  368. });
  369. }, {duration: 500, repeat: true});
  370. this._super();
  371. var self = this;
  372. this.$('.next,.add-container').click(function(){
  373. self.create_container();
  374. });
  375. if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){
  376. this.chrome.widget.keyboard.connect($(this.el.querySelector('.container-name input')));
  377. }
  378. $("#pos-header-text-peser").removeClass('oe_hidden');
  379. $("#pos-topheader-scale-cont").removeClass('oe_hidden');
  380. },
  381. hide: function(){
  382. this._super();
  383. $("#pos-header-text-peser").addClass('oe_hidden');
  384. $("#pos-topheader-scale-cont").addClass('oe_hidden');
  385. },
  386. get_product: function(){
  387. return this.pos.get_container_product();
  388. },
  389. create_container: function(){
  390. if (this.weight != 0) {
  391. var self = this;
  392. var fields = {};
  393. fields['weight'] = this.weight;
  394. fields.barcode = this.gui.get_current_screen_param('barcode') || false;
  395. fields.name = fields.name || _t('Container');
  396. this.pos.push_container(fields).then(
  397. this.pushed_container(fields["barcode"],fields)
  398. );
  399. }
  400. },
  401. pushed_container: function(barcode,container){
  402. var self = this;
  403. var selected_order = this.pos.get_order();
  404. selected_order.add_container(container);
  405. if (this.pos.config.is_comptoir) {
  406. self.gui.show_screen(self.next_screen);
  407. }
  408. else{
  409. self.gui.show_popup('confirm-pesee',{
  410. 'title': _t('Merci'),
  411. 'body': _t('Contenant ajouté, vous pouvez vous servir'),
  412. confirm: function(){
  413. self.gui.show_screen(self.next_screen);
  414. },
  415. });
  416. }
  417. },
  418. close: function(){
  419. this._super();
  420. if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) {
  421. this.chrome.widget.keyboard.hide();
  422. }
  423. },
  424. });
  425. gui.define_screen({
  426. name:'balancecontainerscale',
  427. widget: BalanceContainerScaleScreenWidget,
  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. var self = this;
  591. var queue = this.pos.proxy_queue;
  592. var container = this.gui.get_current_screen_param('container');
  593. queue.schedule(function () {
  594. return self.pos.proxy.reset_weight().then(function () {
  595. self.set_weight(0);
  596. self.set_price(0);
  597. });
  598. }, {duration: 500});
  599. // format price
  600. var scale_screen = this.gui.screen_instances['balancescale'];
  601. var price = scale_screen.format_price(scale_screen.get_product_price());
  602. // var price = this.format_price(this.get_product_price());
  603. if (container) {
  604. // format tare
  605. var tare = this.format_tare(container);
  606. queue.schedule(function () {
  607. return self.pos.proxy.scale_read_data_price_tare(price, tare).then(function (scale_answer) {
  608. self.set_weight(scale_answer.weight);
  609. self.set_price(scale_answer.price);
  610. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  611. self.set_weight(0);
  612. }
  613. });
  614. }, {duration: 500, repeat: true});
  615. } else {
  616. queue.schedule(function () {
  617. return self.pos.proxy.scale_read_data_price(price).then(function (scale_answer) {
  618. self.set_weight(scale_answer.weight);
  619. self.set_price(scale_answer.price);
  620. if ((scale_answer.error === '30' || scale_answer.error === '31') && scale_answer.weight !== 0) {
  621. self.set_weight(0);
  622. }
  623. });
  624. }, {duration: 500, repeat: true});
  625. }
  626. // this._super();
  627. this._super();
  628. var self = this;
  629. var scale_screen = this.gui.screen_instances['balancescale'];
  630. scale_screen.$el.removeClass('oe_hidden');
  631. this.product_categories_widget.reset_category();
  632. this.numpad.state.reset();
  633. this.$('.back').click(function(){
  634. self.gui.show_screen('presentation');
  635. });
  636. // Ajout pour le pb de tare
  637. var container = this.gui.get_current_screen_param('container');
  638. if (container) {
  639. this.pos.proxy.reset_tare();
  640. }
  641. // Ajout pour le pb de tare
  642. $("#pos-header-text-prod").removeClass('oe_hidden');
  643. },
  644. hide: function(){
  645. this._super();
  646. $("#pos-header-text-prod").addClass('oe_hidden');
  647. var screen = this.gui.screen_instances['products'];
  648. },
  649. // Ajout fonction scale
  650. set_weight: function(weight){
  651. var scale_screen = this.gui.screen_instances['balancescale'];
  652. var container = this.gui.get_current_screen_param('container');
  653. scale_screen.weight_container = container.weight;
  654. scale_screen.weight = weight;
  655. scale_screen.weight_brut = container.weight + scale_screen.weight;
  656. scale_screen.$('.weight').text(scale_screen.get_product_weight_string());
  657. scale_screen.$('.computed-price').text(scale_screen.format_currency(scale_screen.get_product_price() * 0));
  658. scale_screen.$('.weight-brut').text(scale_screen.get_product_weight_string_brut());
  659. if (container){
  660. var container_text = (container.weight || 0).toFixed(3) + ' kg';
  661. }
  662. else{
  663. var container_text = ''
  664. }
  665. scale_screen.$('.tare-container').text(container_text);
  666. },
  667. click_product: function(product) {
  668. var scale_screen = this.gui.screen_instances['balancescale'];
  669. if (scale_screen.weight != 0) {
  670. this.create_transaction(product);
  671. }
  672. },
  673. create_transaction: function(product){
  674. var self = this;
  675. var fields = {};
  676. var container = this.gui.get_current_screen_param('container');
  677. var scale_screen = this.gui.screen_instances['balancescale'];
  678. var qrcode = '';
  679. var ean13 = '';
  680. var ean13_verif = '';
  681. fields['qrcode'] = qrcode.concat('https://qr.mayam.fr/', container.barcode);
  682. fields['container_ean13'] = container.barcode;
  683. fields['product_id'] = product.id;
  684. // var product_id = (this.get_product().id).toString();
  685. var product_id = ("00000" + product.default_code.toString()).slice(-5);
  686. var weight_str = (scale_screen.weight * 1000).toString();
  687. weight_str = ("00000" + weight_str).slice(-5);
  688. ean13 = ean13.concat(26,product_id,weight_str,4);
  689. var weight_brut_str = (scale_screen.weight_brut * 1000).toString();
  690. weight_brut_str = ("00000" + weight_brut_str).slice(-5);
  691. ean13_verif = ean13_verif.concat(26,'00999',weight_brut_str,4);
  692. var ean13_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13);
  693. var ean13_verif_digit = this.pos.barcode_reader.barcode_parser.sanitize_ean(ean13_verif);
  694. fields['ean13'] = ean13_digit;
  695. fields['ean13_verif'] = ean13_verif_digit;
  696. fields['balance_id'] = this.pos.get_balance_id();
  697. var today = new Date();
  698. var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
  699. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  700. var date_time = date + ' ' + time;
  701. fields['write_date'] = date_time;
  702. fields['weight_net'] = scale_screen.weight;
  703. fields['weight_tare'] = container.weight;
  704. var pricelist = scale_screen._get_active_pricelist();
  705. fields['price_product'] = (product ? product.get_price(pricelist, scale_screen.weight) : 0) || 0;
  706. fields['price_net'] = fields['weight_net'] * fields['price_product'];
  707. fields.name = product.display_name;
  708. this.pos.push_transaction(fields).then(
  709. this.pushed_transaction(fields["ean13"], product, container)
  710. );
  711. },
  712. pushed_transaction: function(barcode, product, container){
  713. var self = this;
  714. this.gui.show_screen('confirmation',{product: product, container: container});
  715. },
  716. close: function(){
  717. this._super();
  718. this.pos.proxy_queue.clear();
  719. },
  720. });
  721. var CheckBarcodePopupDoublon = popups.extend({
  722. template:'CheckBarcodePopupDoublon',
  723. show: function(options){
  724. var self = this;
  725. options = options || {};
  726. this.name = options.transaction.name ;
  727. this.weight_net = options.transaction.weight_net.toFixed(3) ;
  728. this.price_product = options.transaction.price_product.toFixed(2);
  729. this.price_net = options.transaction.price_net.toFixed(2);
  730. this._super(options);
  731. this.renderElement();
  732. },
  733. });
  734. gui.define_popup({name:'doublon-barcode', widget: CheckBarcodePopupDoublon});
  735. return {
  736. BalanceContainerScaleScreenWidget: BalanceContainerScaleScreenWidget,
  737. PresentationScreenWidget: PresentationScreenWidget,
  738. BalanceScaleScreenWidget: BalanceScaleScreenWidget,
  739. CheckBarcodePopupDoublon: CheckBarcodePopupDoublon,
  740. ConfirmPopupWidgetPesee: ConfirmPopupWidgetPesee,
  741. ConfirmationScreen: ConfirmationScreen,
  742. };
  743. });