diff --git a/stock_location_address/README.rst b/stock_location_address/README.rst index 7e1a1144..4ef8daf2 100644 --- a/stock_location_address/README.rst +++ b/stock_location_address/README.rst @@ -17,13 +17,13 @@ Stock Location address :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--transport-lightgray.png?logo=github - :target: https://github.com/OCA/stock-logistics-transport/tree/15.0/stock_location_address + :target: https://github.com/OCA/stock-logistics-transport/tree/16.0/stock_location_address :alt: OCA/stock-logistics-transport .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/stock-logistics-transport-15-0/stock-logistics-transport-15-0-stock_location_address + :target: https://translation.odoo-community.org/projects/stock-logistics-transport-16-0/stock-logistics-transport-16-0-stock_location_address :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/stock-logistics-transport&target_branch=15.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-transport&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -50,7 +50,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -81,6 +81,6 @@ 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. -This module is part of the `OCA/stock-logistics-transport `_ project on GitHub. +This module is part of the `OCA/stock-logistics-transport `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_location_address/__manifest__.py b/stock_location_address/__manifest__.py index efa498ed..694da0c3 100644 --- a/stock_location_address/__manifest__.py +++ b/stock_location_address/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Location address", "summary": "Adds an address on locations", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "Creu Blanca, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-transport", "category": "Warehouse Management", diff --git a/stock_location_address/models/stock_location.py b/stock_location_address/models/stock_location.py index 9ad4c54f..87402fcf 100644 --- a/stock_location_address/models/stock_location.py +++ b/stock_location_address/models/stock_location.py @@ -12,22 +12,27 @@ class StockLocation(models.Model): comodel_name="res.partner", string="Real Address", compute="_compute_real_address_id", + recursive=True, ) def _get_parent_address(self): + """Recursively fetches the address from parent locations.""" if self.location_id and self.location_id.address_id: return self.location_id.address_id elif self.location_id: return self.location_id._get_parent_address() else: - return self.env["res.partner"] + return self.env["res.partner"].browse() - @api.depends("address_id", "location_id") + @api.depends("address_id", "location_id", "location_id.address_id") def _compute_real_address_id(self): + """ + Computes the real_address_id field. + If the current location has an address, use it. + Otherwise, inherit from the nearest parent location. + """ for record in self: if record.address_id: record.real_address_id = record.address_id - elif record.location_id: - record.real_address_id = record._get_parent_address() else: - record.real_address_id = False + record.real_address_id = record._get_parent_address() diff --git a/stock_location_address/static/description/index.html b/stock_location_address/static/description/index.html index 23bc471e..e21f2d7e 100644 --- a/stock_location_address/static/description/index.html +++ b/stock_location_address/static/description/index.html @@ -1,4 +1,3 @@ - @@ -369,7 +368,7 @@

Stock Location address

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:2ddab809c43b89c0fa4cd0a76b38bf4156e6b8b440058ee2b8bf9f4b4057368f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/stock-logistics-transport Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/stock-logistics-transport Translate me on Weblate Try me on Runboat

This module adds an address on location so it can be used on purchases.

Table of contents

@@ -397,7 +396,7 @@

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.

+feedback.

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

@@ -422,7 +421,7 @@

Maintainers

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.

-

This module is part of the OCA/stock-logistics-transport project on GitHub.

+

This module is part of the OCA/stock-logistics-transport project on GitHub.

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

diff --git a/stock_location_address/tests/test_location_address.py b/stock_location_address/tests/test_location_address.py index fcf47730..46ed8f7f 100644 --- a/stock_location_address/tests/test_location_address.py +++ b/stock_location_address/tests/test_location_address.py @@ -17,3 +17,45 @@ def test_inheritance(self): self.assertEqual(location.real_address_id, partner_1) location.address_id = partner_2 self.assertEqual(location.real_address_id, partner_2) + + def test_parent_without_address(self): + partner_1 = self.env["res.partner"].create({"name": "Partner1"}) + parent_location_no_address = self.env["stock.location"].create( + {"name": "Parent", "usage": "internal"} + ) + location = self.env["stock.location"].create( + { + "name": "Location", + "usage": "internal", + "location_id": parent_location_no_address.id, + } + ) + + # Assert that the real_address_id is empty when no addresses are set + self.assertFalse(location.real_address_id) + # Assert that the child inherits the parent's address + parent_location_no_address.address_id = partner_1 + self.assertEqual(location.real_address_id, partner_1) + + def test_multi_level_hierarchy(self): + partner_1 = self.env["res.partner"].create({"name": "Partner1"}) + partner_2 = self.env["res.partner"].create({"name": "Partner2"}) + grandparent_location = self.env["stock.location"].create( + {"name": "Grandparent", "usage": "internal", "address_id": partner_1.id} + ) + parent_location = self.env["stock.location"].create( + { + "name": "Parent", + "usage": "internal", + "location_id": grandparent_location.id, + } + ) + location = self.env["stock.location"].create( + {"name": "Child", "usage": "internal", "location_id": parent_location.id} + ) + + # Assert that the child's real_address_id inherits from the grandparent + self.assertEqual(location.real_address_id, partner_1) + # Assert that the child now inherits from the parent instead of the grandparent + parent_location.address_id = partner_2 + self.assertEqual(location.real_address_id, partner_2)