Skip to content

Commit

Permalink
[MIG] l10n_it_fatturapa_out_triple_discount: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Nov 15, 2023
1 parent 98026cc commit a555602
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 70 deletions.
8 changes: 6 additions & 2 deletions l10n_it_fatturapa_out_triple_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# Copyright 2019 Simone Rubino - Agile Business Group
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "ITA - Fattura elettronica - Integrazione sconto triplo",
"summary": "Modulo ponte tra emissione " "fatture elettroniche e sconto triplo",
"version": "12.0.2.0.1",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Hidden",
"website": "https://github.com/OCA/l10n-italy"
"/tree/12.0/l10n_it_fatturapa_out_triple_discount",
"/tree/16.0/l10n_it_fatturapa_out_triple_discount",
"author": "Agile Business Group, Odoo Community Association (OCA)",
"license": "AGPL-3",
"auto_install": True,
"depends": [
"l10n_it_fatturapa_out",
"account_invoice_triple_discount",
],
"data": [
"data/invoice_it_template.xml",
],
}
27 changes: 27 additions & 0 deletions l10n_it_fatturapa_out_triple_discount/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2023 Simone Rubino - Aion Tech
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<template
id="account_invoice_it_dati_bollo"
inherit_id="l10n_it_fatturapa_out.account_invoice_line_it_sconto_maggiorazione"
>
<ScontoMaggiorazione position="after">
<t
t-set="triple_ScontoMaggiorazione_values_list"
t-value="get_triple_ScontoMaggiorazione_values_list(line)"
/>
<t
t-foreach="triple_ScontoMaggiorazione_values_list"
t-as="ScontoMaggiorazione_values"
>
<ScontoMaggiorazione t-translation="off">
<Tipo t-out="ScontoMaggiorazione_values['Tipo']" />
<Percentuale t-out="ScontoMaggiorazione_values['Percentuale']" />
</ScontoMaggiorazione>
</t>
</ScontoMaggiorazione>
</template>
</odoo>
5 changes: 1 addition & 4 deletions l10n_it_fatturapa_out_triple_discount/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Copyright 2019 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

# tests disabled because unstable
# TODO https://github.com/OCA/l10n-italy/issues/1588
# from . import test_fatturapa_triple_discount
from . import test_fatturapa_triple_discount
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2016-01-07</Data>
<Numero>INV/2016/0013</Numero>
<Numero>INV/2016/00001</Numero>
<ImportoTotaleDocumento>1.53</ImportoTotaleDocumento>
<Art73>SI</Art73>
</DatiGeneraliDocumento>
Expand Down
39 changes: 39 additions & 0 deletions l10n_it_fatturapa_out_triple_discount/tests/fatturapa_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon


class Common(FatturaPACommon):
def setUp(self):
super().setUp()

# XXX - a company named "YourCompany" alread exists
# we move it out of the way but we should do better here
self.env.company.sudo().search([("name", "=", "YourCompany")]).write(
{"name": "YourCompany_"}
)

self.env.company.name = "YourCompany"
self.env.company.vat = "IT06363391001"
self.env.company.fatturapa_art73 = True
self.env.company.partner_id.street = "Via Milano, 1"
self.env.company.partner_id.city = "Roma"
self.env.company.partner_id.state_id = self.env.ref("base.state_us_2").id
self.env.company.partner_id.zip = "00100"
self.env.company.partner_id.phone = "06543534343"
self.env.company.email = "info@yourcompany.example.com"
self.env.company.partner_id.country_id = self.env.ref("base.it").id
self.env.company.fatturapa_fiscal_position_id = self.env.ref(
"l10n_it_fatturapa.fatturapa_RF01"
).id

self.env["decimal.precision"].search(
[("name", "=", "Product Unit of Measure")]
).digits = 3
self.env["uom.uom"].search([("name", "=", "Units")]).name = "Unit(s)"

def getFile(self, filename, module_name=None):
if module_name is None:
module_name = "l10n_it_fatturapa_out_triple_discount"
return super().getFile(filename, module_name=module_name)
Original file line number Diff line number Diff line change
@@ -1,58 +1,50 @@
# Copyright 2019 Simone Rubino - Agile Business Group
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import codecs
import base64

from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon
from odoo.tests import Form, tagged

from .fatturapa_common import Common

class TestInvoiceTripleDiscount(FatturaPACommon):
def setUp(self):
super(TestInvoiceTripleDiscount, self).setUp()

