[IMP] stock_delivery: route based on shipping method

In this commit, we added a new field in the shipping methods this field can be
used select rules. These rules can only be used when the corresponding SO has
one of the selected shipping methods.

task-3236149

closes odoo/odoo#119320

Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
Surabhi Varma
2023-07-03 12:20:58 +02:00
parent d34cba59c6
commit bbfd5aa614
6 changed files with 130 additions and 0 deletions
@@ -24,6 +24,10 @@ class DeliveryCarrier(models.Model):
"shipping will be updated on the SO after the delivery."
)
route_ids = fields.Many2many(
'stock.route', 'stock_route_shipping', 'shipping_id', 'route_id', 'Routes',
domain=[('shipping_selectable', '=', True)])
# -------------------------- #
# API for external providers #
# -------------------------- #
@@ -42,3 +42,13 @@ class SaleOrder(models.Model):
else:
post = u'\N{NO-BREAK SPACE}{symbol}'.format(symbol=self.currency_id.symbol or '')
return u' {pre}{0}{post}'.format(amount, pre=pre, post=post)
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
def _prepare_procurement_values(self, group_id):
values = super(SaleOrderLine, self)._prepare_procurement_values(group_id)
if not values.get("route_ids") and self.order_id.carrier_id.route_ids:
values['route_ids'] = self.order_id.carrier_id.route_ids
return values
@@ -4,6 +4,12 @@ from odoo import api, fields, models
from odoo.tools.sql import column_exists, create_column
class StockRoute(models.Model):
_inherit = "stock.route"
shipping_selectable = fields.Boolean("Applicable on Shipping Methods")
class StockMove(models.Model):
_inherit = 'stock.move'
@@ -1,5 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import Command
from odoo.tests import Form
from odoo.tests.common import TransactionCase
@@ -125,3 +126,91 @@ class TestCarrierPropagation(TransactionCase):
self.normal_delivery,
move_pack.picking_id.carrier_id,
)
def test_route_based_on_carrier_delivery(self):
"""
Check that the route on the sale order line is selected as per the first priority even if route on shipping mehod is present
Also, Check that the route on the shipping method is selected if there is no route selected on sale order line
"""
route1 = self.env['stock.route'].create({
'name': 'Route1',
'sale_selectable' : True,
'shipping_selectable': True,
'warehouse_ids': [Command.link(self.env.ref("stock.warehouse0").id)],
'rule_ids': [Command.create({
'name': 'rule1',
'location_src_id': self.warehouse.lot_stock_id.id,
'location_dest_id': self.customer_location.id,
'company_id': self.env.company.id,
'action': 'pull',
'auto': 'transparent',
'picking_type_id': self.ref('stock.picking_type_out'),
})],
})
shelf1_location = self.env['stock.location'].create({
'name': 'shelf1',
'usage': 'internal',
'location_id': self.env.ref('stock.stock_location_stock').id,
})
route2 = self.env['stock.route'].create({
'name': 'Route2',
'sale_selectable' : True,
'shipping_selectable':True,
'warehouse_ids': [Command.link(self.env.ref("stock.warehouse0").id)],
'rule_ids': [Command.create({
'name': 'rule2',
'location_src_id': shelf1_location.id,
'location_dest_id': self.customer_location.id,
'company_id': self.env.company.id,
'action': 'pull',
'auto': 'transparent',
'picking_type_id': self.ref('stock.picking_type_out'),
})],
})
self.normal_delivery.write({
"route_ids": [Command.link(route2.id)]
})
sale_order1 = self.SaleOrder.create({
'partner_id': self.partner_propagation.id,
'order_line': [Command.create({
'name': 'Cable Management Box',
'product_id': self.super_product.id,
'product_uom_qty': 2,
'product_uom': self.product_uom_unit.id,
'price_unit': 750.00,
'route_id' : route1.id,
})],
})
delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({
'default_order_id': sale_order1.id,
'default_carrier_id': self.normal_delivery.id,
}))
choose_delivery_carrier = delivery_wizard.save()
choose_delivery_carrier.button_confirm()
sale_order1.action_confirm()
self.assertEqual(sale_order1.picking_ids.location_id, route1.rule_ids.location_src_id)
# check route without add in sale order line
sale_order2 = self.SaleOrder.create({
'partner_id': self.partner_propagation.id,
'order_line': [Command.create({
'name': 'Cable Management Box',
'product_id': self.super_product.id,
'product_uom_qty': 2,
'product_uom': self.product_uom_unit.id,
'price_unit': 750.00,
})],
})
delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({
'default_order_id': sale_order2.id,
'default_carrier_id': self.normal_delivery.id,
}))
choose_delivery_carrier = delivery_wizard.save()
choose_delivery_carrier.button_confirm()
sale_order2.action_confirm()
self.assertEqual(sale_order2.picking_ids.location_id, route2.rule_ids.location_src_id)
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_delivery_carrier_form_inherit_stock_delivery" model="ir.ui.view">
<field name="name">delivery.carrier.form</field>
<field name="model">delivery.carrier</field>
<field name="inherit_id" ref="delivery.view_delivery_carrier_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='provider_details']" position="inside">
<field name="route_ids" string="Routes" options="{'no_create': True}" groups="stock.group_adv_location" widget="many2many_tags"/>
</xpath>
</field>
</record>
<record id="view_picking_withcarrier_out_form" model="ir.ui.view">
<field name="name">delivery.stock.picking_withcarrier.form.view</field>
@@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock_location_route_view_form_inherit_stock_delivery" model="ir.ui.view">
<field name="name">stock.route.form</field>
<field name="model">stock.route</field>
<field name="inherit_id" ref="stock.stock_location_route_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='route_selector']/group" position="inside">
<field name="shipping_selectable" string="Shipping Methods"/>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="stock_move_line_view_search_delivery">
<field name="name">stock.move.line.search.delivery</field>
<field name="model">stock.move.line</field>