take PricePerUnit from customer if not set in invoice position
This commit is contained in:
@@ -32,8 +32,7 @@ class HtmlTemplate:
|
||||
|
||||
@staticmethod
|
||||
def calculate_total(invoice_data):
|
||||
return sum(
|
||||
(pos['Quantity'] * (pos['PricePerUnit'] or invoice_data.PricePerUnit)) for pos in invoice_data.Positions)
|
||||
return sum((pos['Quantity'] * pos['PricePerUnit']) for pos in invoice_data.Positions)
|
||||
|
||||
@staticmethod
|
||||
def named_replace(value, **replacements):
|
||||
|
||||
20
src/main.py
20
src/main.py
@@ -86,13 +86,16 @@ def main():
|
||||
|
||||
print('Envelope data:')
|
||||
envelope_data = DataObject(**envelope)
|
||||
print(envelope_data.__dict__)
|
||||
print('<--->')
|
||||
print(yaml.dump(envelope_data))
|
||||
print('</--->')
|
||||
|
||||
print('Invoice data:')
|
||||
invoice_data = DataObject(**invoice)
|
||||
merge_envelope_data_into_invoice_data(invoice_data, envelope_data.Invoice)
|
||||
|
||||
selected_customer = next((x for x in envelope_data.Customers if x['CustomerId'] == invoice_data.CustomerId), None)
|
||||
selected_customer = next((x for x in envelope_data.Customers if x['CustomerId'] == invoice_data.CustomerId),
|
||||
None)
|
||||
merge_envelope_data_into_invoice_data(invoice_data, selected_customer)
|
||||
|
||||
if not hasattr(invoice_data, 'InvoiceDate'):
|
||||
@@ -103,8 +106,17 @@ def main():
|
||||
if not hasattr(invoice_data, 'Id'):
|
||||
invoice_data.Id = None
|
||||
|
||||
if not hasattr(invoice_data, 'Positions'):
|
||||
invoice_data.Positions = []
|
||||
|
||||
for position in invoice_data.Positions:
|
||||
if 'PricePerUnit' not in position or position['PricePerUnit'] is None:
|
||||
position['PricePerUnit'] = invoice_data.PricePerUnit
|
||||
|
||||
invoice_data.Id = invoice_data.Id or invoice_file.stem
|
||||
print(invoice_data.__dict__)
|
||||
print('<--->')
|
||||
print(yaml.dump(invoice_data))
|
||||
print('</--->')
|
||||
|
||||
except FileNotFoundError as e:
|
||||
print(f'Error: {e}')
|
||||
@@ -119,8 +131,6 @@ def main():
|
||||
generator = html_generator.HtmlTemplate(args.template)
|
||||
template = generator.prepare_template(invoice_data, envelope_data)
|
||||
|
||||
print(template)
|
||||
|
||||
try:
|
||||
print('Generating invoice...')
|
||||
invoice_pdf = Path(invoice_data.Id).with_suffix('.pdf')
|
||||
|
||||
@@ -15,7 +15,6 @@ Positions:
|
||||
|
||||
- Title: "Aschkriechen"
|
||||
SubTitle: "Leistungszeitraum: 10/2022"
|
||||
PricePerUnit: 77.88
|
||||
Quantity: 3
|
||||
|
||||
|
||||
|
||||
@@ -112,6 +112,10 @@
|
||||
border-top: .1pt solid black;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.head_data {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
@@ -136,7 +140,7 @@
|
||||
<body>
|
||||
<!-- Content for Static Frame 'header_frame' -->
|
||||
<div id="address_frame_content">
|
||||
<p class="underline">{{ envelope.AddressContent.AddressBoxSender }}</p>
|
||||
<p class="underline small center">{{ envelope.AddressContent.AddressBoxSender }}</p>
|
||||
<address>
|
||||
{{ invoice.AddressField | markdown_to_html }}
|
||||
</address>
|
||||
@@ -188,20 +192,17 @@
|
||||
{% endfor %}
|
||||
<tr class="summe">
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="rechts">Nettosumme:</td>
|
||||
<td colspan="2" class="rechts">Nettosumme:</td>
|
||||
<td class="rechts">{{ format_float(calculate_total(invoice)) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="rechts">USt. ({{ format_float(invoice.Vat) }}%):</td>
|
||||
<td colspan="2" class="rechts">USt. ({{ format_float(invoice.Vat) }}%):</td>
|
||||
<td class="rechts">{{ format_float(calculate_total(invoice) * ((invoice.Vat / 100))) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="rechts bold overline">Gesamt Summe:</td>
|
||||
<td colspan="2" class="rechts bold overline">Gesamt Summe:</td>
|
||||
<td class="rechts bold overline">{{ format_float(calculate_total(invoice) * ((invoice.Vat / 100)+1)) }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user