Dheeraj Balodia
Dheeraj Balodia

Reputation: 252

How to remove required field `account_id` from a `account.invoice`model in odoo

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?

<code>account.invoice</code> model

<code>Required field</code> in model

Upvotes: 1

Views: 2054

Answers (2)

Holden Rehg
Holden Rehg

Reputation: 927

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')

Upvotes: 6

Michele Zaccheddu
Michele Zaccheddu

Reputation: 519

You can not remove fields. You can remove the required property, but not the field itself. To do that you have to inherit account.invoice model and redefine that field.

Like:

class AccountInherit(models.Model):
    _inherit = 'account.invoice'

    < here define that field, it must be the same as the original but the required property >

Upvotes: 4

Related Questions