diff --git a/stock_orderpoint_purchase_link/__init__.py b/stock_orderpoint_purchase_link/__init__.py index a9e337226..0650744f6 100644 --- a/stock_orderpoint_purchase_link/__init__.py +++ b/stock_orderpoint_purchase_link/__init__.py @@ -1,2 +1 @@ - from . import models diff --git a/stock_orderpoint_purchase_link/__manifest__.py b/stock_orderpoint_purchase_link/__manifest__.py index 6f5a0aed6..8aa1105a8 100644 --- a/stock_orderpoint_purchase_link/__manifest__.py +++ b/stock_orderpoint_purchase_link/__manifest__.py @@ -7,16 +7,10 @@ "version": "12.0.1.0.0", "license": "LGPL-3", "website": "https://github.com/OCA/stock-logistics-warehouse", - "author": "Eficent, " - "Odoo Community Association (OCA)", + "author": "Eficent, " "Odoo Community Association (OCA)", "category": "Warehouse Management", - "depends": [ - "stock_orderpoint_move_link", - "purchase_stock", - ], - "data": [ - "views/purchase_order_views.xml", - ], + "depends": ["stock_orderpoint_move_link", "purchase_stock"], + "data": ["views/purchase_order_views.xml"], "installable": True, "auto_install": True, } diff --git a/stock_orderpoint_purchase_link/models/purchase_order_line.py b/stock_orderpoint_purchase_link/models/purchase_order_line.py index 263e799cf..0e4e45650 100644 --- a/stock_orderpoint_purchase_link/models/purchase_order_line.py +++ b/stock_orderpoint_purchase_link/models/purchase_order_line.py @@ -5,10 +5,11 @@ from odoo import fields, models class PurchaseOrderLine(models.Model): - _inherit = 'purchase.order.line' + _inherit = "purchase.order.line" orderpoint_ids = fields.Many2many( - comodel_name='stock.warehouse.orderpoint', - string='Orderpoints', copy=False, + comodel_name="stock.warehouse.orderpoint", + string="Orderpoints", + copy=False, readonly=True, ) diff --git a/stock_orderpoint_purchase_link/models/stock_rule.py b/stock_orderpoint_purchase_link/models/stock_rule.py index 72b3d8638..3dcbe6754 100644 --- a/stock_orderpoint_purchase_link/models/stock_rule.py +++ b/stock_orderpoint_purchase_link/models/stock_rule.py @@ -5,31 +5,31 @@ from odoo import models class StockRule(models.Model): - _inherit = 'stock.rule' + _inherit = "stock.rule" - def _prepare_purchase_order_line(self, product_id, product_qty, - product_uom, values, po, partner): + def _prepare_purchase_order_line( + self, product_id, product_qty, product_uom, values, po, partner + ): vals = super()._prepare_purchase_order_line( - product_id, product_qty, product_uom, values, po, partner) + product_id, product_qty, product_uom, values, po, partner + ) # If the procurement was run directly by a reordering rule. - if 'orderpoint_id' in values: - vals['orderpoint_ids'] = [ - (4, values['orderpoint_id'].id)] + if "orderpoint_id" in values: + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] # If the procurement was run by a stock move. - elif 'orderpoint_ids' in values: - vals['orderpoint_ids'] = [(4, o.id) - for o in values['orderpoint_ids']] + elif "orderpoint_ids" in values: + vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]] return vals - def _update_purchase_order_line(self, product_id, product_qty, product_uom, - values, line, partner): + def _update_purchase_order_line( + self, product_id, product_qty, product_uom, values, line, partner + ): vals = super()._update_purchase_order_line( - product_id, product_qty, product_uom, values, line, partner) - if 'orderpoint_id' in values: - vals['orderpoint_ids'] = [ - (4, values['orderpoint_id'].id)] + product_id, product_qty, product_uom, values, line, partner + ) + if "orderpoint_id" in values: + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] # If the procurement was run by a stock move. - elif 'orderpoint_ids' in values: - vals['orderpoint_ids'] = [(4, o.id) - for o in values['orderpoint_ids']] + elif "orderpoint_ids" in values: + vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]] return vals diff --git a/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py b/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py index a0771580f..6c4edadab 100644 --- a/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py +++ b/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py @@ -5,10 +5,11 @@ from odoo import fields, models class StockWarehouseOrderpoint(models.Model): - _inherit = 'stock.warehouse.orderpoint' + _inherit = "stock.warehouse.orderpoint" purchase_line_ids = fields.Many2many( - comodel_name='purchase.order.line', - string='Purchase Order Lines', copy=False, + comodel_name="purchase.order.line", + string="Purchase Order Lines", + copy=False, readonly=True, ) diff --git a/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py b/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py index 4c5a48057..d0eebd7df 100644 --- a/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py +++ b/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py @@ -8,69 +8,75 @@ class TestOrderpointPurchaseLink(common.TransactionCase): def setUp(self): super(TestOrderpointPurchaseLink, self).setUp() - self.product_obj = self.env['product.product'] - self.partner_obj = self.env['res.partner'] - self.pol_obj = self.env['purchase.order.line'] - self.location_obj = self.env['stock.location'] - self.orderpoint_obj = self.env['stock.warehouse.orderpoint'] - self.route_obj = self.env['stock.location.route'] - self.rule_obj = self.env['stock.rule'] - self.group_obj = self.env['procurement.group'] + self.product_obj = self.env["product.product"] + self.partner_obj = self.env["res.partner"] + self.pol_obj = self.env["purchase.order.line"] + self.location_obj = self.env["stock.location"] + self.orderpoint_obj = self.env["stock.warehouse.orderpoint"] + self.route_obj = self.env["stock.location.route"] + self.rule_obj = self.env["stock.rule"] + self.group_obj = self.env["procurement.group"] # WH and routes: - self.warehouse = self.env.ref('stock.warehouse0') + self.warehouse = self.env.ref("stock.warehouse0") self.stock_location = self.warehouse.lot_stock_id - self.test_location = self.location_obj.create({ - 'name': 'Test', - 'location_id': self.warehouse.view_location_id.id, - }) - route_buy = self.env.ref('purchase_stock.route_warehouse0_buy').id - route_test = self.route_obj.create({ - 'name': 'Stock to Test', - }).id - self.rule_obj.create({ - 'name': 'Stock to Test', - 'action': 'pull', - 'procure_method': 'make_to_order', - 'location_id': self.test_location.id, - 'location_src_id': self.stock_location.id, - 'route_id': route_test, - 'picking_type_id': self.warehouse.int_type_id.id, - 'warehouse_id': self.warehouse.id, - 'group_propagation_option': 'none', - }) + self.test_location = self.location_obj.create( + {"name": "Test", "location_id": self.warehouse.view_location_id.id} + ) + route_buy = self.env.ref("purchase_stock.route_warehouse0_buy").id + route_test = self.route_obj.create({"name": "Stock to Test"}).id + self.rule_obj.create( + { + "name": "Stock to Test", + "action": "pull", + "procure_method": "make_to_order", + "location_id": self.test_location.id, + "location_src_id": self.stock_location.id, + "route_id": route_test, + "picking_type_id": self.warehouse.int_type_id.id, + "warehouse_id": self.warehouse.id, + "group_propagation_option": "none", + } + ) # Partners: - vendor1 = self.partner_obj.create({'name': 'Vendor 1'}) + vendor1 = self.partner_obj.create({"name": "Vendor 1"}) # Create products: - self.tp1 = self.product_obj.create({ - 'name': 'Test Product 1', - 'type': 'product', - 'list_price': 150.0, - 'route_ids': [(6, 0, [route_buy, route_test])], - 'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 20.0})], - }) + self.tp1 = self.product_obj.create( + { + "name": "Test Product 1", + "type": "product", + "list_price": 150.0, + "route_ids": [(6, 0, [route_buy, route_test])], + "seller_ids": [(0, 0, {"name": vendor1.id, "price": 20.0})], + } + ) # Create Orderpoints: - self.op1 = self.orderpoint_obj.create({ - 'product_id': self.tp1.id, - 'location_id': self.stock_location.id, - 'product_min_qty': 5.0, - 'product_max_qty': 20.0, - }) - self.op2 = self.orderpoint_obj.create({ - 'product_id': self.tp1.id, - 'location_id': self.test_location.id, - 'product_min_qty': 5.0, - 'product_max_qty': 20.0, - }) + self.op1 = self.orderpoint_obj.create( + { + "product_id": self.tp1.id, + "location_id": self.stock_location.id, + "product_min_qty": 5.0, + "product_max_qty": 20.0, + } + ) + self.op2 = self.orderpoint_obj.create( + { + "product_id": self.tp1.id, + "location_id": self.test_location.id, + "product_min_qty": 5.0, + "product_max_qty": 20.0, + } + ) def test_01_po_line_from_orderpoints(self): """Test that a PO line created/updated by two orderpoints keeps the link with both of them.""" self.group_obj.run_scheduler() - po_line = self.env['purchase.order.line'].search( - [('product_id', '=', self.tp1.id)]) + po_line = self.env["purchase.order.line"].search( + [("product_id", "=", self.tp1.id)] + ) self.assertTrue(po_line) # Each orderpoint must have required 20.0 units: self.assertEqual(po_line.product_qty, 40.0)