02.04.26
This commit is contained in:
@@ -375,6 +375,26 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
@property
|
||||
def report_nb_bale(self):
|
||||
total_packages = Decimal(0)
|
||||
package_unit = None
|
||||
has_invoice_line_packages = False
|
||||
for line in self._get_report_invoice_lines():
|
||||
lot = getattr(line, 'lot', None)
|
||||
if not lot or getattr(lot, 'lot_qt', None) in (None, ''):
|
||||
continue
|
||||
has_invoice_line_packages = True
|
||||
if not package_unit and getattr(lot, 'lot_unit', None):
|
||||
package_unit = lot.lot_unit
|
||||
sign = Decimal(1)
|
||||
if Decimal(str(getattr(line, 'quantity', 0) or 0)) < 0:
|
||||
sign = Decimal(-1)
|
||||
total_packages += (
|
||||
Decimal(str(lot.lot_qt or 0)).quantize(
|
||||
Decimal('1'), rounding=ROUND_HALF_UP) * sign)
|
||||
if has_invoice_line_packages:
|
||||
label = self._format_report_package_label(package_unit)
|
||||
return f"NB {label}: {int(total_packages)}"
|
||||
|
||||
lots = self._get_report_invoice_lots()
|
||||
if lots:
|
||||
total_packages = Decimal(0)
|
||||
@@ -384,12 +404,10 @@ class Invoice(metaclass=PoolMeta):
|
||||
total_packages += Decimal(str(lot.lot_qt or 0))
|
||||
if not package_unit and getattr(lot, 'lot_unit', None):
|
||||
package_unit = lot.lot_unit
|
||||
if total_packages:
|
||||
package_qty = total_packages.quantize(
|
||||
Decimal('1'), rounding=ROUND_HALF_UP)
|
||||
if package_qty:
|
||||
label = self._format_report_package_label(package_unit)
|
||||
return f"NB {label}: {int(package_qty)}"
|
||||
package_qty = total_packages.quantize(
|
||||
Decimal('1'), rounding=ROUND_HALF_UP)
|
||||
label = self._format_report_package_label(package_unit)
|
||||
return f"NB {label}: {int(package_qty)}"
|
||||
sale = self._get_report_sale()
|
||||
if sale and sale.report_nb_bale:
|
||||
return sale.report_nb_bale
|
||||
|
||||
Reference in New Issue
Block a user