148 lines
4.9 KiB
Python
148 lines
4.9 KiB
Python
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'''<?xml version="1.0"?>
|
|
<html>
|
|
<body>
|
|
<table>
|
|
<tr><td><b>Buyer</b></td><td></td><td></td><td></td><td><b>Seller</b></td></tr>
|
|
<tr><td>{self.buyer}</td><td></td><td></td><td></td><td>{self.seller}</td></tr>
|
|
|
|
<tr><td><br/><br/>
|
|
<b>Invoice</b>: {self.nr}<br/>
|
|
<b>Receipt</b>: {self.receipt.store}{self.receipt.year}{self.receipt.month}{self.receipt.day}{self.receipt.till}{self.receipt.seq.zfill(6)}<br/>
|
|
<b>Date</b>: {self.receipt.year}-{self.receipt.month}-{self.receipt.day}<br/>
|
|
</td><td></td><td></td><td></td><td></td></tr>
|
|
|
|
<tr><td><br/><br/><br/></td><td></td><td></td><td></td><td></td></tr>
|
|
<tr><td><u>Item</u> </td><td><u>Description</u> </td><td> </td><td> </td><td><u>Price {self.currency()}</u></td></tr>
|
|
{allarticles}
|
|
|
|
<tr><td><br/><br/><b>Totals</b>:<br/>{self.totals}<br/></td><td></td><td></td><td></td><td></td></tr>
|
|
<tr><td><b>Taxes</b>:<br/>{taxestotal}<br/></td><td></td><td></td><td></td><td></td></tr>
|
|
<tr><td><b>Settled</b>:<br/>{alltenders}<br/></td><td></td><td></td><td></td><td></td></tr>
|
|
|
|
|
|
</table><br/>
|
|
</body>
|
|
</html>
|
|
'''
|
|
|
|
# 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}<br/>'''
|
|
|
|
class Tax(BaseTax):
|
|
spaces = 'tax'
|
|
|
|
def __str__(self):
|
|
return f"{self.translated_group()} {self.percentage}% of {self.taxableamount:.2f}: {self.amount:.2f} <br/>"
|
|
|
|
class TotalTax(Tax):
|
|
def __str__(self):
|
|
return f"{self.translated_group()} {self.percentage}% of {self.currency()} {self.taxableamount:.2f}: {self.amount:.2f} <br/>"
|
|
|
|
|
|
class Header(BaseHeader):
|
|
pass
|
|
|
|
|
|
class Totals(BaseTotals):
|
|
def __str__(self):
|
|
return f'''in {self.currency()}<br/>
|
|
Nett: {self.currency()} {self.netAmount:.2f}<br/>
|
|
Gross: {self.currency()} {self.grandAmount:.2f}<br/>'''
|
|
|
|
|
|
|
|
|
|
class Receipt(BaseReceipt):
|
|
pass
|
|
|
|
|
|
|
|
class Buyer(BaseBuyer):
|
|
def __str__(self):
|
|
return f'''{self.scheme}: {self.orgid}<br/>
|
|
{self.name}<br/>
|
|
{self.street1}, {self.street2}<br/>
|
|
{self.zip} {self.city}<br/>
|
|
{self.phone} {self.email}<br/>
|
|
{self.country}<br/>
|
|
VAT: {self.taxID}<br/>'''
|
|
|
|
class Delivery():
|
|
pass
|
|
|
|
class Seller(BaseSeller):
|
|
def __str__(self):
|
|
return f'''{self.scheme}: {self.orgid}, {self.legalid}<br/>
|
|
{self.name}<br/>
|
|
{self.street1}, {self.street2}<br/>
|
|
{self.zip} {self.city}<br/>
|
|
{self.phone} {self.email}<br/>
|
|
{self.country}<br/>
|
|
VAT: {self.taxID}<br/>'''
|
|
|
|
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}<br/>'''
|
|
|
|
class Article(BaseArticle):
|
|
def __str__(self):
|
|
discounts = ''
|
|
for d in self.discounts:
|
|
discounts += str(d)
|
|
|
|
return f'''
|
|
<tr><td>{self.sequence} {self.itemid} </td><td>{self.description} </td><td> </td><td>{'-' if self.returnflag else ''}{self.quantity} </td><td>{'-' if self.returnflag else ''}{self.netBasePrice():.2f}</td></tr>
|
|
<tr><td> </td><td>{self.upc} </td><td> </td><td> </td><td> </td></tr>
|
|
<tr><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
|
|
<tr><td> </td><td> </td><td> </td><td>{discounts} </td><td> </td></tr>
|
|
<tr><td> </td><td>Line total: </td><td> </td><td> </td><td>{'-' if self.returnflag else ''}{self.netSalesPrice():.2f} </td></tr>
|
|
<tr><td> </td><td> </td><td> </td><td>{self.tax.translated_group()} {self.tax.percentage}%: {self.tax.amount:.2f} <br/></td><td> </td></tr>
|
|
'''
|