From e2c30f1a0ee3559f43c3921f3ebb36e7e37aee91 Mon Sep 17 00:00:00 2001 From: ps-tubtim Date: Wed, 11 Mar 2020 16:01:57 +0700 Subject: [PATCH] [IMP] mrp_stock_orderpoint_manual_procurement: black, isort --- .../__manifest__.py | 22 +-- .../models/mrp_production.py | 7 +- .../models/stock_rule.py | 23 ++- .../readme/DESCRIPTION.rst | 2 +- .../tests/test_mrp_manual_procurement.py | 161 +++++++++--------- 5 files changed, 110 insertions(+), 105 deletions(-) diff --git a/mrp_stock_orderpoint_manual_procurement/__manifest__.py b/mrp_stock_orderpoint_manual_procurement/__manifest__.py index 94374bade..915bd8cb6 100644 --- a/mrp_stock_orderpoint_manual_procurement/__manifest__.py +++ b/mrp_stock_orderpoint_manual_procurement/__manifest__.py @@ -4,21 +4,15 @@ { "name": "MRP Stock Orderpoint Manual Procurement", "summary": "Updates the value of MO Responsible and keeps track" - "of changes regarding this field", - "version": "12.0.1.0.0", - "author": "Eficent, " - "Odoo Community Association (OCA)", + "of changes regarding this field", + "version": "13.0.1.0.0", + "author": "Eficent, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/manufacture", "category": "Manufacturing", - "depends": [ - "mrp", - "stock_orderpoint_manual_procurement", - ], - "data": [ - "views/mrp_production_view.xml", - ], + "depends": ["mrp", "stock_orderpoint_manual_procurement"], + "data": ["views/mrp_production_view.xml"], "license": "AGPL-3", - 'installable': True, - 'application': False, - 'auto_install': True + "installable": True, + "application": False, + "auto_install": True, } diff --git a/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py b/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py index b6380253f..f2625c4ca 100644 --- a/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py +++ b/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py @@ -5,9 +5,6 @@ from odoo import fields, models class MrpProduction(models.Model): - _inherit = 'mrp.production' + _inherit = "mrp.production" - requested_by = fields.Many2one( - comodel_name='res.users', - track_visibility='always', - ) + requested_by = fields.Many2one(comodel_name="res.users", track_visibility="always") diff --git a/mrp_stock_orderpoint_manual_procurement/models/stock_rule.py b/mrp_stock_orderpoint_manual_procurement/models/stock_rule.py index 9fc26b4c4..2ac431a3f 100644 --- a/mrp_stock_orderpoint_manual_procurement/models/stock_rule.py +++ b/mrp_stock_orderpoint_manual_procurement/models/stock_rule.py @@ -5,14 +5,23 @@ from odoo import models class StockRule(models.Model): - _inherit = 'stock.rule' + _inherit = "stock.rule" - def _prepare_mo_vals(self, product_id, product_qty, product_uom, - location_id, name, origin, values, bom): + def _prepare_mo_vals( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + values, + bom, + ): res = super(StockRule, self)._prepare_mo_vals( - product_id, product_qty, product_uom, location_id, name, - origin, values, bom) - requested_uid = self.env.context.get('requested_uid') + product_id, product_qty, product_uom, location_id, name, origin, values, bom + ) + requested_uid = self.env.context.get("requested_uid") if requested_uid: - res.update({'requested_by': requested_uid.id}) + res.update({"requested_by": requested_uid.id}) return res diff --git a/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst b/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst index a6b7f9bfe..7c75978f8 100644 --- a/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst +++ b/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst @@ -1,3 +1,3 @@ This module updates a new field *Requested by* in Manufacturing Orders in the case the MO has been created as a result of a manual procurement from -an orderpoint. \ No newline at end of file +an orderpoint. diff --git a/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py b/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py index ac3f310d8..106abd222 100644 --- a/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py +++ b/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py @@ -5,100 +5,107 @@ from odoo.tests.common import TransactionCase class TestMrpManualProcurement(TransactionCase): - def setUp(self): super(TestMrpManualProcurement, self).setUp() - self.production_model = self.env['mrp.production'] - self.product_model = self.env['product.product'] - self.orderpoint_model = self.env['stock.warehouse.orderpoint'] - self.loc_model = self.env['stock.location'] - self.route_model = self.env['stock.location.route'] - self.manual_procurement_wiz = self.env['make.procurement.orderpoint'] - self.bom_model = self.env['mrp.bom'] - self.boml_model = self.env['mrp.bom.line'] + self.production_model = self.env["mrp.production"] + self.product_model = self.env["product.product"] + self.orderpoint_model = self.env["stock.warehouse.orderpoint"] + self.loc_model = self.env["stock.location"] + self.route_model = self.env["stock.location.route"] + self.manual_procurement_wiz = self.env["make.procurement.orderpoint"] + self.bom_model = self.env["mrp.bom"] + self.boml_model = self.env["mrp.bom.line"] - self.warehouse = self.env.ref('stock.warehouse0') - self.stock_loc = self.env.ref('stock.stock_location_stock') - route_manuf = self.env.ref('mrp.route_warehouse0_manufacture') + self.warehouse = self.env.ref("stock.warehouse0") + self.stock_loc = self.env.ref("stock.stock_location_stock") + route_manuf = self.env.ref("mrp.route_warehouse0_manufacture") # Create a new location and route: - self.secondary_loc = self.loc_model.create({ - 'name': 'Test location', - 'usage': 'internal', - 'location_id': self.warehouse.view_location_id.id, - }) - test_route = self.route_model.create({ - 'name': 'Stock -> Test', - 'product_selectable': True, - 'rule_ids': [(0, 0, { - 'name': 'stock to test', - 'action': 'pull', - 'location_id': self.secondary_loc.id, - 'location_src_id': self.stock_loc.id, - 'procure_method': 'make_to_order', - 'picking_type_id': self.env.ref( - 'stock.picking_type_internal').id, - 'propagate': True - })] - }) + self.secondary_loc = self.loc_model.create( + { + "name": "Test location", + "usage": "internal", + "location_id": self.warehouse.view_location_id.id, + } + ) + test_route = self.route_model.create( + { + "name": "Stock -> Test", + "product_selectable": True, + "rule_ids": [ + ( + 0, + 0, + { + "name": "stock to test", + "action": "pull", + "location_id": self.secondary_loc.id, + "location_src_id": self.stock_loc.id, + "procure_method": "make_to_order", + "picking_type_id": self.env.ref( + "stock.picking_type_internal" + ).id, + "propagate": True, + }, + ) + ], + } + ) # Prepare Products: routes = route_manuf + test_route - self.product = self.product_model.create({ - 'name': 'Test Product', - 'route_ids': [(6, 0, routes.ids)], - }) - component = self.product_model.create({ - 'name': 'Test component', - }) + self.product = self.product_model.create( + {"name": "Test Product", "route_ids": [(6, 0, routes.ids)]} + ) + component = self.product_model.create({"name": "Test component"}) # Create Bill of Materials: - self.bom_1 = self.bom_model.create({ - 'product_id': self.product.id, - 'product_tmpl_id': self.product.product_tmpl_id.id, - 'product_uom_id': self.product.uom_id.id, - 'product_qty': 1.0, - }) - self.boml_model.create({ - 'bom_id': self.bom_1.id, - 'product_id': component.id, - 'product_qty': 1.0, - }) + self.bom_1 = self.bom_model.create( + { + "product_id": self.product.id, + "product_tmpl_id": self.product.product_tmpl_id.id, + "product_uom_id": self.product.uom_id.id, + "product_qty": 1.0, + } + ) + self.boml_model.create( + {"bom_id": self.bom_1.id, "product_id": component.id, "product_qty": 1.0} + ) # Create Orderpoint: - self.orderpoint_stock = self.orderpoint_model.create({ - 'warehouse_id': self.warehouse.id, - 'location_id': self.warehouse.lot_stock_id.id, - 'product_id': self.product.id, - 'product_min_qty': 10.0, - 'product_max_qty': 50.0, - 'product_uom': self.product.uom_id.id, - }) - self.orderpoint_secondary_loc = self.orderpoint_model.create({ - 'warehouse_id': self.warehouse.id, - 'location_id': self.secondary_loc.id, - 'product_id': self.product.id, - 'product_min_qty': 10.0, - 'product_max_qty': 20.0, - 'product_uom': self.product.uom_id.id, - }) + self.orderpoint_stock = self.orderpoint_model.create( + { + "warehouse_id": self.warehouse.id, + "location_id": self.warehouse.lot_stock_id.id, + "product_id": self.product.id, + "product_min_qty": 10.0, + "product_max_qty": 50.0, + "product_uom": self.product.uom_id.id, + } + ) + self.orderpoint_secondary_loc = self.orderpoint_model.create( + { + "warehouse_id": self.warehouse.id, + "location_id": self.secondary_loc.id, + "product_id": self.product.id, + "product_min_qty": 10.0, + "product_max_qty": 20.0, + "product_uom": self.product.uom_id.id, + } + ) # Create User: - self.test_user = self.env['res.users'].create({ - 'name': 'John', - 'login': 'test', - }) + self.test_user = self.env["res.users"].create({"name": "John", "login": "test"}) def manual_procurement(self, orderpoint, user): """Make Procurement from Reordering Rule""" context = { - 'active_model': 'stock.warehouse.orderpoint', - 'active_ids': orderpoint.ids, - 'active_id': orderpoint.id + "active_model": "stock.warehouse.orderpoint", + "active_ids": orderpoint.ids, + "active_id": orderpoint.id, } - wizard = self.manual_procurement_wiz.sudo(user).\ - with_context(context).create({}) + wizard = self.manual_procurement_wiz.sudo(user).with_context(context).create({}) wizard.make_procurement() return wizard @@ -106,8 +113,7 @@ class TestMrpManualProcurement(TransactionCase): """Tests manual procurement fills requested_by field. Direct MO creation.""" self.manual_procurement(self.orderpoint_stock, self.test_user) - mo = self.production_model.search([ - ('requested_by', '=', self.test_user.id)]) + mo = self.production_model.search([("requested_by", "=", self.test_user.id)]) self.assertTrue(mo) self.assertEqual(mo.product_id, self.product) self.assertEqual(mo.product_qty, 50.0) @@ -116,8 +122,7 @@ class TestMrpManualProcurement(TransactionCase): """Tests manual procurement fills requested_by field. Indirect MO creation (transfer -> MO).""" self.manual_procurement(self.orderpoint_secondary_loc, self.test_user) - mo = self.production_model.search([ - ('requested_by', '=', self.test_user.id)]) + mo = self.production_model.search([("requested_by", "=", self.test_user.id)]) self.assertTrue(mo) self.assertEqual(mo.product_id, self.product) self.assertEqual(mo.product_qty, 20.0)