Bug Pnl packing

This commit is contained in:
2026-07-17 07:28:35 +02:00
parent 39afd9dc32
commit 0272fc70bc
3 changed files with 910 additions and 13 deletions

View File

@@ -3268,6 +3268,46 @@ class PurchaseTradeTestCase(ModuleTestCase):
'shipment_in': shipment.id,
}])
def test_ppack_fee_valuation_uses_fee_packing_not_lot_packing(self):
'per packing fee valuation keeps the fee quantity and amount'
Valuation = valuation_module.ValuationBase
fee = SimpleNamespace(
mode='ppack',
quantity=Decimal('2'),
price=Decimal('2800'),
amount=Decimal('5600'),
)
lot = Mock(lot_qt=Decimal('440'))
segment = {'quantity': Decimal('26.4'), 'share': None}
qty = Valuation._fee_segment_quantity(fee, lot, segment)
price, amount = Valuation._fee_segment_amount(
fee, lot, qty, Decimal('-1'), segment)
self.assertEqual(qty, Decimal('2'))
self.assertEqual(price, Decimal('2800'))
self.assertEqual(amount, Decimal('-5600'))
def test_ppack_fee_valuation_splits_fee_packing_by_segment_share(self):
'per packing fee valuation prorates fee amount on segment shares'
Valuation = valuation_module.ValuationBase
fee = SimpleNamespace(
mode='ppack',
quantity=Decimal('2'),
price=Decimal('2800'),
amount=Decimal('5600'),
)
lot = Mock(lot_qt=Decimal('440'))
segment = {'quantity': Decimal('13.2'), 'share': Decimal('0.5')}
qty = Valuation._fee_segment_quantity(fee, lot, segment)
price, amount = Valuation._fee_segment_amount(
fee, lot, qty, Decimal('-1'), segment)
self.assertEqual(qty, Decimal('1.00000'))
self.assertEqual(price, Decimal('2800'))
self.assertEqual(amount, Decimal('-2800.0'))
def test_snapshot_identity_prefers_sale_line_over_purchase_line(self):
'valuation snapshot identity ignores purchase line when sale line exists'
Valuation = Pool().get('valuation.valuation')