- 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(
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):
self.ensure_one()
@@ -42,8 +47,11 @@ class StockReportByLocationPrepare(models.TransientModel):
for quant_group in quant_groups
}
products = self.env["product.product"].search([("type", "=", "product")])
vals_list = []
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_category_id": product.categ_id.id,
@@ -54,8 +62,8 @@ class StockReportByLocationPrepare(models.TransientModel):
"default_code": product.default_code,
}
)
recs.append(r.id)
return recs
recs = self.env["stock.report.quantity.by.location"].create(vals_list)
return recs.ids
class StockReportQuantityByLocation(models.TransientModel):

View File

@@ -13,25 +13,42 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<group>
<field name="location_ids" widget="many2many_tags" />
</group>
<group>
<field name="with_quantity" />
</group>
</group>
<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" />
</footer>
</form>
</field>
</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="res_model">stock.report.quantity.by.location.prepare</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>
</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"
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">
<field name="name">Stock Report Quantity By Location Form</field>
@@ -67,9 +84,19 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
<field name="default_code" />
<field name="location_id" groups="stock.group_stock_multi_locations" />
<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">
<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>
</search>
</field>