[FIX] point_of_sale: Warning on posted cash register

To reproduce the problem :

1. Install POS and accounting
2. Open a POS session and make a cash payment
3. Go on accounting -> statement of CASH -> click on the POS statement
4. Try to post the statement -> It works
5. Try to close the session -> Only new statements can be posted.

Now, a check is performed at the beginning of the closing process
and display a useful message to the user if a statement is already posted.

OPW-2494806
OPW-2377190
OPW-2448362
OPW-2485830
OPW-2487628

closes odoo/odoo#72806

X-original-commit: 6c0646aa48900933474ee237ab143967e15f4086
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Jérôme Vanhaudenard
2021-06-25 14:57:10 +00:00
parent 94e4756343
commit 162eb35de8
2 changed files with 22 additions and 0 deletions
@@ -4387,6 +4387,20 @@ msgstr ""
msgid "Slash"
msgstr ""
#. module: point_of_sale
#: model:product.product,name:point_of_sale.small_shelf
#: model:product.template,name:point_of_sale.small_shelf_product_template
msgid "Small Shelf"
msgstr ""
#. module: point_of_sale
#: code:addons/point_of_sale/models/pos_session.py:0
#, python-format
msgid ""
"Some Cash Registers are already posted. Please reset them to new in order to close the session.\n"
"Cash Registers: %r"
msgstr ""
#. module: point_of_sale
#. openerp-web
#: code:addons/point_of_sale/static/src/js/Chrome.js:0
@@ -177,6 +177,13 @@ class PosSession(models.Model):
if (company.period_lock_date and start_date <= company.period_lock_date) or (company.fiscalyear_lock_date and start_date <= company.fiscalyear_lock_date):
raise ValidationError(_("You cannot create a session before the accounting lock date."))
def _check_bank_statement_state(self):
for session in self:
closed_statement_ids = session.statement_ids.filtered(lambda x: x.state != "open")
if closed_statement_ids:
raise UserError(_("Some Cash Registers are already posted. Please reset them to new in order to close the session.\n"
"Cash Registers: %r", list(statement.name for statement in closed_statement_ids)))
@api.model
def create(self, values):
config_id = values.get('config_id') or self.env.context.get('default_config_id')
@@ -277,6 +284,7 @@ class PosSession(models.Model):
# Session without cash payment method will not have a cash register.
# However, there could be other payment methods, thus, session still
# needs to be validated.
self._check_bank_statement_state()
if not self.cash_register_id:
return self._validate_session(balancing_account, amount_to_balance)