Skip to content

Commit

Permalink
[IMP] sale_planner_calendar: New option to only update partner user_i…
Browse files Browse the repository at this point in the history
…d if new_start is empty

TT51461
  • Loading branch information
carlosdauden committed Oct 29, 2024
1 parent 5a00994 commit ceb072d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions sale_planner_calendar/tests/test_sale_planner_calendar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2021 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import date

from freezegun import freeze_time

from odoo.exceptions import AccessError
Expand Down Expand Up @@ -234,6 +236,7 @@ def test_summary_and_event_today(self):
def test_reassign_wizard(self):
wiz_form = Form(self.env["sale.planner.calendar.reassign.wiz"])
wiz_form.user_id = self.commercial_user_1
wiz_form.new_start = date.today()
record = wiz_form.save()
# Recover all planned event lines for commercial user 1
record.action_get_lines()
Expand Down Expand Up @@ -274,6 +277,7 @@ def test_reassign_wizard_subscriptions(self):

wiz_form = Form(self.env["sale.planner.calendar.reassign.wiz"])
wiz_form.user_id = self.commercial_user_1
wiz_form.new_start = date.today()
record = wiz_form.save()
# Recover all planned event lines for commercial user 1
record.action_get_lines()
Expand Down
13 changes: 8 additions & 5 deletions sale_planner_calendar/wizard/sale_planner_calendar_reassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SalePlannerCalendarReassignWiz(models.TransientModel):
string="New salesperson",
domain="[('share','=',False)]",
)
new_start = fields.Date(default=fields.Date.today, required=True)
new_start = fields.Date()
new_end = fields.Date()
assign_new_salesperson_to_partner = fields.Boolean()
unsuscribe_old_salesperson = fields.Boolean()
Expand Down Expand Up @@ -106,6 +106,13 @@ def apply(self):
for line in self.line_ids:
if not line.new_user_id:
continue
if self.assign_new_salesperson_to_partner:
line.partner_id.with_context(
skip_sale_planner_check=True
).user_id = line.new_user_id
# If new_end is empty only update partner user_id
if not self.new_start:
continue
old_event = line.calendar_event_id
recurrence_events = old_event.recurrence_id.calendar_event_ids
new_base_event_start = recurrence_events.filtered(
Expand Down Expand Up @@ -157,10 +164,6 @@ def apply(self):
if self.unsuscribe_old_salesperson and not self.new_end:
old_event_vals["unsubscribe_date"] = self.new_start
old_event.write(old_event_vals)
if self.assign_new_salesperson_to_partner:
line.partner_id.with_context(
skip_sale_planner_check=True
).user_id = line.new_user_id
line.update_subscriptions()
self.action_get_lines()

Expand Down

0 comments on commit ceb072d

Please sign in to comment.