Skip to Content
Menu
This question has been flagged
1 Reply
2520 Views

I am using odoo studio and there is a  very nice address section in the contacts module where the word 'contact' is displayed and then a few address fields underneath to make it into a group of fields, I would like to make the user put in an address on a custom module and I want to know how to make it look similar to the one on the contacts but this module has no relation to the contacts module.

For Example I want to have the fields 'address Line 1', 'address Line 2', 'city', 'zip' etc. but I don't want it to look like completely separate fields, rather I want it to look like a group, something like this:




 

Avatar
Discard

To achieve the same grouped design for address fields in your custom module as seen in the Contacts module, follow these steps:

1. Leverage Odoo Studio (UI Approach)

If you're using Odoo Studio, you can group fields visually to mimic the Contacts module's address section.

  1. Go to Your Custom Module in Studio:
    • Open the module you want to modify in Odoo Studio.
  2. Add a New Group:
    • Drag and drop a Group container to the form view where you want the address section.
  3. Add Fields to the Group:
    • Add fields like Street, Street2, City, ZIP, State, and Country inside the group.
    • Ensure the fields are aligned horizontally (you can adjust this in the group properties).
  4. Customize the Label:
    • Add a Static Text above the group and set it to "Contact" or another label to match the Contacts module.
  5. Apply CSS (Optional):
    • If the design isn’t exactly what you want, you can add custom CSS using the "Custom JavaScript/CSS" section in Odoo Studio (only available in certain editions).

2. Manual XML Customization (Developer Mode)

If Odoo Studio doesn't provide enough flexibility or you're comfortable editing XML, you can directly modify the form view of your custom module.

Example:

Here’s how to create an address-like design:

xmlCopy code<record id="view_custom_module_form" model="ir.ui.view">
    <field name="name">custom.module.form</field>
    <field name="model">custom.module</field>
    <field name="arch" type="xml">
        <form string="Custom Module">
            <sheet>
                <!-- Address Section -->
                <group>
                    <div class="o_address_format">
                        <div>
                            <label>Contact</label>
                        </div>
                        <group>
                            <field name="street" placeholder="Street..." />
                            <field name="street2" placeholder="Street 2..." />
                            <group>
                                <field name="city" placeholder="City..." />
                                <field name="state_id" placeholder="State..." />
                                <field name="zip" placeholder="ZIP..." />
                            </group>
                            <field name="country_id" placeholder="Country..." />
                        </group>
                    </div>
                </group>
            </sheet>
        </form>
    </field>
</record>

3. Use the Address Formatting Style

Odoo's Contacts module uses predefined CSS styles to group address fields. You can apply the same styles to your custom module by adding o_address_format and related CSS classes.

CSS Styling (Optional):

If you want finer control over the appearance, you can add custom CSS.

Example:

xmlCopy code<template id="assets_backend" inherit_id="web.assets_backend" name="Custom Address Styles">
    <xpath expr="." position="inside">
        <style>
            .o_address_format {
                margin-bottom: 10px;
                padding: 10px;
                border: 1px solid #eaeaea;
                border-radius: 5px;
                background-color: #f9f9f9;
            }
            .o_address_format label {
                font-weight: bold;
                margin-bottom: 5px;
                display: block;
            }
        </style>
    </xpath>
</template>

4. Add Country and State Widgets

To enhance the functionality of the fields, use many2one fields for state_id and country_id, referencing the respective models (res.country.state and res.country). This provides dropdowns similar to the Contacts module.

Example:

xmlCopy code<field name="country_id" widget="many2one" options="{'no_create': True}" placeholder="Country..." />
<field name="state_id" widget="many2one" options="{'no_create': True}" placeholder="State..." />

5. Add Placeholders (Optional)

To make the fields look cleaner, you can add placeholders (like "Street...", "City...") as shown in the example XML above. These placeholders guide the user without needing labels for every field.

6. Test and Adjust

  • Once you've implemented the changes, save your modifications and refresh the module.
  • Test the form layout to ensure it looks and functions as expected.

Best Answer
  1. ChatGPT said:
    In Odoo Studio, the "Group" container is not found directly in the fields menu but rather in the form view editor toolbar. Here's how you can locate and use it:

    Steps to Find and Use the "Group" Container in Odoo Studio:

    1. Open Odoo Studio:
      • Navigate to your custom module.
      • Activate the Studio by clicking the "Studio" button in the top-right corner.
    2. Edit the Form View:
      • Select the form view of the model you want to modify.
      • Enter the Edit mode for the form.
    3. Locate the Group Container:
      • In the layout toolbox on the right-hand side, look for the "Group" element.
      • This is usually available under the "Form Elements" or "Structure" section.
    4. Drag and Drop the Group Container:
      • Drag the "Group" element into the form where you want to place the address fields.
    5. Add Fields to the Group:
      • After placing the group, drag the address fields (e.g., Street, City, ZIP) into the group container.
      • Adjust the arrangement of the fields horizontally or vertically as needed.
    6. Customize the Group:
      • Add a static label (e.g., "Contact") above the group for clarity.
      • Adjust the properties of the group (like columns and alignment) using the sidebar options.
    7. Save and Test:
      • Save your changes and test the form layout to ensure it meets your requirements.
    If the "Group" container is not visible, it may be due to limited access permissions or an issue with the Studio configuration. In that case, you can consider customizing the XML code of the form view, as shown in the previous example, for greater control.

Avatar
Discard

there is no "group" container, but maybe it refers to the column container

Related Posts Replies Views Activity
1
Jul 23
2980
1
Jul 25
1246
2
Mar 25
1502
0
Feb 25
1162
0
Feb 25
1327