Test if origin id is greater or equals to 0 before accessing the target record

Closes #13498
(grafted from 497490225779fc8dc210c9cee997cd5ce4b4381e)

--HG--
branch : 6.0
This commit is contained in:
Cédric Krier
2024-09-09 12:46:16 +02:00
parent ad9869f5b5
commit 59f18d44cd
9 changed files with 12 additions and 9 deletions
+1 -1
View File
@@ -2071,7 +2071,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
@property
def origin_name(self):
if isinstance(self.origin, self.__class__):
if isinstance(self.origin, self.__class__) and self.origin.id >= 0:
return self.origin.invoice.rec_name
return self.origin.rec_name if self.origin else None
+3 -2
View File
@@ -119,7 +119,7 @@ class MoveSale(metaclass=PoolMeta):
pool = Pool()
SaleLineComponent = pool.get('sale.line.component')
name = super().origin_name
if isinstance(self.origin, SaleLineComponent):
if isinstance(self.origin, SaleLineComponent) and self.origin.id >= 0:
name = self.origin.line.sale.rec_name
return name
@@ -211,7 +211,8 @@ class MovePurchase(metaclass=PoolMeta):
pool = Pool()
PurchaseLineComponent = pool.get('purchase.line.component')
name = super().origin_name
if isinstance(self.origin, PurchaseLineComponent):
if (isinstance(self.origin, PurchaseLineComponent)
and self.origin.id >= 0):
name = self.origin.line.purchase.rec_name
return name
+1 -1
View File
@@ -123,7 +123,7 @@ class InvoiceLine(metaclass=PoolMeta):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
name = super(InvoiceLine, self).origin_name
if isinstance(self.origin, PurchaseLine):
if isinstance(self.origin, PurchaseLine) and self.origin.id >= 0:
name = self.origin.purchase.rec_name
return name
+1 -1
View File
@@ -221,7 +221,7 @@ class Move(metaclass=PoolMeta):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
name = super(Move, self).origin_name
if isinstance(self.origin, PurchaseLine):
if isinstance(self.origin, PurchaseLine) and self.origin.id >= 0:
name = self.origin.purchase.rec_name
return name
+1 -1
View File
@@ -121,7 +121,7 @@ class Line(metaclass=PoolMeta):
pool = Pool()
SaleLine = pool.get('sale.line')
name = super().origin_name
if isinstance(self.origin, SaleLine):
if isinstance(self.origin, SaleLine) and self.origin.id >= 0:
name = self.origin.sale.rec_name
return name
+1 -1
View File
@@ -188,7 +188,7 @@ class Move(metaclass=PoolMeta):
pool = Pool()
SaleLine = pool.get('sale.line')
name = super(Move, self).origin_name
if isinstance(self.origin, SaleLine):
if isinstance(self.origin, SaleLine) and self.origin.id >= 0:
name = self.origin.sale.rec_name
return name
+1 -1
View File
@@ -11,7 +11,7 @@ class InvoiceLine(metaclass=PoolMeta):
pool = Pool()
SubscriptionLine = pool.get('sale.subscription.line')
name = super(InvoiceLine, self).origin_name
if isinstance(self.origin, SubscriptionLine):
if isinstance(self.origin, SubscriptionLine) and self.origin.id >= 0:
name = self.origin.subscription.rec_name
return name
+2 -1
View File
@@ -550,7 +550,8 @@ class Move(Workflow, ModelSQL, ModelView):
@property
def origin_name(self):
return self.origin.rec_name if self.origin else None
if self.origin and self.origin.id >= 0:
return self.origin.rec_name
@classmethod
def check_period_closed(cls, moves):
+1
View File
@@ -12,6 +12,7 @@ class InvoiceLine(metaclass=PoolMeta):
Move = pool.get('stock.move')
name = super(InvoiceLine, self).origin_name
if (isinstance(self.origin, Move)
and self.origin.id >= 0
and self.origin.shipment):
name = self.origin.shipment.rec_name
return name