Skip to content

[FIX] sale_operating_unit_sequence: resolve operating unit from its d… - #864

Merged
OCA-git-bot merged 1 commit into
OCA:16.0from
AmetrasIntelligence:16.0-fix-sale_operating_unit_sequence-ou-default-when-absent
Jul 27, 2026
Merged

[FIX] sale_operating_unit_sequence: resolve operating unit from its d…#864
OCA-git-bot merged 1 commit into
OCA:16.0from
AmetrasIntelligence:16.0-fix-sale_operating_unit_sequence-ou-default-when-absent

Conversation

@baguenth

Copy link
Copy Markdown
Member

…efault when absent from create vals

operating_unit_id is hidden in the view for users without the Multiple Operating Units permission, so the client never submits it and it is absent from vals on create. The same is true for any programmatic/API create that omits it. _update_sale_order_name only looked at vals.get("operating_unit_id"), so in both cases it silently did nothing and the operating unit's sale sequence was never applied, even though the record still received that operating unit via its field default a moment later (in base create(), which merges defaults after this hook runs).

Add _get_sequence_operating_unit_id(), which falls back to self.default_get(["operating_unit_id"]) when vals has no operating unit, so the sequence is generated consistently for UI and backend/API creates.

@OCA-git-bot OCA-git-bot added series:16.0 mod:sale_operating_unit_sequence Module sale_operating_unit_sequence labels Jul 24, 2026
@baguenth

Copy link
Copy Markdown
Member Author

Hey @AaronHForgeFlow ,

kindly asking for a review :)

@AaronHForgeFlow AaronHForgeFlow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM just some suggestions

Comment on lines +31 to +35
operating_unit_id = vals.get("operating_unit_id")
if not operating_unit_id:
operating_unit_id = self.default_get(["operating_unit_id"]).get(
"operating_unit_id"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok to cover the case when OU is explicitly False?

Suggested change
operating_unit_id = vals.get("operating_unit_id")
if not operating_unit_id:
operating_unit_id = self.default_get(["operating_unit_id"]).get(
"operating_unit_id"
)
if "operating_unit_id" in vals:
operating_unit_id = vals["operating_unit_id"]
else:
operating_unit_id = self.default_get(["operating_unit_id"]).get(
"operating_unit_id"
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok to cover the case when OU is explicitly False?

Important point actually. Good catch :)


@api.model
def _get_sequence_operating_unit_id(self, vals):
"""Resolve the operating unit to use for sequence generation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you summarize this a bit? it is too much explanation for so little code

user.has_group("operating_unit.group_multi_operating_unit"),
"Test user must not have the Multiple Operating Units permission",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

avoid empty lines within methods

}
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as above

…efault when absent from create vals

operating_unit_id is hidden in the view for users without the Multiple
Operating Units permission, so the client never submits it and it is
absent from vals on create. The same is true for any programmatic/API
create that omits it. _update_sale_order_name only looked at
vals.get("operating_unit_id"), so in both cases it silently did nothing
and the operating unit's sale sequence was never applied, even though the
record still received that operating unit via its field default a moment
later (in base create(), which merges defaults after this hook runs).

Add _get_sequence_operating_unit_id(), which falls back to
self.default_get(["operating_unit_id"]) when vals has no operating unit,
so the sequence is generated consistently for UI and backend/API creates.
@baguenth
baguenth force-pushed the 16.0-fix-sale_operating_unit_sequence-ou-default-when-absent branch from c7b8bd1 to 5c519d8 Compare July 24, 2026 16:23
@baguenth

Copy link
Copy Markdown
Member Author

LGTM just some suggestions

Thank you for the review :) Updated the code as per your suggestions.

@baguenth

Copy link
Copy Markdown
Member Author

@AaronHForgeFlow Can we integrate?

@AaronHForgeFlow

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-864-by-AaronHForgeFlow-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 90ea5ea into OCA:16.0 Jul 27, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 6670b00. Thanks a lot for contributing to OCA. ❤️

@baguenth
baguenth deleted the 16.0-fix-sale_operating_unit_sequence-ou-default-when-absent branch July 27, 2026 15:40
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.

6 participants