diff --git a/fieldservice_base_location/README.rst b/fieldservice_base_location/README.rst new file mode 100644 index 0000000000..e6f82a4225 --- /dev/null +++ b/fieldservice_base_location/README.rst @@ -0,0 +1,104 @@ +============================= +Field Service - Base location +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6b800e15ce2d6d2ff13ba4364f50a8106f52f7fb2f27c9c69a103a05fbc5302a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github + :target: https://github.com/OCA/field-service/tree/17.0/fieldservice_base_location + :alt: OCA/field-service +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/field-service-17-0/field-service-17-0-fieldservice_base_location + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/field-service&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the zip_id field to the fsm.location form, enabling +automatic address completion based on the ZIP code entered in the +location’s completion field. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to Contacts → Configuration → ZIPs. + +2. Create a new ZIP entry. (Tip: You can enhance this step by using the + base_location_geonames_import module.) + +3. Navigate to Field Service → Master Data → Locations. + +Select an existing location or create a new one. + +In the address section, you’ll now see the ZIP code autocomplete field. +Simply enter the ZIP code, and the system will automatically fill in all +related address fields. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Apsl - Nagarro + +Contributors +------------ + +- `APSL `__: + + - Bernat Obrador + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-BernatObrador| image:: https://github.com/BernatObrador.png?size=40px + :target: https://github.com/BernatObrador + :alt: BernatObrador + +Current `maintainer `__: + +|maintainer-BernatObrador| + +This module is part of the `OCA/field-service `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/fieldservice_base_location/__init__.py b/fieldservice_base_location/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_base_location/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_base_location/__manifest__.py b/fieldservice_base_location/__manifest__.py new file mode 100644 index 0000000000..d4f1fc2f04 --- /dev/null +++ b/fieldservice_base_location/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright (C) 2025 Bernat Obrador (APSL - Nagarro) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Field Service - Base location", + "summary": "Autocomplete address in field service locations", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "category": "Field Service", + "author": "Apsl - Nagarro, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": ["fieldservice", "base_location"], + "data": [ + "views/fsm_location.xml", + ], + "auto_install": True, + "maintainers": ["BernatObrador"], +} diff --git a/fieldservice_base_location/i18n/ca.po b/fieldservice_base_location/i18n/ca.po new file mode 100644 index 0000000000..0b47feb231 --- /dev/null +++ b/fieldservice_base_location/i18n/ca.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_base_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-04-03 12:26+0000\n" +"PO-Revision-Date: 2025-04-03 12:26+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: fieldservice_base_location +#: model_terms:ir.ui.view,arch_db:fieldservice_base_location.fsm_location_form_view_address_autocomplete_inherit +msgid "Location completion" +msgstr "Finalització de la ubicació" diff --git a/fieldservice_base_location/i18n/es.po b/fieldservice_base_location/i18n/es.po new file mode 100644 index 0000000000..238a7ec55e --- /dev/null +++ b/fieldservice_base_location/i18n/es.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_base_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-04-03 12:27+0000\n" +"PO-Revision-Date: 2025-04-03 12:27+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: fieldservice_base_location +#: model_terms:ir.ui.view,arch_db:fieldservice_base_location.fsm_location_form_view_address_autocomplete_inherit +msgid "Location completion" +msgstr "Completado de ubicación" diff --git a/fieldservice_base_location/models/__init__.py b/fieldservice_base_location/models/__init__.py new file mode 100644 index 0000000000..a947d7f914 --- /dev/null +++ b/fieldservice_base_location/models/__init__.py @@ -0,0 +1 @@ +from . import fsm_location diff --git a/fieldservice_base_location/models/fsm_location.py b/fieldservice_base_location/models/fsm_location.py new file mode 100644 index 0000000000..628fc47ff1 --- /dev/null +++ b/fieldservice_base_location/models/fsm_location.py @@ -0,0 +1,46 @@ +from odoo import models + + +class FsmLocation(models.Model): + _inherit = "fsm.location" + + def write(self, vals): + for record in self: + partner = record.partner_id + if not partner: + continue + + vals = vals.copy() + + zip_id = vals.get("zip_id") or (record.zip_id.id or False) + zip_rec = self.env["res.city.zip"].browse(zip_id) if zip_id else False + new_zip = vals.get("zip", record.zip) + + if zip_rec and zip_rec.exists() and zip_rec.name != new_zip: + vals["zip_id"] = False + if partner.zip_id: + partner.zip_id = False + + partner_updates = { + key: vals[key] + for key in [ + "zip", + "city", + "state_id", + "country_id", + "street", + "street2", + ] + if key in vals + and vals[key] + != ( + getattr(partner, key).id + if key.endswith("_id") + else getattr(partner, key) + ) + } + + if partner_updates: + partner.write(partner_updates) + + return super().write(vals) diff --git a/fieldservice_base_location/pyproject.toml b/fieldservice_base_location/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_base_location/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_base_location/readme/CONTRIBUTORS.md b/fieldservice_base_location/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..0f38841388 --- /dev/null +++ b/fieldservice_base_location/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [APSL](https://apsl.tech): + - Bernat Obrador \<\> diff --git a/fieldservice_base_location/readme/DESCRIPTION.md b/fieldservice_base_location/readme/DESCRIPTION.md new file mode 100644 index 0000000000..7b5ba69072 --- /dev/null +++ b/fieldservice_base_location/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module adds the zip_id field to the fsm.location form, enabling automatic address completion based on the ZIP code entered in the location’s completion field. \ No newline at end of file diff --git a/fieldservice_base_location/readme/USAGE.md b/fieldservice_base_location/readme/USAGE.md new file mode 100644 index 0000000000..2d298c78bf --- /dev/null +++ b/fieldservice_base_location/readme/USAGE.md @@ -0,0 +1,11 @@ +1. Go to Contacts → Configuration → ZIPs. + +2. Create a new ZIP entry. +(Tip: You can enhance this step by using the base_location_geonames_import module.) + +3. Navigate to Field Service → Master Data → Locations. + +Select an existing location or create a new one. + +In the address section, you’ll now see the ZIP code autocomplete field. +Simply enter the ZIP code, and the system will automatically fill in all related address fields. diff --git a/fieldservice_base_location/static/description/icon.png b/fieldservice_base_location/static/description/icon.png new file mode 100644 index 0000000000..955674d8f0 Binary files /dev/null and b/fieldservice_base_location/static/description/icon.png differ diff --git a/fieldservice_base_location/static/description/index.html b/fieldservice_base_location/static/description/index.html new file mode 100644 index 0000000000..f403ce1afc --- /dev/null +++ b/fieldservice_base_location/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +Field Service - Base location + + + +
+

