HOW TO SOLVE THE FOLLOWING?
To prevent inconsistencies in branch/company assignment in Odoo, the system must enforce strict alignment of the branch on all related documents.
Proposed rule
When a source document (e.g. Sales Order) is created, its Branch/Company field becomes the reference branch for all subsequent documents generated from it (Delivery Orders, Invoices, Credit Notes, etc.).
At the time of posting/validation of any follow-up document (e.g. Customer Invoice), the system must:
Check that the Branch/Company on the new document is identical to the branch on the original Sales Order.
Block posting if the branches differ (e.g. Sales Order = Branch A, Invoice = Branch B).
Display a validation error similar to:
“Branch mismatch: The invoice branch must be the same as the branch of the source Sales Order.”
Users may only change the branch on the Sales Order before any downstream document is created; once a dependent document exists, changing the branch on either the source or target document must be disallowed (or cascade consistently, depending on the design decision).
There _is_ a global mechanism – but only for company, not branch
Odoo already has a built-in consistency system at ORM level using:
_check_company_auto = True