From cdeb65ae35d885dfc1428e44af21105cfaea7efa Mon Sep 17 00:00:00 2001 From: Robin Heinz Date: Thu, 18 Jul 2019 13:34:39 +0000 Subject: [PATCH] [IMP] point_of_sale: difference amount authorized on POS config You can currently set a difference amount authorised in a cash journal when a pos session is closed. This feature, allow a POS user to validate a POS session having a difference between what you are supposed to have in your cashbox and what you are really have. If the difference is too big, you have to be POS manager to close the session. We've improved the feature: First we've moved the difference limit from the journal on POS config and not on the journal as it is more a way that the POS is used than an accounting configuration. We've also added a wizard to warn a pos manager that the difference is too big, because before the manager could always validate a session without being warned that there can be a problem. TASK-ID: 1934784 --- .../point_of_sale/models/account_journal.py | 4 -- addons/point_of_sale/models/pos_config.py | 4 ++ addons/point_of_sale/models/pos_session.py | 63 ++++++++++++++----- .../point_of_sale/views/pos_config_view.xml | 4 ++ .../point_of_sale/views/pos_session_view.xml | 18 ++++++ 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/addons/point_of_sale/models/account_journal.py b/addons/point_of_sale/models/account_journal.py index e6e0898013c..dfb20ef43db 100644 --- a/addons/point_of_sale/models/account_journal.py +++ b/addons/point_of_sale/models/account_journal.py @@ -9,10 +9,6 @@ class AccountJournal(models.Model): journal_user = fields.Boolean('Use in Point of Sale', help="Check this box if this journal define a payment method that can be used in a point of sale.") - amount_authorized_diff = fields.Float('Amount Authorized Difference', - help="This field depicts the maximum difference allowed between the ending balance and the theoretical cash when " - "closing a session, for non-POS managers. If this maximum is reached, the user will have an error message at " - "the closing of his session saying that he needs to contact his manager.") @api.model def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 5ba9cd31983..e95e14410d4 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -201,6 +201,10 @@ class PosConfig(models.Model): is_posbox = fields.Boolean("PosBox") is_header_or_footer = fields.Boolean("Header & Footer") module_pos_hr = fields.Boolean(help="Show employee login screen") + amount_authorized_diff = fields.Float('Amount Authorized Difference', + help="This field depicts the maximum difference allowed between the ending balance and the theoretical cash when " + "closing a session, for non-POS managers. If this maximum is reached, the user will have an error message at " + "the closing of his session saying that he needs to contact his manager.") def _compute_is_installed_account_accountant(self): account_accountant = self.env['ir.module.module'].sudo().search([('name', '=', 'account_accountant'), ('state', '=', 'installed')]) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index f7fcf871125..5326205bd5c 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -277,23 +277,18 @@ class PosSession(models.Model): def action_pos_session_validate(self): self._check_pos_session_balance() - self.action_pos_session_close() + return self.action_pos_session_close() - def action_pos_session_close(self): - # Close CashBox - for session in self: - company_id = session.config_id.company_id.id - ctx = dict(self.env.context, force_company=company_id, company_id=company_id, default_partner_type='customer') - ctx_notrack = dict(ctx, mail_notrack=True) - for st in session.statement_ids: - if abs(st.difference) > st.journal_id.amount_authorized_diff: - # The pos manager can close statements with maximums. - if not self.user_has_groups("point_of_sale.group_pos_manager"): - raise UserError(_("Your ending balance is too different from the theoretical cash closing (%.2f), the maximum allowed is: %.2f. You can contact your manager to force it.") % (st.difference, st.journal_id.amount_authorized_diff)) - if (st.journal_id.type not in ['bank', 'cash']): - raise UserError(_("The journal type for your payment method should be bank or cash.")) - st.with_context(ctx_notrack).sudo().button_confirm_bank() - session.activity_unlink(['point_of_sale.mail_activity_old_session']) + def _validate_session(self): + self.ensure_one() + company_id = self.config_id.company_id.id + ctx = dict(self.env.context, force_company=company_id, company_id=company_id, default_partner_type='customer') + ctx_notrack = dict(ctx, mail_notrack=True) + for st in self.statement_ids: + if (st.journal_id.type not in ['bank', 'cash']): + raise UserError(_("The journal type for your payment method should be bank or cash.")) + st.with_context(ctx_notrack).sudo().button_confirm_bank() + self.activity_unlink(['point_of_sale.mail_activity_old_session']) self.with_context(ctx)._confirm_orders() self.write({'state': 'closed'}) return { @@ -303,6 +298,17 @@ class PosSession(models.Model): 'params': {'menu_id': self.env.ref('point_of_sale.menu_point_root').id}, } + def action_pos_session_close(self): + # Close CashBox + for st in self.statement_ids: + if any(abs(st.difference) > self.config_id.amount_authorized_diff for st in self.statement_ids): + if not self.user_has_groups("point_of_sale.group_pos_manager"): + raise UserError(_("Your ending balance is too different from the theoretical cash closing (%.2f), the maximum allowed is: %.2f. You can contact your manager to force it.") % (st.difference, self.config_id.amount_authorized_diff)) + else: + return self._warning_balance_closing() + else: + self._validate_session() + def open_frontend_cb(self): if not self.ids: return {} @@ -343,6 +349,23 @@ class PosSession(models.Model): user_id=session.user_id.id, note=_("Your PoS Session is open since ") + fields.Date.to_string(session.start_at) + _(", we advise you to close it and to create a new one.")) + def _warning_balance_closing(self): + self.ensure_one() + + context = dict(self._context) + context['session_id'] = self.id + + return { + 'name': _('Balance control'), + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'closing.balance.confirm.wizard', + 'view_id': self.env.ref('point_of_sale.closing_balance_confirm').id, + 'type': 'ir.actions.act_window', + 'context': context, + 'target': 'new' + } + class ProcurementGroup(models.Model): _inherit = 'procurement.group' @@ -352,3 +375,11 @@ class ProcurementGroup(models.Model): self.env['pos.session']._alert_old_session() if use_new_cursor: self.env.cr.commit() + +class ClosingBalanceConfirm(models.TransientModel): + _name = 'closing.balance.confirm.wizard' + _description = 'This wizard is used to display a warning message if the manager wants to close a session with a too high difference between real and expected closing balance' + + def confirm_closing_balance(self): + current_session = self.env['pos.session'].browse(self._context['session_id']) + current_session._validate_session() diff --git a/addons/point_of_sale/views/pos_config_view.xml b/addons/point_of_sale/views/pos_config_view.xml index fcfdb6ef42b..5bd22307294 100644 --- a/addons/point_of_sale/views/pos_config_view.xml +++ b/addons/point_of_sale/views/pos_config_view.xml @@ -345,6 +345,10 @@ +
+
diff --git a/addons/point_of_sale/views/pos_session_view.xml b/addons/point_of_sale/views/pos_session_view.xml index 297a0f093e7..e2998a102ad 100644 --- a/addons/point_of_sale/views/pos_session_view.xml +++ b/addons/point_of_sale/views/pos_session_view.xml @@ -214,6 +214,24 @@ 0 + + + Confirming balance closing + closing.balance.confirm.wizard + form + +
+ + There is a difference between the expected and actual closing in cash. Are you sure you want to close the session and post the accounting entries? + + +
+
+
+