Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] calendar: Select correct base event when current is archived #149349

Closed
wants to merge 1 commit into from

Conversation

CarlosRoca13
Copy link
Contributor

@CarlosRoca13 CarlosRoca13 commented Jan 15, 2024

When the base event is archived, it continues being the base event of the recurrence, and when trying to change the recurrence of all the events of the recurrence, an error is thrown or some inconsistencies occur.

To test the problem, you can follow these steps:

  1. Create a recurrence of events from a non included day on the recurrence (example: recurrence on tuesday and friday and the start of the recurrence on monday). The first event will be archived automatically.
  2. Open other event of the recurrence.
  3. Modify the recurrence for all events (example: change the weekdays, set just tuesday instead of tuesday and friday)

An error will be thrown.

See next gif:
ERROR

By making these changes, the base event will be updated, as indicated in the _select_new_base_event method, so these inconsistencies will not occur when making the changes.

See next gif:
Correct

cc @Tecnativa TT46742

ping @pedrobaeza @chienandalu


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Jan 15, 2024

@CarlosRoca13 CarlosRoca13 force-pushed the 15.0-FIX-calendar branch 2 times, most recently from f441349 to 8f7b3a1 Compare January 15, 2024 07:46
@C3POdoo C3POdoo requested a review from a team January 15, 2024 07:48
@pedrobaeza
Copy link
Collaborator

Isn't this reproducible when you add the recurrence from a non-included day? Or do you need to manually archive the base event?

@CarlosRoca13
Copy link
Contributor Author

Yes sorry, when a recurring calendar event is created from a day that is not included in the recurrence, it is archived and the recurrence data in that event is lost, but it remains the base event of the recurrence. Therefore, when trying to make changes to the recurrence, the following error is thrown:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 368, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 357, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 921, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 546, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/auto/addons/web/controllers/main.py", line 1324, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/auto/addons/web/controllers/main.py", line 1316, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 469, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 456, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/auto/addons/calendar/models/calendar_event.py", line 502, in write
    self._rewrite_recurrence(values, time_values, recurrence_values)
  File "/opt/odoo/auto/addons/calendar/models/calendar_event.py", line 913, in _rewrite_recurrence
    detached_events = base_event._apply_recurrence_values(new_values)
  File "/opt/odoo/auto/addons/sale_planner_calendar/models/calendar.py", line 51, in _apply_recurrence_values
    return super()._apply_recurrence_values(values, future=future)
  File "/opt/odoo/auto/addons/calendar/models/calendar_event.py", line 809, in _apply_recurrence_values
    return to_update._apply_recurrence()
  File "/opt/odoo/auto/addons/calendar/models/calendar_recurrence.py", line 225, in _apply_recurrence
    ranges = recurrence._range_calculation(event, duration)
  File "/opt/odoo/auto/addons/calendar/models/calendar_recurrence.py", line 421, in _range_calculation
    ranges = set(self._get_ranges(event.start, duration))
  File "/opt/odoo/auto/addons/calendar/models/calendar_recurrence.py", line 435, in _get_ranges
    starts = self._get_occurrences(start)
  File "/opt/odoo/auto/addons/calendar/models/calendar_recurrence.py", line 450, in _get_occurrences
    return self._get_rrule(dtstart=dtstart)
  File "/opt/odoo/auto/addons/calendar/models/calendar_recurrence.py", line 530, in _get_rrule
    freq_to_rrule(freq), **rrule_params
  File "/opt/odoo/auto/addons/calendar/models/calendar_recurrence.py", line 85, in freq_to_rrule
    return SELECT_FREQ_TO_RRULE[freq]
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
KeyError: False

Copy link
Collaborator

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please change the steps to reproduce the problem (both in the main PR message and in the commit message) with the real use case.

addons/calendar/models/calendar_event.py Outdated Show resolved Hide resolved
@CarlosRoca13
Copy link
Contributor Author

Changes done @pedrobaeza

Copy link
Contributor

@arj-odoo arj-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thanks for these changes. Could you add a small test to make sure the issue is not coming back ? It will improve our codebase. Thanks a lot. :-)

