Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD]adaugare modul fix discount in xml #183

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: "3.10"
Expand Down
66 changes: 66 additions & 0 deletions l10n_ro_edi_ubl_discount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
===================================
Romania - EDI UBL Line Discount Fix
===================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f2b76e933db6c7e3a497719e18919b77308f45e1829c739cb94728a5a6c8ad69
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github
:target: https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_edi_ubl_discount
:alt: dhongu/l10n-romania

|badge1| |badge2| |badge3|

- Fix xml values for invoices with line discounts
- Only one VAT value is accepted in invoice (for now)

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/dhongu/l10n-romania/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/dhongu/l10n-romania/issues/new?body=module:%20l10n_ro_edi_ubl_discount%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Terrabit

Contributors
~~~~~~~~~~~~

* `Terrabit <https://www.terrabit.ro>`_:

* Dan Stoica <[email protected]>


Do not contact contributors directly about support or help with technical issues.

Maintainers
~~~~~~~~~~~

This module is part of the `dhongu/l10n-romania <https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_edi_ubl_discount>`_ project on GitHub.

You are welcome to contribute.
4 changes: 4 additions & 0 deletions l10n_ro_edi_ubl_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2024-now Dan Stoica <danila(@)terrabit(.)ro
# See README.rst file on addons root folder for license details

from . import models
15 changes: 15 additions & 0 deletions l10n_ro_edi_ubl_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# © 2024-now Dan Stoica <danila(@)terrabit(.)ro
# See README.rst file on addons root folder for license details
{
"name": "Romania - EDI UBL Line Discount Fix",
"license": "AGPL-3",
"version": "15.0.0.0.1",
"author": "Terrabit," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-romania",
"category": "Tools",
"depends": [
"l10n_ro_account_edi_ubl",
],
"data": [],
"installable": True,
}
4 changes: 4 additions & 0 deletions l10n_ro_edi_ubl_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2024-now Dan Stoica <danila(@)terrabit(.)ro
# See README.rst file on addons root folder for license details

from . import account_edi_xml_cius_ro
99 changes: 99 additions & 0 deletions l10n_ro_edi_ubl_discount/models/account_edi_xml_cius_ro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# © 2024-now Dan Stoica <danila(@)terrabit(.)ro
# See README.rst file on addons root folder for license details

from odoo import models


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

def _export_invoice_vals(self, invoice):
vals_list = super()._export_invoice_vals(invoice)
with_discount = any(line.discount for line in invoice.invoice_line_ids)
if not with_discount:
return vals_list
# corectie discount
if invoice.move_type == "out_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"])
line_extension_amount += value
if vals_list["vals"]["legal_monetary_total_vals"]["line_extension_amount"] != line_extension_amount:
# aplicare corectie:
# total fara discount = suma linii fara discount
vals_list["vals"]["legal_monetary_total_vals"]["line_extension_amount"] = line_extension_amount

# total fara taxe = total fara discount - total discount
if vals_list["vals"]["legal_monetary_total_vals"]["allowance_total_amount"]:
vals_list["vals"]["legal_monetary_total_vals"]["tax_exclusive_amount"] = (
line_extension_amount - vals_list["vals"]["legal_monetary_total_vals"]["allowance_total_amount"]
)

# 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"])

# total cu taxe = total fara taxe + total taxe
vals_list["vals"]["legal_monetary_total_vals"]["tax_inclusive_amount"] = (
vals_list["vals"]["legal_monetary_total_vals"]["tax_exclusive_amount"] + taxes_total
)

# fix taxable
if len(vals_list["vals"]["tax_total_vals"]) == 1:
vals_list["vals"]["tax_total_vals"][0]["tax_subtotal_vals"][0]["taxable_amount"] = vals_list[
"vals"
]["legal_monetary_total_vals"]["tax_exclusive_amount"]
vals_list["taxes_vals"]["base_amount"] = vals_list["vals"]["legal_monetary_total_vals"][
"tax_exclusive_amount"
]
vals_list["taxes_vals"]["base_amount_currency"] = vals_list["vals"]["legal_monetary_total_vals"][
"tax_exclusive_amount"
]

# fix payable amount
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"]
)
elif invoice.move_type == "out_refund":
# aplicare corectie, deocamdata discount inclus in pret pana vedem de ce da erori ciudate:
line_extension_amount = 0.0
for line_vals in vals_list["vals"]["invoice_line_vals"]:
# includere discount in pret
if "allowance_charge_vals" in line_vals:
if len(line_vals["allowance_charge_vals"]) == 1:
charge_vals = line_vals["allowance_charge_vals"][0]
line_vals.pop("allowance_charge_vals")
line_vals["line_extension_amount"] = line_vals["line_extension_amount"] - charge_vals["amount"]
if line_vals["invoiced_quantity"]:
price_per_unit = line_vals["line_extension_amount"] / line_vals["invoiced_quantity"]
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"])
vals_list["vals"]["legal_monetary_total_vals"]["line_extension_amount"] = line_extension_amount

# aplicare restul de corectii pe totaluri
vals_list["vals"]["legal_monetary_total_vals"]["tax_exclusive_amount"] = line_extension_amount

# 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"])
vals_list["vals"]["legal_monetary_total_vals"]["tax_inclusive_amount"] = line_extension_amount + taxes_total

# fix taxable
if len(vals_list["vals"]["tax_total_vals"]) == 1:
vals_list["vals"]["tax_total_vals"][0]["tax_subtotal_vals"][0]["taxable_amount"] = line_extension_amount
vals_list["taxes_vals"]["base_amount"] = line_extension_amount
vals_list["taxes_vals"]["base_amount_currency"] = line_extension_amount

# fix payable amount
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"]
)

return vals_list
6 changes: 6 additions & 0 deletions l10n_ro_edi_ubl_discount/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* `Terrabit <https://www.terrabit.ro>`_:

* Dan Stoica <[email protected]>


Do not contact contributors directly about support or help with technical issues.
2 changes: 2 additions & 0 deletions l10n_ro_edi_ubl_discount/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix xml values for invoices with line discounts
- Only one VAT value is accepted in invoice (for now)
Loading
Loading