Skip to content

Commit 38edbfb

Browse files
committed
[FIX] shoppingfeed_integration: avoid singleton error on order import
Method _shoppingfeed_format_phone called without order Temporary sale order lines can compute their invoice status before they are linked to a sale order. TT62646
1 parent f098b90 commit 38edbfb

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

shoppingfeed_integration/models/sale_order.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SaleOrder(models.Model):
6060
]
6161

6262
def _is_shoppingfeed_disable_invoicing(self):
63-
return self.shoppingfeed_channel_id.disable_invoicing
63+
return bool(self and self.shoppingfeed_channel_id.disable_invoicing)
6464

6565
@api.depends("shoppingfeed_channel_id")
6666
def _compute_invoice_status(self):
@@ -93,6 +93,8 @@ def _shoppingfeed_fetch_orders(self, store):
9393

9494
@api.model
9595
def _shoppingfeed_format_phone(self, phone_number, country):
96+
if not self:
97+
return phone_number
9698
phone_sanitized = self._phone_format(
9799
number=phone_number, country=country, force_format="INTERNATIONAL"
98100
)
@@ -487,6 +489,7 @@ class SaleOrderLine(models.Model):
487489
def _compute_invoice_status(self):
488490
res = super()._compute_invoice_status()
489491
self.filtered(
490-
lambda sol: sol.order_id._is_shoppingfeed_disable_invoicing()
492+
lambda sol: sol.order_id
493+
and sol.order_id._is_shoppingfeed_disable_invoicing()
491494
).invoice_status = "no"
492495
return res

shoppingfeed_integration/tests/test_shoppingfeed_integration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ def test_invoice_not_auto_paid_when_disabled(self):
119119
self.assertNotEqual(invoice.payment_state, "paid")
120120
self.sf_channel.auto_pay = True
121121

122+
def test_invoice_status_on_new_line_without_order(self):
123+
"""Temporary lines can compute invoice status before an order exists."""
124+
line = self.env["sale.order.line"].new({"product_id": self.product_a.id})
125+
line._compute_invoice_status()
126+
self.assertEqual(line.invoice_status, "no")
127+
122128
def test_product_reference_cleaning(self):
123129
"""_shoppingfeed_clean_product_reference strips 2-char country suffixes only."""
124130
so = self.env["sale.order"]

0 commit comments

Comments
 (0)