mirror of
https://github.com/bringout/oca-ocb-mrp.git
synced 2026-04-26 17:52:01 +02:00
34 lines
1.7 KiB
Python
34 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
from odoo.tools import float_compare
|
|
|
|
|
|
class StockPicking(models.Model):
|
|
_inherit = 'stock.picking'
|
|
|
|
def _compute_is_dropship(self):
|
|
dropship_subcontract_pickings = self.filtered(lambda p: p.location_dest_id.is_subcontract() and p.location_id.usage == 'supplier')
|
|
dropship_subcontract_pickings.is_dropship = True
|
|
super(StockPicking, self - dropship_subcontract_pickings)._compute_is_dropship()
|
|
|
|
def _get_warehouse(self, subcontract_move):
|
|
if subcontract_move.sale_line_id:
|
|
return subcontract_move.sale_line_id.order_id.warehouse_id
|
|
return super()._get_warehouse(subcontract_move)
|
|
|
|
def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
|
|
res = super()._prepare_subcontract_mo_vals(subcontract_move, bom)
|
|
if not res.get('picking_type_id') and (
|
|
subcontract_move.location_dest_id.usage == 'customer'
|
|
or subcontract_move.location_dest_id.is_subcontract()
|
|
):
|
|
# If the if-condition is respected, it means that `subcontract_move` is not
|
|
# related to a specific warehouse. This can happen if, for instance, the user
|
|
# confirms a PO with a subcontracted product that should be delivered to a
|
|
# customer (dropshipping). In that case, we can use a default warehouse to
|
|
# get the picking type
|
|
default_warehouse = self.env['stock.warehouse'].search([('company_id', '=', subcontract_move.company_id.id)], limit=1)
|
|
res['picking_type_id'] = default_warehouse.subcontracting_type_id.id,
|
|
return res
|