[FIX] sale_operating_unit_sequence: resolve operating unit from its d… - #864
Conversation
|
Hey @AaronHForgeFlow , kindly asking for a review :) |
AaronHForgeFlow
left a comment
There was a problem hiding this comment.
LGTM just some suggestions
| 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" | ||
| ) |
There was a problem hiding this comment.
Ok to cover the case when OU is explicitly False?
| 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" | |
| ) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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", | ||
| ) | ||
|
|
There was a problem hiding this comment.
avoid empty lines within methods
| } | ||
| ) | ||
| ) | ||
|
|
…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.
c7b8bd1 to
5c519d8
Compare
Thank you for the review :) Updated the code as per your suggestions. |
|
@AaronHForgeFlow Can we integrate? |
|
/ocabot merge patch |
|
What a great day to merge this nice PR. Let's do it! |
|
Congratulations, your PR was merged at 6670b00. Thanks a lot for contributing to OCA. ❤️ |
…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.