Odoo Help

2

2
2 Answers
2
Avatar

Muhammad Anees ซาอุดิอาระเบีย

--Muhammad Anees--

5123
| 6 3 7
Riyadh, ซาอุดิอาระเบีย
--Muhammad Anees--

Odoo, Dynamics AX and Web Developer.

Muhammad Anees ซาอุดิอาระเบีย
25/8/19 04:24

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)]}}
else:
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
@api.onchange('state_id')
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)]}}



0
Avatar

Paresh Wagh อินเดีย

--Paresh Wagh--

8295
| 4 2 4
Navi Mumbai, อินเดีย
--Paresh Wagh--
Paresh Wagh อินเดีย
5/8/19 01:07

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
Writer
ป้ายกำกับ
Keep Informed
1 ผู้ติดตาม
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.

Register
Odoo Training Center

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

Test it now