[IMP] stock_report_quantity_by_location: show qty on hand, reserved and

unreserved
This commit is contained in:
JordiMForgeFlow
2022-07-26 14:53:53 +02:00
committed by Christopher Ormaza
parent 82af5b8ae9
commit 72bca56d37
2 changed files with 29 additions and 25 deletions

View File

@@ -10,12 +10,6 @@ class StockReportByLocationPrepare(models.TransientModel):
location_ids = fields.Many2many( location_ids = fields.Many2many(
comodel_name="stock.location", string="Locations", required=True comodel_name="stock.location", string="Locations", required=True
) )
availability = fields.Selection(
string="Availability",
selection=[("on_hand", "On Hand"), ("unreserved", "Unreserved")],
default="on_hand",
help="Unreserved is the Stock On Hand minus the reservations",
)
with_quantity = fields.Boolean( with_quantity = fields.Boolean(
string="Quantity > 0", string="Quantity > 0",
default=True, default=True,
@@ -48,28 +42,33 @@ class StockReportByLocationPrepare(models.TransientModel):
["quantity", "reserved_quantity", "product_id"], ["quantity", "reserved_quantity", "product_id"],
["product_id"], ["product_id"],
) )
if self.availability == "on_hand": mapping = {}
mapping = { for quant_group in quant_groups:
quant_group["product_id"][0]: quant_group["quantity"] qty_on_hand = quant_group["quantity"]
for quant_group in quant_groups qty_reserved = quant_group["reserved_quantity"]
} qty_unreserved = qty_on_hand - qty_reserved
else: qty_dict = {
mapping = { "quantity_on_hand": qty_on_hand,
quant_group["product_id"][0]: quant_group["quantity"] "quantity_reserved": qty_reserved,
- quant_group["reserved_quantity"] "quantity_unreserved": qty_unreserved,
for quant_group in quant_groups
} }
mapping.setdefault(quant_group["product_id"][0], qty_dict)
products = self.env["product.product"].search([("type", "=", "product")]) products = self.env["product.product"].search([("type", "=", "product")])
vals_list = [] vals_list = []
for product in products: for product in products:
quantity = mapping.get(product.id, 0.0) qty_dict = mapping.get(product.id, {})
if (self.with_quantity and quantity) or not self.with_quantity: 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( vals_list.append(
{ {
"product_id": product.id, "product_id": product.id,
"product_category_id": product.categ_id.id, "product_category_id": product.categ_id.id,
"uom_id": product.uom_id.id, "uom_id": product.uom_id.id,
"quantity": mapping.get(product.id, 0.0), "quantity_on_hand": qty_on_hand,
"quantity_reserved": qty_reserved,
"quantity_unreserved": qty_unreserved,
"location_id": loc.id, "location_id": loc.id,
"wiz_id": self.id, "wiz_id": self.id,
"default_code": product.default_code, "default_code": product.default_code,
@@ -89,6 +88,8 @@ class StockReportQuantityByLocation(models.TransientModel):
comodel_name="product.category", string="Product Category" comodel_name="product.category", string="Product Category"
) )
location_id = fields.Many2one(comodel_name="stock.location", required=True) location_id = fields.Many2one(comodel_name="stock.location", required=True)
quantity = fields.Float() quantity_on_hand = fields.Float(string="Qty On Hand")
quantity_reserved = fields.Float(string="Qty Reserved")
quantity_unreserved = fields.Float(string="Qty Unreserved")
uom_id = fields.Many2one(comodel_name="uom.uom", string="Product UoM") uom_id = fields.Many2one(comodel_name="uom.uom", string="Product UoM")
default_code = fields.Char("Internal Reference") default_code = fields.Char("Internal Reference")

View File

@@ -14,7 +14,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<field name="location_ids" widget="many2many_tags" /> <field name="location_ids" widget="many2many_tags" />
</group> </group>
<group> <group>
<field name="availability" />
<field name="with_quantity" /> <field name="with_quantity" />
</group> </group>
</group> </group>
@@ -58,7 +57,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<tree> <tree>
<field name="product_id" /> <field name="product_id" />
<field name="location_id" /> <field name="location_id" />
<field name="quantity" /> <field name="quantity_on_hand" />
<field name="quantity_reserved" />
<field name="quantity_unreserved" />
<field name="uom_id" groups="uom.group_uom" /> <field name="uom_id" groups="uom.group_uom" />
</tree> </tree>
</field> </field>
@@ -71,7 +72,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<pivot string="Stock by Location" disable_linking="True"> <pivot string="Stock by Location" disable_linking="True">
<field name="product_id" type="row" /> <field name="product_id" type="row" />
<field name="location_id" type="col" /> <field name="location_id" type="col" />
<field name="quantity" type="measure" /> <field name="quantity_on_hand" type="measure" />
<field name="quantity_reserved" type="measure" />
<field name="quantity_unreserved" type="measure" />
</pivot> </pivot>
</field> </field>
</record> </record>
@@ -87,8 +90,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<field name="product_category_id" /> <field name="product_category_id" />
<filter <filter
name="quantity_gt_zero" name="quantity_gt_zero"
string="Quantity > 0" string="Quantity On Hand > 0"
domain="[('quantity', '>', '0.0')]" domain="[('quantity_on_hand', '>', '0.0')]"
/> />
<group expand="0" string="Group By"> <group expand="0" string="Group By">
<filter <filter