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.

52 lines
1.8 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. initialize: function (session, attributes) {
  12. var product_model = _.find(this.models, function(model){
  13. return model.model === 'product.product';
  14. });
  15. product_model.fields.push('total_with_vat');
  16. // Inheritance
  17. return _super_PosModel.initialize.call(this, session, attributes);
  18. },
  19. scan_product: function(parsed_code) {
  20. if (! (parsed_code.type === 'price_to_weight')){
  21. // Normal behaviour
  22. return _super_PosModel.scan_product.apply(this, [parsed_code]);
  23. }
  24. // Compute quantity, based on price and unit price
  25. var selectedOrder = this.get_order();
  26. var product = this.db.get_product_by_barcode(parsed_code.base_code);
  27. if(!product){
  28. return false;
  29. }
  30. var quantity = 0;
  31. var price = parseFloat(parsed_code.value) || 0;
  32. if (price !== 0 && product.price !== 0){
  33. // replace the initial line cause this only work for price with
  34. // vat include in the price in the pos.
  35. quantity = price / product.total_with_vat;
  36. }
  37. selectedOrder.add_product(product, {quantity: quantity, merge: false});
  38. return true;
  39. },
  40. });
  41. });