Skip to content

Commit

Permalink
Merge pull request #189 from dhongu/15.0-ubl-discount
Browse files Browse the repository at this point in the history
[15.0][FIX] ubl discount: fix rounding
  • Loading branch information
danila12 authored May 31, 2024
2 parents 188686a + 2c41085 commit 393e689
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion l10n_ro_edi_ubl_discount/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Romania - EDI UBL Line Discount Fix
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f2b76e933db6c7e3a497719e18919b77308f45e1829c739cb94728a5a6c8ad69
!! source digest: sha256:225679b70ba8cc3877399446f6ac80d2662377d48d6dc5f2c45da4c90f4bbd77
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion l10n_ro_edi_ubl_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Romania - EDI UBL Line Discount Fix",
"license": "AGPL-3",
"version": "15.0.0.0.1",
"version": "15.0.0.0.2",
"author": "Terrabit," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-romania",
"category": "Tools",
Expand Down
23 changes: 19 additions & 4 deletions l10n_ro_edi_ubl_discount/models/account_edi_xml_cius_ro.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# © 2024-now Dan Stoica <danila(@)terrabit(.)ro
# See README.rst file on addons root folder for license details

import math

from odoo import models


def round_up(value, decimals=2):
"""
Rounds up from .5 like anaf . Ex. 17.555 will be rounded to 17.56
:param value: value to round
:param decimals: decimals to use
:return:
"""
expo = value * 10**decimals
if abs(expo) - abs(math.floor(expo)) < 0.5:
return math.floor(expo) / 10**decimals
return math.ceil(expo) / 10**decimals


class AccountEdiXmlCIUSRO(models.Model):
_inherit = "account.edi.xml.cius_ro"

Expand All @@ -17,7 +32,7 @@ def _export_invoice_vals(self, invoice):
# calcul amount fara discount din linii
line_extension_amount = 0.0
for line_vals in vals_list["vals"]["invoice_line_vals"]:
value = round(line_vals["line_extension_amount"], line_vals["currency_dp"])
value = round_up(line_vals["line_extension_amount"], line_vals["currency_dp"])
line_extension_amount += value
if vals_list["vals"]["legal_monetary_total_vals"]["line_extension_amount"] != line_extension_amount:
# aplicare corectie:
Expand All @@ -33,7 +48,7 @@ def _export_invoice_vals(self, invoice):
# calcul total taxe
taxes_total = 0.0
for tax in vals_list["vals"]["tax_total_vals"]:
taxes_total += round(tax["tax_amount"], tax["currency_dp"])
taxes_total += round_up(tax["tax_amount"], tax["currency_dp"])

# total cu taxe = total fara taxe + total taxe
vals_list["vals"]["legal_monetary_total_vals"]["tax_inclusive_amount"] = (
Expand Down Expand Up @@ -72,7 +87,7 @@ def _export_invoice_vals(self, invoice):
else:
price_per_unit = line_vals["price_vals"]["price_amount"]
line_vals["price_vals"]["price_amount"] = price_per_unit
line_extension_amount += round(line_vals["line_extension_amount"], line_vals["currency_dp"])
line_extension_amount += round_up(line_vals["line_extension_amount"], line_vals["currency_dp"])
vals_list["vals"]["legal_monetary_total_vals"]["line_extension_amount"] = line_extension_amount

# aplicare restul de corectii pe totaluri
Expand All @@ -81,7 +96,7 @@ def _export_invoice_vals(self, invoice):
# calcul total taxe
taxes_total = 0.0
for tax in vals_list["vals"]["tax_total_vals"]:
taxes_total += round(tax["tax_amount"], tax["currency_dp"])
taxes_total += round_up(tax["tax_amount"], tax["currency_dp"])
vals_list["vals"]["legal_monetary_total_vals"]["tax_inclusive_amount"] = line_extension_amount + taxes_total

# fix taxable
Expand Down
2 changes: 1 addition & 1 deletion l10n_ro_edi_ubl_discount/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ <h1 class="title">Romania - EDI UBL Line Discount Fix</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f2b76e933db6c7e3a497719e18919b77308f45e1829c739cb94728a5a6c8ad69
!! source digest: sha256:225679b70ba8cc3877399446f6ac80d2662377d48d6dc5f2c45da4c90f4bbd77
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_edi_ubl_discount"><img alt="dhongu/l10n-romania" src="https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github" /></a></p>
<blockquote>
Expand Down

0 comments on commit 393e689

Please sign in to comment.