- Make use of create_multi to speed up.

- Add an option in the wizard 'Quantity > 0' to speed up the report
This commit is contained in:
Jordi Ballester
2021-04-28 23:07:09 +02:00
committed by Christopher Ormaza
parent f89089fd10
commit 2fcb7ec412
2 changed files with 70 additions and 35 deletions

View File

@@ -10,6 +10,11 @@ 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
) )
with_quantity = fields.Boolean(
string="Quantity > 0",
default=True,
help="Show only the products that have existing quantity on hand",
)
def open(self): def open(self):
self.ensure_one() self.ensure_one()
@@ -42,8 +47,11 @@ class StockReportByLocationPrepare(models.TransientModel):
for quant_group in quant_groups for quant_group in quant_groups
} }
products = self.env["product.product"].search([("type", "=", "product")]) products = self.env["product.product"].search([("type", "=", "product")])
vals_list = []
for product in products: for product in products:
r = self.env["stock.report.quantity.by.location"].create( quantity = mapping.get(product.id, 0.0)
if (self.with_quantity and quantity) or not self.with_quantity:
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,
@@ -54,8 +62,8 @@ class StockReportByLocationPrepare(models.TransientModel):
"default_code": product.default_code, "default_code": product.default_code,
} }
) )
recs.append(r.id) recs = self.env["stock.report.quantity.by.location"].create(vals_list)
return recs return recs.ids
class StockReportQuantityByLocation(models.TransientModel): class StockReportQuantityByLocation(models.TransientModel):

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<!-- <!--
Copyright 2019 Eficent Business and IT Consulting Services, S.L. Copyright 2019 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -11,37 +11,54 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<form> <form>
<group> <group>
<group> <group>
<field name="location_ids" widget="many2many_tags"/> <field name="location_ids" widget="many2many_tags" />
</group>
<group>
<field name="with_quantity" />
</group> </group>
</group> </group>
<footer> <footer>
<button name="open" string="Retrieve the Inventory Quantities" type="object" class="btn-primary"/> <button
name="open"
string="Retrieve the Inventory Quantities"
type="object"
class="btn-primary"
/>
<button string="Cancel" class="btn-default" special="cancel" /> <button string="Cancel" class="btn-default" special="cancel" />
</footer> </footer>
</form> </form>
</field> </field>
</record> </record>
<record id="action_stock_report_quantity_by_location_prepare" model="ir.actions.act_window"> <record
id="action_stock_report_quantity_by_location_prepare"
model="ir.actions.act_window"
>
<field name="name">Inventory By Location</field> <field name="name">Inventory By Location</field>
<field name="res_model">stock.report.quantity.by.location.prepare</field> <field name="res_model">stock.report.quantity.by.location.prepare</field>
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="view_id" ref="stock_report_quantity_by_location_prepare_form_view"/> <field
name="view_id"
ref="stock_report_quantity_by_location_prepare_form_view"
/>
<field name="target">new</field> <field name="target">new</field>
</record> </record>
<menuitem id="menu_quantity_by_location" name="Inventory by Location" <menuitem
id="menu_quantity_by_location"
name="Inventory by Location"
parent="stock.menu_warehouse_report" parent="stock.menu_warehouse_report"
action="action_stock_report_quantity_by_location_prepare" action="action_stock_report_quantity_by_location_prepare"
groups="stock.group_stock_manager"/> groups="stock.group_stock_manager"
/>
<record id="stock_report_quantity_by_location_tree_view" model="ir.ui.view"> <record id="stock_report_quantity_by_location_tree_view" model="ir.ui.view">
<field name="name">Stock Report Quantity By Location Form</field> <field name="name">Stock Report Quantity By Location Form</field>
<field name="model">stock.report.quantity.by.location</field> <field name="model">stock.report.quantity.by.location</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree> <tree>
<field name="product_id"/> <field name="product_id" />
<field name="location_id"/> <field name="location_id" />
<field name="quantity"/> <field name="quantity" />
<field name="uom_id" groups="uom.group_uom"/> <field name="uom_id" groups="uom.group_uom" />
</tree> </tree>
</field> </field>
</record> </record>
@@ -51,9 +68,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<field name="model">stock.report.quantity.by.location</field> <field name="model">stock.report.quantity.by.location</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<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" type="measure" />
</pivot> </pivot>
</field> </field>
</record> </record>
@@ -63,13 +80,23 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<field name="model">stock.report.quantity.by.location</field> <field name="model">stock.report.quantity.by.location</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Search Stock Report Quantity by Location"> <search string="Search Stock Report Quantity by Location">
<field name="product_id"/> <field name="product_id" />
<field name="default_code"/> <field name="default_code" />
<field name="location_id" groups="stock.group_stock_multi_locations"/> <field name="location_id" groups="stock.group_stock_multi_locations" />
<field name="product_category_id"/> <field name="product_category_id" />
<filter name="quantity_gt_zero" string="Quantity > 0" domain="[('quantity', '>', '0.0')]"/> <filter
name="quantity_gt_zero"
string="Quantity > 0"
domain="[('quantity', '>', '0.0')]"
/>
<group expand="0" string="Group By"> <group expand="0" string="Group By">
<filter name="location" string="Location" domain="[]" context="{'group_by':'location_id'}" help="Group by Location"/> <filter
name="location"
string="Location"
domain="[]"
context="{'group_by':'location_id'}"
help="Group by Location"
/>
</group> </group>
</search> </search>
</field> </field>