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.

56 lines
2.2 KiB

  1. /* Copyright 2018 Tecnativa - David Vidal
  2. License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
  3. odoo.define("pos_lot_selection.models", function (require) {
  4. "use strict";
  5. var models = require("point_of_sale.models");
  6. var session = require("web.session");
  7. models.PosModel = models.PosModel.extend({
  8. get_lot: function (product, location_id) {
  9. var done = new $.Deferred();
  10. session.rpc("/web/dataset/search_read", {
  11. "model": "stock.quant",
  12. "domain": [
  13. ["location_id", "=", location_id],
  14. ["product_id", "=", product],
  15. ["lot_id", "!=", false]]
  16. }, {'async': false}).then(function (result) {
  17. var product_lot = {};
  18. if (result.length) {
  19. for (var i = 0; i < result.length; i++) {
  20. if (product_lot[result.records[i].lot_id[1]]) {
  21. product_lot[result.records[i].lot_id[1]] += result.records[i].quantity;
  22. } else {
  23. product_lot[result.records[i].lot_id[1]] = result.records[i].quantity;
  24. }
  25. }
  26. }
  27. done.resolve(product_lot);
  28. });
  29. return done;
  30. },
  31. });
  32. var _orderline_super = models.Orderline.prototype;
  33. models.Orderline = models.Orderline.extend({
  34. compute_lot_lines: function(){
  35. var done = new $.Deferred();
  36. var compute_lot_lines = _orderline_super.compute_lot_lines.apply(this, arguments);
  37. this.pos.get_lot(this.product.id, this.pos.config.stock_location_id[0])
  38. .then(function (product_lot) {
  39. var lot_name = Object.keys(product_lot);
  40. for (var i = 0; i < lot_name.length; i++) {
  41. if (product_lot[lot_name[i]] < compute_lot_lines.order_line.quantity) {
  42. lot_name.splice(i, 1);
  43. }
  44. }
  45. compute_lot_lines.lot_name = lot_name;
  46. done.resolve(compute_lot_lines);
  47. });
  48. return compute_lot_lines;
  49. },
  50. });
  51. });