Use isinstance() to check if origin points to a purchase.

If origin only points to a model without a specific ID, then 'origin'
evaluates to True but is not an object (but str) so using
origin.__name__ crashes.
This commit is contained in:
Albert Cervera i Areny 2021-03-29 23:32:56 +02:00
parent 0224697827
commit f98cf7464d
1 changed files with 2 additions and 2 deletions

View File

@ -303,6 +303,7 @@ class EdiShipmentInLine(ModelSQL, ModelView):
pool = Pool()
Barcode = pool.get('product.code')
REF = pool.get('edi.shipment.in.reference')
Purchase = pool.get('purchase.purchase')
domain = [('number', '=', self.code)]
barcode = Barcode.search(domain, limit=1)
@ -312,8 +313,7 @@ class EdiShipmentInLine(ModelSQL, ModelView):
self.product = product
purchases = [x.origin for x in edi_shipment.references if
x.type_ == 'ON' and x.origin
and x.origin.__name__ == 'purchase.purchase']
x.type_ == 'ON' and isinstance(x.origin, Purchase)]
self.references = []
for purchase in purchases: