[MIG] stock_report_quantity_by_location: Migration to 16.0

This commit is contained in:
Hugo
2023-11-24 00:45:05 +01:00
parent 706e4344a3
commit b1766c6d9b
9 changed files with 104 additions and 94 deletions

View File

@@ -7,7 +7,7 @@ Stock Report Quantity By Location
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:57c3689eae5fca6394308789a0d776c7eae48bd21fc51808841922b00e25ebfb
!! source digest: sha256:a267bfa205872d07d7a0a055440a79c70bca49f300b53a8ad40f0114d80fab09
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Stock Report Quantity By Location
: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--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-reporting/tree/15.0/stock_report_quantity_by_location
:target: https://github.com/OCA/stock-logistics-reporting/tree/16.0/stock_report_quantity_by_location
:alt: OCA/stock-logistics-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-reporting-15-0/stock-logistics-reporting-15-0-stock_report_quantity_by_location
:target: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_report_quantity_by_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/stock-logistics-reporting&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-reporting&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -42,7 +42,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-reporting/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-reporting/issues/new?body=module:%20stock_report_quantity_by_location%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-reporting/issues/new?body=module:%20stock_report_quantity_by_location%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.
@@ -64,6 +64,9 @@ Contributors
* Ecosoft (http://ecosoft.co.th)
* Kranokporn Thongdoung <kranokpornt@ecosoft.co.th>
* FactorLibre (http://factorlibre.com)
* Hugo Córdoba <hugo.cordoba@factorlibre.com>
Maintainers
~~~~~~~~~~~
@@ -77,6 +80,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-reporting <https://github.com/OCA/stock-logistics-reporting/tree/15.0/stock_report_quantity_by_location>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-reporting <https://github.com/OCA/stock-logistics-reporting/tree/16.0/stock_report_quantity_by_location>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -3,7 +3,7 @@
{
"name": "Stock Report Quantity By Location",
"summary": "Stock Report Quantity By Location",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-reporting",
"category": "Warehouse Management",

View File

@@ -4,3 +4,6 @@
* Ecosoft (http://ecosoft.co.th)
* Kranokporn Thongdoung <kranokpornt@ecosoft.co.th>
* FactorLibre (http://factorlibre.com)
* Hugo Córdoba <hugo.cordoba@factorlibre.com>

View File

@@ -367,9 +367,9 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:57c3689eae5fca6394308789a0d776c7eae48bd21fc51808841922b00e25ebfb
!! source digest: sha256:a267bfa205872d07d7a0a055440a79c70bca49f300b53a8ad40f0114d80fab09
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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-reporting/tree/15.0/stock_report_quantity_by_location"><img alt="OCA/stock-logistics-reporting" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-reporting-15-0/stock-logistics-reporting-15-0-stock_report_quantity_by_location"><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-reporting&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-reporting/tree/16.0/stock_report_quantity_by_location"><img alt="OCA/stock-logistics-reporting" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_report_quantity_by_location"><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-reporting&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 additional reporting on Inventory side where warehouse
location quantities are shown by all stockable products.</p>
<p><strong>Table of contents</strong></p>
@@ -389,7 +389,7 @@ location quantities are shown by all stockable products.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/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-reporting/issues/new?body=module:%20stock_report_quantity_by_location%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-reporting/issues/new?body=module:%20stock_report_quantity_by_location%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">
@@ -411,6 +411,8 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<ul class="simple">
<li>Ecosoft (<a class="reference external" href="http://ecosoft.co.th">http://ecosoft.co.th</a>)
* Kranokporn Thongdoung &lt;<a class="reference external" href="mailto:kranokpornt&#64;ecosoft.co.th">kranokpornt&#64;ecosoft.co.th</a>&gt;</li>
<li>FactorLibre (<a class="reference external" href="http://factorlibre.com">http://factorlibre.com</a>)
* Hugo Córdoba &lt;<a class="reference external" href="mailto:hugo.cordoba&#64;factorlibre.com">hugo.cordoba&#64;factorlibre.com</a>&gt;</li>
</ul>
</blockquote>
</div>
@@ -421,7 +423,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<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-reporting/tree/15.0/stock_report_quantity_by_location">OCA/stock-logistics-reporting</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/tree/16.0/stock_report_quantity_by_location">OCA/stock-logistics-reporting</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>

View File

@@ -7,7 +7,7 @@ from odoo.tests.common import TransactionCase
class TestStockReportQuantityByLocation(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestStockReportQuantityByLocation, cls).setUpClass()
super().setUpClass()
cls.stock_loc = cls.env.ref("stock.stock_location_stock")
def test_wizard(self):

View File

@@ -1 +1,2 @@
from . import stock_report_quantity_by_location_prepare
from . import stock_report_quantity_by_location

View File

@@ -1,86 +1,6 @@
# Copyright 2019-21 ForgeFlow, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
class StockReportByLocationPrepare(models.TransientModel):
_name = "stock.report.quantity.by.location.prepare"
_description = "Stock Report Quantity By Location Prepare"
location_ids = fields.Many2many(
comodel_name="stock.location", string="Locations", required=True
)
availability = fields.Selection(
selection=[("on_hand", "On Hand"), ("unreserved", "Unreserved")],
default="on_hand",
help="Unreserved is the Stock On Hand minus the reservations",
)
with_quantity = fields.Boolean(
string="Quantity > 0",
default=True,
help="Show only the products that have existing quantity on hand",
)
def open(self):
self.ensure_one()
self._compute_stock_report_by_location()
action = {
"type": "ir.actions.act_window",
"view_mode": "pivot,tree",
"name": _("Stock Report by Location"),
"context": {
"search_default_quantity_gt_zero": 1,
"group_by_no_leaf": 1,
"group_by": [],
},
"res_model": "stock.report.quantity.by.location",
"domain": [("wiz_id", "=", self.id)],
}
return action
def _compute_stock_report_by_location(self):
self.ensure_one()
recs = []
for loc in self.location_ids:
quant_groups = self.env["stock.quant"].read_group(
[("location_id", "child_of", [loc.id])],
["quantity", "reserved_quantity", "product_id"],
["product_id"],
)
mapping = {}
for quant_group in quant_groups:
qty_on_hand = quant_group["quantity"]
qty_reserved = quant_group["reserved_quantity"]
qty_unreserved = qty_on_hand - qty_reserved
qty_dict = {
"quantity_on_hand": qty_on_hand,
"quantity_reserved": qty_reserved,
"quantity_unreserved": qty_unreserved,
}
mapping.setdefault(quant_group["product_id"][0], qty_dict)
products = self.env["product.product"].search([("type", "=", "product")])
vals_list = []
for product in products:
qty_dict = mapping.get(product.id, {})
qty_on_hand = qty_dict.get("quantity_on_hand", 0.0)
qty_reserved = qty_dict.get("quantity_reserved", 0.0)
qty_unreserved = qty_dict.get("quantity_unreserved", 0.0)
if (self.with_quantity and qty_on_hand) or not self.with_quantity:
vals_list.append(
{
"product_id": product.id,
"product_category_id": product.categ_id.id,
"uom_id": product.uom_id.id,
"quantity_on_hand": qty_on_hand,
"quantity_reserved": qty_reserved,
"quantity_unreserved": qty_unreserved,
"location_id": loc.id,
"wiz_id": self.id,
"default_code": product.default_code,
}
)
recs = self.env["stock.report.quantity.by.location"].create(vals_list)
return recs.ids
from odoo import fields, models
class StockReportQuantityByLocation(models.TransientModel):

View File

@@ -0,0 +1,81 @@
# Copyright 2019-21 ForgeFlow, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
class StockReportByLocationPrepare(models.TransientModel):
_name = "stock.report.quantity.by.location.prepare"
_description = "Stock Report Quantity By Location Prepare"
location_ids = fields.Many2many(
comodel_name="stock.location", string="Locations", required=True
)
availability = fields.Selection(
selection=[("on_hand", "On Hand"), ("unreserved", "Unreserved")],
default="on_hand",
help="Unreserved is the Stock On Hand minus the reservations",
)
with_quantity = fields.Boolean(
string="Quantity > 0",
default=True,
help="Show only the products that have existing quantity on hand",
)
def open(self):
self.ensure_one()
self._compute_stock_report_by_location()
action = {
"type": "ir.actions.act_window",
"view_mode": "pivot,tree",
"name": _("Stock Report by Location"),
"context": {
"search_default_quantity_gt_zero": 1,
"group_by_no_leaf": 1,
"group_by": [],
},
"res_model": "stock.report.quantity.by.location",
"domain": [("wiz_id", "=", self.id)],
}
return action
def _compute_stock_report_by_location(self):
self.ensure_one()
vals_list = []
for loc in self.location_ids:
quant_groups = self.env["stock.quant"].read_group(
[("location_id", "child_of", [loc.id])],
["quantity", "reserved_quantity", "product_id"],
["product_id"],
)
mapping = {}
for quant_group in quant_groups:
qty_on_hand = quant_group["quantity"]
qty_reserved = quant_group["reserved_quantity"]
qty_unreserved = qty_on_hand - qty_reserved
qty_dict = {
"quantity_on_hand": qty_on_hand,
"quantity_reserved": qty_reserved,
"quantity_unreserved": qty_unreserved,
}
mapping.setdefault(quant_group["product_id"][0], qty_dict)
products = self.env["product.product"].search([("type", "=", "product")])
for product in products:
qty_dict = mapping.get(product.id, {})
qty_on_hand = qty_dict.get("quantity_on_hand", 0.0)
qty_reserved = qty_dict.get("quantity_reserved", 0.0)
qty_unreserved = qty_dict.get("quantity_unreserved", 0.0)
if not self.with_quantity or qty_on_hand:
vals_list.append(
{
"product_id": product.id,
"product_category_id": product.categ_id.id,
"uom_id": product.uom_id.id,
"quantity_on_hand": qty_on_hand,
"quantity_reserved": qty_reserved,
"quantity_unreserved": qty_unreserved,
"location_id": loc.id,
"wiz_id": self.id,
"default_code": product.default_code,
}
)
self.env["stock.report.quantity.by.location"].create(vals_list)

View File

@@ -79,7 +79,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
</field>
</record>
<record id="stock_report_quantity_by_location_search_view" model="ir.ui.view">
<record id="stock_report_quantity_by_location_search_view" model="ir.ui.view">
<field name="name">Stock Report Quantity By Location Search</field>
<field name="model">stock.report.quantity.by.location</field>
<field name="arch" type="xml">