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.

77 lines
2.8 KiB

  1. /** ***************************************************************************
  2. Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
  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_picking_load.model', function (require) {
  7. "use strict";
  8. var models = require('point_of_sale.models');
  9. /** **********************************************************************
  10. Extend Model Order:
  11. * Add getter and setter function for field 'origin_picking_id';
  12. */
  13. var moduleOrderParent = models.Order;
  14. models.Order = models.Order.extend({
  15. load_from_picking_data: function (picking_data) {
  16. var self = this;
  17. var partner = this.pos.db.get_partner_by_id(
  18. picking_data.partner_id);
  19. this.set({
  20. 'origin_picking_id': picking_data.id,
  21. 'origin_picking_name': picking_data.name,
  22. });
  23. this.set_client(partner);
  24. picking_data.line_ids.forEach(function (picking_line_data) {
  25. // Create new line and add it to the current order
  26. var product = self.pos.db.get_product_by_id(
  27. picking_line_data.product_id);
  28. var order_line_data =
  29. self.prepare_order_line_from_picking_line_data(
  30. product, picking_line_data);
  31. self.add_product(product, order_line_data);
  32. });
  33. },
  34. prepare_order_line_from_picking_line_data: function (
  35. product, picking_line_data) {
  36. return {
  37. quantity: picking_line_data.quantity,
  38. price: picking_line_data.price_unit || product.price,
  39. discount: picking_line_data.discount || 0.0,
  40. };
  41. },
  42. export_for_printing: function () {
  43. var order = moduleOrderParent.prototype.export_for_printing.apply(
  44. this, arguments);
  45. order.origin_picking_name = this.get('origin_picking_name');
  46. return order;
  47. },
  48. export_as_JSON: function () {
  49. var order = moduleOrderParent.prototype.export_as_JSON.apply(
  50. this, arguments);
  51. order.origin_picking_id = this.get('origin_picking_id');
  52. order.origin_picking_name = this.get('origin_picking_name');
  53. return order;
  54. },
  55. init_from_JSON: function (json) {
  56. moduleOrderParent.prototype.init_from_JSON.apply(this, arguments);
  57. this.set({
  58. 'origin_picking_id': json.origin_picking_id,
  59. 'origin_picking_name': json.origin_picking_name,
  60. });
  61. },
  62. });
  63. });