2

I'm creating a custom module to set 'city' field as mandatory on base.view_partner_form, in Odoo 14.

I have tried

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="required_city_field" model="ir.ui.view">
            <field name="name">required.city.field</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="arch" type="xml">
            <field name="city" position="attributes">
                    <attribute name="required">1</attribute>
            </field>
            </field>
        </record>
    </data>
</odoo>

But it isn't working, no errors, just nothing happening. With others fields as "zip" it works just fine as it should. I'm guessing there is some modification in other class or inheritance, but can't find it.

I have found a similar discussion here, but even trying what I understand of that solution, I can't set city field as mandatory.

Does anyone know how to aproeach this?

3
  • Maybe the field in this particular form is replaced by another form. If that is the case then you need to find which form is inheriting this form and then you set the attribute in that form instead. Commented Oct 25, 2023 at 2:41
  • @holydragon I suspected it at first, but I haven't found that. Do you know any way I can verify if there is another form replacing the field? Commented Oct 25, 2023 at 2:58
  • Use the debugging tool and go to Edit View. There will be a tab named Inherited Views. See if there is any view that is inheriting this. Commented Oct 25, 2023 at 5:44

3 Answers 3

3

The city field is probably replaced in base_address_city module, you can avoid that by setting no_address_format to True in the action's context.

Sign up to request clarification or add additional context in comments.

1 Comment

It works! thank you so much! If anyone else is trying this approach, don't forget to restart the service before installing or updating the module (I always forget).
1

Odoo is postprocessing the address div in the form view(s). It happens on the format.address.mixin here if some conditions are met.

This feature is for allowing country depending address formats. The country of the user's company is used for that. So you probably have set an input view on that country?

Note: that's probably not your problem, but i will let this answer stay to point out the feature ;-)

Comments

0

if your plan is to make city mandatory for partners in the whole app, i suggest you to do it from python like below. this eliminates the issue of other modules overriding your logic.

from odoo import models, fields

class ResPartner(models.Model):
    _inherit = 'res.partner'

    city = fields.Char(required=True)

if you have any questions about this solution please let me know.

1 Comment

A very good suggestion, but "eliminates" isn't appropriate, because other modules can override this change, depending on the module dependency.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.