[IMP] stock_orderpoint_manual_procurement_uom: black, isort

This commit is contained in:
ps-tubtim
2020-03-11 10:57:59 +07:00
committed by Miquel Raïch
parent 3b3cad505e
commit 69ebd208e4
4 changed files with 104 additions and 104 deletions

View File

@@ -1,20 +1,15 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L. # Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com)
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{ {
"name": "Stock Orderpoint Manual Procurement UoM", "name": "Stock Orderpoint Manual Procurement UoM",
"summary": "Glue module for stock_orderpoint_uom and " "summary": "Glue module for stock_orderpoint_uom and "
"stock_orderpoint_manual_procurement", "stock_orderpoint_manual_procurement",
"version": "12.0.1.0.0", "version": "13.0.1.0.0",
"author": "Eficent, " "author": "Eficent, Odoo Community Association (OCA)",
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse", "website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management", "category": "Warehouse Management",
"depends": [ "depends": ["stock_orderpoint_uom", "stock_orderpoint_manual_procurement"],
"stock_orderpoint_uom",
"stock_orderpoint_manual_procurement",
],
"license": "AGPL-3", "license": "AGPL-3",
'installable': True, "installable": True,
'application': False, "application": False,
} }

View File

@@ -1,19 +1,19 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L. # Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com)
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models from odoo import api, models
class StockWarehouseOrderpoint(models.Model): class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint' _inherit = "stock.warehouse.orderpoint"
@api.multi @api.multi
def _get_procure_recommended_qty(self, virtual_qty, op_qtys): def _get_procure_recommended_qty(self, virtual_qty, op_qtys):
product_qty = \ product_qty = super(
super(StockWarehouseOrderpoint, self)._get_procure_recommended_qty( StockWarehouseOrderpoint, self
virtual_qty, op_qtys) )._get_procure_recommended_qty(virtual_qty, op_qtys)
if self.procure_uom_id: if self.procure_uom_id:
product_qty = self.product_id.uom_id._compute_quantity( product_qty = self.product_id.uom_id._compute_quantity(
product_qty, self.procure_uom_id) product_qty, self.procure_uom_id
)
return product_qty return product_qty

View File

