コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
2049 ビュー


Good morning,

I need your assistance to make entering the postal code in the website form for invoicing adress and delivery adress,  optional instead of mandatory,

Thanks for your help,



アバター
破棄
最善の回答

Whether the zip field is mandatory or not is defined in the res_country record. This model contains a 'zip_required' field and 'state_required' field for each country. The website_sale controller (i.e., responsible for the checkout), checks for all required fields:

def _get_mandatory_fields_billing(self, country_id=False):
    req = ["name", "email", "street", "city", "country_id"]
    if country_id:
        country = request.env['res.country'].browse(country_id)
        if country.state_required:
            req += ['state_id']
        if country.zip_required:
            req += ['zip']
    return req

def _get_mandatory_fields_shipping(self, country_id=False):
    req = ["name", "street", "city", "country_id"]
    if country_id:
        country = request.env['res.country'].browse(country_id)
        if country.state_required:
            req += ['state_id']
        if country.zip_required:
            req += ['zip']
    return req

Source: https://github.com/odoo/odoo/blob/15.0/addons/website_sale/controllers/main.py (lines: 685-703).

So you could manually change this value for the res_country record. 


Please note that in the template view there is also a hidden field that allows you to set required fields (https://www.odoo.com/forum/help-1/change-required-field-in-checkout-form-in-ecommerce-180454):​

<input type="hidden" name="field_required" t-att-value="'phone,name'" />

I hope this helps!

アバター
破棄
最善の回答

Hi,

By default in Odoo 16, The zip code is optional.


The ones marked in red are the required fields. If you are having the zip code as required, it may be because you have customised it, or some customised module you are using is making it required.


Hope it helps

アバター
破棄
最善の回答

Hello, Odoo by default makes these forms optional, But the website administrators can make it required via editing the forum.

アバター
破棄
著作者

Hello,
I think it's the opposite on odoo 16, because by default the zip code is mandatory, and so I want to make it optional, thank you for your answer!