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.

72 lines
2.6 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):
  16. return [
  17. ('state', 'in', ['confirmed', 'partially_available', 'assigned']),
  18. ('invoice_state', '=', '2binvoiced'),
  19. ]
  20. @api.model
  21. def _prepare_fields_for_pos_list(self):
  22. return ['name', 'partner_id', 'min_date', 'origin']
  23. @api.model
  24. def search_pickings_for_pos(self, query):
  25. # Get Picking Types available for PoS
  26. picking_type_obj = self.env['stock.picking.type']
  27. picking_types = picking_type_obj.search(
  28. [('available_in_pos', '=', True)])
  29. condition = self._prepare_filter_for_pos() + [
  30. ('picking_type_id', 'in', picking_types.ids),
  31. '|', '|',
  32. ('name', 'ilike', query),
  33. ('origin', 'ilike', query),
  34. ('partner_id', 'ilike', query)
  35. ]
  36. fields = self._prepare_fields_for_pos_list()
  37. return self.search_read(condition, fields, limit=10)
  38. @api.model
  39. def _prepare_pos_order(self, picking):
  40. pickinglines = []
  41. for line in picking.move_lines.filtered(lambda x: x.state != 'cancel'):
  42. picking_line = {
  43. 'name': line.name,
  44. 'product_id': line.product_id.id,
  45. 'quantity': line.product_uom_qty,
  46. }
  47. sale_order_line =\
  48. line.procurement_id and line.procurement_id.sale_line_id
  49. if sale_order_line:
  50. # Get price and discount of the order if available
  51. picking_line['price_unit'] = sale_order_line.price_unit
  52. picking_line['discount'] = sale_order_line.discount
  53. pickinglines.append(picking_line)
  54. return {
  55. 'id': picking.id,
  56. 'name': picking.name,
  57. 'partner_id': picking.partner_id.id,
  58. 'line_ids': pickinglines,
  59. }
  60. @api.model
  61. def load_picking_for_pos(self, picking_id):
  62. picking = self.browse(picking_id)
  63. return self._prepare_pos_order(picking)