reports: BaseODS.currency_cell() sets default style.
It'll be rare we don't want this.
This commit is contained in:
parent
8333ed8876
commit
72f58d80d7
2 changed files with 15 additions and 0 deletions
|
@ -922,6 +922,8 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
|
||||||
return self.multiline_cell(lines, **attrs)
|
return self.multiline_cell(lines, **attrs)
|
||||||
|
|
||||||
def currency_cell(self, amount: data.Amount, **attrs: Any) -> odf.table.TableCell:
|
def currency_cell(self, amount: data.Amount, **attrs: Any) -> odf.table.TableCell:
|
||||||
|
if 'stylename' not in attrs:
|
||||||
|
attrs['stylename'] = self.currency_style(amount.currency)
|
||||||
number, currency = amount
|
number, currency = amount
|
||||||
cell = odf.table.TableCell(valuetype='currency', value=number, **attrs)
|
cell = odf.table.TableCell(valuetype='currency', value=number, **attrs)
|
||||||
cell.addElement(odf.text.P(text=babel.numbers.format_currency(
|
cell.addElement(odf.text.P(text=babel.numbers.format_currency(
|
||||||
|
|
|
@ -470,6 +470,19 @@ def test_ods_writer_currency_cell(ods_writer, cell_source, style_name):
|
||||||
)
|
)
|
||||||
assert get_text(cell) == expected
|
assert get_text(cell) == expected
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('currency', [
|
||||||
|
'EUR',
|
||||||
|
'CHF',
|
||||||
|
'GBP',
|
||||||
|
])
|
||||||
|
def test_ods_writer_currency_cell_default_style(ods_writer, currency):
|
||||||
|
amount = testutil.Amount(1000, currency)
|
||||||
|
expected_stylename = ods_writer.currency_style(currency).getAttribute('name')
|
||||||
|
cell = ods_writer.currency_cell(amount)
|
||||||
|
assert cell.getAttribute('valuetype') == 'currency'
|
||||||
|
assert cell.getAttribute('value') == '1000'
|
||||||
|
assert cell.getAttribute('stylename') == expected_stylename
|
||||||
|
|
||||||
@pytest.mark.parametrize('date,style_name', testutil.combine_values(
|
@pytest.mark.parametrize('date,style_name', testutil.combine_values(
|
||||||
[datetime.date(1980, 2, 5), datetime.date(2030, 10, 30)],
|
[datetime.date(1980, 2, 5), datetime.date(2030, 10, 30)],
|
||||||
XML_NAMES_LIST,
|
XML_NAMES_LIST,
|
||||||
|
|
Loading…
Reference in a new issue