Skip to content

Commit

Permalink
[MIG] stock_location_address: migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kluna1998 committed Jan 13, 2025
1 parent 4c98767 commit b48d405
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
10 changes: 5 additions & 5 deletions stock_location_address/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -50,7 +50,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-transport/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 <https://github.com/OCA/stock-logistics-transport/issues/new?body=module:%20stock_location_address%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/stock-logistics-transport/issues/new?body=module:%20stock_location_address%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -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 <https://github.com/OCA/stock-logistics-transport/tree/15.0/stock_location_address>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-transport <https://github.com/OCA/stock-logistics-transport/tree/16.0/stock_location_address>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion stock_location_address/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 10 additions & 5 deletions stock_location_address/models/stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 3 additions & 4 deletions stock_location_address/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">Stock Location address</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2ddab809c43b89c0fa4cd0a76b38bf4156e6b8b440058ee2b8bf9f4b4057368f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-transport/tree/15.0/stock_location_address"><img alt="OCA/stock-logistics-transport" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--transport-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-transport-15-0/stock-logistics-transport-15-0-stock_location_address"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-transport&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-transport/tree/16.0/stock_location_address"><img alt="OCA/stock-logistics-transport" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--transport-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-transport-16-0/stock-logistics-transport-16-0-stock_location_address"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-transport&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds an address on location so it can be used on purchases.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -397,7 +396,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-transport/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/stock-logistics-transport/issues/new?body=module:%20stock_location_address%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/stock-logistics-transport/issues/new?body=module:%20stock_location_address%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -422,7 +421,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-transport/tree/15.0/stock_location_address">OCA/stock-logistics-transport</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-transport/tree/16.0/stock_location_address">OCA/stock-logistics-transport</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
42 changes: 42 additions & 0 deletions stock_location_address/tests/test_location_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b48d405

Please sign in to comment.