From 7b7e6d4e9cfefb5a11b35de40c74cbe3598b24fd Mon Sep 17 00:00:00 2001 From: Ernesto Tejeda Date: Thu, 8 Apr 2021 17:00:00 -0400 Subject: [PATCH] [IMP] stock_picking_procure_method: black, isort, prettier --- stock_picking_procure_method/__manifest__.py | 25 ++-- .../models/stock_picking.py | 35 +++--- .../test_stock_picking_procure_method.py | 114 +++++++++--------- .../views/stock_picking_views.xml | 14 +-- 4 files changed, 94 insertions(+), 94 deletions(-) diff --git a/stock_picking_procure_method/__manifest__.py b/stock_picking_procure_method/__manifest__.py index 2ab308c09..309801c66 100644 --- a/stock_picking_procure_method/__manifest__.py +++ b/stock_picking_procure_method/__manifest__.py @@ -1,19 +1,14 @@ # Copyright 2018 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Stock Picking Procure Method', - 'summary': 'Allows to force the procurement method from the picking', - 'version': '12.0.1.0.0', - 'category': 'Warehouse', - 'author': 'Tecnativa,' - 'Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/stock-logistics-warehouse', - 'license': 'AGPL-3', - 'depends': [ - 'stock', - ], - 'data': [ - 'views/stock_picking_views.xml', - ], - 'installable': True, + "name": "Stock Picking Procure Method", + "summary": "Allows to force the procurement method from the picking", + "version": "12.0.1.0.0", + "category": "Warehouse", + "author": "Tecnativa," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "license": "AGPL-3", + "depends": ["stock",], + "data": ["views/stock_picking_views.xml",], + "installable": True, } diff --git a/stock_picking_procure_method/models/stock_picking.py b/stock_picking_procure_method/models/stock_picking.py index fba52c82c..e2616f0d7 100644 --- a/stock_picking_procure_method/models/stock_picking.py +++ b/stock_picking_procure_method/models/stock_picking.py @@ -6,26 +6,27 @@ from odoo import api, fields, models class StockPicking(models.Model): - _inherit = 'stock.picking' + _inherit = "stock.picking" procure_method = fields.Selection( - selection='_selection_procure_method', - compute='_compute_procure_method', - inverse='_inverse_procure_method', - string='Supply Method', - help='By default, the system will take from the stock in the source ' - 'location and passively wait for availability. The other ' - 'possibility allows you to directly create a procurement on the ' - 'source location (and thus ignore its current stock) to gather ' - 'products. If we want to chain moves and have this one to wait ' - 'for the previous, this second option should be chosen.', + selection="_selection_procure_method", + compute="_compute_procure_method", + inverse="_inverse_procure_method", + string="Supply Method", + help="By default, the system will take from the stock in the source " + "location and passively wait for availability. The other " + "possibility allows you to directly create a procurement on the " + "source location (and thus ignore its current stock) to gather " + "products. If we want to chain moves and have this one to wait " + "for the previous, this second option should be chosen.", ) def _selection_procure_method(self): - return self.env['stock.move'].fields_get( - allfields=['procure_method'])['procure_method']['selection'] + return self.env["stock.move"].fields_get(allfields=["procure_method"])[ + "procure_method" + ]["selection"] - @api.depends('move_lines.procure_method') + @api.depends("move_lines.procure_method") def _compute_procure_method(self): for picking in self: procure_method = False @@ -38,6 +39,6 @@ class StockPicking(models.Model): picking.procure_method = procure_method def _inverse_procure_method(self): - self.filtered('procure_method').mapped('move_lines').update({ - 'procure_method': self.procure_method, - }) + self.filtered("procure_method").mapped("move_lines").update( + {"procure_method": self.procure_method,} + ) diff --git a/stock_picking_procure_method/tests/test_stock_picking_procure_method.py b/stock_picking_procure_method/tests/test_stock_picking_procure_method.py index c23fb16e2..a94ee52fd 100644 --- a/stock_picking_procure_method/tests/test_stock_picking_procure_method.py +++ b/stock_picking_procure_method/tests/test_stock_picking_procure_method.py @@ -8,67 +8,71 @@ class TestStockPickingMTO(common.SavepointCase): @classmethod def setUpClass(cls): super(TestStockPickingMTO, cls).setUpClass() - cls.mto_route = cls.env.ref('stock.route_warehouse0_mto') - cls.product = cls.env['product.product'].create({ - 'name': 'Test MTO Product', - 'route_ids': [ - (6, 0, cls.mto_route.ids)], - 'type': 'product', - }) - cls.wh_obj = cls.env['stock.warehouse'] - cls.wh1 = cls.wh_obj.create({ - 'name': 'Test WH1', - 'code': 'TSWH1', - }) - cls.wh2 = cls.wh_obj.create({ - 'name': 'Test WH2', - 'code': 'TSWH2', - 'resupply_wh_ids': [(6, 0, cls.wh1.ids)], - }) - cls.procurement_rule = cls.env['stock.rule'].create({ - 'name': 'TST-WH1 -> TST-WH2 MTO', - 'route_id': cls.mto_route.id, - 'action': 'pull', - 'location_src_id': cls.wh1.lot_stock_id.id, - 'procure_method': 'make_to_stock', - 'picking_type_id': cls.wh1.int_type_id.id, - 'location_id': cls.wh2.lot_stock_id.id, - 'warehouse_id': cls.wh2.id, - 'group_propagation_option': 'propagate', - 'propagate': True, - 'propagate_warehouse_id': cls.wh1.id, - }) - cls.picking_obj = cls.env['stock.picking'].with_context( - planned_picking=True) - cls.picking = cls.picking_obj.create({ - 'picking_type_id': cls.wh1.int_type_id.id, - 'location_id': cls.wh1.lot_stock_id.id, - 'location_dest_id': cls.wh2.lot_stock_id.id, - }) + cls.mto_route = cls.env.ref("stock.route_warehouse0_mto") + cls.product = cls.env["product.product"].create( + { + "name": "Test MTO Product", + "route_ids": [(6, 0, cls.mto_route.ids)], + "type": "product", + } + ) + cls.wh_obj = cls.env["stock.warehouse"] + cls.wh1 = cls.wh_obj.create({"name": "Test WH1", "code": "TSWH1",}) + cls.wh2 = cls.wh_obj.create( + { + "name": "Test WH2", + "code": "TSWH2", + "resupply_wh_ids": [(6, 0, cls.wh1.ids)], + } + ) + cls.procurement_rule = cls.env["stock.rule"].create( + { + "name": "TST-WH1 -> TST-WH2 MTO", + "route_id": cls.mto_route.id, + "action": "pull", + "location_src_id": cls.wh1.lot_stock_id.id, + "procure_method": "make_to_stock", + "picking_type_id": cls.wh1.int_type_id.id, + "location_id": cls.wh2.lot_stock_id.id, + "warehouse_id": cls.wh2.id, + "group_propagation_option": "propagate", + "propagate": True, + "propagate_warehouse_id": cls.wh1.id, + } + ) + cls.picking_obj = cls.env["stock.picking"].with_context(planned_picking=True) + cls.picking = cls.picking_obj.create( + { + "picking_type_id": cls.wh1.int_type_id.id, + "location_id": cls.wh1.lot_stock_id.id, + "location_dest_id": cls.wh2.lot_stock_id.id, + } + ) def test_compute_procure_method(self): # No moves self.assertFalse(self.picking.procure_method) # A new move defaults to MTS - move_line = self.env['stock.move'].create({ - 'name': 'TSTMOVE001', - 'picking_id': self.picking.id, - 'product_id': self.product.id, - 'product_uom': self.product.uom_id.id, - 'product_uom_qty': 100, - 'location_id': self.wh1.lot_stock_id.id, - 'location_dest_id': self.wh2.lot_stock_id.id, - }) - self.assertEqual(self.picking.procure_method, 'make_to_stock') + move_line = self.env["stock.move"].create( + { + "name": "TSTMOVE001", + "picking_id": self.picking.id, + "product_id": self.product.id, + "product_uom": self.product.uom_id.id, + "product_uom_qty": 100, + "location_id": self.wh1.lot_stock_id.id, + "location_dest_id": self.wh2.lot_stock_id.id, + } + ) + self.assertEqual(self.picking.procure_method, "make_to_stock") # Change move procure method to MTO - move_line.procure_method = 'make_to_order' - self.assertEqual(self.picking.procure_method, 'make_to_order') + move_line.procure_method = "make_to_order" + self.assertEqual(self.picking.procure_method, "make_to_order") # Add a new line with MTS rule - move_line.copy({ - 'procure_method': 'make_to_stock', - }) + move_line.copy( + {"procure_method": "make_to_stock",} + ) self.assertFalse(self.picking.procure_method) # We set the procure method in the picking - self.picking.procure_method = 'make_to_order' - self.assertEqual(self.picking.move_lines[1].procure_method, - 'make_to_order') + self.picking.procure_method = "make_to_order" + self.assertEqual(self.picking.move_lines[1].procure_method, "make_to_order") diff --git a/stock_picking_procure_method/views/stock_picking_views.xml b/stock_picking_procure_method/views/stock_picking_views.xml index 332d4d332..95d0413e1 100644 --- a/stock_picking_procure_method/views/stock_picking_views.xml +++ b/stock_picking_procure_method/views/stock_picking_views.xml @@ -1,16 +1,16 @@ - + - stock.picking - + - + -