Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
2628 Vizualizări

class Egypt(models.Model):

    _name = 'egypt'

    _rec_name = 'id'


    id = fields.Integer()

    name = fields.Char()


class Germany(models.Model):

    _name = 'germany'

    _rec_name = 'id'


    id = fields.Integer()

    name = fields.Char()


class MyModule(models.Model):

    _name = 'my.module'


    country = fields.Selection([('1', 'Egypt'),

                                ('2', 'Germany'),

                               ], default='1')


    egypt_towns = fields.Many2one('egypt.name')

    geramny_towns = fields.Many2one('geramny.name')

    towns = fields.Many2one()


in XML Code


    <field name="country"/>

    <field name="towns"/>



1 - 

if country is egypt, towns field = egypt_towns

and if country us germany, towns = geramny_towns

How ?


2- (egypt.name) is't work , how to solve ?

Note : don't use name_get this will change it in whole system which i don't want


thanks in advance

Imagine profil
Abandonează
Cel mai bun răspuns

i think you need to use odoo default country feature ...

then you can change condition on country wise ..


Imagine profil
Abandonează
Cel mai bun răspuns

Hello Ahmed,

In odoo have default on model for Country (res.country), and state (res.country.state). Just like you set up for town related as in odoo have states. On Partner Form have example if you select country, state should enabled country related. same logic apply for Town Inherit/add onchange methods for town based on your requirements. class ResCountryTown(models.Model): _name = 'res.country.town' _rec_name = 'name' name = fields.Char() country_id = fields.Many2one('res.country', 'Country')

In odoo have default on model for Country (res.country), and state (res.country.state). Just like you set up for town related as in odoo have states.

On Partner Form have example if you select country, state should enabled country related. same logic apply for Town Inherit/add onchange methods for town based on your requirements.


class ResCountryTown(models.Model):
    _name = 'res.country.town'
    _rec_name = 'name'
    name = fields.Char()
    country_id = fields.Many2one('res.country', 'Country')
 
Imagine profil
Abandonează
Autor Cel mai bun răspuns

thanks for your answer

but still don't understand , my 5th month on odoo

 i have in each country many towns and need to display country towns when i chose country from country field  

Imagine profil
Abandonează