bug template

This commit is contained in:
2026-04-09 21:38:26 +02:00
parent 9c8d7f11ae
commit 4bbd7a5e76
2 changed files with 106 additions and 0 deletions

View File

@@ -1183,6 +1183,63 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(invoice.report_net, Decimal('800'))
self.assertEqual(invoice.report_gross, Decimal('820'))
def test_invoice_report_uses_line_quantities_when_same_lot_is_invoiced_twice(self):
'invoice final note keeps line differences when two lines share the same lot'
Invoice = Pool().get('account.invoice')
mt = Mock(id=1, rec_name='MT')
kg = Mock(id=2, rec_name='KILOGRAM')
shared_lot = Mock(id=10, lot_type='physic', lot_unit_line=kg)
shared_lot.get_hist_quantity.return_value = (
Decimal('999995'),
Decimal('999995'),
)
negative = Mock(
type='line',
quantity=Decimal('-999.995'),
unit=mt,
lot=shared_lot,
)
positive = Mock(
type='line',
quantity=Decimal('999.990'),
unit=mt,
lot=shared_lot,
)
invoice = Invoice()
negative.invoice = invoice
positive.invoice = invoice
invoice.lines = [negative, positive]
uom_model = Mock()
uom_model.search.return_value = [Mock(id=3, rec_name='LBS', symbol='LBS')]
uom_model.compute_qty.side_effect = (
lambda from_unit, qty, to_unit: (
qty * 1000
if getattr(from_unit, 'rec_name', None) == 'MT'
and getattr(to_unit, 'rec_name', None) == 'KILOGRAM'
else (
qty * 2.20462
if getattr(from_unit, 'rec_name', None) == 'KILOGRAM'
and getattr(to_unit, 'rec_name', None) == 'LBS'
else qty
)
)
)
with patch('trytond.modules.purchase_trade.invoice.Pool') as PoolMock:
PoolMock.return_value.get.return_value = uom_model
self.assertEqual(invoice.report_net, Decimal('-5.000'))
self.assertEqual(
invoice.report_quantity_lines.splitlines(),
[
'-999995.0 KILOGRAM (-2204608.98 LBS)',
'999990.0 KILOGRAM (2204597.95 LBS)',
])
def test_invoice_report_weights_use_single_virtual_lot_when_no_physical(self):
'invoice uses the unique virtual lot hist when no physical lot exists'
Invoice = Pool().get('account.invoice')