@@ -1,48 +1,49 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L. # Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com)
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests import common from odoo.tests import common
class TestStockWarehouseOrderpoint(common.TransactionCase): class TestStockWarehouseOrderpoint(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestStockWarehouseOrderpoint, self).setUp() super(TestStockWarehouseOrderpoint, self).setUp()
# Refs # Refs
self.group_stock_manager = self.env.ref('stock.group_stock_manager') self.group_stock_manager = self.env.ref("stock.group_stock_manager")
self.group_purchase_manager = self.env.ref( self.group_purchase_manager = self.env.ref("purchase.group_purchase_manager")
'purchase.group_purchase_manager')
self.vendor = self.env.ref( self.vendor = self.env.ref(
'stock_orderpoint_manual_procurement.product_supplierinfo_product_7') # noqa "stock_orderpoint_manual_procurement.product_supplierinfo_product_7"
) # noqa
self.group_change_procure_qty = self.env.ref( self.group_change_procure_qty = self.env.ref(
'stock_orderpoint_manual_procurement.' "stock_orderpoint_manual_procurement." "group_change_orderpoint_procure_qty"
'group_change_orderpoint_procure_qty') )
self.company1 = self.env.ref('base.main_company') self.company1 = self.env.ref("base.main_company")
# Get required Model # Get required Model
self.reordering_rule_model = self.env['stock.warehouse.orderpoint'] self.reordering_rule_model = self.env["stock.warehouse.orderpoint"]
self.product_model = self.env['product.product'] self.product_model = self.env["product.product"]
self.purchase_model = self.env['purchase.order'] self.purchase_model = self.env["purchase.order"]
self.purchase_line_model = self.env['purchase.order.line'] self.purchase_line_model = self.env["purchase.order.line"]
self.user_model = self.env['res.users'] self.user_model = self.env["res.users"]
self.product_ctg_model = self.env['product.category'] self.product_ctg_model = self.env["product.category"]
self.stock_change_model = self.env['stock.change.product.qty'] self.stock_change_model = self.env["stock.change.product.qty"]
self.make_procurement_orderpoint_model =\ self.make_procurement_orderpoint_model = self.env["make.procurement.orderpoint"]
self.env['make.procurement.orderpoint']
# Create users # Create users
self.user = self._create_user('user_1', self.user = self._create_user(
[self.group_stock_manager, "user_1",
self.group_change_procure_qty, [
self.group_purchase_manager], self.group_stock_manager,
self.company1) self.group_change_procure_qty,
self.group_purchase_manager,
],
self.company1,
)
# Get required Model data # Get required Model data
self.product_uom = self.env.ref('uom.product_uom_unit') self.product_uom = self.env.ref("uom.product_uom_unit")
self.location = self.env.ref('stock.stock_location_stock') self.location = self.env.ref("stock.stock_location_stock")
self.product = self.env.ref('product.product_product_7') self.product = self.env.ref("product.product_product_7")
self.dozen = self.env.ref('uom.product_uom_dozen') self.dozen = self.env.ref("uom.product_uom_dozen")
# Create Product category and Product # Create Product category and Product
self.product_ctg = self._create_product_category() self.product_ctg = self._create_product_category()
@@ -58,67 +59,75 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
def _create_user(self, login, groups, company): def _create_user(self, login, groups, company):
""" Create a user.""" """ Create a user."""
group_ids = [group.id for group in groups] group_ids = [group.id for group in groups]
user = \ user = self.user_model.with_context({"no_reset_password": True}).create(
self.user_model.with_context({'no_reset_password': True}).create({ {
'name': 'Test User', "name": "Test User",
'login': login, "login": login,
'password': 'demo', "password": "demo",
'email': 'test@yourcompany.com', "email": "test@yourcompany.com",
'company_id': company.id, "company_id": company.id,
'company_ids': [(4, company.id)], "company_ids": [(4, company.id)],
'groups_id': [(6, 0, group_ids)] "groups_id": [(6, 0, group_ids)],
}) }
)
return user return user
def _create_product_category(self): def _create_product_category(self):
"""Create a Product Category.""" """Create a Product Category."""
product_ctg = self.product_ctg_model.create({ product_ctg = self.product_ctg_model.create({"name": "test_product_ctg"})
'name': 'test_product_ctg',
})
return product_ctg return product_ctg
def _create_product(self): def _create_product(self):
"""Create a Product.""" """Create a Product."""
product = self.product_model.create({ product = self.product_model.create(
'name': 'Test Product', {
'categ_id': self.product_ctg.id, "name": "Test Product",
'type': 'product', "categ_id": self.product_ctg.id,
'uom_id': self.product_uom.id, "type": "product",
'variant_seller_ids': [(6, 0, [self.vendor.id])], "uom_id": self.product_uom.id,
}) "variant_seller_ids": [(6, 0, [self.vendor.id])],
}
)
return product return product
def _update_product_qty(self, product, location, quantity): def _update_product_qty(self, product, location, quantity):
"""Update Product quantity.""" """Update Product quantity."""
change_product_qty = self.stock_change_model.create({ change_product_qty = self.stock_change_model.create(
'location_id': location.id, {
'product_id': product.id, "location_id": location.id,
'new_quantity': quantity, "product_id": product.id,
}) "new_quantity": quantity,
}
)
change_product_qty.change_product_qty() change_product_qty.change_product_qty()
return change_product_qty return change_product_qty
def create_orderpoint(self): def create_orderpoint(self):
"""Create a Reordering Rule""" """Create a Reordering Rule"""
reorder = self.reordering_rule_model.sudo(self.user).create({ reorder = self.reordering_rule_model.sudo(self.user).create(
'name': 'Order-point', {
'product_id': self.product.id, "name": "Order-point",
'product_min_qty': 100.0, "product_id": self.product.id,
'product_max_qty': 500.0, "product_min_qty": 100.0,
'qty_multiple': 1.0, "product_max_qty": 500.0,
'procure_uom_id': self.dozen.id, "qty_multiple": 1.0,
}) "procure_uom_id": self.dozen.id,
}
)
return reorder return reorder
def create_orderpoint_procurement(self): def create_orderpoint_procurement(self):
"""Make Procurement from Reordering Rule""" """Make Procurement from Reordering Rule"""
context = { context = {
'active_model': 'stock.warehouse.orderpoint', "active_model": "stock.warehouse.orderpoint",
'active_ids': self.reorder.ids, "active_ids": self.reorder.ids,
'active_id': self.reorder.id "active_id": self.reorder.id,
} }
wizard = self.make_procurement_orderpoint_model.sudo(self.user).\ wizard = (
with_context(context).create({}) self.make_procurement_orderpoint_model.sudo(self.user)
.with_context(context)
.create({})
)
for line in wizard.item_ids: for line in wizard.item_ids:
line.onchange_uom_id() line.onchange_uom_id()
wizard.make_procurement() wizard.make_procurement()
@@ -132,19 +141,18 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
# As per route configuration, it will create Purchase order # As per route configuration, it will create Purchase order
# Assert that Procurement is created with the desired quantity # Assert that Procurement is created with the desired quantity
purchase = self.purchase_model.search( purchase = self.purchase_model.search([("origin", "ilike", self.reorder.name)])
[('origin', 'ilike', self.reorder.name)])
self.assertEquals(len(purchase), 1) self.assertEquals(len(purchase), 1)
purchase_line = self.purchase_line_model.search( purchase_line = self.purchase_line_model.search(
[('orderpoint_id', '=', self.reorder.id), [("orderpoint_id", "=", self.reorder.id), ("order_id", "=", purchase.id)]
('order_id', '=', purchase.id)]) )
self.assertEquals(len(purchase_line), 1) self.assertEquals(len(purchase_line), 1)
self.assertEqual(self.reorder.product_id.id, self.assertEqual(self.reorder.product_id.id, purchase_line.product_id.id)
purchase_line.product_id.id)
# it could be using an existing PO, thus there could be more origins. # it could be using an existing PO, thus there could be more origins.
self.assertTrue(self.reorder.name in purchase.origin) self.assertTrue(self.reorder.name in purchase.origin)
self.assertNotEqual(self.reorder.procure_recommended_qty, self.assertNotEqual(
purchase_line.product_qty) self.reorder.procure_recommended_qty, purchase_line.product_qty
)
if self.reorder.procure_uom_id == self.reorder.product_id.uom_po_id: if self.reorder.procure_uom_id == self.reorder.product_id.uom_po_id:
# Our PO unit of measure is also dozens (procure uom) # Our PO unit of measure is also dozens (procure uom)
self.assertEqual(purchase_line.product_qty, 40) self.assertEqual(purchase_line.product_qty, 40)

