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.

38 lines
1.3 KiB

  1. ///*
  2. // Copyright (C) 2017-Today: La Louve (<http://www.lalouve.net/>)
  3. // @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. //*/
  6. odoo.define('pos_price_to_weight.models', function (require) {
  7. "use strict";
  8. var models = require('point_of_sale.models');
  9. var _super_PosModel = models.PosModel.prototype;
  10. models.PosModel = models.PosModel.extend({
  11. scan_product: function(parsed_code) {
  12. if (! (parsed_code.type === 'price_to_weight')){
  13. // Normal behaviour
  14. return _super_PosModel.scan_product.apply(this, [parsed_code]);
  15. }
  16. // Compute quantity, based on price and unit price
  17. var selectedOrder = this.get_order();
  18. var product = this.db.get_product_by_barcode(parsed_code.base_code);
  19. if(!product){
  20. return false;
  21. }
  22. var quantity = 0;
  23. var price = parseFloat(parsed_code.value) || 0;
  24. if (price !== 0 && product.price !== 0){
  25. quantity = price / product.price;
  26. }
  27. selectedOrder.add_product(product, {quantity: quantity, merge: false});
  28. return true;
  29. },
  30. });
  31. });