[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
This commit is contained in:
Robin Heinz
2019-07-23 07:41:20 +00:00
committed by Pierre Masereel
parent 2eb1cde534
commit cdeb65ae35
5 changed files with 73 additions and 20 deletions
@@ -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):
@@ -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')])
+47 -16
View File
@@ -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()
@@ -345,6 +345,10 @@
<field name="default_cashbox_id" domain="[('is_a_template', '=', True)]" context="{'default_is_a_template': True}"/>
</div>
</div>
<div attrs="{'invisible': [('cash_control', '=', False)]}">
<label for="amount_authorized_diff" string="Authorized Difference" class="font-weight-normal"/>
<field name="amount_authorized_diff"/>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
@@ -214,6 +214,24 @@
<field name="delay_count">0</field>
</record>
<record model="ir.ui.view" id="closing_balance_confirm">
<field name="name">Confirming balance closing</field>
<field name="model">closing.balance.confirm.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<group>
<span>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?</span>
</group>
<footer>
<button name="confirm_closing_balance" string="Confirm" type="object" class="oe_highlight, btn-primary" />
<button string="Discard" special="cancel" class="oe_highlight, btn-secondary"/>
</footer>
</form>
</field>
</record>
<menuitem
id="menu_pos_session_all"
parent="menu_point_of_sale"