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.

55 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  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. from openerp import models, api, fields
  6. class PosOrder(models.Model):
  7. _inherit = 'pos.order'
  8. # Field Section
  9. origin_picking_id = fields.Many2one(
  10. string='Origin Picking', comodel_name='stock.picking',
  11. readonly=True)
  12. # Overloadable Section
  13. @api.multi
  14. def _handle_orders_with_original_picking(self):
  15. """By default, the module cancel original stock picking and sale
  16. order. Overload / Overwrite this function if you want another
  17. behaviour"""
  18. sale_order_obj = self.env['sale.order']
  19. for order in self:
  20. # Cancel Picking
  21. order.origin_picking_id.action_cancel()
  22. order.origin_picking_id.write({'final_pos_order_id': order.id})
  23. # Ignore Delivery exception of the Sale Order
  24. sale_orders = sale_order_obj.search([
  25. ('procurement_group_id', '=',
  26. order.origin_picking_id.group_id.id)])
  27. # sale_orders.action_ignore_delivery_exception()
  28. sale_orders.signal_workflow('ship_corrected')
  29. sale_orders.write({'final_pos_order_id': order.id})
  30. # Overload Section
  31. @api.model
  32. def create_from_ui(self, orders):
  33. """Cancel the original picking, when the pos order is done"""
  34. res = super(PosOrder, self).create_from_ui(orders)
  35. orders_with_original_picking = self.search([
  36. ('id', 'in', res), ('origin_picking_id', '!=', False),
  37. ('state', 'not in', [('draft')])])
  38. orders_with_original_picking._handle_orders_with_original_picking()
  39. return res
  40. @api.model
  41. def _order_fields(self, ui_order):
  42. res = super(PosOrder, self)._order_fields(ui_order)
  43. if 'origin_picking_id' in ui_order:
  44. res['origin_picking_id'] = ui_order['origin_picking_id']
  45. return res