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.

49 lines
1.8 KiB

  1. # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. from odoo.addons.queue_job.job import job
  5. class PosOrder(models.Model):
  6. _inherit = 'pos.order'
  7. has_picking_delayed = fields.Boolean(
  8. default=False, help="This checkbox is checked if the generation of"
  9. " the picking has been delayed. The picking will be created by cron.")
  10. # Overload Section
  11. @api.model
  12. def create_from_ui(self, orders):
  13. PosSession = self.env['pos.session']
  14. for order_data in orders:
  15. session_id = order_data.get('data').get('pos_session_id')
  16. session = PosSession.browse(session_id)
  17. order_data['data']['has_picking_delayed'] =\
  18. session.config_id.picking_creation_delayed
  19. return super(PosOrder, self.with_context(
  20. create_from_ui=True)).create_from_ui(orders)
  21. def create_picking(self):
  22. if self.env.context.get('create_from_ui', False):
  23. orders = self.filtered(lambda x: not x.has_picking_delayed)
  24. delayed_orders = self.filtered(lambda x: x.has_picking_delayed)
  25. delayed_orders.with_delay()._create_delayed_picking()
  26. else:
  27. orders = self
  28. res = super(PosOrder, orders).create_picking()
  29. orders.write({'has_picking_delayed': False})
  30. return res
  31. @api.model
  32. def _order_fields(self, ui_order):
  33. res = super(PosOrder, self)._order_fields(ui_order)
  34. res['has_picking_delayed'] = ui_order['has_picking_delayed']
  35. return res
  36. # Custom Section
  37. @api.multi
  38. @job(default_channel='root.pos_picking_delayed')
  39. def _create_delayed_picking(self):
  40. super(PosOrder, self).create_picking()
  41. self.write({'has_picking_delayed': False})