跳至內容
選單
此問題已被標幟
3 回覆
2636 瀏覽次數

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  

頭像
捨棄