From 204d4ebf5e13c452ed4d109255dc58dccb520e55 Mon Sep 17 00:00:00 2001 From: JF Aubert Date: Fri, 24 Mar 2023 12:52:45 +0000 Subject: [PATCH] [FIX] mrp_subcontracting_dropshipping: ease po's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ease 'dropship' purchase orders for subcontractors. At the moment, it is not possible to dropship a subcontractor with a mix of products, some of which are part of a subcontracting BOM and some of which are not. This becomes possible, but it remains mandatory to choose between - Dropship (for the 'customer' location) - Dropship Subcontractor (for the 'subcontracting' location). Due to the destination location, it is not possible to combine the two streams in a single purchase order. closes odoo/odoo#119404 Task: 3199595 X-original-commit: c7f49776c74303e277246a4b6302e8a87d6a7def Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Jean-François Aubert --- .../models/purchase.py | 31 +++++-------------- .../tests/test_purchase_subcontracting.py | 8 +---- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/addons/mrp_subcontracting_dropshipping/models/purchase.py b/addons/mrp_subcontracting_dropshipping/models/purchase.py index c8cf393310c..9548e237699 100644 --- a/addons/mrp_subcontracting_dropshipping/models/purchase.py +++ b/addons/mrp_subcontracting_dropshipping/models/purchase.py @@ -18,30 +18,15 @@ class PurchaseOrder(models.Model): order.dest_address_id = subcontractor_ids if len(subcontractor_ids) == 1 else False super(PurchaseOrder, self - dropship_subcontract_pos)._compute_dest_address_id() + @api.onchange('picking_type_id') + def onchange_picking_type_id(self): + if self.default_location_dest_id_is_subcontracting_loc: + return { + 'warning': {'title': _('Warning'), 'message': _('Please note this purchase order is for subcontracting purposes.')} + } + def _get_destination_location(self): self.ensure_one() - if not self.dest_address_id: - return super()._get_destination_location() - - mrp_production_ids = self._get_mrp_productions(remove_archived_picking_types=False) - if mrp_production_ids: - if self.dest_address_id in mrp_production_ids.bom_id.subcontractor_ids: - return self.dest_address_id.property_stock_subcontractor.id - elif self.sale_order_count: - return super()._get_destination_location() - - in_bom_products = False - not_in_bom_products = self.env['purchase.order.line'] - for order_line in self.order_line: - if any(bom_line.bom_id.type == 'subcontract' and self.dest_address_id in bom_line.bom_id.subcontractor_ids for bom_line in order_line.product_id.bom_line_ids.filtered(lambda line: line.company_id == self.company_id)): - in_bom_products = True - elif not order_line.display_type: - not_in_bom_products |= order_line - if in_bom_products and not_in_bom_products: - raise UserError( - _("It appears some components in this RFQ are not meant for subcontracting. Please create a separate order for these.") + - '\n\n' + '\n'.join(not_in_bom_products.mapped('name')) - ) - elif in_bom_products: + if self.default_location_dest_id_is_subcontracting_loc: return self.dest_address_id.property_stock_subcontractor.id return super()._get_destination_location() diff --git a/addons/mrp_subcontracting_dropshipping/tests/test_purchase_subcontracting.py b/addons/mrp_subcontracting_dropshipping/tests/test_purchase_subcontracting.py index a776b38aee9..a24498d617f 100644 --- a/addons/mrp_subcontracting_dropshipping/tests/test_purchase_subcontracting.py +++ b/addons/mrp_subcontracting_dropshipping/tests/test_purchase_subcontracting.py @@ -324,15 +324,9 @@ class TestSubcontractingDropshippingFlows(TestMrpSubcontractingCommon): ], }]) - dropship_picking_type = self.env['stock.picking.type'].search([ - ('company_id', '=', self.env.company.id), - ('default_location_src_id.usage', '=', 'supplier'), - ('default_location_dest_id.usage', '=', 'customer'), - ], limit=1, order='sequence') - po = self.env['purchase.order'].create({ "partner_id": subcontractor.id, - "picking_type_id": dropship_picking_type.id, + "picking_type_id": self.env.company.dropship_subcontractor_pick_type_id.id, "dest_address_id": super_subcontractor.id, "order_line": [(0, 0, { 'product_id': product.id,