I am working with Odoo v17. I had extended the account.move model to include the 'serie' field
class AccountMove(models.Model): _inherit = "account.move" serie = fields.Selection([ ('a', 'A'), ('e', 'E'), ('f', 'F'), ('g', 'G'), ('i', 'I'), ('cp', 'CP'), ], string='Serie', required=True, default='a')
The code was on production and several invoices where created. Now it is necesary to delete some options of the field. Options, 'e', 'f', 'g' are not going to be available anymore. But just remove those options from the field would cause that an Error would raise when accessing a previously created invoice with a serie 'e', 'f', or 'g'. So I desiided to keep the fields definition as it is, but modify the widget to show only options 'a', 'i', 'cp'. with the following code i was able to achieve that only the options 'a', 'i', 'cp' where shown for the series field. But when i try to open an invoice previously created with series= 'e', 'f', 'g', it shows an error. This is the code:
/** @odoo-module **/ import {registry} from "@web/core/registry"; import { SelectionField, selectionField, } from "@web/views/fields/selection/selection_field"; export class FilteredSerieSelection extends SelectionField { get availableOptions() { return ['a','i','cp']; } /** Override **/ get options() { const availableOptions = this.availableOptions; return super.options.filter((x) => availableOptions.includes(x[0])); } } registry.category("fields").add("custom_serie_select", { ...selectionField, component: FilteredSerieSelection, });
In the view:
<?xml version="1.0" encoding="utf-8" ?> <odoo> <record id="account_move_viixoo_form_inherited" model="ir.ui.view"> <field name="name">account.move.viixoo.form.inherit</field> <field name="model">account.move</field> <field name="inherit_id" ref="account.view_move_form" /> <field name="arch" type="xml"> <field name="l10n_mx_edi_usage" position="after"> <field name="serie" widget="custom_serie_select" required="move_type == 'out_invoice'" invisible="move_type != 'out_invoice'" readonly="id != False and name != '/'"/> </field> </field> </record> </odoo>
This is the error shown:
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property) OwlError@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:684:1 handleError@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:916:101 handleError@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:1542:29 _render@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:941:19 render@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:939:6 initiateRender@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:1007:47 Caused by: TypeError: this.options.find(...) is undefined get string@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:8386:224 template@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js line 1500 > Function:15:18 _render@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:940:96 render@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:939:6 initiateRender@http://127.0.0.1:8069/web/assets/a3292ec/web.assets_web.min.js:1007:47
When creating a new invoice, the desired options are shown correctly without error.
I need to be able to shown only those options, but for the previously
created invoices it should show the series 'e', 'f', 'g' without error.