From 69ebd208e4ddf756cad71b7f68b523ffc8a6ea3c Mon Sep 17 00:00:00 2001 From: ps-tubtim Date: Wed, 11 Mar 2020 10:57:59 +0700 Subject: [PATCH] [IMP] stock_orderpoint_manual_procurement_uom: black, isort --- .../__manifest__.py | 19 +-- .../models/stock_warehouse_orderpoint.py | 14 +- ...est_stock_orderpoint_manual_procurement.py | 156 +++++++++--------- .../wizards/make_procurement_orderpoint.py | 19 +-- 4 files changed, 104 insertions(+), 104 deletions(-) diff --git a/stock_orderpoint_manual_procurement_uom/__manifest__.py b/stock_orderpoint_manual_procurement_uom/__manifest__.py index 69eaefe97..51fa730c6 100644 --- a/stock_orderpoint_manual_procurement_uom/__manifest__.py +++ b/stock_orderpoint_manual_procurement_uom/__manifest__.py @@ -1,20 +1,15 @@ -# Copyright 2018 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Stock Orderpoint Manual Procurement UoM", "summary": "Glue module for stock_orderpoint_uom and " - "stock_orderpoint_manual_procurement", - "version": "12.0.1.0.0", - "author": "Eficent, " - "Odoo Community Association (OCA)", + "stock_orderpoint_manual_procurement", + "version": "13.0.1.0.0", + "author": "Eficent, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", - "depends": [ - "stock_orderpoint_uom", - "stock_orderpoint_manual_procurement", - ], + "depends": ["stock_orderpoint_uom", "stock_orderpoint_manual_procurement"], "license": "AGPL-3", - 'installable': True, - 'application': False, + "installable": True, + "application": False, } diff --git a/stock_orderpoint_manual_procurement_uom/models/stock_warehouse_orderpoint.py b/stock_orderpoint_manual_procurement_uom/models/stock_warehouse_orderpoint.py index 82f04be16..a30bb31e3 100644 --- a/stock_orderpoint_manual_procurement_uom/models/stock_warehouse_orderpoint.py +++ b/stock_orderpoint_manual_procurement_uom/models/stock_warehouse_orderpoint.py @@ -1,19 +1,19 @@ -# Copyright 2018 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, models class StockWarehouseOrderpoint(models.Model): - _inherit = 'stock.warehouse.orderpoint' + _inherit = "stock.warehouse.orderpoint" @api.multi def _get_procure_recommended_qty(self, virtual_qty, op_qtys): - product_qty = \ - super(StockWarehouseOrderpoint, self)._get_procure_recommended_qty( - virtual_qty, op_qtys) + product_qty = super( + StockWarehouseOrderpoint, self + )._get_procure_recommended_qty(virtual_qty, op_qtys) if self.procure_uom_id: product_qty = self.product_id.uom_id._compute_quantity( - product_qty, self.procure_uom_id) + product_qty, self.procure_uom_id + ) return product_qty diff --git a/stock_orderpoint_manual_procurement_uom/tests/test_stock_orderpoint_manual_procurement.py b/stock_orderpoint_manual_procurement_uom/tests/test_stock_orderpoint_manual_procurement.py index 5192dd1f6..9a8ed3d54 100644 --- a/stock_orderpoint_manual_procurement_uom/tests/test_stock_orderpoint_manual_procurement.py +++ b/stock_orderpoint_manual_procurement_uom/tests/test_stock_orderpoint_manual_procurement.py @@ -1,48 +1,49 @@ -# Copyright 2018 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo.tests import common class TestStockWarehouseOrderpoint(common.TransactionCase): - def setUp(self): super(TestStockWarehouseOrderpoint, self).setUp() # Refs - self.group_stock_manager = self.env.ref('stock.group_stock_manager') - self.group_purchase_manager = self.env.ref( - 'purchase.group_purchase_manager') + self.group_stock_manager = self.env.ref("stock.group_stock_manager") + self.group_purchase_manager = self.env.ref("purchase.group_purchase_manager") 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( - 'stock_orderpoint_manual_procurement.' - 'group_change_orderpoint_procure_qty') - self.company1 = self.env.ref('base.main_company') + "stock_orderpoint_manual_procurement." "group_change_orderpoint_procure_qty" + ) + self.company1 = self.env.ref("base.main_company") # Get required Model - self.reordering_rule_model = self.env['stock.warehouse.orderpoint'] - self.product_model = self.env['product.product'] - self.purchase_model = self.env['purchase.order'] - self.purchase_line_model = self.env['purchase.order.line'] - self.user_model = self.env['res.users'] - self.product_ctg_model = self.env['product.category'] - self.stock_change_model = self.env['stock.change.product.qty'] - self.make_procurement_orderpoint_model =\ - self.env['make.procurement.orderpoint'] + self.reordering_rule_model = self.env["stock.warehouse.orderpoint"] + self.product_model = self.env["product.product"] + self.purchase_model = self.env["purchase.order"] + self.purchase_line_model = self.env["purchase.order.line"] + self.user_model = self.env["res.users"] + self.product_ctg_model = self.env["product.category"] + self.stock_change_model = self.env["stock.change.product.qty"] + self.make_procurement_orderpoint_model = self.env["make.procurement.orderpoint"] # Create users - self.user = self._create_user('user_1', - [self.group_stock_manager, - self.group_change_procure_qty, - self.group_purchase_manager], - self.company1) + self.user = self._create_user( + "user_1", + [ + self.group_stock_manager, + self.group_change_procure_qty, + self.group_purchase_manager, + ], + self.company1, + ) # Get required Model data - self.product_uom = self.env.ref('uom.product_uom_unit') - self.location = self.env.ref('stock.stock_location_stock') - self.product = self.env.ref('product.product_product_7') - self.dozen = self.env.ref('uom.product_uom_dozen') + self.product_uom = self.env.ref("uom.product_uom_unit") + self.location = self.env.ref("stock.stock_location_stock") + self.product = self.env.ref("product.product_product_7") + self.dozen = self.env.ref("uom.product_uom_dozen") # Create Product category and Product self.product_ctg = self._create_product_category() @@ -58,67 +59,75 @@ class TestStockWarehouseOrderpoint(common.TransactionCase): def _create_user(self, login, groups, company): """ Create a user.""" group_ids = [group.id for group in groups] - user = \ - self.user_model.with_context({'no_reset_password': True}).create({ - 'name': 'Test User', - 'login': login, - 'password': 'demo', - 'email': 'test@yourcompany.com', - 'company_id': company.id, - 'company_ids': [(4, company.id)], - 'groups_id': [(6, 0, group_ids)] - }) + user = self.user_model.with_context({"no_reset_password": True}).create( + { + "name": "Test User", + "login": login, + "password": "demo", + "email": "test@yourcompany.com", + "company_id": company.id, + "company_ids": [(4, company.id)], + "groups_id": [(6, 0, group_ids)], + } + ) return user def _create_product_category(self): """Create a Product Category.""" - product_ctg = self.product_ctg_model.create({ - 'name': 'test_product_ctg', - }) + product_ctg = self.product_ctg_model.create({"name": "test_product_ctg"}) return product_ctg def _create_product(self): """Create a Product.""" - product = self.product_model.create({ - 'name': 'Test Product', - 'categ_id': self.product_ctg.id, - 'type': 'product', - 'uom_id': self.product_uom.id, - 'variant_seller_ids': [(6, 0, [self.vendor.id])], - }) + product = self.product_model.create( + { + "name": "Test Product", + "categ_id": self.product_ctg.id, + "type": "product", + "uom_id": self.product_uom.id, + "variant_seller_ids": [(6, 0, [self.vendor.id])], + } + ) return product def _update_product_qty(self, product, location, quantity): """Update Product quantity.""" - change_product_qty = self.stock_change_model.create({ - 'location_id': location.id, - 'product_id': product.id, - 'new_quantity': quantity, - }) + change_product_qty = self.stock_change_model.create( + { + "location_id": location.id, + "product_id": product.id, + "new_quantity": quantity, + } + ) change_product_qty.change_product_qty() return change_product_qty def create_orderpoint(self): """Create a Reordering Rule""" - reorder = self.reordering_rule_model.sudo(self.user).create({ - 'name': 'Order-point', - 'product_id': self.product.id, - 'product_min_qty': 100.0, - 'product_max_qty': 500.0, - 'qty_multiple': 1.0, - 'procure_uom_id': self.dozen.id, - }) + reorder = self.reordering_rule_model.sudo(self.user).create( + { + "name": "Order-point", + "product_id": self.product.id, + "product_min_qty": 100.0, + "product_max_qty": 500.0, + "qty_multiple": 1.0, + "procure_uom_id": self.dozen.id, + } + ) return reorder def create_orderpoint_procurement(self): """Make Procurement from Reordering Rule""" context = { - 'active_model': 'stock.warehouse.orderpoint', - 'active_ids': self.reorder.ids, - 'active_id': self.reorder.id + "active_model": "stock.warehouse.orderpoint", + "active_ids": self.reorder.ids, + "active_id": self.reorder.id, } - wizard = self.make_procurement_orderpoint_model.sudo(self.user).\ - with_context(context).create({}) + wizard = ( + self.make_procurement_orderpoint_model.sudo(self.user) + .with_context(context) + .create({}) + ) for line in wizard.item_ids: line.onchange_uom_id() wizard.make_procurement() @@ -132,19 +141,18 @@ class TestStockWarehouseOrderpoint(common.TransactionCase): # As per route configuration, it will create Purchase order # Assert that Procurement is created with the desired quantity - purchase = self.purchase_model.search( - [('origin', 'ilike', self.reorder.name)]) + purchase = self.purchase_model.search([("origin", "ilike", self.reorder.name)]) self.assertEquals(len(purchase), 1) purchase_line = self.purchase_line_model.search( - [('orderpoint_id', '=', self.reorder.id), - ('order_id', '=', purchase.id)]) + [("orderpoint_id", "=", self.reorder.id), ("order_id", "=", purchase.id)] + ) self.assertEquals(len(purchase_line), 1) - self.assertEqual(self.reorder.product_id.id, - purchase_line.product_id.id) + self.assertEqual(self.reorder.product_id.id, purchase_line.product_id.id) # it could be using an existing PO, thus there could be more origins. self.assertTrue(self.reorder.name in purchase.origin) - self.assertNotEqual(self.reorder.procure_recommended_qty, - purchase_line.product_qty) + self.assertNotEqual( + self.reorder.procure_recommended_qty, purchase_line.product_qty + ) if self.reorder.procure_uom_id == self.reorder.product_id.uom_po_id: # Our PO unit of measure is also dozens (procure uom) self.assertEqual(purchase_line.product_qty, 40) diff --git a/stock_orderpoint_manual_procurement_uom/wizards/make_procurement_orderpoint.py b/stock_orderpoint_manual_procurement_uom/wizards/make_procurement_orderpoint.py index d97ad2207..09c0a12a0 100644 --- a/stock_orderpoint_manual_procurement_uom/wizards/make_procurement_orderpoint.py +++ b/stock_orderpoint_manual_procurement_uom/wizards/make_procurement_orderpoint.py @@ -1,31 +1,28 @@ -# Copyright 2018 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, models class MakeProcurementOrderpoint(models.TransientModel): - _inherit = 'make.procurement.orderpoint' + _inherit = "make.procurement.orderpoint" @api.model def _prepare_item(self, orderpoint): vals = super(MakeProcurementOrderpoint, self)._prepare_item(orderpoint) if orderpoint.procure_uom_id: product_uom = orderpoint.procure_uom_id - vals['uom_id'] = product_uom.id + vals["uom_id"] = product_uom.id return vals 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): for rec in self: - uom = rec.orderpoint_id.procure_uom_id or \ - rec.orderpoint_id.product_uom + uom = rec.orderpoint_id.procure_uom_id or rec.orderpoint_id.product_uom rec.qty = uom._compute_quantity( - rec.orderpoint_id.procure_recommended_qty, - rec.uom_id) + rec.orderpoint_id.procure_recommended_qty, rec.uom_id + )