from invoice_base import * import xml.etree.ElementTree as ET class Invoice(BaseInvoice): def filter_elements_by_country(self, xml_string): root = ET.fromstring(xml_string) for parent in root.iter(): for child in list(parent): include = child.attrib.get("include") # No include attribute → keep element as-is if include is None: continue values = [v.strip() for v in include.split(",")] print(f" {self.country()} {values}") # Remove element if include does not contains the country if self.country() not in values: parent.remove(child) else: # Otherwise, remove only the include attribute del child.attrib["include"] return ET.tostring(root, encoding="unicode") def __str__(self): taxestotal = '' for x in self.taxes: taxestotal += str(x) allarticles = '' for a in self.articles: allarticles += str(a) alltenders = '' for t in self.tenders: alltenders += str(t) xml = f''' {allarticles}
BuyerSeller
{self.buyer}{self.seller}


Invoice: {self.nr}
Receipt: {self.receipt.store}{self.receipt.year}{self.receipt.month}{self.receipt.day}{self.receipt.till}{self.receipt.seq.zfill(6)}
Date: {self.receipt.year}-{self.receipt.month}-{self.receipt.day}



Item Description Price {self.currency()}


Totals:
{self.totals}
Taxes:
{taxestotal}
Settled:
{alltenders}

''' # return self.filter_elements_by_country(xml) return xml class Discount(BaseDiscount): def __str__(self): return f'''{self.promotionID}: {self.currency()} {self.net_amount():.2f}
''' class Tax(BaseTax): spaces = 'tax' def __str__(self): return f"{self.translated_group()} {self.percentage}% of {self.taxableamount:.2f}: {self.amount:.2f}
" class TotalTax(Tax): def __str__(self): return f"{self.translated_group()} {self.percentage}% of {self.currency()} {self.taxableamount:.2f}: {self.amount:.2f}
" class Header(BaseHeader): pass class Totals(BaseTotals): def __str__(self): return f'''in {self.currency()}
Nett: {self.currency()} {self.netAmount:.2f}
Gross: {self.currency()} {self.grandAmount:.2f}
''' class Receipt(BaseReceipt): pass class Buyer(BaseBuyer): def __str__(self): return f'''{self.scheme}: {self.orgid}
{self.name}
{self.street1}, {self.street2}
{self.zip} {self.city}
{self.phone} {self.email}
{self.country}
VAT: {self.taxID}
''' class Delivery(): pass class Seller(BaseSeller): def __str__(self): return f'''{self.scheme}: {self.orgid}, {self.legalid}
{self.name}
{self.street1}, {self.street2}
{self.zip} {self.city}
{self.phone} {self.email}
{self.country}
VAT: {self.taxID}
''' class Tender(BaseTender): def translate(self, code): return '54' # credit card def __str__(self): return f'''{self.description} {self.translated_type()} {self.my_currency} {self.amount}
''' class Article(BaseArticle): def __str__(self): discounts = '' for d in self.discounts: discounts += str(d) return f''' {self.sequence} {self.itemid} {self.description} {'-' if self.returnflag else ''}{self.quantity} {'-' if self.returnflag else ''}{self.netBasePrice():.2f} {self.upc} {discounts} Line total: {'-' if self.returnflag else ''}{self.netSalesPrice():.2f} {self.tax.translated_group()} {self.tax.percentage}%: {self.tax.amount:.2f}
'''