diff --git a/setup/stock_location_address/odoo/addons/stock_location_address b/setup/stock_location_address/odoo/addons/stock_location_address new file mode 120000 index 00000000..ebcc2d82 --- /dev/null +++ b/setup/stock_location_address/odoo/addons/stock_location_address @@ -0,0 +1 @@ +../../../../stock_location_address \ No newline at end of file diff --git a/setup/stock_location_address/setup.py b/setup/stock_location_address/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/stock_location_address/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_location_address/README.rst b/stock_location_address/README.rst new file mode 100644 index 00000000..4ef8daf2 --- /dev/null +++ b/stock_location_address/README.rst @@ -0,0 +1,86 @@ +====================== +Stock Location address +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2ddab809c43b89c0fa4cd0a76b38bf4156e6b8b440058ee2b8bf9f4b4057368f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--logistics--transport-lightgray.png?logo=github + :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-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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds an address on location so it can be used on purchases. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module you have to activate storage locations, going to +Configuration > settings > and activate Storage Locations. +then, +Go to 'Inventory > Settings > Locations' and select an address for the location. +If no address is selected, parent address will be used. + +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 +~~~~~~~ + +* Creu Blanca + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella +* Joan Mateu + +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. + +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/__init__.py b/stock_location_address/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/stock_location_address/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_location_address/__manifest__.py b/stock_location_address/__manifest__.py new file mode 100644 index 00000000..694da0c3 --- /dev/null +++ b/stock_location_address/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2018 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Stock Location address", + "summary": "Adds an address on locations", + "version": "16.0.1.0.0", + "author": "Creu Blanca, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-transport", + "category": "Warehouse Management", + "depends": ["stock"], + "data": ["views/stock_location_views.xml"], + "license": "AGPL-3", + "installable": True, + "application": False, +} diff --git a/stock_location_address/i18n/stock_location_address.pot b/stock_location_address/i18n/stock_location_address.pot new file mode 100644 index 00000000..c12a7b8a --- /dev/null +++ b/stock_location_address/i18n/stock_location_address.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_location_address +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \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: stock_location_address +#: model:ir.model.fields,field_description:stock_location_address.field_stock_location__address_id +#: model_terms:ir.ui.view,arch_db:stock_location_address.view_location_form +msgid "Address" +msgstr "" + +#. module: stock_location_address +#: model:ir.model,name:stock_location_address.model_stock_location +msgid "Inventory Locations" +msgstr "" + +#. module: stock_location_address +#: model:ir.model.fields,field_description:stock_location_address.field_stock_location__real_address_id +msgid "Real Address" +msgstr "" diff --git a/stock_location_address/models/__init__.py b/stock_location_address/models/__init__.py new file mode 100644 index 00000000..88493e35 --- /dev/null +++ b/stock_location_address/models/__init__.py @@ -0,0 +1 @@ +from . import stock_location diff --git a/stock_location_address/models/stock_location.py b/stock_location_address/models/stock_location.py new file mode 100644 index 00000000..87402fcf --- /dev/null +++ b/stock_location_address/models/stock_location.py @@ -0,0 +1,38 @@ +# Copyright 2018 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + address_id = fields.Many2one(comodel_name="res.partner", string="Address") + real_address_id = fields.Many2one( + 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"].browse() + + @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 + else: + record.real_address_id = record._get_parent_address() diff --git a/stock_location_address/readme/CONTRIBUTORS.rst b/stock_location_address/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..a8d378fb --- /dev/null +++ b/stock_location_address/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Enric Tobella +* Joan Mateu diff --git a/stock_location_address/readme/DESCRIPTION.rst b/stock_location_address/readme/DESCRIPTION.rst new file mode 100644 index 00000000..8a193c01 --- /dev/null +++ b/stock_location_address/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds an address on location so it can be used on purchases. diff --git a/stock_location_address/readme/USAGE.rst b/stock_location_address/readme/USAGE.rst new file mode 100644 index 00000000..e7fb845b --- /dev/null +++ b/stock_location_address/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module you have to activate storage locations, going to +Configuration > settings > and activate Storage Locations. +then, +Go to 'Inventory > Settings > Locations' and select an address for the location. +If no address is selected, parent address will be used. diff --git a/stock_location_address/static/description/icon.png b/stock_location_address/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/stock_location_address/static/description/icon.png differ diff --git a/stock_location_address/static/description/index.html b/stock_location_address/static/description/index.html new file mode 100644 index 00000000..e21f2d7e --- /dev/null +++ b/stock_location_address/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +Stock Location address + + + +
+

Stock Location address

+ + +

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

+ +
+

Usage

+

To use this module you have to activate storage locations, going to +Configuration > settings > and activate Storage Locations. +then, +Go to ‘Inventory > Settings > Locations’ and select an address for the location. +If no address is selected, parent address will be used.

+
+
+

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

+
    +
  • Creu Blanca
  • +
+
+
+

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.

+

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/__init__.py b/stock_location_address/tests/__init__.py new file mode 100644 index 00000000..bba73b9f --- /dev/null +++ b/stock_location_address/tests/__init__.py @@ -0,0 +1 @@ +from . import test_location_address diff --git a/stock_location_address/tests/test_location_address.py b/stock_location_address/tests/test_location_address.py new file mode 100644 index 00000000..46ed8f7f --- /dev/null +++ b/stock_location_address/tests/test_location_address.py @@ -0,0 +1,61 @@ +# Copyright 2018 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests import TransactionCase + + +class TestLocationAddress(TransactionCase): + def test_inheritance(self): + partner_1 = self.env["res.partner"].create({"name": "Partner1"}) + partner_2 = self.env["res.partner"].create({"name": "Partner2"}) + parent_location = self.env["stock.location"].create( + {"name": "Parent", "usage": "internal", "address_id": partner_1.id} + ) + location = self.env["stock.location"].create( + {"name": "Location", "usage": "internal", "location_id": parent_location.id} + ) + 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) diff --git a/stock_location_address/views/stock_location_views.xml b/stock_location_address/views/stock_location_views.xml new file mode 100644 index 00000000..e50f3f48 --- /dev/null +++ b/stock_location_address/views/stock_location_views.xml @@ -0,0 +1,22 @@ + + + + + stock.location.form + stock.location + + + + + + +