Skip to content

Commit

Permalink
[IMP] point_of_sale: warn when session too long
Browse files Browse the repository at this point in the history
Log a next activity on the PoS.Session if open since more than a week
(responsible = pos user)
"Your PoS Session is open since xx/xx/xx, we advise you to close it and
to create a new one."
  • Loading branch information
Gert Pellin committed Feb 22, 2019
1 parent 5028507 commit fd644b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions addons/point_of_sale/models/pos_session.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from datetime import timedelta
from odoo import api, fields, models, SUPERUSER_ID, _
from odoo.exceptions import UserError, ValidationError

Expand All @@ -9,6 +10,7 @@ class PosSession(models.Model):
_name = 'pos.session'
_order = 'id desc'
_description = 'Point of Sale Session'
_inherit = ['mail.thread', 'mail.activity.mixin']

POS_SESSION_STATE = [
('opening_control', 'Opening Control'), # method action_pos_session_open
Expand Down Expand Up @@ -279,6 +281,7 @@ def action_pos_session_close(self):
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).sudo().button_confirm_bank()
session.activity_unlink(['point_of_sale.mail_activity_old_session'])
self.with_context(ctx)._confirm_orders()
self.write({'state': 'closed'})
return {
Expand Down Expand Up @@ -330,3 +333,24 @@ def open_cashbox(self):
action['res_id'] = cashbox_id

return action

@api.model
def _alert_old_session(self):
# If the session is open for more then one week,
# log a next activity to close the session.
sessions = self.search([('start_at', '<=', (fields.datetime.now() - timedelta(days=7))), ('state', '!=', 'closed')])
for session in sessions:
if self.env['mail.activity'].search_count([('res_id', '=', session.id), ('res_model', '=', 'pos.session')]) == 0:
session.activity_schedule('point_of_sale.mail_activity_old_session',
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."))

class ProcurementGroup(models.Model):
_inherit = 'procurement.group'

@api.model
def _run_scheduler_tasks(self, use_new_cursor=False, company_id=False):
super(ProcurementGroup, self)._run_scheduler_tasks(use_new_cursor=use_new_cursor, company_id=company_id)
self.env['pos.session']._alert_old_session()
if use_new_cursor:
self.env.cr.commit()
12 changes: 12 additions & 0 deletions addons/point_of_sale/views/pos_session_view.xml
Expand Up @@ -125,6 +125,9 @@
</tree>
</field>
</sheet>
<div class="oe_chatter">
<field name="activity_ids" widget="mail_activity"/>
</div>
</form>
</field>
</record>
Expand Down Expand Up @@ -217,6 +220,15 @@
</field>
</record>

<record id="mail_activity_old_session" model="mail.activity.type">
<field name="name">Session open over 7 days</field>
<field name="summary">note</field>
<field name="category">default</field>
<field name="res_model_id" ref="model_pos_session"/>
<field name="icon">fa-tasks</field>
<field name="delay_count">0</field>
</record>

<menuitem
id="menu_pos_session_all"
parent="menu_point_of_sale"
Expand Down

0 comments on commit fd644b9

Please sign in to comment.