diff --git a/stock_orderpoint_move_link/__manifest__.py b/stock_orderpoint_move_link/__manifest__.py index faa44c025..4e8d0d5ed 100644 --- a/stock_orderpoint_move_link/__manifest__.py +++ b/stock_orderpoint_move_link/__manifest__.py @@ -9,12 +9,8 @@ "website": "https://github.com/stock-logistics-warehouse", "author": "Eficent, Odoo Community Association (OCA)", "category": "Warehouse Management", - "depends": [ - "stock", - ], - "data": [ - "views/stock_move_views.xml", - ], + "depends": ["stock"], + "data": ["views/stock_move_views.xml"], "installable": True, "auto_install": False, } diff --git a/stock_orderpoint_move_link/models/stock.py b/stock_orderpoint_move_link/models/stock.py index 937fdf2c8..b2d726e08 100644 --- a/stock_orderpoint_move_link/models/stock.py +++ b/stock_orderpoint_move_link/models/stock.py @@ -4,16 +4,31 @@ from odoo import models class StockRule(models.Model): - _inherit = 'stock.rule' + _inherit = "stock.rule" - def _get_stock_move_values(self, product_id, product_qty, product_uom, - location_id, name, origin, values, group_id): + def _get_stock_move_values( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + values, + group_id, + ): vals = super()._get_stock_move_values( - product_id, product_qty, product_uom, - location_id, name, origin, values, group_id) - if 'orderpoint_id' in values: - vals['orderpoint_ids'] = [(4, values['orderpoint_id'].id)] - elif 'orderpoint_ids' in values: - vals['orderpoint_ids'] = [(4, o.id) - for o in values['orderpoint_ids']] + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + values, + group_id, + ) + if "orderpoint_id" in values: + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] + elif "orderpoint_ids" in values: + vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]] return vals diff --git a/stock_orderpoint_move_link/models/stock_move.py b/stock_orderpoint_move_link/models/stock_move.py index 29c989783..853c3f467 100644 --- a/stock_orderpoint_move_link/models/stock_move.py +++ b/stock_orderpoint_move_link/models/stock_move.py @@ -4,21 +4,19 @@ from odoo import fields, models class StockMove(models.Model): - _inherit = 'stock.move' + _inherit = "stock.move" orderpoint_ids = fields.Many2many( - comodel_name='stock.warehouse.orderpoint', - string='Linked Reordering Rules', + comodel_name="stock.warehouse.orderpoint", string="Linked Reordering Rules" ) def _prepare_procurement_values(self): res = super(StockMove, self)._prepare_procurement_values() if self.orderpoint_ids: - res['orderpoint_ids'] = self.orderpoint_ids + res["orderpoint_ids"] = self.orderpoint_ids return res def _merge_moves_fields(self): res = super(StockMove, self)._merge_moves_fields() - res['orderpoint_ids'] = [(4, m.id) - for m in self.mapped('orderpoint_ids')] + res["orderpoint_ids"] = [(4, m.id) for m in self.mapped("orderpoint_ids")] return res diff --git a/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py b/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py index 4d0d4c4fe..1d9076862 100644 --- a/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py +++ b/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py @@ -6,14 +6,17 @@ from odoo import api, models class StockWarehouseOrderpoint(models.Model): - _inherit = 'stock.warehouse.orderpoint' + _inherit = "stock.warehouse.orderpoint" @api.multi def action_view_stock_picking(self): - action = self.env.ref('stock.action_picking_tree_all') + action = self.env.ref("stock.action_picking_tree_all") result = action.read()[0] - result['context'] = {} - picking_ids = self.env['stock.move'].search( - [('orderpoint_ids', 'in', self.id)]).mapped('picking_id') - result['domain'] = "[('id','in',%s)]" % picking_ids.ids + result["context"] = {} + picking_ids = ( + self.env["stock.move"] + .search([("orderpoint_ids", "in", self.id)]) + .mapped("picking_id") + ) + result["domain"] = "[('id','in',%s)]" % picking_ids.ids return result diff --git a/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py b/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py index e50166db0..32dc36dd8 100644 --- a/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py +++ b/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py @@ -1,95 +1,118 @@ # Copyright 2019 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import ast + from odoo.tests.common import SavepointCase class TestStockOrderpointMoveLink(SavepointCase): - @classmethod def setUpClass(cls): super().setUpClass() - cls.product_obj = cls.env['product.product'] - cls.orderpoint_obj = cls.env['stock.warehouse.orderpoint'] - cls.loc_obj = cls.env['stock.location'] - cls.route_obj = cls.env['stock.location.route'] - cls.group_obj = cls.env['procurement.group'] - cls.move_obj = cls.env['stock.move'] - cls.picking_obj = cls.env['stock.picking'] + cls.product_obj = cls.env["product.product"] + cls.orderpoint_obj = cls.env["stock.warehouse.orderpoint"] + cls.loc_obj = cls.env["stock.location"] + cls.route_obj = cls.env["stock.location.route"] + cls.group_obj = cls.env["procurement.group"] + cls.move_obj = cls.env["stock.move"] + cls.picking_obj = cls.env["stock.picking"] - cls.warehouse = cls.env.ref('stock.warehouse0') - cls.stock_loc = cls.env.ref('stock.stock_location_stock') + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.stock_loc = cls.env.ref("stock.stock_location_stock") # Create a new locations and routes: - cls.intermediate_loc = cls.loc_obj.create({ - 'name': 'Test location 1', - 'usage': 'internal', - 'location_id': cls.warehouse.view_location_id.id, - }) - cls.test_route = cls.route_obj.create({ - 'name': 'Stock -> Test 1', - 'product_selectable': True, - 'rule_ids': [(0, 0, { - 'name': 'stock to test', - 'action': 'pull', - 'location_id': cls.intermediate_loc.id, - 'location_src_id': cls.stock_loc.id, - 'procure_method': 'make_to_stock', - 'picking_type_id': cls.env.ref( - 'stock.picking_type_internal').id, - 'propagate': True - })] - }) - cls.need_loc = cls.loc_obj.create({ - 'name': 'Test location 2', - 'usage': 'internal', - 'location_id': cls.warehouse.view_location_id.id, - }) - cls.test_route_2 = cls.route_obj.create({ - 'name': 'Test 1 -> Test 2', - 'product_selectable': True, - 'rule_ids': [(0, 0, { - 'name': 'Test 1 to Test 2', - 'action': 'pull', - 'location_id': cls.need_loc.id, - 'location_src_id': cls.intermediate_loc.id, - 'procure_method': 'make_to_order', - 'picking_type_id': cls.env.ref( - 'stock.picking_type_internal').id, - 'propagate': True - })] - }) + cls.intermediate_loc = cls.loc_obj.create( + { + "name": "Test location 1", + "usage": "internal", + "location_id": cls.warehouse.view_location_id.id, + } + ) + cls.test_route = cls.route_obj.create( + { + "name": "Stock -> Test 1", + "product_selectable": True, + "rule_ids": [ + ( + 0, + 0, + { + "name": "stock to test", + "action": "pull", + "location_id": cls.intermediate_loc.id, + "location_src_id": cls.stock_loc.id, + "procure_method": "make_to_stock", + "picking_type_id": cls.env.ref( + "stock.picking_type_internal" + ).id, + "propagate": True, + }, + ) + ], + } + ) + cls.need_loc = cls.loc_obj.create( + { + "name": "Test location 2", + "usage": "internal", + "location_id": cls.warehouse.view_location_id.id, + } + ) + cls.test_route_2 = cls.route_obj.create( + { + "name": "Test 1 -> Test 2", + "product_selectable": True, + "rule_ids": [ + ( + 0, + 0, + { + "name": "Test 1 to Test 2", + "action": "pull", + "location_id": cls.need_loc.id, + "location_src_id": cls.intermediate_loc.id, + "procure_method": "make_to_order", + "picking_type_id": cls.env.ref( + "stock.picking_type_internal" + ).id, + "propagate": True, + }, + ) + ], + } + ) # Prepare Products: routes = cls.test_route_2 + cls.test_route - cls.product = cls.product_obj.create({ - 'name': 'Test Product', - 'route_ids': [(6, 0, routes.ids)], - }) + cls.product = cls.product_obj.create( + {"name": "Test Product", "route_ids": [(6, 0, routes.ids)]} + ) # Create Orderpoint: - cls.orderpoint_need_loc = cls.orderpoint_obj.create({ - 'warehouse_id': cls.warehouse.id, - 'location_id': cls.need_loc.id, - 'product_id': cls.product.id, - 'product_min_qty': 10.0, - 'product_max_qty': 50.0, - 'product_uom': cls.product.uom_id.id, - }) + cls.orderpoint_need_loc = cls.orderpoint_obj.create( + { + "warehouse_id": cls.warehouse.id, + "location_id": cls.need_loc.id, + "product_id": cls.product.id, + "product_min_qty": 10.0, + "product_max_qty": 50.0, + "product_uom": cls.product.uom_id.id, + } + ) cls.group_obj.run_scheduler() def test_01_stock_orderpoint_move_link(self): """Tests if manual procurement fills orderpoint_ids field.""" - move = self.move_obj.search([ - ('orderpoint_ids', '=', self.orderpoint_need_loc.id)]) + move = self.move_obj.search( + [("orderpoint_ids", "=", self.orderpoint_need_loc.id)] + ) self.assertTrue(len(move), 2) def test_02_stock_orderpoint_move_link_action_view(self): sp_orderpoint = self.move_obj.search( - [('orderpoint_ids', 'in', self.orderpoint_need_loc.id)]).mapped( - 'picking_id') + [("orderpoint_ids", "in", self.orderpoint_need_loc.id)] + ).mapped("picking_id") result = self.orderpoint_need_loc.action_view_stock_picking() - sp_action = self.picking_obj.search( - ast.literal_eval(result['domain'])) + sp_action = self.picking_obj.search(ast.literal_eval(result["domain"])) self.assertEquals(sp_orderpoint, sp_action)