Skip to content

Commit 0c6eb8e

Browse files
[IMP] shoppingfeed_integration: Change the carrier field from many2one to many2many in store carrier mappings
With this change, for each mapping line the user can configure multiple carriers, and the logic selects the first one that matches the shipping address. For example, the customer buys from the Spain store, but the delivery address is in another country.
1 parent 612fdb4 commit 0c6eb8e

5 files changed

Lines changed: 31 additions & 10 deletions

File tree

shoppingfeed_integration/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33
{
44
"name": "Shoppingfeed Integration",
5-
"version": "18.0.1.0.2",
5+
"version": "18.0.1.0.3",
66
"summary": "Integrate Odoo with Shoppingfeed for product export and order sync",
77
"category": "Sales",
88
"author": "Tecnativa, Odoo Community Association (OCA)",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 Tecnativa - Carlos Lopez
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from openupgradelib import openupgrade
5+
6+
7+
@openupgrade.migrate()
8+
def migrate(env, version):
9+
openupgrade.m2o_to_x2m(
10+
env.cr,
11+
env["shoppingfeed.store.carrier.map"],
12+
"shoppingfeed_store_carrier_map",
13+
"delivery_carrier_ids",
14+
"delivery_carrier_id",
15+
)

shoppingfeed_integration/models/sale_order.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,25 @@ def _shoppingfeed_validate_products(self, order):
255255
return missing_products
256256

257257
def _shoppingfeed_get_carrier(
258-
self, store, channel, carrier_name, shipping_country=None
258+
self, store, channel, carrier_name, partner, shipping_partner=None
259259
):
260260
carrier = False
261+
shipping_partner = shipping_partner or partner
262+
shipping_country = shipping_partner.country_id if shipping_partner else None
261263
if carrier_name:
262264
carrier_map = store.carrier_map_ids.filtered(
263265
lambda m, carrier_name=carrier_name: m.carrier_name.strip().lower()
264266
== carrier_name.strip().lower()
265267
)
266268
if carrier_map:
267-
carrier = carrier_map.delivery_carrier_id
269+
for candidate_carrier in carrier_map.delivery_carrier_ids:
270+
if candidate_carrier._match_address(shipping_partner):
271+
carrier = candidate_carrier
272+
break
268273
if not carrier:
269274
if channel and shipping_country and channel.country_carrier_ids:
270275
country_rule = channel.country_carrier_ids.filtered(
271-
lambda r, c=shipping_country: r.country_id == c
276+
lambda rule, country=shipping_country: rule.country_id == country
272277
)
273278
if country_rule:
274279
carrier = country_rule[0].delivery_carrier_id
@@ -442,11 +447,8 @@ def _import_orders_from_shoppingfeed(self, store):
442447
# Carrier mapping
443448
shipment = order.get("shipment", {}) or {}
444449
carrier_name = shipment.get("carrier")
445-
shipping_country = (
446-
shipping_partner.country_id if shipping_partner else None
447-
)
448450
carrier = self._shoppingfeed_get_carrier(
449-
store, sf_channel, carrier_name, shipping_country
451+
store, sf_channel, carrier_name, partner, shipping_partner
450452
)
451453
new_sale = self._shoppingfeed_create_sale_order(
452454
store,

shoppingfeed_integration/models/shoppingfeed_store_carrier_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ShoppingfeedStoreCarrierMap(models.Model):
1717
required=True,
1818
help="Carrier name as received from Shoppingfeed",
1919
)
20-
delivery_carrier_id = fields.Many2one(
20+
delivery_carrier_ids = fields.Many2many(
2121
comodel_name="delivery.carrier",
2222
string="Odoo Delivery Carrier",
2323
required=True,

shoppingfeed_integration/views/shoppingfeed_store_views.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@
209209
<field name="carrier_map_ids">
210210
<list editable="bottom">
211211
<field name="carrier_name" />
212-
<field name="delivery_carrier_id" />
212+
<field
213+
name="delivery_carrier_ids"
214+
widget="many2many_tags"
215+
options="{'no_create': True}"
216+
/>
213217
</list>
214218
</field>
215219
</group>

0 commit comments

Comments
 (0)