From 57a84dde4c1ec4001ec1eae3c9d28655a32e2dd5 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Sun, 14 Jun 2026 10:39:36 +0700 Subject: [PATCH] feat: move branch coordinates to pos.config and clean up res.company inheritance --- __manifest__.py | 2 +- controllers/main.py | 27 ++++++++++++++++++--------- models/__init__.py | 2 +- models/pos_config.py | 8 ++++++++ models/res_company.py | 9 --------- views/pos_config_views.xml | 16 ++++++++++++++++ views/res_company_views.xml | 14 -------------- 7 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 models/pos_config.py delete mode 100644 models/res_company.py create mode 100644 views/pos_config_views.xml delete mode 100644 views/res_company_views.xml diff --git a/__manifest__.py b/__manifest__.py index 8e402d6..bed4442 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -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', diff --git a/controllers/main.py b/controllers/main.py index 8793b3b..1caa8cc 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -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)} diff --git a/models/__init__.py b/models/__init__.py index ba9a33e..c9a6465 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -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 diff --git a/models/pos_config.py b/models/pos_config.py new file mode 100644 index 0000000..9705fb1 --- /dev/null +++ b/models/pos_config.py @@ -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") diff --git a/models/res_company.py b/models/res_company.py deleted file mode 100644 index 93ae03e..0000000 --- a/models/res_company.py +++ /dev/null @@ -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") - diff --git a/views/pos_config_views.xml b/views/pos_config_views.xml new file mode 100644 index 0000000..be539c3 --- /dev/null +++ b/views/pos_config_views.xml @@ -0,0 +1,16 @@ + + + + pos.config.form.inherit.geo + pos.config + + + + + + + + + + + diff --git a/views/res_company_views.xml b/views/res_company_views.xml deleted file mode 100644 index 5dc2e40..0000000 --- a/views/res_company_views.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - res.company.form.inherit.geo - res.company - - - - - - - - -