Field Service - Base location

+ + +

Beta License: AGPL-3 OCA/field-service Translate me on Weblate Try me on Runboat

+

This module adds the zip_id field to the fsm.location form, enabling +automatic address completion based on the ZIP code entered in the +location’s completion field.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Contacts → Configuration → ZIPs.
  2. +
  3. Create a new ZIP entry. (Tip: You can enhance this step by using the +base_location_geonames_import module.)
  4. +
  5. Navigate to Field Service → Master Data → Locations.
  6. +
+

Select an existing location or create a new one.

+

In the address section, you’ll now see the ZIP code autocomplete field. +Simply enter the ZIP code, and the system will automatically fill in all +related address fields.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Apsl - Nagarro
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

BernatObrador

+

This module is part of the OCA/field-service project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/fieldservice_base_location/tests/__init__.py b/fieldservice_base_location/tests/__init__.py new file mode 100644 index 0000000000..59c3d610d0 --- /dev/null +++ b/fieldservice_base_location/tests/__init__.py @@ -0,0 +1 @@ +from . import test_address_autocomplete diff --git a/fieldservice_base_location/tests/test_address_autocomplete.py b/fieldservice_base_location/tests/test_address_autocomplete.py new file mode 100644 index 0000000000..faa8564a15 --- /dev/null +++ b/fieldservice_base_location/tests/test_address_autocomplete.py @@ -0,0 +1,102 @@ +import requests + +from odoo.tests.common import TransactionCase + + +class TestFsmLocationZipSync(TransactionCase): + @classmethod + def setUpClass(cls): + cls._super_send = requests.Session.send + super().setUpClass() + cls.country = cls.env.ref("base.us") + cls.state = cls.env.ref("base.state_us_1") + cls.city = cls.env["res.city"].create( + { + "name": "Sample City", + "state_id": cls.state.id, + "country_id": cls.country.id, + } + ) + + cls.res_partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + } + ) + cls.zip_record = cls.env["res.city.zip"].create( + { + "name": "07001", + "city_id": cls.city.id, + } + ) + cls.zip_record_other = cls.env["res.city.zip"].create( + { + "name": "99999", + "city_id": cls.city.id, + } + ) + + cls.location = cls.env["fsm.location"].create( + { + "name": "Test Location", + "partner_id": cls.res_partner.id, + "zip": "07001", + "zip_id": cls.zip_record.id, + "owner_id": cls.res_partner.id, + } + ) + + @classmethod + def _request_handler(cls, s, r, /, **kw): + """Don't block external requests.""" + return cls._super_send(s, r, **kw) + + def test_zip_id_mismatch_resets_zip_id(self): + """Should reset zip_id if it doesn't match zip""" + self.location.write({"zip": "99999"}) + self.assertFalse(self.location.zip_id, "zip_id should be reset to False") + self.assertFalse(self.res_partner.zip_id, "Partner zip_id should also be reset") + + def test_zip_id_match_keeps_zip_id(self): + """Should keep zip_id if zip matches zip_id.name""" + self.location.write({"zip": "07001"}) + self.assertEqual( + self.location.zip_id, self.zip_record, "zip_id should remain unchanged" + ) + + def test_partner_fields_synced(self): + """Should sync fields like zip, city, state_id, etc. to partner""" + state = self.env.ref("base.state_us_1") + country = self.env.ref("base.us") + + self.location.write( + { + "zip": "12345", + "city": "Test City", + "state_id": state.id, + "country_id": country.id, + "street": "Main St", + "street2": "Apt 42", + } + ) + + partner = self.location.partner_id + self.assertEqual(partner.zip, "12345") + self.assertEqual(partner.city, "Test City") + self.assertEqual(partner.state_id, state) + self.assertEqual(partner.country_id, country) + self.assertEqual(partner.street, "Main St") + self.assertEqual(partner.street2, "Apt 42") + + def test_no_partner_does_not_fail(self): + """Should not fail if location has no partner""" + location = self.env["fsm.location"].create( + { + "name": "Orphan Location", + "zip": "07001", + "zip_id": self.zip_record.id, + "owner_id": self.res_partner.id, + } + ) + location.write({"zip": "99999"}) + self.assertFalse(location.zip_id) diff --git a/fieldservice_base_location/views/fsm_location.xml b/fieldservice_base_location/views/fsm_location.xml new file mode 100644 index 0000000000..b216f0dadd --- /dev/null +++ b/fieldservice_base_location/views/fsm_location.xml @@ -0,0 +1,20 @@ + + + + + + fsm_location_form_view_inherit + fsm.location + + + + + + + +