Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
2058 มุมมอง


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!