diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 15:47:32 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 15:47:32 +0700 |
| commit | df0467f8e493840f3013bc58ca26fc6d98793c95 (patch) | |
| tree | 05a01e1dee6bf866caaecfb5651f849fcf37cf86 /indoteknik_custom/models | |
| parent | 5ca33915f1e3d052cfa989163d43a15dbc9ddec9 (diff) | |
(andri) add openstreetmaps pada contact
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 0f1edac2..fee0e73b 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -146,6 +146,7 @@ class ResPartner(models.Model): date_payment_terms_purchase = fields.Datetime(string='Date Update Payment Terms') longtitude = fields.Char(string='Longtitude') latitude = fields.Char(string='Latitude') + map_view = fields.Char(string='Map') address_map = fields.Char(string='Address Map') company_type = fields.Selection(string='Company Type', selection=[('person', 'Individual'), ('company', 'Company')], @@ -526,12 +527,24 @@ class ResPartner(models.Model): def geocode_address(self): for rec in self: + # Ambil nama dari relasi (Many2one) atau gunakan nilai default + kelurahan = rec.kelurahan_id.name if rec.kelurahan_id else '' + kecamatan = rec.kecamatan_id.name if rec.kecamatan_id else '' + kota = rec.kota_id.name if rec.kota_id else '' + zip_code = rec.zip or '' + state = rec.state_id.name if rec.state_id else '' + country = rec.country_id.name if rec.country_id else '' + street = rec.street or '' + + # Susun alamat lengkap sesuai urutan lokal address = ', '.join(filter(None, [ - rec.street, - rec.city, - rec.state_id.name if rec.state_id else '', - rec.zip, - rec.country_id.name if rec.country_id else '' + street, + kelurahan, + kecamatan, + kota, + zip_code, + state, + country, ])) if not address: @@ -539,6 +552,7 @@ class ResPartner(models.Model): api_key = self.env['ir.config_parameter'].sudo().get_param('google.maps.api_key') url = f'https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={api_key}' + response = requests.get(url) if response.ok: @@ -546,4 +560,4 @@ class ResPartner(models.Model): if result.get('results'): location = result['results'][0]['geometry']['location'] rec.latitude = location['lat'] - rec.longtitude = location['lng']
\ No newline at end of file + rec.longtitude = location['lng'] |
