diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py index fca5fe1..c35bfcd 100755 --- a/modules/purchase_trade/lot.py +++ b/modules/purchase_trade/lot.py @@ -2898,17 +2898,21 @@ class LotInvoiceStart(ModelView): }) @fields.depends('type') - def on_change_with_action(self, name=None): - if self.lot_p and self.type == 'purchase': - if self.lot_p[0].lot.line.purchase.wb.qt_type in [e.quantity_type for e in self.lot_p[0].lot.lot_hist]: - return 'final' - else: - return 'prov' - if self.lot_s and self.type == 'sale': - if self.lot_s[0].lot.sale_line.sale.wb.qt_type in [e.quantity_type for e in self.lot_s[0].lot.lot_hist]: - return 'final' - else: - return 'prov' + def on_change_with_action(self, name=None): + if self.lot_p and self.type == 'purchase': + purchase = getattr(getattr(self.lot_p[0].lot, 'line', None), 'purchase', None) + wb = getattr(purchase, 'wb', None) + if wb and wb.qt_type in [e.quantity_type for e in self.lot_p[0].lot.lot_hist]: + return 'final' + else: + return 'prov' + if self.lot_s and self.type == 'sale': + sale = getattr(getattr(self.lot_s[0].lot, 'sale_line', None), 'sale', None) + wb = getattr(sale, 'wb', None) + if wb and wb.qt_type in [e.quantity_type for e in self.lot_s[0].lot.lot_hist]: + return 'final' + else: + return 'prov' @fields.depends('lot_p','type','quantity') def on_change_with_quantity(self, name=None):