Set 'city' field as mandatory base.view_partner_form (Odoo 14)

89 views Asked by At

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

There are 3 answers

1
Kenly On BEST ANSWER

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.

1
Amin Dehghani On

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.

0
CZoellner On

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