Skip to content

Commit

Permalink
[FIX] datev_export_xml: Negate values for refunds (invoice corrections)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkantelberg committed Aug 9, 2023
1 parent c0ebb82 commit dacb898
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions datev_export_xml/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class AccountMove(models.Model):
"If you need to export the invoices again, set this field to False.",
)

def datev_format_total(self, value):
def datev_format_total(self, value, prec=2):
self.ensure_one()
return f"-{value:.2f}" if self.move_type.endswith("_refund") else f"{value:.2f}"
return f"-{value:.{prec}f}" if self.move_type.endswith("_refund") else f"{value:.{prec}f}"

def datev_sanitize(self, value, length=36):
return re.sub(r"[^a-zA-Z0-9$%&\*\+\-/]", "-", value)[:length]
Expand Down
14 changes: 7 additions & 7 deletions datev_export_xml/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<template id="export_invoice_line_item">
<price_line_amount
t-att-currency="line.currency_id.name"
t-att-gross_price_line_amount="'%.02f' % prices['total_included']"
t-att-net_price_line_amount="'%.02f' % prices['total_excluded']"
t-att-tax="'%.02f' % line.tax_ids.amount"
t-att-gross_price_line_amount="doc.datev_format_total(prices['total_included'])"
t-att-net_price_line_amount="doc.datev_format_total(prices['total_excluded'])"
t-att-tax="doc.datev_format_total(line.tax_ids.amount)"
/>

<accounting_info
Expand All @@ -46,15 +46,15 @@
t-call="datev_export_xml.export_invoice_line_item"
t-att-product_id="line.product_id.default_code"
t-att-description_short="(line.name or line.product_id.name)[:40]"
t-att-net_product_price="'%.03f' % prices['total_excluded']"
t-att-net_product_price="doc.datev_format_total(prices['total_excluded'], 3)"
t-att-order_unit="line.product_uom_id.name"
t-att-quantity="'%.02f' % line.quantity"
/>
<invoice_item_list
t-else=""
t-call="datev_export_xml.export_invoice_line_item"
t-att-description_short="line.name or ''"
t-att-net_product_price="'%.03f' % prices['total_excluded']"
t-att-net_product_price="doc.datev_format_total(prices['total_excluded'], 3)"
t-att-quantity="'%.02f' % line.quantity"
/>
</template>
Expand Down Expand Up @@ -126,8 +126,8 @@
t-if="line.tax_line_id"
t-att-tax="'%.02f' % line.tax_line_id.amount"
t-att-currency="line.currency_id.name"
t-att-net_price_line_amount="'%.02f' % line.tax_base_amount"
t-att-tax_amount="'%.02f' % (line.price_total or abs(line.balance))"
t-att-net_price_line_amount="doc.datev_format_total(line.tax_base_amount)"
t-att-tax_amount="doc.datev_format_total(line.price_total or abs(line.balance))"
/>
</t>
<tax_line
Expand Down

0 comments on commit dacb898

Please sign in to comment.