Customer invoice validation fails in accounts receivable due to custom JavaScript widget error

We’re experiencing a critical issue with invoice validation in our AR module after deploying a custom JavaScript widget for client-side validation. When users try to post customer invoices, they receive a validation error and the invoice remains in draft status.

The custom widget was developed to enforce additional validation rules for specific customer categories before allowing invoice posting. However, since deployment last week, approximately 30% of invoices are failing validation with the following console error:

Uncaught TypeError: Cannot read property 'partner_category_ids' of undefined
    at Widget._validateCustomerCategory (invoice_validation.js:47)
    at Widget._onValidateInvoice (invoice_validation.js:89)
    at Class.trigger (web.core.js:1234)

The widget code attempts to access partner category information during the validation phase, but it seems the field data isn’t available in certain scenarios. This is blocking our month-end closing process. Has anyone encountered similar issues with custom client-side validation in Odoo 14’s AR module? What’s the proper way to ensure field data is loaded before validation executes?

Check your widget’s dependencies array. You probably need to explicitly declare dependency on the partner_id field and its related categories. Without proper dependency declaration, Odoo’s form view won’t know to load that relational data before your widget initializes.

The 30% failure rate suggests this happens with specific invoice types or customer records. I’d investigate whether certain partner records have incomplete category assignments or if the issue only occurs with invoices created through specific workflows (like imports or API calls versus manual creation). This could point to a data consistency problem rather than purely a widget timing issue.

Classic async data loading issue. Your widget is trying to access relational field data before it’s fully loaded into the form view. You need to ensure the partner_category_ids field is explicitly included in your view definition and loaded before validation runs.

Have you verified that the partner_category_ids field is actually included in the form view’s field list? Sometimes custom validations fail because the field isn’t explicitly declared in the view XML, even if it exists in the model. Add it to your view definition with invisible=‘1’ if you don’t want it displayed but need it for validation logic.

We implemented something similar for invoice validation rules. The key is understanding Odoo’s widget lifecycle. Your validation method is being called too early in the rendering process. You should hook into the _onFieldChanged event instead of trying to validate during form initialization. This ensures all relational data is properly loaded and available in the record’s datapoint. Also consider moving complex validation logic to the server side using Python constraints - it’s more reliable and doesn’t depend on client-side timing issues. Client-side validation should be for UX enhancement only, not business rule enforcement.