Skip to content

Commit

Permalink
[ADD][12.0] New module to add ability to modify e-invoice vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Jul 31, 2022
1 parent 2d010bd commit 91adc24
Show file tree
Hide file tree
Showing 26 changed files with 2,429 additions and 0 deletions.
86 changes: 86 additions & 0 deletions l10n_it_fatturapa_in_recompute/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
===========================================
Compute invoice taxes with e-invoice values
===========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_fatturapa_in_recompute
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-12-0/l10n-italy-12-0-l10n_it_fatturapa_in_recompute
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/122/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Con questo modulo è possibile utilizzare i valori della fattura elettronica importata con più decimali rispetto a quelli in uso ordinariamente senza perdita di dati, anche in caso di modifiche sulla fattura.

**Table of contents**

.. contents::
:local:

Configuration
=============

Nulla da configurare.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_fatturapa_in_recompute%0Aversion:%2012.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
~~~~~~~

* Sergio Corato

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

* Sergio Corato <https://github.com/sergiocorato>

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

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-sergiocorato| image:: https://github.com/sergiocorato.png?size=40px
:target: https://github.com/sergiocorato
:alt: sergiocorato

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergiocorato|

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_fatturapa_in_recompute>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions l10n_it_fatturapa_in_recompute/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
26 changes: 26 additions & 0 deletions l10n_it_fatturapa_in_recompute/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2022 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Compute invoice taxes with e-invoice values",
"summary": "This module enables recomputation of the invoice on e-invoices values "
"as if imported with custom precisions, these values will not be "
"mantained.",
"version": "12.0.1.0.0",
"development_status": "Alpha",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/l10n-italy/tree/12.0/"
"l10n_it_fatturapa_in_recompute",
"author": "Sergio Corato, Odoo Community Association (OCA)",
"maintainers": ["sergiocorato"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"l10n_it_fatturapa_in",
],
"data": [
"views/res_config_settings_view.xml",
"views/account_invoice_view.xml",
"wizard/wizard_import_fatturapa_view.xml",
],
}
62 changes: 62 additions & 0 deletions l10n_it_fatturapa_in_recompute/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_it_fatturapa_in_recompute
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-17 14:16+0000\n"
"PO-Revision-Date: 2022-07-17 14:16+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model.fields,field_description:l10n_it_fatturapa_in_recompute.field_account_invoice__compute_on_einvoice_values
msgid "Compute On Einvoice Values"
msgstr "Calcola Sui Valori della E-fattura"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model,name:l10n_it_fatturapa_in_recompute.model_einvoice_line
msgid "E-invoice line"
msgstr "Riga e-fattura"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model,name:l10n_it_fatturapa_in_recompute.model_wizard_import_fatturapa
msgid "Import E-bill"
msgstr "Importa e-fattura"

#. module: l10n_it_fatturapa_in_recompute
#: model_terms:ir.ui.view,arch_db:l10n_it_fatturapa_in_recompute.view_invoice_form_fatturapa_in
msgid "Import Precisions"
msgstr "Precisione Importazione"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model,name:l10n_it_fatturapa_in_recompute.model_account_invoice
msgid "Invoice"
msgstr "Fattura"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model,name:l10n_it_fatturapa_in_recompute.model_account_invoice_line
msgid "Invoice Line"
msgstr "Riga fattura"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model.fields,field_description:l10n_it_fatturapa_in_recompute.field_einvoice_line__qty
msgid "Quantity"
msgstr "Quantità"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model.fields,field_description:l10n_it_fatturapa_in_recompute.field_account_invoice_line__e_invoice_line_id
msgid "Related E-bill Line"
msgstr "Riga e-fattura collegata"

#. module: l10n_it_fatturapa_in_recompute
#: model:ir.model.fields,field_description:l10n_it_fatturapa_in_recompute.field_einvoice_line__unit_price
msgid "Unit Price"
msgstr "Prezzo unitario"

3 changes: 3 additions & 0 deletions l10n_it_fatturapa_in_recompute/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_config_settings
from . import einvoice_line
from . import account_invoice
110 changes: 110 additions & 0 deletions l10n_it_fatturapa_in_recompute/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Copyright 2022 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools.float_utils import float_round


class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"

e_invoice_line_id = fields.Many2one(
'einvoice.line', 'Related E-bill Line', readonly=True)