@tagged("post_install", "-at_install")
class TestEInvoiceTripleDiscount(Common):
def test_xml_export_triple_discount(self):
self.set_sequences(13, "2016-01-07")
invoice = self.invoice_model.create(
{
"date_invoice": "2016-01-07",
"partner_id": self.res_partner_fatturapa_0.id,
"journal_id": self.sales_journal.id,
"account_id": self.a_recv.id,
"payment_term_id": self.account_payment_term.id,
"user_id": self.user_demo.id,
"type": "out_invoice",
"currency_id": self.EUR.id,
"invoice_line_ids": [
(
0,
0,
{
"account_id": self.a_sale.id,
"product_id": self.product_product_10.id,
"name": "Mouse\nOptical",
"quantity": 1,
"uom_id": self.product_uom_unit.id,
"price_unit": 10,
"discount": 50,
"discount2": 50,
"discount3": 50,
"invoice_line_tax_ids": [(6, 0, {self.tax_22.id})],
},
)
],
}
partner = self.res_partner_fatturapa_0
partner.vat = "IT00146089990"
partner.fiscalcode = "00146089990"
invoice = self.init_invoice(
"out_invoice",
invoice_date="2016-01-07",
partner=partner,
products=self.product_product_10,
taxes=self.tax_22,
)
invoice.action_invoice_open()
invoice_form = Form(invoice)
invoice_form.invoice_payment_term_id = self.account_payment_term
with invoice_form.invoice_line_ids.edit(0) as line:
line.name = "Mouse\nOptical"
line.price_unit = 10
line.discount = 50
line.discount2 = 50
line.discount3 = 50
invoice = invoice_form.save()
invoice.action_post()
res = self.run_wizard(invoice.id)

self.assertTrue(res)
attachment = self.attach_model.browse(res["res_id"])
self.set_e_invoice_file_id(attachment, "IT06363391001_00001.xml")

# XML doc to be validated
xml_content = codecs.decode(attachment.datas, "base64")
self.check_content(
xml_content,
"IT06363391001_00001.xml",
module_name="l10n_it_fatturapa_out_triple_discount",
xml_content = base64.decodebytes(attachment.datas)
xml_tree = self.get_xml_tree_from_string(xml_content)
expected_xml = self.getFile("IT06363391001_00001.xml")[1]
expected_xml_content = base64.decodebytes(expected_xml)
expected_xml_tree = self.get_xml_tree_from_string(expected_xml_content)
self.assertXmlTreeEqual(
xml_tree,
expected_xml_tree,
)
2 changes: 2 additions & 0 deletions l10n_it_fatturapa_out_triple_discount/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import wizard_export_fatturapa
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
# Copyright 2019 Simone Rubino - Agile Business Group
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
from odoo.tools.float_utils import float_round
from odoo.tools import float_is_zero

from odoo.addons.l10n_it_fatturapa.bindings.fatturapa import ScontoMaggiorazioneType


class WizardExportFatturapa(models.TransientModel):
class WizardExportFatturaPA(models.TransientModel):
_inherit = "wizard.export.fatturapa"

def setDettaglioLinea(self, line_no, line, body, price_precision, uom_precision):
res = super(WizardExportFatturapa, self).setDettaglioLinea(
line_no, line, body, price_precision, uom_precision
)
if line.discount2 or line.discount3:
DettaglioLinea = body.DatiBeniServizi.DettaglioLinee[-1]
if line.discount2:
DettaglioLinea.ScontoMaggiorazione.append(
ScontoMaggiorazioneType(
Tipo="SC", Percentuale="%.2f" % float_round(line.discount2, 8)
)
)
if line.discount3:
DettaglioLinea.ScontoMaggiorazione.append(
ScontoMaggiorazioneType(
Tipo="SC", Percentuale="%.2f" % float_round(line.discount3, 8)
def _get_efattura_class(self):
efattura_class = super()._get_efattura_class()

class EInvoiceOutTripleDiscount(efattura_class):
def get_template_values(self):
template_values = super().get_template_values()

format_numbers_two = template_values["format_numbers_two"]

def get_triple_ScontoMaggiorazione_values_list(line):
ScontoMaggiorazione_values_list = []

discount_fields = line._get_multiple_discount_field_names()

discounts_digits = line.fields_get(
allfields=discount_fields,
attributes=[
"digits",
],
)
)
return res
for discount_field in discount_fields:
discount_perc = line[discount_field]
all_digits, precision_digits = discounts_digits[discount_field][
"digits"
]
is_discount_zero = float_is_zero(
discount_perc,
precision_digits=precision_digits,
)
if not is_discount_zero:
ScontoMaggiorazione_values = {
"Tipo": "SC",
"Percentuale": format_numbers_two(discount_perc),
}
ScontoMaggiorazione_values_list.append(
ScontoMaggiorazione_values
)
return ScontoMaggiorazione_values_list

template_values[
"get_triple_ScontoMaggiorazione_values_list"
] = get_triple_ScontoMaggiorazione_values_list
return template_values

return EInvoiceOutTripleDiscount

0 comments on commit a555602

Please sign in to comment.