This question has been flagged
3 Replies
30054 Views

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

 

Avatar
Discard

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

hi sir,
how about view inherit?
<?xml version="1.0"?>
<xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="after">
<field name="purchase_price" groups="base.group_user"/>
</xpath>

i try put required="1" , also try your method position="attributes"> <attribute name="required">True</attribute>, not work

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