Skip to content

Commit

Permalink
[IMP] crm_timesheet: Tell the user no running line was found
Browse files Browse the repository at this point in the history
Imagine this scenario:

1. In tab 1 of the browser, you have opened lead 1.
2. In tab 2 of the browser, you have opened lead 2.
3. You go to tab 1 and start a timer.
4. Work, work, work...
5. You go to tab 2 and start a timer, stopping that of lead 1.
6. Work, work, work...
7. You go to tab 1 and see that timer as running (it is not, but you didn't refresh). You hit stop.

Before this commit, it just seemed like the timer was actually stopped. What did happen behind the scenes is that your view was refreshed, but no timer was touched fortunately.

After this commit, you get a message telling you that there's no timer to stop and that your browser is most likely out of sync. This mimics the behavior previously found when doing the same, but directly in the AAL. Now it's present in leads too.
  • Loading branch information
yajo authored and fshah-initos committed Mar 31, 2021
1 parent b4419f6 commit a5fd0ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crm_timesheet/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import UserError


class CrmLead(models.Model):
Expand Down Expand Up @@ -68,4 +69,9 @@ def button_end_work(self):
running_lines = self.env["account.analytic.line"].search(
self._timesheet_running_domain(),
)
if not running_lines:
raise UserError(
_("No running timer found in lead/opportunity %s. "
"Refresh the page and check again.") % self.display_name,
)
return running_lines.button_end_work()
4 changes: 4 additions & 0 deletions crm_timesheet/tests/test_account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import date, datetime, timedelta
from odoo import exceptions
from odoo.tests.common import SavepointCase


Expand Down Expand Up @@ -73,6 +74,9 @@ def test_lead_time_control_flow(self):
# Running line found, stop the timer
self.assertEqual(self.lead.show_time_control, "stop")
self.lead.button_end_work()
# No more running lines, cannot stop again
with self.assertRaises(exceptions.UserError):
self.lead.button_end_work()
# All lines stopped, start new one
self.lead.invalidate_cache()
self.assertEqual(self.lead.show_time_control, "start")
Expand Down

0 comments on commit a5fd0ac

Please sign in to comment.