diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 11:17:57 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 11:17:57 +0700 |
| commit | 5ca33915f1e3d052cfa989163d43a15dbc9ddec9 (patch) | |
| tree | 828c56626d0c298d17f3b698cc9fb5ae0db1f011 /indoteknik_custom/models | |
| parent | 2760b81f8a650ea95d36c125d1ab4e2feb011e44 (diff) | |
(andri) add button get koordinat pada contact
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index f1e362e6..0f1edac2 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -3,6 +3,7 @@ from odoo.exceptions import UserError, ValidationError from datetime import datetime from odoo.http import request import re +import requests class GroupPartner(models.Model): _name = 'group.partner' @@ -521,4 +522,28 @@ class ResPartner(models.Model): @api.onchange('name') def _onchange_name(self): if self.company_type == 'person': - self.nama_wajib_pajak = self.name
\ No newline at end of file + self.nama_wajib_pajak = self.name + + def geocode_address(self): + for rec in self: + 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 '' + ])) + + if not address: + continue + + 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: + result = response.json() + if result.get('results'): + location = result['results'][0]['geometry']['location'] + rec.latitude = location['lat'] + rec.longtitude = location['lng']
\ No newline at end of file |
