I tried removing it from the file account-> models-> account_invoice.py
.
But it is showing error. So, is there any other way I can remove it from python file. How can I customize predefined model in odoo?
Definitely agree with Michele Zacceddu having the correct answer where you should be overriding the model, and updating properties on that field such as required
or readonly
, especially for important fields such as account_id
.
But you do have the option to remove fields all together if there happens to be a scenario where you absolutely need it. You will want to make sure that you handle removing all references in the xml views and python methods to the field you are about to delete.
<record>
...
<field name="arch" type="xml">
<field name="account_id" position="replace"/>
</field>
</record>
class Invoice(models.Model):
_inherit = 'account.invoice'
def _method(self):
# override methods that reference or use the fields we
# are about to delete so that we don't break core
delattr(odoo.addons.account.models.account_invoice.AccountInvoice, 'account_id')