Lot invoicing + fee padding

This commit is contained in:
2026-06-23 13:12:37 +02:00
parent ef8d914820
commit fbf3842e6c
3 changed files with 200 additions and 10 deletions

View File

@@ -3238,6 +3238,66 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(invoice_line.quantity, Decimal('7'))
fee.get_billing_quantity.assert_called_once_with()
def test_lot_invoice_sale_padding_refreshes_per_quantity_fee_amount(self):
'sale padding refreshes displayed per quantity fee amount'
start = lot_module.LotInvoiceStart()
unit = SimpleNamespace(id=1)
lot = SimpleNamespace(id=10, sale_line=SimpleNamespace(unit=unit))
fee = SimpleNamespace(
add_padding=True,
mode='perqt',
price=Decimal('10'),
quantity=Decimal('5'),
_get_effective_fee_lots=Mock(return_value=[lot]),
_get_effective_fee_lots_quantity=Mock(return_value=Decimal('5')),
_convert_padding_quantity=Mock(
side_effect=lambda quantity, unit: Decimal(str(quantity))),
get_quantity=Mock(return_value=Decimal('5')))
fee_line = SimpleNamespace(
fee=fee,
fee_quantity=Decimal('5'),
fee_amount=Decimal('50'))
start.type = 'sale'
start.sale_padding = Decimal('2')
start.lot_s = [SimpleNamespace(lot=lot)]
start.fee_sale = [fee_line]
start.on_change_sale_padding()
self.assertEqual(fee_line.fee_quantity, Decimal('7'))
self.assertEqual(fee_line.fee_amount, Decimal('70.00'))
def test_lot_invoice_sale_padding_refreshes_percent_price_fee_amount(self):
'sale padding refreshes displayed percent price fee amount'
start = lot_module.LotInvoiceStart()
unit = SimpleNamespace(id=1)
sale_line = SimpleNamespace(unit=unit, unit_price=Decimal('100'))
lot = SimpleNamespace(id=10, sale_line=sale_line)
fee = SimpleNamespace(
add_padding=True,
mode='pprice',
price=Decimal('2'),
quantity=Decimal('5'),
sale_line=sale_line,
_get_effective_fee_lots=Mock(return_value=[lot]),
_get_effective_fee_lots_quantity=Mock(return_value=Decimal('5')),
_convert_padding_quantity=Mock(
side_effect=lambda quantity, unit: Decimal(str(quantity))),
get_quantity=Mock(return_value=Decimal('5')))
fee_line = SimpleNamespace(
fee=fee,
fee_quantity=Decimal('5'),
fee_amount=Decimal('10'))
start.type = 'sale'
start.sale_padding = Decimal('2')
start.lot_s = [SimpleNamespace(lot=lot)]
start.fee_sale = [fee_line]
start.on_change_sale_padding()
self.assertEqual(fee_line.fee_quantity, Decimal('7'))
self.assertEqual(fee_line.fee_amount, Decimal('14.00'))
def test_fee_get_non_cog_returns_zero_without_move_lines(self):
'fee non-cog amount is zero before any accounting move line exists'
fee = fee_module.Fee()
@@ -7939,6 +7999,36 @@ class PurchaseTradeTestCase(ModuleTestCase):
Invoice._sale_padding_lots_to_clear_on_delete([invoice]),
[lot])
def test_fee_invoice_delete_collects_fee_to_reset(self):
'deleting a draft fee invoice resets the linked fee to not invoiced'
Invoice = Pool().get('account.invoice')
fee = SimpleNamespace(id=20, dn_cn=None)
invoice = SimpleNamespace(
id=10,
number=None,
lines=[SimpleNamespace(fee=fee)])
reset_fees, clear_dn_cn_fees = Invoice._fee_updates_on_delete(
[invoice])
self.assertEqual(reset_fees, [fee])
self.assertEqual(clear_dn_cn_fees, [])
def test_fee_dn_cn_delete_collects_fee_to_clear_dn_cn_only(self):
'deleting a draft fee DN/CN clears only the fee DN/CN link'
Invoice = Pool().get('account.invoice')
invoice = SimpleNamespace(id=10, number=None, lines=[])
fee = SimpleNamespace(id=20, dn_cn=invoice)
invoice.lines = [SimpleNamespace(fee=fee)]
reset_fees, clear_dn_cn_fees = Invoice._fee_updates_on_delete(
[invoice])
self.assertEqual(reset_fees, [])
self.assertEqual(clear_dn_cn_fees, [fee])
def test_lot_invoice_message_mentions_processed_fees(self):
'lot invoice success message mentions selected fee invoicing'
wizard = lot_module.LotInvoice()
@@ -7946,8 +8036,7 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(
wizard.default_message(None)['message'],
'The invoice has been successfully created. '
'2 selected fee invoice(s) have also been processed.')
'Invoice created. Fee invoices: 2.')
def test_invoice_report_net_sums_signed_invoice_lines(self):
'invoice report net uses the signed differential from invoice lines'