From ceb072dfe1dee77ded191b78b77a9605b38c583d Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Mon, 28 Oct 2024 12:52:23 +0100 Subject: [PATCH] [IMP] sale_planner_calendar: New option to only update partner user_id if new_start is empty TT51461 --- .../tests/test_sale_planner_calendar.py | 4 ++++ .../wizard/sale_planner_calendar_reassign.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sale_planner_calendar/tests/test_sale_planner_calendar.py b/sale_planner_calendar/tests/test_sale_planner_calendar.py index 260c62b7bd7..5f27b89ac1a 100644 --- a/sale_planner_calendar/tests/test_sale_planner_calendar.py +++ b/sale_planner_calendar/tests/test_sale_planner_calendar.py @@ -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 @@ -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() @@ -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() diff --git a/sale_planner_calendar/wizard/sale_planner_calendar_reassign.py b/sale_planner_calendar/wizard/sale_planner_calendar_reassign.py index 4ca73c14a02..505c8fda92e 100644 --- a/sale_planner_calendar/wizard/sale_planner_calendar_reassign.py +++ b/sale_planner_calendar/wizard/sale_planner_calendar_reassign.py @@ -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() @@ -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( @@ -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()