[ADD] mrp_subcontracting_dropshipping
Allow to do a dropshipping with a subcontractor. If the product uses the routes drophipping and have a subcontracting BoM. Then a PO for the subcontractors will genrate a need in the subcontracting location for the required components. A module is needed because the picking_type_id for dropshipping do not have a warehouse_id. The warehouse_id is needed in order to know from which warehouse the subcontracting components should be deliver.
This commit is contained in:
@@ -64,6 +64,9 @@ class StockPicking(models.Model):
|
||||
self.ensure_one()
|
||||
return self.move_lines.mapped('move_orig_ids.production_id')
|
||||
|
||||
def _get_warehouse(self, subcontract_move):
|
||||
return subcontract_move.warehouse_id or self.picking_type_id.warehouse_id
|
||||
|
||||
def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
|
||||
subcontract_move.ensure_one()
|
||||
group = self.env['procurement.group'].create({
|
||||
@@ -71,7 +74,7 @@ class StockPicking(models.Model):
|
||||
'partner_id': self.partner_id.id,
|
||||
})
|
||||
product = subcontract_move.product_id
|
||||
warehouse = subcontract_move.warehouse_id or self.picking_type_id.warehouse_id
|
||||
warehouse = self._get_warehouse(subcontract_move)
|
||||
vals = {
|
||||
'procurement_group_id': group.id,
|
||||
'product_id': product.id,
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
{
|
||||
'name': 'Dropship and Subcontracting Management',
|
||||
'version': '0.1',
|
||||
'category': 'Hidden',
|
||||
'description': """
|
||||
This bridge module allows to manage subcontracting with the dropshipping module.
|
||||
""",
|
||||
'depends': ['mrp_subcontracting', 'stock_dropshipping'],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import stock_picking
|
||||
@@ -0,0 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def _get_warehouse(self, subcontract_move):
|
||||
if subcontract_move.sale_line_id:
|
||||
return subcontract_move.sale_line_id.order_id.warehouse_id
|
||||
return super(StockPicking, self)._get_warehouse(subcontract_move)
|
||||
@@ -0,0 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_purchase_subcontracting
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import Form
|
||||
from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon
|
||||
|
||||
|
||||
class TestSubcontractingDropshippingFlows(TestMrpSubcontractingCommon):
|
||||
|
||||
def test_mrp_subcontracting_dropshipping_1(self):
|
||||
""" Mark the subcontracted product with the route dropship and add the
|
||||
subcontractor as seller. The component has the routes 'MTO', 'Replenish
|
||||
on order' and 'Buy'. Also another partner is set as vendor on the comp.
|
||||
Create a SO and check that:
|
||||
- Delivery between subcontractor and customer for subcontracted product.
|
||||
- Delivery for the component to the subcontractor for the specified wh.
|
||||
- Po created for the component.
|
||||
"""
|
||||
mto_route = self.env['stock.location.route'].search([('name', '=', 'Replenish on Order (MTO)')])
|
||||
resupply_route = self.env['stock.location.route'].search([('name', '=', 'Resupply Subcontractor on Order')])
|
||||
buy_route = self.env['stock.location.route'].search([('name', '=', 'Buy')])
|
||||
dropship_route = self.env['stock.location.route'].search([('name', '=', 'Dropship')])
|
||||
self.comp2.write({'route_ids': [(4, buy_route.id), (4, mto_route.id), (4, resupply_route.id)]})
|
||||
self.finished.write({'route_ids': [(4, dropship_route.id)]})
|
||||
|
||||
warehouse = self.env['stock.warehouse'].create({
|
||||
'name': 'Warehouse For subcontract',
|
||||
'code': 'WFS'
|
||||
})
|
||||
|
||||
self.env['product.supplierinfo'].create({
|
||||
'product_tmpl_id': self.finished.product_tmpl_id.id,
|
||||
'name': self.subcontractor_partner1.id
|
||||
})
|
||||
|
||||
partner = self.env['res.partner'].create({
|
||||
'name': 'Toto'
|
||||
})
|
||||
self.env['product.supplierinfo'].create({
|
||||
'product_tmpl_id': self.comp2.product_tmpl_id.id,
|
||||
'name': partner.id
|
||||
})
|
||||
|
||||
# Create a receipt picking from the subcontractor
|
||||
so_form = Form(self.env['sale.order'])
|
||||
so_form.partner_id = partner
|
||||
so_form.warehouse_id = warehouse
|
||||
with so_form.order_line.new() as line:
|
||||
line.product_id = self.finished
|
||||
line.product_uom_qty = 1
|
||||
so = so_form.save()
|
||||
so.action_confirm()
|
||||
|
||||
# Pickings should directly be created
|
||||
po = self.env['purchase.order'].search([('origin', 'ilike', so.name)])
|
||||
self.assertTrue(po)
|
||||
|
||||
po.button_approve()
|
||||
|
||||
picking_finished = po.picking_ids
|
||||
self.assertEqual(len(picking_finished), 1.0)
|
||||
self.assertEqual(picking_finished.location_dest_id, partner.property_stock_customer)
|
||||
self.assertEqual(picking_finished.location_id, self.subcontractor_partner1.property_stock_supplier)
|
||||
self.assertEqual(picking_finished.state, 'assigned')
|
||||
|
||||
picking_delivery = self.env['stock.move'].search([
|
||||
('product_id', '=', self.comp2.id),
|
||||
('location_id', '=', warehouse.lot_stock_id.id),
|
||||
('location_dest_id', '=', self.subcontractor_partner1.property_stock_subcontractor.id),
|
||||
]).picking_id
|
||||
self.assertTrue(picking_delivery)
|
||||
self.assertEqual(picking_delivery.state, 'waiting')
|
||||
|
||||
po = self.env['purchase.order.line'].search([
|
||||
('product_id', '=', self.comp2.id),
|
||||
('partner_id', '=', partner.id),
|
||||
]).order_id
|
||||
self.assertTrue(po)
|
||||
Reference in New Issue
Block a user