From 45441f6fbba3c98eadbdbec10fd4bd2c8d86bc01 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Tue, 22 Jun 2021 15:47:21 +0000 Subject: [PATCH] [FIX] point_of_sale: always post bank statement of cash The amount of cash present in the POS may be incorrect To reproduce the error: 1. In POS settings, enable "Advanced Cash Control" 2. Start a POS session 3. Make an order of 70$, payment in cash 4. Close the POS session (correctly set the closing cash) 5. Start a POS session, close it (correctly set the closing cash) Error: Back to kanban view, the information about the POS are incorrect: the cash balance is equal to zero, it should be $70 The value of the cash balance is computed in `_compute_last_session`: https://github.com/odoo/odoo/blob/5ea1d31df9041ca7b25fbea6178e798e62bebca0/addons/point_of_sale/models/pos_config.py#L276-L291 This method gets the last session and extracts the information. However, in the above case, there were no sales during the last session (step 5). In such situation, the bank statement of cash is deleted. As a result, in `_compute_last_session`, `last_session_closing_cashbox` will be defined to `False`. This is the reason why the cash balance will be equal to 0 The deletion of `cash_register` has been introduced in case the user closes a session that does not contain any SO. This fix suggests keeping such a bank statement and automatically posting it. Linked to OPW-2507394 closes odoo/odoo#72663 X-original-commit: dae9ba62d98d4238600ccd637dd5e879f1cac903 Signed-off-by: pimodoo Signed-off-by: Adrien Widart --- addons/point_of_sale/models/pos_session.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index aa83a5dab1d..292671e25f1 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -334,10 +334,10 @@ class PosSession(models.Model): self.env['pos.order'].search([('session_id', '=', self.id), ('state', '=', 'paid')]).write({'state': 'done'}) else: self.move_id.unlink() - elif not self.cash_register_id.difference: - cash_register = self.cash_register_id.sudo() if sudo else self.cash_register_id - cash_register.pos_session_id = False - cash_register.unlink() + else: + statement = self.cash_register_id + statement.button_post() + statement.button_validate() self.write({'state': 'closed'}) return { 'type': 'ir.actions.client',