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.

89 lines
3.3 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 StockPicking(models.Model):
  7. _inherit = 'stock.picking'
  8. # Field Section
  9. final_pos_order_id = fields.Many2one(
  10. string='Final PoS Order', comodel_name='pos.order', readonly=True,
  11. help="This picking has been canceled, because it has been replaced by"
  12. " this PoS Order")
  13. # Custom Section
  14. @api.model
  15. def _prepare_filter_for_pos(self, pos_session_id):
  16. picking_type_obj = self.env['stock.picking.type']
  17. picking_types = picking_type_obj.search(
  18. [('available_in_pos', '=', True)])
  19. return [
  20. ('picking_type_id', 'in', picking_types.ids),
  21. ('state', 'in', ['confirmed', 'partially_available', 'assigned']),
  22. ('invoice_state', '=', '2binvoiced'),
  23. ]
  24. @api.model
  25. def _prepare_filter_query_for_pos(self, pos_session_id, query):
  26. return [
  27. '|', '|',
  28. ('name', 'ilike', query),
  29. ('origin', 'ilike', query),
  30. ('partner_id', 'ilike', query),
  31. ]
  32. @api.model
  33. def _prepare_fields_for_pos_list(self):
  34. return ['name', 'partner_id', 'min_date', 'origin']
  35. @api.model
  36. def search_pickings_for_pos(self, query, pos_session_id):
  37. session_obj = self.env['pos.session']
  38. config = session_obj.browse(pos_session_id).config_id
  39. condition = self._prepare_filter_for_pos(pos_session_id) +\
  40. self._prepare_filter_query_for_pos(pos_session_id, query)
  41. fields = self._prepare_fields_for_pos_list()
  42. return self.search_read(
  43. condition, fields, limit=config.iface_load_picking_max_qty)
  44. @api.multi
  45. def load_picking_for_pos(self):
  46. self.ensure_one()
  47. pickinglines = []
  48. for line in self.move_lines.filtered(lambda x: x.state != 'cancel'):
  49. picking_line = {
  50. 'name': line.name,
  51. 'product_id': line.product_id.id,
  52. 'quantity': line.product_uom_qty,
  53. }
  54. sale_order_line =\
  55. line.procurement_id and line.procurement_id.sale_line_id
  56. if sale_order_line:
  57. # Get price and discount of the order if available
  58. picking_line['price_unit'] = sale_order_line.price_unit
  59. picking_line['discount'] = sale_order_line.discount
  60. pickinglines.append(picking_line)
  61. return {
  62. 'id': self.id,
  63. 'name': self.name,
  64. 'partner_id': self.partner_id.id,
  65. 'line_ids': pickinglines,
  66. }
  67. @api.multi
  68. def update_from_origin_picking(self, origin_picking):
  69. if origin_picking.group_id:
  70. self.filtered(lambda p: not p.group_id).write({
  71. 'group_id': origin_picking.group_id.id})
  72. @api.multi
  73. def action_confirm(self):
  74. """ Assign to same procurement group as the origin picking """
  75. if self.env.context.get('origin_picking_id'):
  76. self.update_from_origin_picking(
  77. self.browse(self.env.context['origin_picking_id']))
  78. return super(StockPicking, self).action_confirm()