diff --git a/models/__pycache__/pos_session.cpython-312.pyc b/models/__pycache__/pos_session.cpython-312.pyc index d233cf2..8a29b9a 100644 Binary files a/models/__pycache__/pos_session.cpython-312.pyc and b/models/__pycache__/pos_session.cpython-312.pyc differ diff --git a/models/pos_session.py b/models/pos_session.py index 872b937..ce6f70d 100644 --- a/models/pos_session.py +++ b/models/pos_session.py @@ -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):