Odoo Help


2 Answers

Muhammad Anees Saudi Arabia

--Muhammad Anees--

| 7 3 9
Riyadh, Saudi Arabia
--Muhammad Anees--

Odoo, Dynamics AX and Web Developer.

Muhammad Anees Saudi Arabia
8/25/19, 4:24 AM

Here is how I added Cities and Districts to my private address.

1. Install standard City Addresses module
2. Contacts > Configurations > Countries > select a country to apply cities > Edit > Select Enforce Cities check box
3. On the same page add States
4. On the same page there is Cities link
5. Add your cities under the Country and State
6. to add districts create a new module

class District(models.Model): 
_name = 'res.city.district' _description = 'District' _order = 'name' name = fields.Char("Name", required=True, translate=True)
country_id = fields.Many2one('res.country', string='Country', help='Select Country', ondelete='restrict')
city_id = fields.Many2one('res.city', 'City', ondelete='restrict')

7. Add new view for District and show next to Cities link on country detail page
8. Inherit res.partner and change street2 field type to Many2one

class HrResPartner(models.Model):
_inherit = 'res.partner' street2 = fields.Many2one('res.city.district', string='District') @api.onchange('city_id')
def _onchange_city_id(self):
if self.city_id: self.street2 = False self.state_id = self.city_id.state_id
return {'domain': {'street2': [('city_id', '=', self.city_id.id)]}}
self.street2 = False
self.state_id = False
return {'domain': {'district_id': []}} @api.onchange('country_id')
def _onchange_country_id(self):
if self.country_id and self.country_id != self.state_id.country_id:
self.state_id = False
self.city_id = False
self.street2 = False
def _onchange_state(self):
if self.state_id.country_id:
self.country_id = self.state_id.country_id
self.street2 = False
return {'domain': {'city_id': [('state_id', '=', self.state_id.id)]}}


Paresh Wagh India

--Paresh Wagh--

| 4 2 5
Navi Mumbai, India
--Paresh Wagh--

Paresh Wagh India
8/5/19, 1:07 AM

Hi Muhammad: You cannot change the definition of existing fields. You will need to define new custom fields, display them in your views and hide the existing fields.

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now