Commission CN/DN

This commit is contained in:
2026-06-17 11:04:43 +02:00
parent 6ba5361269
commit 02e5c43f3d
3 changed files with 53 additions and 3 deletions

View File

@@ -532,6 +532,49 @@ class Invoice(metaclass=PoolMeta):
totals['difference'], totals['unit'])
return self._format_report_quantity_display(lbs)
@property
def report_commission_adjustment_rate_line(self):
fee = self._get_report_commission_fee()
if not fee:
return self.report_commission_rate_line
mode = getattr(fee, 'mode', None)
price = getattr(fee, 'price', None) or 0
if mode in {'pprice', 'rate', 'pcost'}:
kind = self._get_report_commission_kind() or 'sale'
return ' '.join(part for part in [
self._format_report_number(price, digits='0.0000'),
'% on',
kind,
'amount',
self._get_report_commission_base_amount_display_for(kind),
self._get_report_commission_currency_name_for(kind),
] if part)
if (getattr(fee, 'enable_linked_currency', False)
and getattr(fee, 'linked_price', None) is not None):
price = fee.linked_price
currency = getattr(fee, 'linked_currency', None)
unit = getattr(fee, 'linked_unit', None)
else:
currency = getattr(fee, 'currency', None)
unit = getattr(fee, 'unit', None)
price_text = self._format_report_number(price, digits='0.0000')
currency_text = self._report_record_name(currency)
unit_text = self._report_record_name(unit)
if currency_text and unit_text:
return '%s %s / %s' % (price_text, currency_text, unit_text)
return ' '.join(part for part in [
price_text, currency_text or unit_text,
] if part)
@property
def report_commission_tax_rate_line(self):
for tax in getattr(self, 'taxes', []) or []:
description = getattr(tax, 'description', None) or '0%'
return 'VAT %s RATE' % description
return 'VAT 0% RATE'
@property
def report_commission_address(self):
trade = self._get_report_commission_trade()

View File

@@ -5481,6 +5481,9 @@ class PurchaseTradeTestCase(ModuleTestCase):
get_current_quantity_converted=lambda state=0, unit=None: Decimal('397'))
fee = SimpleNamespace(
enable_linked_currency=False,
mode='perqt',
price=Decimal('7.85719'),
currency=SimpleNamespace(rec_name='USD'),
unit=unit,
sale_line=SimpleNamespace(sale=SimpleNamespace()),
line=None,
@@ -5497,6 +5500,10 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(
invoice.report_commission_weight_difference_display, '3.00')
self.assertEqual(invoice.report_commission_adjustment_unit_upper, 'MT')
self.assertEqual(
invoice.report_commission_adjustment_rate_line,
'7.8572 USD / MT')
self.assertEqual(invoice.report_commission_tax_rate_line, 'VAT 0% RATE')
def test_fee_delete_detects_generated_ordered_purchase(self):
'ordered fee deletion targets only its generated service purchase'