Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

Hi everyone,

I'm working on a customization in Odoo Enterprise Edition(Standard)  where I've extended the product (property) model with additional location-related attributes:

  • Region – eg, Kenya, UAE
  • Area – eg, Nairobi, Mombasa (specific to a region)
  • Neighborhood – eg, Kilimani (specific to an area)

Here's what I want to achieve:

  • When I select Region = Kenya , I should only see Areas that belong to Kenya.
  • When I select Area = Nairobi , I should only see Neighborhoods within Nairobi.

Basically, I need cascading dropdowns (Region → Area → Neighborhood) inside the product.template model.

I already know how to write the Python and XML parts to define the relationships and domains — what I need guidance on is where exactly in the Odoo setup this kind of extension should be placed.

Should I create a small custom module to inherit product.template , or is there a better place within the existing product module structure to add these models and view modifications?

Any pointers or best practices on organizing this kind of dependency within the Odoo framework would be appreciated.

Thanks in advance!

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,


You are essentially implementing cascading selection fields in product.template for Region → Area → Neighborhood. Since this is a custom extension to the standard Product model, the recommended approach is to create a small custom module, rather than modifying the core product module directly. Modifying the core module is risky because updates could break your customizations.


Follow the steps


Create a new custom module


    Example: product_location_extension


    Place your Python models, fields, and relationships here.


    Example structure:


    product_location_extension/

    ├── __init__.py

    ├── __manifest__.py

    ├── models/

    │   ├── __init__.py

    │   └── product_template_extension.py

    └── views/

        └── product_template_views.xml


Python Models


    In models/product_template_extension.py, inherit product.template:


from odoo import models, fields


class ProductTemplate(models.Model):

    _inherit = 'product.template'


    region_id = fields.Many2one('res.region', string='Region')

    area_id = fields.Many2one('res.area', string='Area', domain="[('region_id','=',region_id)]")

    neighborhood_id = fields.Many2one('res.neighborhood', string='Neighborhood', domain="[('area_id','=',area_id)]")


XML Views


    Extend the product.template form view:


<record id="view_product_template_form_inherit_location" model="ir.ui.view">

    <field name="name">product.template.form.location</field>

    <field name="model">product.template</field>

    <field name="inherit_id" ref="product.product_template_only_form_view"/>

    <field name="arch" type="xml">

        <xpath expr="//sheet/notebook/page[@string='General Information']" position="inside">

            <group>

                <field name="region_id"/>

                <field name="area_id"/>

                <field name="neighborhood_id"/>

            </group>

        </xpath>

    </field>

</record>


* Always use a separate custom module to extend product.template.

* Use Many2one fields with domains for cascading dropdowns.

* Keep models, views, and Python logic together in the module for maintainability.


Hope it helps

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thanks @cybrosys,

Does this mean, I will have to download the Odoo Enterprise code and do the development locally?


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
wrz 25
4062
2
mar 25
1861
0
lis 24
1344
0
lis 24
1262
3
wrz 25
400