@CarlosRoca13
Copy link
Contributor Author

@arj-odoo test added 😄

Comment on lines 699 to 721
class TestUpdateMultiDayWeeklyDayNotIncludedRecurrentEvents(TestRecurrentEvents):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.event = cls.env['calendar.event'].create({
'name': 'Recurrent Event',
'start': datetime(2019, 10, 22, 1, 0),
'stop': datetime(2019, 10, 22, 2, 0),
'recurrency': True,
'rrule_type': 'weekly',
'tue': False,
'wed': True,
'fri': True,
'interval': 1,
'count': 3,
'event_tz': 'Etc/GMT-4',
})
cls.recurrence = cls.env['calendar.recurrence'].search([])
cls.events = cls.recurrence.calendar_event_ids.sorted('start')
# Tuesday datetime(2019, 10, 22, 1, 0)
# Wednesday datetime(2019, 10, 23, 1, 0)
# Friday datetime(2019, 10, 25, 1, 0)
# Wednesday datetime(2019, 10, 30, 1, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding a new test class ? The setup will be heavy for just one single test. You can do everything in the current class. Your test coould be in the class TestUpdateRecurrentEvents. Thanks :-)

Comment on lines +547 to +564
if values.get("active") is False:
recurrences = self.env["calendar.recurrence"].search([
('base_event_id', 'in', self.ids)
])
recurrences._select_new_base_event()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your change is working but I am afraid of the performances with a large amount of events. I hope it won't be too slow and rollback 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR I have used the same philosophy that has been used for the unlink method. So I understand that there will be the same doubt for that method…

recurrences = self.env["calendar.recurrence"].search([
('base_event_id.id', 'in', [e.id for e in self])
])
result = super().unlink()
if recurrences:
recurrences._select_new_base_event()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, the scope is limited to when you archive an event, so the impact is also very limited.

@arj-odoo
Copy link
Contributor

@robodoo r+

@robodoo
Copy link
Contributor

robodoo commented Jan 18, 2024

@CarlosRoca13 @arj-odoo staging failed: ci/runbot on 2cccbdeb2f28e3439cc0669109012d8d471f8b70 (view more at https://runbot.odoo.com/runbot/build/56671293)

@CarlosRoca13
Copy link
Contributor Author

Something has failed when trying to set this changes @arj-odoo

@arj-odoo
Copy link
Contributor

Something has failed when trying to set this changes @arj-odoo

Can you rebase the code? I lost this one in the process, sorry /o\

When the base event is archived, it continues being the base event
of the recurrence, and when trying to change the recurrence of all
the events of the recurrence, an error is thrown or some inconsistencies
occur.

To test the problem, you can follow these steps:

1. Create a recurrence of events from a non included day on the
   recurrence (example: recurrence on tuesday and friday and the start
   of the recurrence on monday). The first event will be archived
   automatically.
2. Open other event of the recurrence.
3. Modify the recurrence for all events (example: change the weekdays,
   set just tuesday instead of tuesday and friday)

An error will be thrown.

By making these changes, the base event will be updated, as
indicated in the _select_new_base_event method, so these
inconsistencies will not occur when making the changes.
@CarlosRoca13
Copy link
Contributor Author

Done @arj-odoo

@arj-odoo
Copy link
Contributor

@robodoo r+

robodoo pushed a commit that referenced this pull request May 15, 2024
When the base event is archived, it continues being the base event
of the recurrence, and when trying to change the recurrence of all
the events of the recurrence, an error is thrown or some inconsistencies
occur.

To test the problem, you can follow these steps:

1. Create a recurrence of events from a non included day on the
   recurrence (example: recurrence on tuesday and friday and the start
   of the recurrence on monday). The first event will be archived
   automatically.
2. Open other event of the recurrence.
3. Modify the recurrence for all events (example: change the weekdays,
   set just tuesday instead of tuesday and friday)

An error will be thrown.

By making these changes, the base event will be updated, as
indicated in the _select_new_base_event method, so these
inconsistencies will not occur when making the changes.

closes #149349

Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
@robodoo robodoo closed this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants