تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
2627 أدوات العرض

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  

الصورة الرمزية
إهمال