diff options
Diffstat (limited to 'indoteknik_custom')
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 65 | ||||
| -rw-r--r-- | indoteknik_custom/views/res_partner.xml | 27 |
2 files changed, 87 insertions, 5 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index f1e362e6..a15398c7 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' @@ -145,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')], @@ -521,4 +523,65 @@ 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 action_open_full_form(self): + return { + 'type': 'ir.actions.act_window', + 'name': 'Partner', + 'res_model': 'res.partner', + 'res_id': self.id, + 'view_mode': 'form', + 'target': 'current', + } + + def geocode_address(self): + for rec in self: + # Daftar field penting + required_fields = { + 'Alamat Jalan (street)': rec.street, + '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 '', + 'Kode Pos': rec.zip, + 'Provinsi': rec.state_id.name if rec.state_id else '', + 'Negara': rec.country_id.name if rec.country_id else '', + } + + # Cek jika ada yang kosong + missing = [label for label, val in required_fields.items() if not val] + if missing: + raise UserError( + "Alamat tidak lengkap. Mohon lengkapi field berikut:\n- " + "\n- ".join(missing) + ) + + # Susun alamat lengkap + address = ', '.join([ + required_fields['Alamat Jalan (street)'], + required_fields['Kelurahan'], + required_fields['Kecamatan'], + required_fields['Kota'], + required_fields['Kode Pos'], + required_fields['Provinsi'], + required_fields['Negara'], + ]) + + # Ambil API Key + api_key = self.env['ir.config_parameter'].sudo().get_param('google.maps.api_key') + if not api_key: + raise UserError("API Key Google Maps belum dikonfigurasi. Silakan isi melalui Settings.") + + # Request ke Google Maps + 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'] + else: + raise UserError("Tidak ditemukan hasil geocode untuk alamat tersebut.") + else: + raise UserError("Permintaan ke Google Maps gagal. Periksa koneksi internet atau API Key.") diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index 9fb6530c..6acfeaa0 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -65,10 +65,20 @@ <group name="purchase" position="inside"> <field name="leadtime"/> </group> - <field name="vat" position="before"> - <field name="latitude"/> - <field name="longtitude"/> - </field> + <xpath expr="//notebook/page[@name='contact_addresses']" position="before"> + <page string="Pin Point Location" name="map_location" autofocus="autofocus"> + <group> + <button name="geocode_address" type="object" string="Get Pin Point Location" class="btn btn-primary"/> + </group> + <div style="margin: 16px 0;"> + <field name="map_view" widget="openstreetmap" nolabel="1" style="width: 100%;"/> + </div> + <group> + <field name="latitude" readonly="1"/> + <field name="longtitude" readonly="1"/> + </group> + </page> + </xpath> <field name="vat" position="after"> <field name="email_finance" widget="email"/> <field name="email_sales" widget="email"/> @@ -82,6 +92,15 @@ <field name="main_parent_id" invisible="1" /> <field name="site_id" attrs="{'readonly': [('parent_id', '=', False)]}" domain="[('partner_id', '=', main_parent_id)]" context="{'default_partner_id': active_id}" /> </xpath> + <xpath expr="//field[@name='child_ids']/form/sheet/group" position="after"> + <div class="oe_left" style="margin-top: 16px;"> + <button name="action_open_full_form" + type="object" + string="Detail Information" + class="btn btn-primary" + /> + </div> + </xpath> <xpath expr="//field[@name='property_payment_term_id']" position="attributes"> <attribute name="readonly">0</attribute> </xpath> |
