Skip to content

Commit

Permalink
recalculare totaluri din linii
Browse files Browse the repository at this point in the history
  • Loading branch information
danila12 committed Jun 26, 2024
1 parent 3a4d8ec commit 511edb8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 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:fc81337159dbab847d5981a795124859d04d170e908285173dae175485139826
!! source digest: sha256:f7546206dd729a5ce4a57d5f726ec2f73181438b5f20580f1e7e521b18fcc15e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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.5",
"version": "15.0.0.0.6",
"author": "Terrabit," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-romania",
"category": "Tools",
Expand Down
52 changes: 35 additions & 17 deletions l10n_ro_edi_ubl_discount/models/account_edi_xml_cius_ro.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# 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

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):
Expand All @@ -25,6 +28,27 @@ def _export_invoice_vals(self, invoice):
with_discount = any(line.discount for line in invoice.invoice_line_ids)
if not with_discount:
return vals_list
# re-adunare linii (LineExtensionAmount)
sum_lines = 0.0
for line in vals_list["vals"]["invoice_line_vals"]:
discount = 0.0
value_without_discount = line["price_vals"]["price_amount"] * line["invoiced_quantity"]
for discount_val in line["allowance_charge_vals"]:
discount += discount_val["amount"]
line["line_extension_amount"] = round_up(value_without_discount - discount, 2)
sum_lines += line["line_extension_amount"]
if vals_list["vals"]["legal_monetary_total_vals"]["tax_exclusive_amount"] != sum_lines:
vals_list["vals"]["legal_monetary_total_vals"]["tax_exclusive_amount"] = sum_lines
taxes = 0.00
for tax_line in vals_list["vals"]["tax_total_vals"]:
taxes += tax_line["tax_amount"]
vals_list["vals"]["legal_monetary_total_vals"]["tax_inclusive_amount"] = (
vals_list["vals"]["legal_monetary_total_vals"]["tax_exclusive_amount"] + taxes
)
vals_list["vals"]["legal_monetary_total_vals"]["payable_amount"] = (
vals_list["vals"]["legal_monetary_total_vals"]["tax_inclusive_amount"]
- vals_list["vals"]["legal_monetary_total_vals"]["prepaid_amount"]
)
# corectie discount
if "allowance_charge_vals" in vals_list["vals"]:
vals_list["vals"].pop("allowance_charge_vals")
Expand All @@ -33,12 +57,6 @@ def _export_invoice_vals(self, invoice):
]["tax_exclusive_amount"]
if "allowance_total_amount" in vals_list["vals"]["legal_monetary_total_vals"]:
vals_list["vals"]["legal_monetary_total_vals"].pop("allowance_total_amount")
for line in vals_list["vals"]["invoice_line_vals"]:
discount = 0.0
value_without_discount = line["price_vals"]["price_amount"] * line["invoiced_quantity"]
for discount_val in line["allowance_charge_vals"]:
discount += discount_val["amount"]
line["line_extension_amount"] = value_without_discount - discount
return vals_list

# if invoice.move_type == "out_invoice":
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:fc81337159dbab847d5981a795124859d04d170e908285173dae175485139826
!! source digest: sha256:f7546206dd729a5ce4a57d5f726ec2f73181438b5f20580f1e7e521b18fcc15e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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 511edb8

Please sign in to comment.