Files
JF Aubert 204d4ebf5e [FIX] mrp_subcontracting_dropshipping: ease po's
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) <arm@odoo.com>
Signed-off-by: Jean-François Aubert <ajf@odoo.com>
2023-04-24 07:33:22 +02:00

33 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
default_location_dest_id_is_subcontracting_loc = fields.Boolean(related='picking_type_id.default_location_dest_id.is_subcontracting_location')
@api.depends('default_location_dest_id_is_subcontracting_loc')
def _compute_dest_address_id(self):
dropship_subcontract_pos = self.filtered(lambda po: po.default_location_dest_id_is_subcontracting_loc)
for order in dropship_subcontract_pos:
subcontractor_ids = order.picking_type_id.default_location_dest_id.subcontractor_ids
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 self.default_location_dest_id_is_subcontracting_loc:
return self.dest_address_id.property_stock_subcontractor.id
return super()._get_destination_location()