Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
2629 Представления

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

Аватар
Отменить
Лучший ответ

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

then you can change condition on country wise ..


Аватар
Отменить
Лучший ответ

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')
 
Аватар
Отменить
Автор Лучший ответ

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  

Аватар
Отменить