forked from NextERP-Romania/odoo-community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from NextERP-Romania/16.0
Fork Sync Branch 16.0
- Loading branch information
Showing
15 changed files
with
953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
===================================== | ||
NextERP - POS Session Closing by Date | ||
===================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/github-NextERP-Romania%2Fodoo--community-lightgray.png?logo=github | ||
:target: https://github.com/NextERP-Romania/odoo-community/tree/14.0/nexterp_pos_session_closing_by_date | ||
:alt: NextERP-Romania/odoo-community | ||
|
||
|badge1| |badge2| | ||
|
||
If there are multiple sessions opened on several days for the same location, the user can close the selected session. Otherwise, the system will close the last opened session | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
To install this module, you need to: | ||
|
||
* clone the branch 16.0 of the repository https://github.com/NextERP-Romania/odoo-community | ||
* add the path to this repository in your configuration (addons-path) | ||
* update the module list | ||
* search for "NextERP - POS Session Closing by Date" in your addons | ||
* install the module | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/NextERP-Romania/odoo-community/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/NextERP-Romania/odoo-community/issues/new?body=module:%20nexterp_pos_session_closing_by_date%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* NextERP Romania | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `NextERP Romania <https://www.nexterp.ro>`_: | ||
|
||
* Fekete Mihai <feketemihai@nexterp.ro> | ||
* Sima Elisabeta <elisabeta.sima@nexterp.ro> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `NextERP-Romania/odoo-community <https://github.com/NextERP-Romania/odoo-community/tree/14.0/nexterp_pos_session_closing_by_date>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2024 NextERP Romania SRL | ||
# License OPL-1.0 or later | ||
# (https://www.odoo.com/documentation/user/16.0/legal/licenses/licenses.html#). | ||
|
||
{ | ||
"name": "NextERP - POS Session Closing by Date", | ||
"version": "16.0.1.0.0", | ||
"summary": """ NextERP - POS Session Closing by Date""", | ||
"category": "Sales", | ||
"author": "NextERP Romania", | ||
"website": "https://nexterp.ro", | ||
"support": "odoo_apps@nexterp.ro", | ||
"license": "OPL-1", | ||
"currency": "EUR", | ||
"data": [ | ||
"views/res_config_settings_views.xml", | ||
], | ||
"depends": ["point_of_sale"], | ||
"installable": True, | ||
"auto_install": False, | ||
"application": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
|
||
from odoo import http | ||
from odoo.http import request | ||
from odoo.osv.expression import AND | ||
|
||
from odoo.addons.point_of_sale.controllers.main import PosController | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class SessionPosController(PosController): | ||
@http.route(["/pos/web", "/pos/ui"], type="http", auth="user") | ||
def pos_web(self, config_id=False, **k): | ||
is_internal_user = request.env.user.has_group("base.group_user") | ||
if not is_internal_user: | ||
return request.not_found() | ||
if config_id: | ||
pos_config = request.env["pos.config"].sudo().browse(int(config_id)) | ||
if k.get("session_id"): | ||
pos_session = ( | ||
request.env["pos.session"].sudo().browse(int(k.get("session_id"))) | ||
) | ||
else: | ||
domain = [ | ||
("state", "in", ["opening_control", "opened"]), | ||
("user_id", "=", request.session.uid), | ||
("rescue", "=", False), | ||
] | ||
if config_id: | ||
domain = AND([domain, [("config_id", "=", int(config_id))]]) | ||
pos_session = request.env["pos.session"].sudo().search(domain, limit=1) | ||
|
||
# The same POS session can be opened by a different user => | ||
# search without restricting to | ||
# current user. Note: the config must be explicitly given | ||
# to avoid fallbacking on a random | ||
# session. | ||
if not pos_session and config_id: | ||
domain = [ | ||
("state", "in", ["opening_control", "opened"]), | ||
("rescue", "=", False), | ||
("config_id", "=", int(config_id)), | ||
] | ||
pos_session = request.env["pos.session"].sudo().search(domain, limit=1) | ||
if not pos_session or config_id and not pos_config.active: | ||
return request.redirect("/web#action=point_of_sale.action_client_pos_menu") | ||
# The POS only work in one company, so we enforce the one of the session in the context | ||
company = pos_session.company_id | ||
session_info = request.env["ir.http"].session_info() | ||
session_info["user_context"]["allowed_company_ids"] = company.ids | ||
session_info["user_companies"] = { | ||
"current_company": company.id, | ||
"allowed_companies": { | ||
company.id: session_info["user_companies"]["allowed_companies"][ | ||
company.id | ||
] | ||
}, | ||
} | ||
context = { | ||
"session_info": session_info, | ||
"login_number": pos_session.login(), | ||
"pos_session_id": pos_session.id, | ||
} | ||
response = request.render("point_of_sale.index", context) | ||
response.headers["Cache-Control"] = "no-store" | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import pos_session | ||
from . import pos_config | ||
from . import res_company | ||
from . import res_config_settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2024 NextERP Romania SRL | ||
# License OPL-1.0 or later | ||
# (https://www.odoo.com/documentation/user/16.0/legal/licenses/licenses.html#). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class PosConfig(models.Model): | ||
_inherit = "pos.config" | ||
|
||
@api.depends("session_ids", "session_ids.state") | ||
def _compute_current_session(self): | ||
""" | ||
Compute the current session based on the context or params. | ||
If the context has a session_id, | ||
use it and store it to current_session_id / current_session_state. | ||
""" | ||
params = self.env.context.get("params") | ||
session = False | ||
if params and (params.get("model") == "pos.session") and params.get("id"): | ||
session = self.env["pos.session"].browse(params.get("id")) | ||
elif self.env.context.get("session_id"): | ||
session = self.env["pos.session"].browse(self.env.context.get("session_id")) | ||
if session and len(session) == 1 and session.state != "closed": | ||
self.current_session_id = session.id | ||
self.current_session_state = session.state | ||
else: | ||
return super(PosConfig, self)._compute_current_session() | ||
|
||
def _action_to_open_ui(self): | ||
res = super(PosConfig, self)._action_to_open_ui() | ||
|
||
# get current session, raise error if there is a previous session not closed | ||
session = self.current_session_id | ||
not_closed_sesions = session.search( | ||
[ | ||
("config_id", "=", session.config_id.id), | ||
("state", "!=", "closed"), | ||
("start_at", "<", session.start_at), | ||
] | ||
) | ||
if not_closed_sesions: | ||
raise ValidationError( | ||
_( | ||
"You cannot open the current session because there is another \ | ||
previous session that is not closed." | ||
) | ||
) | ||
if res.get("url"): | ||
res["url"] += "&session_id=%s" % session.id | ||
return res |
Oops, something went wrong.