[IMP] pos: better default start date
1;2802;0c now() was bad as it excluded the orders of the latest session midnight is not good either because - midnight server != midnight user (timezone) - some restaurant, bars start in the evening and finish after midgnight With this default, with 4 sessions: - POS A, start 2016-12-21 08:05:36 - POS B, start 2016-12-21 08:08:11 - POS A, start 2016-12-22 08:17:51 - POS B, start 2016-12-21 08:19:23 The default start date will be 2016-12-22 08:17:51 to include all orders of both sessions.
This commit is contained in:
@@ -9,7 +9,25 @@ class PosDetails(models.TransientModel):
|
||||
_name = 'pos.details.wizard'
|
||||
_description = 'Open Sale Details Report'
|
||||
|
||||
start_date = fields.Datetime(required=True, default=fields.Datetime.now)
|
||||
def _default_start_date(self):
|
||||
""" Find the earliest start_date of the latests sessions """
|
||||
# restrict to configs available to the user
|
||||
config_ids = self.env['pos.config'].search([]).ids
|
||||
# exclude configs has not been opened for 2 days
|
||||
self.env.cr.execute("""
|
||||
SELECT
|
||||
max(start_at) as start,
|
||||
config_id
|
||||
FROM pos_session
|
||||
WHERE config_id = ANY(%s)
|
||||
AND start_at > (NOW() - INTERVAL '2 DAYS')
|
||||
GROUP BY config_id
|
||||
""", (config_ids,))
|
||||
latest_start_dates = [res['start'] for res in self.env.cr.dictfetchall()]
|
||||
# earliest of the latest sessions
|
||||
return latest_start_dates and min(latest_start_dates) or fields.Datetime.now()
|
||||
|
||||
start_date = fields.Datetime(required=True, default=_default_start_date)
|
||||
end_date = fields.Datetime(required=True, default=fields.Datetime.now)
|
||||
pos_config_ids = fields.Many2many('pos.config', 'pos_detail_configs',
|
||||
default=lambda s: s.env['pos.config'].search([]))
|
||||
|
||||
Reference in New Issue
Block a user