[IMP] stock_report_quantity_by_location: black, isort, prettier

This commit is contained in:
kranokporn
2020-07-14 17:52:49 +07:00
committed by Christopher Ormaza
parent 73c549355b
commit bab7136a1b
6 changed files with 58 additions and 70 deletions

View File

@@ -3,18 +3,12 @@
{
"name": "Stock Report Quantity By Location",
"summary": "Stock Report Quantity By Location",
"version": "12.0.1.0.0",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"version": "13.0.1.0.0",
"author": "Eficent, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-reporting",
"category": "Warehouse Management",
"license": "AGPL-3",
"depends": [
"product",
"stock",
],
"data": [
'wizards/stock_report_quantity_by_location_views.xml',
],
"depends": ["product", "stock"],
"data": ["wizards/stock_report_quantity_by_location_views.xml"],
"installable": True,
}

View File

@@ -1,3 +1,3 @@
* Eficent Business and IT Consulting Services, S.L. (https://www.eficent.com)
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Hector Villarreal <hector.villarreal@eficent.com>
* Hector Villarreal <hector.villarreal@eficent.com>

View File

@@ -1,2 +1,2 @@
This module adds an additional reporting on Inventory side where warehouse
location quantities are shown by all stockable products.
location quantities are shown by all stockable products.

View File

@@ -5,18 +5,17 @@ from odoo.tests.common import SavepointCase
class TestStockReportQuantityByLocation(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestStockReportQuantityByLocation, cls).setUpClass()
cls.stock_loc = cls.env.ref('stock.stock_location_stock')
cls.stock_loc = cls.env.ref("stock.stock_location_stock")
def test_wizard(self):
self.wizard = self.env[
'stock.report.quantity.by.location.prepare'].create(
{'location_ids': [(4, self.stock_loc.id)]})
self.wizard = self.env["stock.report.quantity.by.location.prepare"].create(
{"location_ids": [(4, self.stock_loc.id)]}
)
wiz_creator = self.wizard.open()
wizard_lines = self.env['stock.report.quantity.by.location'].search(
wiz_creator['domain'])
self.assertFalse(
any(wiz.location_id != self.stock_loc for wiz in wizard_lines))
wizard_lines = self.env["stock.report.quantity.by.location"].search(
wiz_creator["domain"]
)
self.assertFalse(any(wiz.location_id != self.stock_loc for wiz in wizard_lines))

View File

@@ -1,27 +1,30 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models, _
from odoo import _, fields, models
class StockReportByLocationPrepare(models.TransientModel):
_name = 'stock.report.quantity.by.location.prepare'
_description = 'Stock Report Quantity By Location Prepare'
_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)
location_ids = fields.Many2many(
comodel_name="stock.location", string="Locations", required=True
)
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)],
"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
@@ -29,49 +32,42 @@ class StockReportByLocationPrepare(models.TransientModel):
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', 'product_id'],
['product_id'])
mapping = dict(
[(quant_group['product_id'][0],
quant_group['quantity'])
for quant_group in quant_groups]
quant_groups = self.env["stock.quant"].read_group(
[("location_id", "child_of", [loc.id])],
["quantity", "product_id"],
["product_id"],
)
products = self.env['product.product'].search(
[('type', '=', 'product')])
mapping = {
quant_group["product_id"][0]: quant_group["quantity"]
for quant_group in quant_groups
}
products = self.env["product.product"].search([("type", "=", "product")])
for product in products:
r = self.env['stock.report.quantity.by.location'].create({
'product_id': product.id,
'product_category_id': product.categ_id.id,
'uom_id': product.uom_id.id,
'quantity': mapping.get(product.id, 0.0),
'location_id': loc.id,
'wiz_id': self.id,
'default_code': product.default_code,
})
r = self.env["stock.report.quantity.by.location"].create(
{
"product_id": product.id,
"product_category_id": product.categ_id.id,
"uom_id": product.uom_id.id,
"quantity": mapping.get(product.id, 0.0),
"location_id": loc.id,
"wiz_id": self.id,
"default_code": product.default_code,
}
)
recs.append(r.id)
return recs
class StockReportQuantityByLocation(models.TransientModel):
_name = 'stock.report.quantity.by.location'
_description = 'Stock Report By Location'
_name = "stock.report.quantity.by.location"
_description = "Stock Report By Location"
wiz_id = fields.Many2one(
comodel_name='stock.report.quantity.by.location.prepare')
product_id = fields.Many2one(
comodel_name='product.product',
required=True,
)
wiz_id = fields.Many2one(comodel_name="stock.report.quantity.by.location.prepare")
product_id = fields.Many2one(comodel_name="product.product", required=True)
product_category_id = fields.Many2one(
comodel_name='product.category',
string='Product Category',
)
location_id = fields.Many2one(
comodel_name='stock.location',
required=True,
comodel_name="product.category", string="Product Category"
)
location_id = fields.Many2one(comodel_name="stock.location", required=True)
quantity = fields.Float()
uom_id = fields.Many2one(comodel_name='uom.uom', string='Product UoM',)
default_code = fields.Char('Internal Reference',)
uom_id = fields.Many2one(comodel_name="uom.uom", string="Product UoM")
default_code = fields.Char("Internal Reference")

View File

@@ -77,4 +77,3 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
</record>
</odoo>