refactor: implement morning shift bypass logic for draft order validation in pos.session
This commit is contained in:
parent
d60b04c690
commit
cfdf586fcd
Binary file not shown.
@ -6,21 +6,29 @@ from datetime import datetime
|
||||
class PosSession(models.Model):
|
||||
_inherit = 'pos.session'
|
||||
|
||||
def _check_if_no_draft_orders(self):
|
||||
"""
|
||||
Bypass standard Odoo draft order check if the current time in the user's timezone
|
||||
is before the configured morning_shift_end_time on the pos.config.
|
||||
"""
|
||||
draft_orders = self.get_session_orders().filtered(lambda order: order.state == 'draft')
|
||||
if draft_orders and self.config_id.morning_shift_end_time:
|
||||
user_tz = pytz.timezone(self.env.user.tz or 'UTC')
|
||||
def _is_morning_shift_bypass(self):
|
||||
"""Check if we should bypass draft order validation based on shift time."""
|
||||
self.ensure_one()
|
||||
if self.config_id.morning_shift_end_time:
|
||||
user_tz = pytz.timezone('Asia/Jakarta')
|
||||
local_dt = datetime.now(pytz.utc).astimezone(user_tz)
|
||||
local_hour = local_dt.hour + (local_dt.minute / 60.0)
|
||||
|
||||
if local_hour < self.config_id.morning_shift_end_time:
|
||||
# It's the morning shift, we bypass the check
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_session_orders(self):
|
||||
"""Hide draft orders during the morning shift bypass period."""
|
||||
res = super().get_session_orders()
|
||||
if self._is_morning_shift_bypass():
|
||||
return res.filtered(lambda o: o.state != 'draft')
|
||||
return res
|
||||
|
||||
def _check_if_no_draft_orders(self):
|
||||
"""Bypass check if it's morning shift."""
|
||||
if self._is_morning_shift_bypass():
|
||||
return True
|
||||
return super()._check_if_no_draft_orders()
|
||||
|
||||
def _set_opening_control_data(self, cashbox_value: int, notes: str):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user