Skip to content

Commit

Permalink
[ADD] new module pos_cash_control_multiple_config to handle correctl…
Browse files Browse the repository at this point in the history
…y cash control in a multi point of sale context
  • Loading branch information
legalsylvain committed Nov 23, 2020
1 parent 989462d commit 6a1c148
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pos_cash_control_multiple_config/README.rst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions pos_cash_control_multiple_config/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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": "http://www.grap.coop",
"license": "AGPL-3",
"depends": [
"point_of_sale",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions pos_cash_control_multiple_config/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 self.env.context.get("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

return super()._get_opening_balance(journal_id)
16 changes: 16 additions & 0 deletions pos_cash_control_multiple_config/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
12 changes: 12 additions & 0 deletions pos_cash_control_multiple_config/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6a1c148

Please sign in to comment.