Price composition
This commit is contained in:
@@ -1646,7 +1646,7 @@
|
||||
<table:table-column table:style-name="Tableau3.B"/>
|
||||
<table:table-row>
|
||||
<table:table-cell table:style-name="Tableau3.A1" office:value-type="string">
|
||||
<text:p text:style-name="P24"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><if test="invoice.report_rate_lines"></text:placeholder></text:span></text:span></text:p>
|
||||
<text:p text:style-name="P24"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><if test="invoice.report_rate_rows"></text:placeholder></text:span></text:span></text:p>
|
||||
</table:table-cell>
|
||||
<table:table-cell table:style-name="Tableau3.A1" office:value-type="string">
|
||||
<text:p text:style-name="P9"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"/></text:span></text:p>
|
||||
@@ -1654,7 +1654,7 @@
|
||||
</table:table-row>
|
||||
<table:table-row>
|
||||
<table:table-cell table:style-name="Tableau3.A1" office:value-type="string">
|
||||
<text:p text:style-name="P11"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><for each="pc in invoice.report_rate_lines.splitlines()"></text:placeholder></text:span></text:span><text:soft-page-break/></text:p>
|
||||
<text:p text:style-name="P11"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><for each="pc in invoice.report_rate_rows"></text:placeholder></text:span></text:span><text:soft-page-break/></text:p>
|
||||
</table:table-cell>
|
||||
<table:table-cell table:style-name="Tableau3.A1" office:value-type="string">
|
||||
<text:p text:style-name="P9"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T9"/></text:span></text:p>
|
||||
@@ -1662,10 +1662,10 @@
|
||||
</table:table-row>
|
||||
<table:table-row>
|
||||
<table:table-cell table:style-name="Tableau3.A1" office:value-type="string">
|
||||
<text:p text:style-name="P12"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><pc></text:placeholder></text:span></text:span><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:s/>Value in </text:span></text:span><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><invoice.currency.name></text:placeholder></text:span></text:span></text:p>
|
||||
<text:p text:style-name="P12"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><pc['label']></text:placeholder></text:span></text:span></text:p>
|
||||
</table:table-cell>
|
||||
<table:table-cell table:style-name="Tableau3.A1" office:value-type="string">
|
||||
<text:p text:style-name="P13"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><''></text:placeholder></text:span></text:span></text:p>
|
||||
<text:p text:style-name="P13"><text:span text:style-name="Police_20_par_20_défaut"><text:span text:style-name="T8"><text:placeholder text:placeholder-type="text"><format_currency(pc['amount'], invoice.party.lang, invoice.currency) if pc['amount'] is not None else ''></text:placeholder></text:span></text:span></text:p>
|
||||
</table:table-cell>
|
||||
</table:table-row>
|
||||
<table:table-row>
|
||||
@@ -1710,4 +1710,4 @@
|
||||
<text:p text:style-name="Standard"><text:placeholder text:placeholder-type="text"></for></text:placeholder></text:p>
|
||||
</office:text>
|
||||
</office:body>
|
||||
</office:document>
|
||||
</office:document>
|
||||
|
||||
@@ -916,9 +916,22 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
@property
|
||||
def report_rate_lines(self):
|
||||
price_composition_lines = self._get_report_price_composition_lines()
|
||||
if price_composition_lines:
|
||||
return price_composition_lines
|
||||
rows = self.report_rate_rows
|
||||
if rows:
|
||||
return '\n'.join(row['label'] for row in rows)
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_rows(self):
|
||||
price_composition_rows = self._get_report_price_composition_rows()
|
||||
if price_composition_rows:
|
||||
return price_composition_rows
|
||||
return [{
|
||||
'label': line,
|
||||
'amount': None,
|
||||
} for line in self._get_report_rate_line_details()]
|
||||
|
||||
def _get_report_rate_line_details(self):
|
||||
details = []
|
||||
for line in self._get_report_invoice_lines():
|
||||
currency = getattr(line, 'report_rate_currency_upper', '') or ''
|
||||
@@ -941,19 +954,18 @@ class Invoice(metaclass=PoolMeta):
|
||||
] if part)
|
||||
if detail:
|
||||
details.append(detail)
|
||||
return '\n'.join(details)
|
||||
return details
|
||||
|
||||
def _get_report_price_composition_lines(self):
|
||||
def _get_report_price_composition_rows(self):
|
||||
sale = self._get_report_sale()
|
||||
if sale and getattr(sale, 'report_price_composition_lines', None):
|
||||
return sale.report_price_composition_lines
|
||||
details = []
|
||||
if sale and getattr(sale, 'report_price_composition_rows', None):
|
||||
return sale.report_price_composition_rows
|
||||
for line in self._get_report_invoice_lines():
|
||||
origin = getattr(line, 'origin', None)
|
||||
sale = getattr(origin, 'sale', None)
|
||||
if sale and getattr(sale, 'report_price_composition_lines', None):
|
||||
return sale.report_price_composition_lines
|
||||
return '\n'.join(details)
|
||||
if sale and getattr(sale, 'report_price_composition_rows', None):
|
||||
return sale.report_price_composition_rows
|
||||
return []
|
||||
|
||||
@property
|
||||
def report_positive_rate_lines(self):
|
||||
|
||||
@@ -848,34 +848,34 @@ class Sale(metaclass=PoolMeta):
|
||||
|
||||
@property
|
||||
def report_price_composition_lines(self):
|
||||
return '\n'.join(
|
||||
row['label'] for row in self.report_price_composition_rows)
|
||||
|
||||
@property
|
||||
def report_price_composition_rows(self):
|
||||
lines = []
|
||||
for line in self._get_report_lines():
|
||||
currency = self._get_report_display_currency(line)
|
||||
unit = self._get_report_display_unit(line)
|
||||
currency_name = (
|
||||
currency.rec_name.upper()
|
||||
if currency and currency.rec_name else '')
|
||||
unit_name = (
|
||||
unit.rec_name.upper()
|
||||
if unit and unit.rec_name else '')
|
||||
for composition in getattr(line, 'price_composition', []) or []:
|
||||
component = getattr(composition, 'component', '') or ''
|
||||
price = getattr(composition, 'price', None)
|
||||
if price in (None, ''):
|
||||
continue
|
||||
price_text = self._format_report_number(
|
||||
price, strip_trailing_zeros=False)
|
||||
detail = ' '.join(
|
||||
label = ' '.join(
|
||||
part for part in [
|
||||
component,
|
||||
'value in',
|
||||
currency_name,
|
||||
price_text,
|
||||
'PER' if unit_name else '',
|
||||
unit_name,
|
||||
] if part)
|
||||
if detail:
|
||||
lines.append(detail)
|
||||
return '\n'.join(lines)
|
||||
if label:
|
||||
lines.append({
|
||||
'label': label,
|
||||
'amount': Decimal(str(price or 0)),
|
||||
})
|
||||
return lines
|
||||
|
||||
@property
|
||||
def report_trade_blocks(self):
|
||||
|
||||
@@ -2612,25 +2612,38 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(
|
||||
sale.report_price_composition_lines.splitlines(),
|
||||
[
|
||||
'FOB EUR 2500.0000 PER MT',
|
||||
'FREIGHT EUR 25.0000 PER MT',
|
||||
'FOB value in EUR',
|
||||
'FREIGHT value in EUR',
|
||||
])
|
||||
self.assertEqual(
|
||||
sale.report_price_composition_rows,
|
||||
[
|
||||
{'label': 'FOB value in EUR', 'amount': Decimal('2500')},
|
||||
{'label': 'FREIGHT value in EUR', 'amount': Decimal('25')},
|
||||
])
|
||||
|
||||
def test_invoice_report_rate_lines_prefers_sale_price_composition(self):
|
||||
'invoice_melya rate block uses sale price composition when available'
|
||||
Invoice = Pool().get('account.invoice')
|
||||
sale = Mock(
|
||||
report_price_composition_lines=(
|
||||
'FOB EUR 2500.0000 PER MT\n'
|
||||
'FREIGHT EUR 25.0000 PER MT'))
|
||||
report_price_composition_rows=[
|
||||
{'label': 'FOB value in EUR', 'amount': Decimal('2500')},
|
||||
{'label': 'FREIGHT value in EUR', 'amount': Decimal('25')},
|
||||
])
|
||||
invoice = Invoice()
|
||||
invoice.sales = [sale]
|
||||
|
||||
self.assertEqual(
|
||||
invoice.report_rate_lines.splitlines(),
|
||||
[
|
||||
'FOB EUR 2500.0000 PER MT',
|
||||
'FREIGHT EUR 25.0000 PER MT',
|
||||
'FOB value in EUR',
|
||||
'FREIGHT value in EUR',
|
||||
])
|
||||
self.assertEqual(
|
||||
invoice.report_rate_rows,
|
||||
[
|
||||
{'label': 'FOB value in EUR', 'amount': Decimal('2500')},
|
||||
{'label': 'FREIGHT value in EUR', 'amount': Decimal('25')},
|
||||
])
|
||||
|
||||
def test_sale_report_converts_mixed_units_for_total_and_words(self):
|
||||
|
||||
Reference in New Issue
Block a user