This commit is contained in:
2026-04-02 16:31:05 +02:00
parent cc6ce82ec1
commit 58cd66e543
2 changed files with 4 additions and 26 deletions

View File

@@ -377,31 +377,15 @@ class Invoice(metaclass=PoolMeta):
def report_nb_bale(self):
lots = self._get_report_invoice_lots()
if lots:
Uom = Pool().get('product.uom')
line = self._get_report_invoice_line() or self._get_report_trade_line()
invoice_unit = getattr(line, 'unit', None) if line else None
net = Decimal(str(self.report_net or 0))
total_packages = Decimal(0)
total_weight = Decimal(0)
package_unit = None
for lot in lots:
if getattr(lot, 'lot_qt', None):
total_packages += Decimal(str(lot.lot_qt or 0))
if not package_unit and getattr(lot, 'lot_unit', None):
package_unit = lot.lot_unit
lot_quantity = Decimal(str(getattr(lot, 'lot_quantity', 0) or 0))
lot_unit_line = getattr(lot, 'lot_unit_line', None)
if lot_quantity and lot_unit_line and invoice_unit:
total_weight += Decimal(str(
Uom.compute_qty(
lot_unit_line, float(lot_quantity), invoice_unit,
round=False) or 0))
if total_packages:
package_qty = total_packages
if total_weight and net:
package_qty = (
net / (total_weight / total_packages))
package_qty = package_qty.quantize(
package_qty = total_packages.quantize(
Decimal('1'), rounding=ROUND_HALF_UP)
if package_qty:
label = self._format_report_package_label(package_unit)

View File

@@ -333,8 +333,8 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(invoice.report_net, Decimal('800'))
def test_invoice_report_nb_bale_uses_linked_lot_packaging(self):
'invoice reports packaging from linked physical lots with signed prorata'
def test_invoice_report_nb_bale_uses_linked_lot_quantity_only(self):
'invoice reports packaging from linked physical lots using lot_qt only'
Invoice = Pool().get('account.invoice')
line = Mock(type='line', quantity=Decimal('-15'))
@@ -353,17 +353,11 @@ class PurchaseTradeTestCase(ModuleTestCase):
)
sale_line.lots = [lot]
sale = Mock(lines=[sale_line])
uom_model = Mock()
uom_model.compute_qty.return_value = Decimal('2000')
invoice = Invoice()
invoice.sales = [sale]
invoice.lines = [line]
with patch(
'trytond.modules.purchase_trade.invoice.Pool'
) as PoolMock:
PoolMock.return_value.get.return_value = uom_model
self.assertEqual(invoice.report_nb_bale, 'NB BALES: -5')
self.assertEqual(invoice.report_nb_bale, 'NB BALES: 700')
def test_invoice_report_positive_rate_lines_keep_positive_components(self):
'invoice final note pricing section keeps only positive component lines'