Skip to content
Permalink
Browse files

[IMP] point_of_sale: warn when session too long

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...
switch87 committed Dec 3, 2018
1 parent 5028507 commit fd644b9768934e1708219b82219ee33372f5b946
Showing with 36 additions and 0 deletions.
  1. +24 −0 addons/point_of_sale/models/pos_session.py
  2. +12 −0 addons/point_of_sale/views/pos_session_view.xml
@@ -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

@@ -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
@@ -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 {
@@ -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()
@@ -125,6 +125,9 @@
</tree>
</field>
</sheet>
<div class="oe_chatter">
<field name="activity_ids" widget="mail_activity"/>
</div>
</form>
</field>
</record>
@@ -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"

0 comments on commit fd644b9

Please sign in to comment.
You can’t perform that action at this time.