feat: use branch_latitude and branch_longitude on res.company and map them in the API to avoid related fields and geolocalize model conflicts
This commit is contained in:
parent
4748ace653
commit
3b48e32205
@ -212,9 +212,12 @@ class AppNotificationController(http.Controller):
|
||||
try:
|
||||
branches = request.env['res.company'].sudo().search_read(
|
||||
[('parent_id', '!=', False)],
|
||||
['name', 'street', 'city', 'phone', 'partner_latitude', 'partner_longitude'],
|
||||
['name', 'street', 'city', 'phone', 'branch_latitude', 'branch_longitude'],
|
||||
limit=50
|
||||
)
|
||||
for branch in branches:
|
||||
branch['partner_latitude'] = branch.pop('branch_latitude', 0.0)
|
||||
branch['partner_longitude'] = branch.pop('branch_longitude', 0.0)
|
||||
return {'status': 'success', 'data': branches}
|
||||
except Exception as e:
|
||||
return {'status': 'error', 'message': str(e)}
|
||||
|
||||
@ -4,17 +4,6 @@ from odoo import models, fields
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
partner_latitude = fields.Float(string="Latitude", compute="_compute_coords", inverse="_inverse_coords", store=False)
|
||||
partner_longitude = fields.Float(string="Longitude", compute="_compute_coords", inverse="_inverse_coords", store=False)
|
||||
branch_latitude = fields.Float(string="Latitude")
|
||||
branch_longitude = fields.Float(string="Longitude")
|
||||
|
||||
def _compute_coords(self):
|
||||
for company in self:
|
||||
company.partner_latitude = getattr(company.partner_id, 'partner_latitude', 0.0)
|
||||
company.partner_longitude = getattr(company.partner_id, 'partner_longitude', 0.0)
|
||||
|
||||
def _inverse_coords(self):
|
||||
for company in self:
|
||||
if hasattr(company.partner_id, 'partner_latitude'):
|
||||
company.partner_id.partner_latitude = company.partner_latitude
|
||||
if hasattr(company.partner_id, 'partner_longitude'):
|
||||
company.partner_id.partner_longitude = company.partner_longitude
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
<field name="inherit_id" ref="base.view_company_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='website']" position="after">
|
||||
<field name="partner_latitude" string="Latitude"/>
|
||||
<field name="partner_longitude" string="Longitude"/>
|
||||
<field name="branch_latitude" string="Latitude"/>
|
||||
<field name="branch_longitude" string="Longitude"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user