feat: move branch coordinates to pos.config and clean up res.company inheritance

This commit is contained in:
Suherdy Yacob 2026-06-14 10:39:36 +07:00
parent 3b48e32205
commit 57a84dde4c
7 changed files with 44 additions and 34 deletions

View File

@ -20,7 +20,7 @@
'security/ir.model.access.csv',
'wizard/push_wizard_views.xml',
'views/res_partner_views.xml',
'views/res_company_views.xml',
'views/pos_config_views.xml',
'views/app_notification_views.xml',
'views/app_carousel_views.xml',
'views/app_promo_views.xml',

View File

@ -210,15 +210,24 @@ class AppNotificationController(http.Controller):
Includes latitude/longitude for geolocation-based distance sorting on the client.
"""
try:
branches = request.env['res.company'].sudo().search_read(
[('parent_id', '!=', False)],
['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}
companies = request.env['res.company'].sudo().search([
('parent_id', '!=', False)
])
data = []
for comp in companies:
pos = request.env['pos.config'].sudo().search([
('company_id', '=', comp.id)
], limit=1)
data.append({
'id': comp.id,
'name': comp.name,
'street': comp.street or '',
'city': comp.city or '',
'phone': comp.phone or '',
'partner_latitude': pos.branch_latitude if pos else 0.0,
'partner_longitude': pos.branch_longitude if pos else 0.0,
})
return {'status': 'success', 'data': data}
except Exception as e:
return {'status': 'error', 'message': str(e)}

View File

@ -1,5 +1,5 @@
from . import res_partner
from . import res_company
from . import pos_config
from . import app_notification
from . import app_carousel
from . import app_promo

8
models/pos_config.py Normal file
View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from odoo import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
branch_latitude = fields.Float(string="Branch Latitude")
branch_longitude = fields.Float(string="Branch Longitude")

View File

@ -1,9 +0,0 @@
# -*- coding: utf-8 -*-
from odoo import models, fields
class ResCompany(models.Model):
_inherit = 'res.company'
branch_latitude = fields.Float(string="Latitude")
branch_longitude = fields.Float(string="Longitude")

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_pos_config_form_inherit_geo" model="ir.ui.view">
<field name="name">pos.config.form.inherit.geo</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='configuration']" position="inside">
<group string="Branch Coordinates" name="branch_coordinates_group">
<field name="branch_latitude" string="Latitude"/>
<field name="branch_longitude" string="Longitude"/>
</group>
</xpath>
</field>
</record>
</odoo>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_company_form_inherit_geo" model="ir.ui.view">
<field name="name">res.company.form.inherit.geo</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='website']" position="after">
<field name="branch_latitude" string="Latitude"/>
<field name="branch_longitude" string="Longitude"/>
</xpath>
</field>
</record>
</odoo>