Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] new module pos_cash_control_multiple_config to handle correctly cash control in a multi point of sale context #569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions pos_cash_control_multiple_config/README.rst
@@ -0,0 +1,8 @@
=======================================
Point Of Sale - Correct Opening Balance
=======================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1 change: 1 addition & 0 deletions pos_cash_control_multiple_config/__init__.py
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions pos_cash_control_multiple_config/__manifest__.py
@@ -0,0 +1,18 @@
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Point Of Sale - Correct Opening Balance",
"summary": "Handle correctly opening balance in a multi point of sale"
" context with Cash control enabled.",
"version": "12.0.1.0.1",
"category": "Point of Sale",
"author": "GRAP, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": [
"point_of_sale",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions pos_cash_control_multiple_config/models/__init__.py
@@ -0,0 +1,2 @@
from . import account_bank_statement
from . import pos_session
31 changes: 31 additions & 0 deletions pos_cash_control_multiple_config/models/account_bank_statement.py
@@ -0,0 +1,31 @@
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class AccountBankStatement(models.Model):
_inherit = "account.bank.statement"

@api.multi
def _get_opening_balance(self, journal_id):
PosSession = self.env["pos.session"]
pos_config_id = self.env.context.get("pos_config_id")
if pos_config_id:
sessions = PosSession.search(
[('config_id', '=', pos_config_id)],
order="start_at desc", limit=1)
if not sessions:
# it is the first time the pos config is opened.
# returning 0
return 0
else:
last_valid_statement = False
for old_statement in sessions.mapped('statement_ids'):
if old_statement.journal_id.id == journal_id:
last_valid_statement = old_statement
if last_valid_statement:
return last_valid_statement.balance_end_real

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also remove this extra line.

return super()._get_opening_balance(journal_id)
16 changes: 16 additions & 0 deletions pos_cash_control_multiple_config/models/pos_session.py
@@ -0,0 +1,16 @@
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class PosSession(models.Model):
_inherit = "pos.session"

@api.model
def create(self, values):
pos_config_id = values.get('config_id')\
or self.env.context.get('default_config_id')
return super(PosSession, self.with_context(
pos_config_id=pos_config_id)).create(values)
1 change: 1 addition & 0 deletions pos_cash_control_multiple_config/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
12 changes: 12 additions & 0 deletions pos_cash_control_multiple_config/readme/DESCRIPTION.rst
@@ -0,0 +1,12 @@
This module extends the functionality of the point of sale fixing
cash control in a multi pos config context.

By default, in Odoo, if we have two Point of Sale (``pos.config``) with cash control
enabled on each Point of sale, the opening balance will be bad, when opening many
session.

This module fixes that bug.

Ref :

https://github.com/odoo/odoo/issues/62147