Skip to content

Commit

Permalink
[16.0][IMP]stock_report_quantity_by_location: Included report generation
Browse files Browse the repository at this point in the history
    Included pdf report generation functionality for module
stock_report_quantity_by_location
  • Loading branch information
anusriNPS committed Oct 4, 2024
1 parent 9960d1f commit a6aefc7
Show file tree
Hide file tree
Showing 13 changed files with 980 additions and 5 deletions.
1 change: 1 addition & 0 deletions stock_report_quantity_by_location/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"data": [
"wizards/stock_report_quantity_by_location_views.xml",
"security/ir.model.access.csv",
"data/paperformat_data.xml",
],
"installable": True,
}
20 changes: 20 additions & 0 deletions stock_report_quantity_by_location/data/paperformat_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="paperformat_report_quantity_by_location" model="report.paperformat">
<field name="name">Stock Report Qunatity By Location A4</field>
<field name="default" eval="True" />
<field name="format">A4</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
<field name="orientation">Portrait</field>
<field name="margin_top">28</field>
<field name="margin_bottom">28</field>
<field name="margin_left">7</field>
<field name="margin_right">7</field>
<field name="header_line" eval="False" />
<field name="header_spacing">24</field>
<field name="dpi">90</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions stock_report_quantity_by_location/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_report_quantity_by_location_pdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from odoo import api, fields, models


class StockReportQuantityByProductView(models.TransientModel):
_name = "stock.report.quantity.by.product.view"
_description = "Stock Report Quantity By Product View"

report_id = fields.Many2one("report.stock.report.quantity.by.location.pdf")
name = fields.Char()


class StockReportQuantityByLocationView(models.TransientModel):
_name = "stock.report.quantity.by.location.view"
_description = "Stock Report Quantity By Location View"

report_location_id = fields.Many2one("report.stock.report.quantity.by.location.pdf")

loc_name = fields.Char()
product_name = fields.Char()
quantity_on_hand = fields.Float()
quantity_reserved = fields.Float()
quantity_unreserved = fields.Float()


class StockReportQuantityByLocationReport(models.TransientModel):
_name = "report.stock.report.quantity.by.location.pdf"
_description = "Stock Report Quantity By Location"

location_ids = fields.Many2many(
comodel_name="stock.location", string="Locations", required=True
)

with_quantity = fields.Boolean(
string="Quantity>0",
default=True,
help="Show only the products that have existing quantity on hand",
)

results = fields.One2many(
comodel_name="stock.report.quantity.by.product.view",
inverse_name="report_id",
compute="_compute_results",
)

results_location = fields.One2many(
comodel_name="stock.report.quantity.by.location.view",
inverse_name="report_location_id",
compute="_compute_results",
)

@api.depends("location_ids")
def _compute_results(self):
"""
Generate report lines
"""
self.ensure_one()
results = self.env["stock.report.quantity.by.product.view"]
results_location = self.env["stock.report.quantity.by.location.view"]
products = self.env["product.product"].search([("type", "=", "product")])
for product in products:
product_exist = False
for loc in self.location_ids:
available_products = self.env["stock.quant"].read_group(
[
("product_id", "=", product.id),
("location_id", "child_of", [loc.id]),
],
["quantity", "reserved_quantity", "product_id"],
["product_id"],
)
if available_products:
qty_on_hand = available_products[0]["quantity"]
qty_reserved = available_products[0]["reserved_quantity"]
qty_unreserved = qty_on_hand - qty_reserved
if not self.with_quantity or qty_on_hand > 0:
product_exist = True
vals = {
"loc_name": loc.display_name,
"product_name": product.display_name,
"quantity_on_hand": qty_on_hand,
"quantity_reserved": qty_reserved,
"quantity_unreserved": qty_unreserved,
}
results_location |= results_location.new(vals)
if product_exist:
vals_product = {
"name": product.display_name,
}
results |= results.new(vals_product)
self.results = results
self.results_location = results_location

def print_report(self, report_type="qweb"):
self.ensure_one()
action = (
report_type == "xlsx"
and self.env.ref(
"stock_report_quantity_by_location_pdf."
"action_stock_report_quantity_by_location_xlsx",
raise_if_not_found=False,
)
or self.env.ref(
"stock_report_quantity_by_location_pdf."
"action_stock_report_quantity_by_location_pdf",
raise_if_not_found=False,
)
)
return action.report_action(self, config=False)

def _get_html(self):
result = {}
rcontext = {}
report = self.browse(self._context.get("active_id"))
if report:
rcontext["o"] = report
result["html"] = self.env["ir.qweb"]._render(
"stock_report_quantity_by_location_pdf.report_stock_report_quantity_by_location_html",
rcontext,
)
return result

@api.model
def get_html(self, given_context=None):
return self.with_context(given_context)._get_html()
Loading

0 comments on commit a6aefc7

Please sign in to comment.