[IMP] stock_warehouse_orderpoint_stock_info: black, isort

This commit is contained in:
ps-tubtim
2019-12-19 10:04:40 +07:00
parent 6982ed997d
commit dcc895ac41
3 changed files with 88 additions and 83 deletions

View File

@@ -8,19 +8,15 @@
{
"name": "Stock Warehouse Orderpoint Stock Info",
"version": "12.0.1.0.0",
"depends": [
"stock",
],
"version": "13.0.1.0.0",
"depends": ["stock"],
"author": "OdooMRP team, "
"AvanzOSC, "
"Tecnativa, "
"Odoo Community Association (OCA)",
"AvanzOSC, "
"Tecnativa, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse",
"license": "AGPL-3",
"data": [
"views/stock_warehouse_orderpoint_view.xml",
],
"installable": True
"data": ["views/stock_warehouse_orderpoint_view.xml"],
"installable": True,
}

View File

@@ -12,50 +12,48 @@ from odoo import api, fields, models
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
_inherit = "stock.warehouse.orderpoint"
product_location_qty = fields.Float(
string='Quantity On Location',
compute='_compute_product_available_qty'
string="Quantity On Location", compute="_compute_product_available_qty"
)
incoming_location_qty = fields.Float(
string='Incoming On Location',
compute='_compute_product_available_qty'
string="Incoming On Location", compute="_compute_product_available_qty"
)
outgoing_location_qty = fields.Float(
string='Outgoing On Location',
compute='_compute_product_available_qty'
string="Outgoing On Location", compute="_compute_product_available_qty"
)
virtual_location_qty = fields.Float(
string='Forecast On Location',
compute='_compute_product_available_qty'
string="Forecast On Location", compute="_compute_product_available_qty"
)
product_category = fields.Many2one(
string='Product Category',
related='product_id.categ_id',
store=True
string="Product Category", related="product_id.categ_id", store=True
)
@api.multi
def _compute_product_available_qty(self):
operation_by_locaion = defaultdict(
lambda: self.env['stock.warehouse.orderpoint']
lambda: self.env["stock.warehouse.orderpoint"]
)
for order in self:
operation_by_locaion[order.location_id] |= order
for location_id, order_in_locaion in operation_by_locaion.items():
products = order_in_locaion.mapped('product_id').with_context(
location=location_id.id
)._compute_quantities_dict(
lot_id=self.env.context.get('lot_id'),
owner_id=self.env.context.get('owner_id'),
package_id=self.env.context.get('package_id')
products = (
order_in_locaion.mapped("product_id")
.with_context(location=location_id.id)
._compute_quantities_dict(
lot_id=self.env.context.get("lot_id"),
owner_id=self.env.context.get("owner_id"),
package_id=self.env.context.get("package_id"),
)
)
for order in order_in_locaion:
product = products[order.product_id.id]
order.update({
'product_location_qty': product['qty_available'],
'incoming_location_qty': product['incoming_qty'],
'outgoing_location_qty': product['outgoing_qty'],
'virtual_location_qty': product['virtual_available'],
})
order.update(
{
"product_location_qty": product["qty_available"],
"incoming_location_qty": product["incoming_qty"],
"outgoing_location_qty": product["outgoing_qty"],
"virtual_location_qty": product["virtual_available"],
}
)

View File

@@ -10,54 +10,57 @@ from odoo.tests.common import SavepointCase
class TestStockWarehouseOrderpoint(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Get required Model
cls.reordering_rule_model = cls.env['stock.warehouse.orderpoint']
cls.stock_move_model = cls.env['stock.move']
cls.product_model = cls.env['product.product']
cls.product_ctg_model = cls.env['product.category']
cls.reordering_rule_model = cls.env["stock.warehouse.orderpoint"]
cls.stock_move_model = cls.env["stock.move"]
cls.product_model = cls.env["product.product"]
cls.product_ctg_model = cls.env["product.category"]
# Get required Model data
cls.product_uom = cls.env.ref('uom.product_uom_unit')
cls.dest_location = cls.env.ref('stock.stock_location_stock')
cls.location = cls.env.ref('stock.stock_location_locations_partner')
cls.picking = cls.env.ref('stock.picking_type_in')
cls.product_uom = cls.env.ref("uom.product_uom_unit")
cls.dest_location = cls.env.ref("stock.stock_location_stock")
cls.location = cls.env.ref("stock.stock_location_locations_partner")
cls.picking = cls.env.ref("stock.picking_type_in")
# Create product category and product
cls.product_ctg = cls.product_ctg_model.create({
'name': 'test_product_ctg',
})
cls.product = cls.product_model.create({
'name': 'Test Product',
'categ_id': cls.product_ctg.id,
'type': 'product',
'uom_id': cls.product_uom.id,
})
cls.product_ctg = cls.product_ctg_model.create({"name": "test_product_ctg"})
cls.product = cls.product_model.create(
{
"name": "Test Product",
"categ_id": cls.product_ctg.id,
"type": "product",
"uom_id": cls.product_uom.id,
}
)
# Create Reordering Rule
cls.reordering_record = cls.reordering_rule_model.create({
'name': 'Reordering Rule',
'product_id': cls.product.id,
'product_min_qty': '1',
'product_max_qty': '5',
'qty_multiple': '1',
'location_id': cls.dest_location.id,
})
cls.reordering_record = cls.reordering_rule_model.create(
{
"name": "Reordering Rule",
"product_id": cls.product.id,
"product_min_qty": "1",
"product_max_qty": "5",
"qty_multiple": "1",
"location_id": cls.dest_location.id,
}
)
def create_stock_move(self):
"""Create a Stock Move."""
move = self.stock_move_model.create({
'name': 'Reordering Product',
'product_id': self.product.id,
'product_uom': self.product_uom.id,
'product_uom_qty': '10.0',
'picking_type_id': self.picking.id,
'location_id': self.location.id,
'location_dest_id': self.dest_location.id
})
move = self.stock_move_model.create(
{
"name": "Reordering Product",
"product_id": self.product.id,
"product_uom": self.product_uom.id,
"product_uom_qty": "10.0",
"picking_type_id": self.picking.id,
"location_id": self.location.id,
"location_dest_id": self.dest_location.id,
}
)
move._action_confirm()
return move
@@ -66,17 +69,25 @@ class TestStockWarehouseOrderpoint(SavepointCase):
# Create & process moves to test the product quantity
move = self.create_stock_move()
self.reordering_record.refresh()
self.assertEqual(self.reordering_record.incoming_location_qty,
self.product.incoming_qty,
'Incoming Qty does not match')
self.assertEqual(self.reordering_record.virtual_location_qty,
self.product.virtual_available,
'Virtual Qty does not match')
self.assertEqual(
self.reordering_record.incoming_location_qty,
self.product.incoming_qty,
"Incoming Qty does not match",
)
self.assertEqual(
self.reordering_record.virtual_location_qty,
self.product.virtual_available,
"Virtual Qty does not match",
)
move._action_done()
self.reordering_record.refresh()
self.assertEqual(self.reordering_record.product_location_qty,
self.product.qty_available,
'Available Qty does not match')
self.assertEqual(self.reordering_record.virtual_location_qty,
self.product.virtual_available,
'Virtual Qty does not match')
self.assertEqual(
self.reordering_record.product_location_qty,
self.product.qty_available,
"Available Qty does not match",
)
self.assertEqual(
self.reordering_record.virtual_location_qty,
self.product.virtual_available,
"Virtual Qty does not match",
)