View File

@@ -1,31 +1,28 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L. # Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com)
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models from odoo import api, models
class MakeProcurementOrderpoint(models.TransientModel): class MakeProcurementOrderpoint(models.TransientModel):
_inherit = 'make.procurement.orderpoint' _inherit = "make.procurement.orderpoint"
@api.model @api.model
def _prepare_item(self, orderpoint): def _prepare_item(self, orderpoint):
vals = super(MakeProcurementOrderpoint, self)._prepare_item(orderpoint) vals = super(MakeProcurementOrderpoint, self)._prepare_item(orderpoint)
if orderpoint.procure_uom_id: if orderpoint.procure_uom_id:
product_uom = orderpoint.procure_uom_id product_uom = orderpoint.procure_uom_id
vals['uom_id'] = product_uom.id vals["uom_id"] = product_uom.id
return vals return vals
class MakeProcurementOrderpointItem(models.TransientModel): class MakeProcurementOrderpointItem(models.TransientModel):
_inherit = 'make.procurement.orderpoint.item' _inherit = "make.procurement.orderpoint.item"
@api.multi @api.onchange("uom_id")
@api.onchange('uom_id')
def onchange_uom_id(self): def onchange_uom_id(self):
for rec in self: for rec in self:
uom = rec.orderpoint_id.procure_uom_id or \ uom = rec.orderpoint_id.procure_uom_id or rec.orderpoint_id.product_uom
rec.orderpoint_id.product_uom
rec.qty = uom._compute_quantity( rec.qty = uom._compute_quantity(
rec.orderpoint_id.procure_recommended_qty, rec.orderpoint_id.procure_recommended_qty, rec.uom_id
rec.uom_id) )