diff --git a/delivery_multi_destination/__manifest__.py b/delivery_multi_destination/__manifest__.py
index 2a3f7517a0..febf0dda5d 100644
--- a/delivery_multi_destination/__manifest__.py
+++ b/delivery_multi_destination/__manifest__.py
@@ -4,7 +4,7 @@
{
"name": "Multiple destinations for the same delivery method",
- "version": "12.0.1.1.0",
+ "version": "12.0.2.0.0",
"category": "Delivery",
"website": "https://github.com/OCA/delivery-carrier",
"author": "Tecnativa, "
diff --git a/delivery_multi_destination/demo/delivery_carrier_demo.xml b/delivery_multi_destination/demo/delivery_carrier_demo.xml
index c266ae0485..dbe41eaea1 100644
--- a/delivery_multi_destination/demo/delivery_carrier_demo.xml
+++ b/delivery_multi_destination/demo/delivery_carrier_demo.xml
@@ -10,6 +10,7 @@
International Carrier Inc.
4
multi
+ base_on_destination
diff --git a/delivery_multi_destination/migrations/12.0.2.0.0/pre-migration.py b/delivery_multi_destination/migrations/12.0.2.0.0/pre-migration.py
new file mode 100644
index 0000000000..b1375e4e31
--- /dev/null
+++ b/delivery_multi_destination/migrations/12.0.2.0.0/pre-migration.py
@@ -0,0 +1,15 @@
+# Copyright 2022 Coop IT Easy SC
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
+from openupgradelib import openupgrade
+
+
+@openupgrade.migrate()
+def migrate(env, version):
+ openupgrade.logged_query(
+ env.cr,
+ """
+ UPDATE delivery_carrier
+ SET delivery_type = 'base_on_destination'
+ WHERE destination_type = 'multi'
+ """
+ )
diff --git a/delivery_multi_destination/models/delivery_carrier.py b/delivery_multi_destination/models/delivery_carrier.py
index e497c3ed86..638ebe59d2 100644
--- a/delivery_multi_destination/models/delivery_carrier.py
+++ b/delivery_multi_destination/models/delivery_carrier.py
@@ -21,8 +21,35 @@ class DeliveryCarrier(models.Model):
('one', 'One destination'),
('multi', 'Multiple destinations'),
],
- default="one", required=True,
+ compute="_compute_destination_type",
+ inverse="_inverse_destination_type",
+ store=True,
)
+ delivery_type = fields.Selection(
+ selection_add=[("base_on_destination", "Based on Destination")]
+ )
+
+ @api.depends("delivery_type")
+ def _compute_destination_type(self):
+ for carrier in self:
+ if carrier.delivery_type == "base_on_destination":
+ carrier.destination_type = "multi"
+ else:
+ carrier.destination_type = "one"
+
+ def _inverse_destination_type(self):
+ for carrier in self:
+ # Switch to multi
+ if carrier.destination_type == "multi":
+ carrier.delivery_type = "base_on_destination"
+ # Switch away from multi -> we know that destination_type is
+ # non-multi. However, in a hypothetical scenario where we switch
+ # from one non-multi destination_type to another, we don't want to
+ # forcibly reset delivery_type to 'fixed' each time, so we check
+ # whether delivery_type is invalid for a non-multi destination_type
+ # before we forcibly reset to 'fixed'.
+ elif carrier.delivery_type == "base_on_destination":
+ carrier.delivery_type = "fixed"
def search(self, args, offset=0, limit=None, order=None, count=False):
"""Don't show by default children carriers."""
diff --git a/delivery_multi_destination/readme/newsfragments/540.feature.rst b/delivery_multi_destination/readme/newsfragments/540.feature.rst
new file mode 100644
index 0000000000..efc3b8dc70
--- /dev/null
+++ b/delivery_multi_destination/readme/newsfragments/540.feature.rst
@@ -0,0 +1,4 @@
+Introduced 'based on destination' delivery type. This is the delivery type used
+by all multi-destination carriers instead of 'fixed'. Consequently, destination
+type has been turned into a computed field that checks if the delivery type is
+'based on destination' or not.
diff --git a/delivery_multi_destination/tests/test_delivery_multi_destination.py b/delivery_multi_destination/tests/test_delivery_multi_destination.py
index ed67973dc1..29c36c0570 100644
--- a/delivery_multi_destination/tests/test_delivery_multi_destination.py
+++ b/delivery_multi_destination/tests/test_delivery_multi_destination.py
@@ -52,7 +52,7 @@ def setUpClass(cls):
'name': 'Test carrier multi',
'product_id': cls.product.id,
'destination_type': 'multi',
- 'delivery_type': 'fixed',
+ 'delivery_type': 'base_on_destination',
'fixed_price': 100,
'child_ids': [
(0, 0, {
@@ -123,6 +123,20 @@ def test_delivery_multi_destination(self):
order.get_delivery_price()
self.assertAlmostEqual(order.delivery_price, 150, 2)
+ def test_compute(self):
+ self.carrier_multi.delivery_type = "fixed"
+ self.assertEqual(self.carrier_multi.destination_type, "one")
+ self.carrier_multi.delivery_type = "base_on_destination"
+ self.assertEqual(self.carrier_multi.destination_type, "multi")
+
+ def test_inverse(self):
+ self.carrier_multi.destination_type = "one"
+ self.assertEqual(self.carrier_multi.destination_type, "one")
+ self.assertEqual(self.carrier_multi.delivery_type, "fixed")
+ self.carrier_multi.destination_type = "multi"
+ self.assertEqual(self.carrier_multi.destination_type, "multi")
+ self.assertEqual(self.carrier_multi.delivery_type, "base_on_destination")
+
def test_search(self):
carriers = self.env['delivery.carrier'].search([])
children_carrier = self.carrier_multi.with_context(