[14.0][ADD] stock_location_warehouse

This commit is contained in:
Bernat Puig Font
2021-09-21 16:28:28 +02:00
parent 580697a502
commit 394a73af18
14 changed files with 219 additions and 0 deletions

View File

@@ -0,0 +1 @@
../../../../stock_location_warehouse

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@@ -0,0 +1,92 @@
=========================
Stock Location Warehouse
=========================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |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--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_available
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_available
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/14.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module adds the associated warehouse to every location. If we have a tree of locations and sublocations, this module will update the associated warehouse every time we modify a location parent.
If a location changes its father location, it will change its associated warehouse and all its childs too.
**Table of contents**
.. contents::
:local:
Configuration
=============
To use the module, our instance must be configured first:
We have to go to configuration > settings and check the box in the warehouse section called "storage locations".
Usage
=====
The usage of this module is automatic but here's an explanation to force its behavior.
Go to Configuration>Locations and select a location that at least has one child. Edit the location's "Parent Location" to a different one and save the changes. Once the changes are saved, "Associated Warehouse" will be updated with a new warehouse. After this, go to any of its children and check the info: if things go well, "Associated Warehouse" will have changed too.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_available%0Aversion:%2014.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.
Credits
=======
Authors
~~~~~~~
* ForgeFlow
Contributors
~~~~~~~~~~~~
* `ForgeFlow <https://forgeflow.com>`_:
* Joan Mateu <joan.mateu@forgeflow.com>
* Bernat Puig <bernat.puig@forgeflow.com>
* Álvaro Trius <alvaro.trius@forgeflow.com>
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-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_available>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,16 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Location Warehouse",
"version": "14.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"summary": "Warehouse associated with a location",
"category": "Stock Management",
"depends": ["stock"],
"data": ["views/stock_location.xml"],
"installable": True,
"development_status": "Alpha",
"license": "LGPL-3",
}

View File

@@ -0,0 +1 @@
from . import stock_location

View File

@@ -0,0 +1,33 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from collections import OrderedDict
from odoo import api, fields, models
class StockLocation(models.Model):
_inherit = "stock.location"
warehouse_view_ids = fields.One2many(
"stock.warehouse", "view_location_id", readonly=True
)
warehouse_id = fields.Many2one(
comodel_name="stock.warehouse", compute="_compute_warehouse_id", store=True
)
@api.depends("warehouse_view_ids", "parent_path")
def _compute_warehouse_id(self):
self.invalidate_cache(["parent_path", "warehouse_view_ids"])
warehouses = (
self.env["stock.warehouse"].with_context(active_test=False).search([])
)
view_by_wh = OrderedDict((wh.view_location_id.id, wh.id) for wh in warehouses)
for loc in self:
if not loc.parent_path:
continue
path = [int(loc_id) for loc_id in loc.parent_path.split("/")[:-1]]
for view_location_id in view_by_wh:
if len(path) > 1 and view_location_id == path[1]:
loc.warehouse_id = view_by_wh[view_location_id]
break

View File

@@ -0,0 +1,2 @@
To use the module, our instance must be configured first:
We have to go to configuration > settings and check the box in the warehouse section called "storage locations".

View File

@@ -0,0 +1,7 @@
* `ForgeFlow <https://forgeflow.com>`_:
* Joan Mateu <joan.mateu@forgeflow.com>
* Bernat Puig <bernat.puig@forgeflow.com>
* Álvaro Trius <alvaro.trius@forgeflow.com>

View File

@@ -0,0 +1,2 @@
This module adds the associated warehouse to every location. If we have a tree of locations and sublocations, this module will update the associated warehouse every time we modify a location parent.
If a location changes its father location, it will change its associated warehouse and all its childs too.

View File

@@ -0,0 +1,2 @@
The usage of this module is automatic but here's an explanation to force its behavior.
Go to Configuration>Locations and select a location that at least has one child. Edit the location's "Parent Location" to a different one and save the changes. Once the changes are saved, "Associated Warehouse" will be updated with a new warehouse. After this, go to any of its children and check the info: if things go well, "Associated Warehouse" will have changed too.

View File

@@ -0,0 +1 @@
from . import test_location_warehouse

View File

@@ -0,0 +1,42 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.tests.common import TransactionCase
class TestLocationWarehouse(TransactionCase):
def setUp(self, *args, **kwargs):
super(TestLocationWarehouse, self).setUp(*args, **kwargs)
self.wh_sf = self.env.ref("stock.warehouse0")
self.loc_sf = self.wh_sf.lot_stock_id
self.wh2 = self.env["stock.warehouse"].create(
{
"name": "WH 2",
"code": "WH3",
"company_id": self.wh_sf.company_id.id,
"partner_id": self.wh_sf.partner_id.id,
"reception_steps": "one_step",
}
)
self.loc_wh2 = self.wh2.lot_stock_id
self.location1 = self.env["stock.location"].create(
{"name": "sunblock_1", "location_id": self.loc_sf.id}
)
self.location2 = self.env["stock.location"].create(
{"name": "sunblock_2", "location_id": self.location1.id}
)
self.location3 = self.env["stock.location"].create(
{"name": "sunblock_3", "location_id": self.location2.id}
)
def test_main_location(self):
self.assertEqual(self.loc_sf.warehouse_id, self.wh_sf)
def test_compute_location(self):
self.location1.location_id = self.loc_wh2
self.assertEqual(self.location1.warehouse_id, self.wh2)
def test_compute_location_childs(self):
self.location1.location_id = self.loc_wh2
self.assertEqual(self.location2.warehouse_id, self.wh2)
self.assertEqual(self.location3.warehouse_id, self.wh2)

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="stock_location_form_inherit" model="ir.ui.view">
<field name="name">stock.location.inherit</field>
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_form" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="warehouse_id" />
</field>
</field>
</record>
</odoo>