Skip to content

Commit 0d65ed0

Browse files
committed
feat: add support for OSS/IOSS
1 parent 6043268 commit 0d65ed0

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/ksef/models/invoice_rows.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Models for individual invoice rows/positions."""
22

3-
from typing import Literal, Sequence
3+
from decimal import Decimal
4+
from typing import Literal, Optional, Sequence
45

56
from pydantic import BaseModel
67

@@ -37,12 +38,16 @@
3738
"np II",
3839
]
3940

41+
# Set of valid P_12 integer rates for quick lookup
42+
VALID_P12_RATES = {23, 22, 8, 7, 5, 4, 3}
43+
4044

4145
class InvoiceRow(BaseModel):
4246
"""Single individual invoice position."""
4347

4448
name: str # P_7, nazwa (rodzaj) towaru lub usługi
45-
tax: TaxRate # P_12, tax rate
49+
tax: Optional[TaxRate] = None # P_12, standard tax rate
50+
tax_oss: Optional[Decimal] = None # P_12_XII, OSS/IOSS procedure tax rate (arbitrary %)
4651

4752

4853
class InvoiceRows(BaseModel):

src/ksef/xml_converters.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,16 @@ def _build_invoice_data(root: ElementTree.Element, invoice: Invoice) -> None:
195195
invoice_data_row = ElementTree.SubElement(invoice_data, "FaWiersz")
196196
invoice_data_row_number = ElementTree.SubElement(invoice_data_row, "NrWierszaFa")
197197
invoice_data_row_name = ElementTree.SubElement(invoice_data_row, "P_7")
198-
invoice_data_row_tax_rate = ElementTree.SubElement(invoice_data_row, "P_12")
199198

200199
invoice_data_row_number.text = str(index)
201200
invoice_data_row_name.text = row.name
202-
invoice_data_row_tax_rate.text = str(row.tax)
201+
202+
if row.tax_oss is not None:
203+
invoice_data_row_tax_oss = ElementTree.SubElement(invoice_data_row, "P_12_XII")
204+
invoice_data_row_tax_oss.text = str(row.tax_oss)
205+
elif row.tax is not None:
206+
invoice_data_row_tax_rate = ElementTree.SubElement(invoice_data_row, "P_12")
207+
invoice_data_row_tax_rate.text = str(row.tax)
203208

204209

205210
def convert_invoice_to_xml(invoice: Invoice, invoicing_software_name: str = "python-ksef") -> bytes:

0 commit comments

Comments
 (0)