first commit
This commit is contained in:
commit
f659ed99ad
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import models
|
||||
18
__manifest__.py
Normal file
18
__manifest__.py
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
'name': 'POS Shift Close',
|
||||
'version': '1.0',
|
||||
'category': 'Sales/Point of Sale',
|
||||
'summary': 'Bypass POS session close draft order validation for morning shift and transfer orders.',
|
||||
'description': """
|
||||
This module allows cashiers on the morning shift to close the POS session even if there are unpaid/draft orders.
|
||||
Those pending orders will automatically be moved to the next session when it is opened.
|
||||
The afternoon/evening shift will maintain the standard Odoo behavior (blocking closure if pending orders exist).
|
||||
""",
|
||||
'depends': ['point_of_sale'],
|
||||
'data': [
|
||||
'views/res_config_settings_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
3
models/__init__.py
Normal file
3
models/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from . import pos_config
|
||||
from . import pos_session
|
||||
from . import res_config_settings
|
||||
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/pos_config.cpython-312.pyc
Normal file
BIN
models/__pycache__/pos_config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/pos_session.cpython-312.pyc
Normal file
BIN
models/__pycache__/pos_session.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/res_config_settings.cpython-312.pyc
Normal file
BIN
models/__pycache__/res_config_settings.cpython-312.pyc
Normal file
Binary file not shown.
10
models/pos_config.py
Normal file
10
models/pos_config.py
Normal file
@ -0,0 +1,10 @@
|
||||
from odoo import fields, models
|
||||
|
||||
class PosConfig(models.Model):
|
||||
_inherit = 'pos.config'
|
||||
|
||||
morning_shift_end_time = fields.Float(
|
||||
string='Morning Shift End Time',
|
||||
default=15.0,
|
||||
help="Time (in hours) after which closing a POS session will run the standard checks for draft orders, preventing closure. Before this time, the check is bypassed so the morning shift can close."
|
||||
)
|
||||
43
models/pos_session.py
Normal file
43
models/pos_session.py
Normal file
@ -0,0 +1,43 @@
|
||||
from odoo import models
|
||||
from odoo.exceptions import UserError
|
||||
import pytz
|
||||
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')
|
||||
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 super()._check_if_no_draft_orders()
|
||||
|
||||
def _set_opening_control_data(self, cashbox_value: int, notes: str):
|
||||
"""
|
||||
When a new session is opened, we pull the draft orders from the previous
|
||||
closed sessions of this same config, so the afternoon shift can handle them.
|
||||
"""
|
||||
res = super()._set_opening_control_data(cashbox_value, notes)
|
||||
|
||||
# Find draft orders belonging to closed sessions of the same POS
|
||||
pending_orders = self.env['pos.order'].search([
|
||||
('session_id.config_id', '=', self.config_id.id),
|
||||
('session_id.state', '=', 'closed'),
|
||||
('state', '=', 'draft')
|
||||
])
|
||||
|
||||
if pending_orders:
|
||||
pending_orders.write({'session_id': self.id})
|
||||
|
||||
return res
|
||||
9
models/res_config_settings.py
Normal file
9
models/res_config_settings.py
Normal file
@ -0,0 +1,9 @@
|
||||
from odoo import fields, models
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
pos_morning_shift_end_time = fields.Float(
|
||||
related='pos_config_id.morning_shift_end_time',
|
||||
readonly=False,
|
||||
)
|
||||
15
views/res_config_settings_views.xml
Normal file
15
views/res_config_settings_views.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.pos_shift_close</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//block[@id='pos_accounting_section']" position="inside">
|
||||
<setting id="morning_shift_end_time_setting" string="Morning Shift End Time" help="Time (in hours) after which closing a POS session behaves standard. Before this time, draft orders won't block closure.">
|
||||
<field name="pos_morning_shift_end_time" widget="float_time"/>
|
||||
</setting>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue
Block a user