@api.one
@api.depends('price_unit', 'discount', 'invoice_line_tax_ids', 'quantity',
'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id',
'invoice_id.company_id', 'invoice_id.date_invoice', 'invoice_id.date')
def _compute_price(self):
super()._compute_price()
# Reset price subtotal to e-invoice value
if self.e_invoice_line_id and (
self._context.get('compute_on_einvoice_values', False)
or self.invoice_id.compute_on_einvoice_values
):
currency = self.invoice_id and self.invoice_id.currency_id or self.\
company_id.currency_id
price = self.e_invoice_line_id.unit_price * (
1 - (self.discount or 0.0) / 100.0)
subtotal_price = self.e_invoice_line_id.total_price
taxes = False
if self.invoice_line_tax_ids:
taxes = self.invoice_line_tax_ids.compute_all(
subtotal_price, currency,
1,
product=self.product_id,
partner=self.invoice_id.partner_id)
self.price_subtotal = price_subtotal_signed = taxes[
'total_excluded'] if taxes else self.e_invoice_line_id.qty * price
price_total = taxes['total_included'] if taxes else self.price_subtotal
taxes_amount = sum(
[x['amount'] for x in taxes['taxes']]) if taxes else \
price_total - self.price_subtotal
self.price_total = self.price_subtotal + taxes_amount
if self.invoice_id.currency_id and self.invoice_id.currency_id \
!= self.invoice_id.company_id.currency_id:
currency = self.invoice_id.currency_id
date = self.invoice_id._get_currency_rate_date()
price_subtotal_signed = currency._convert(
price_subtotal_signed,
self.invoice_id.company_id.currency_id,
self.company_id or self.env.user.company_id,
date or fields.Date.today())
sign = self.invoice_id.type in ['in_refund', 'out_refund'] and -1 or 1
self.price_subtotal_signed = price_subtotal_signed * sign


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

compute_on_einvoice_values = fields.Boolean()

@api.multi
def get_taxes_values(self):
taxes_grouped = super().get_taxes_values()
if self.compute_on_einvoice_values:
tax_grouped = {}
for line in self.invoice_line_ids:
if not line.account_id or line.display_type:
continue
if len(line.invoice_line_tax_ids) != 1:
continue
if line.e_invoice_line_id:
invoice_line_tax = line.invoice_line_tax_ids[0]
if invoice_line_tax not in tax_grouped:
tax_grouped.update({invoice_line_tax: {
'base': line.e_invoice_line_id.total_price,
'amount': 0}}
)
else:
tax_grouped[invoice_line_tax]['base'] += \
line.e_invoice_line_id.total_price
else:
invoice_line_tax = line.invoice_line_tax_ids[0]
if invoice_line_tax not in tax_grouped:
tax_grouped.update({invoice_line_tax: {
'base': line.price_subtotal,
'amount': 0}}
)
else:
tax_grouped[invoice_line_tax]['base'] += \
line.price_subtotal
# compute taxes by group
for key in taxes_grouped:
for tax_group in tax_grouped:
if taxes_grouped[key]['tax_id'] == tax_group.id:
taxes_recomputed = tax_group.compute_all(
tax_grouped[tax_group]['base'])
if any(t.get('price_include', False) for t
in taxes_recomputed['taxes']):
# no need to do this check for price included taxes
continue
amount_recomputed = sum(
[float_round(x['amount'],
precision_rounding=self.currency_id.rounding
) for x in taxes_recomputed['taxes']])
taxes_grouped[key]['amount'] = amount_recomputed
taxes_grouped[key]['base'] = sum(
[float_round(x['base'],
precision_rounding=self.currency_id.rounding
) for x in taxes_recomputed['taxes']])
return taxes_grouped
15 changes: 15 additions & 0 deletions l10n_it_fatturapa_in_recompute/models/einvoice_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class EInvoiceLine(models.Model):
_inherit = 'einvoice.line'

# set unlimited digits
unit_price = fields.Float(
digits=(19, 8)
)
qty = fields.Float(
digits=(20, 8)
)
23 changes: 23 additions & 0 deletions l10n_it_fatturapa_in_recompute/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2022 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ResCompany(models.Model):
_inherit = 'res.company'

compute_on_einvoice_values = fields.Boolean(
string="Compute imported invoices on e-invoices precision values",
help="Import vendor invoices preserving e-invoices datas.",
)


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

compute_on_einvoice_values = fields.Boolean(
related='company_id.compute_on_einvoice_values',
string="Compute imported invoices on e-invoices precision values",
help="Import vendor invoices preserving e-invoices datas.",
readonly=False,
)
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in_recompute/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nulla da configurare.
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in_recompute/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sergio Corato <https://github.com/sergiocorato>
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in_recompute/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Con questo modulo è possibile utilizzare i valori della fattura elettronica importata con più decimali rispetto a quelli in uso ordinariamente senza perdita di dati, anche in caso di modifiche sulla fattura.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 91adc24

Please sign in to comment.