Help

2

Set existing field required. What is right way?

Avatar
vital_zaq6

For example i have

'property_account_position': fields.property(
            'account.fiscal.position',
            type='many2one',
            relation='account.fiscal.position',
            string="Fiscal Position",
            view_load=True,
            help="The fiscal position will determine taxes and accounts used for the partner.",
        )

1 way :

inherit model and redefine field

'property_account_position': fields.property(
            'account.fiscal.position',
            type='many2one',
            relation='account.fiscal.position',
            string="Fiscal Position",
            view_load=True,
            help="The fiscal position will determine taxes and accounts used for the partner.",

required=true,

        )

but i think it's not good redefine field just to set it required or set new caption

2 way:

set required in xml

<field name="property_account_position" position="replace">

<field name="property_account_position" required="true"/>

</field>

but in this way i need to set it all xml views

---------------

May be here is a good way just set some field option ?

something like field_name['option_name'] = new_value

Avatar
Discard
2 Answers
3
Best Answer

You can set it in xml by inheriting the original view and setting the required attribute of a field.

<field name="property_account_position" position="attributes">

    <attribute name="required">True</attribute>

</field>

 

1 Comment
Avatar
Discard
Avatar
Nikhil Krishnan
-

if we inheriting this original view, is necessary use the <xpath>?

2
Best Answer
  • Go into the view in developper mode.

  • In the debug menu, select edit view

  • In the dialog, select "Inherited views" and click Add new. This creates a new inherited view in the database, so you don't need to develope a whole module.

  • Give it a name you'll recognize. Could be anything but for uniformity, I suggest you follow what other views do.

  • Set the inheritance mode to Extension View

  • In the architecture field, enter what you'd normally enter in a XML view file. See below for an example:

<data>

<field name="street" position="attributes">

  <attribute name="required">True</attribute>

</field>

</data>

Avatar
Discard