Skip to content

Conversation

BernatObrador
Copy link
Contributor

@BernatObrador BernatObrador commented May 28, 2025

Prevent "Expected Singleton" error when applying mass edit actions on FSM Orders.

Issue:
Mass editing multiple FSM Orders was causing a ValueError: Expected singleton due to the incorrect use of self in write, where self was assumed to be a singleton but was actually a recordset.

cc https://github.com/APSL HT02030

@miquelalzanillas @lbarry-apsl @mpascuall @peluko00 @javierobcn @ppyczko please review

@OCA-git-bot
Copy link
Contributor

Hi @max3903, @wolfhall,
some modules you are maintaining are being modified, check this out!

Copy link
Contributor

@peluko00 peluko00 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@lbarry-apsl lbarry-apsl left a comment

Choose a reason for hiding this comment

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

Code reviwed LGTM

Copy link

@mpascuall mpascuall left a comment

Choose a reason for hiding this comment

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

LGTM!

@BernatObrador BernatObrador force-pushed the 15-0-fix-fieldservice branch 2 times, most recently from 41ef1cb to 63f9208 Compare May 28, 2025 12:49
@BernatObrador BernatObrador force-pushed the 15-0-fix-fieldservice branch from 63f9208 to cc6f232 Compare May 28, 2025 13:17
self._calc_scheduled_dates(vals)
for record in self:
if vals.get("stage_id", False) and vals.get("is_button", False):
vals["is_button"] = False
Copy link
Member

Choose a reason for hiding this comment

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

get(x, False) is redundant, as the default result for a missing key is already a falsy value.
Does this if need to be inside the loop? It doesn't make any use of the iterated record.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

I do not change the write logic, just solved an error when you try to mass update records that was throwing an expected singleton error.

I just added for record in self, and change the self._calc_scheduled_dates(vals) for record._calc_scheduled_dates(vals) to avoid that.

If you want, I can do this too, but it wasn't the main goal.

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Copy link
Contributor

@ivantodorovich ivantodorovich left a comment

Choose a reason for hiding this comment

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

Hello @BernatObrador .

I think this will not work correctly.

The issue you're trying to solve is that _calc_scheduled_dates is sometimes reading a record field (e.g.: self.scheduled_duration), and of course that doesn't work when self is a recordset.

However, _calc_scheduled_dates is modifying the vals dictionary. Meaning each record could potentially have a different dictionary.

IMO the solution is to get rid of _calc_scheduled_dates, and solve with computed fields and/or inverses.

Maybe even some onchanges.

I see 3 things that this method is doing:

  • Computing the scheduled_duration when both scheduled_date_start and scheduled_date_end are set --> solution: make scheduled_duration computed
  • Modifying the scheduled_date_start when only scheduled_date_end is changed, to respect the duration (shift the interval) --> IMO this behavior can be dropped, as we don't see this thing in other modules like the core calendar for example, it doesn't make sense from a UX point of view IMO
  • Modifying the scheduled_date_end when scheduled_duration is modified and scheduled_date_start is set, to respect the duration (shift the interval) --> IMO this behavior can be dropped, as we don't see this thing in other modules like the core calendar for example, it doesn't make sense from a UX point of view IMO

For the last two, besides dropping this behavior, I would suggest switching the form widget to use daterange, and so align the UX to other Odoo core modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants