Skip to content

Commit c33d910

Browse files
SirAionTechChionne27
authored andcommitted
[MIG] l10n_it_fatturapa_out_triple_discount: Migration to 16.0
1 parent 39c246b commit c33d910

File tree

8 files changed

+156
-70
lines changed

8 files changed

+156
-70
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# Copyright 2019 Simone Rubino - Agile Business Group
2+
# Copyright 2023 Simone Rubino - Aion Tech
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34

45
{
56
"name": "ITA - Fattura elettronica - Integrazione sconto triplo",
67
"summary": "Modulo ponte tra emissione " "fatture elettroniche e sconto triplo",
7-
"version": "12.0.2.0.1",
8+
"version": "16.0.1.0.0",
89
"development_status": "Beta",
910
"category": "Hidden",
1011
"website": "https://github.com/OCA/l10n-italy"
11-
"/tree/12.0/l10n_it_fatturapa_out_triple_discount",
12+
"/tree/16.0/l10n_it_fatturapa_out_triple_discount",
1213
"author": "Agile Business Group, Odoo Community Association (OCA)",
1314
"license": "AGPL-3",
1415
"auto_install": True,
1516
"depends": [
1617
"l10n_it_fatturapa_out",
1718
"account_invoice_triple_discount",
1819
],
20+
"data": [
21+
"data/invoice_it_template.xml",
22+
],
1923
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
~ Copyright 2023 Simone Rubino - Aion Tech
4+
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5+
-->
6+
<odoo>
7+
<template
8+
id="account_invoice_it_dati_bollo"
9+
inherit_id="l10n_it_fatturapa_out.account_invoice_line_it_sconto_maggiorazione"
10+
>
11+
<ScontoMaggiorazione position="after">
12+
<t
13+
t-set="triple_ScontoMaggiorazione_values_list"
14+
t-value="get_triple_ScontoMaggiorazione_values_list(line)"
15+
/>
16+
<t
17+
t-foreach="triple_ScontoMaggiorazione_values_list"
18+
t-as="ScontoMaggiorazione_values"
19+
>
20+
<ScontoMaggiorazione t-translation="off">
21+
<Tipo t-out="ScontoMaggiorazione_values['Tipo']" />
22+
<Percentuale t-out="ScontoMaggiorazione_values['Percentuale']" />
23+
</ScontoMaggiorazione>
24+
</t>
25+
</ScontoMaggiorazione>
26+
</template>
27+
</odoo>
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Copyright 2019 Simone Rubino - Agile Business Group
21
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
32

4-
# tests disabled because unstable
5-
# TODO https://github.com/OCA/l10n-italy/issues/1588
6-
# from . import test_fatturapa_triple_discount
3+
from . import test_fatturapa_triple_discount

l10n_it_fatturapa_out_triple_discount/tests/data/IT06363391001_00001.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<TipoDocumento>TD01</TipoDocumento>
6767
<Divisa>EUR</Divisa>
6868
<Data>2016-01-07</Data>
69-
<Numero>INV/2016/0013</Numero>
69+
<Numero>INV/2016/00001</Numero>
7070
<ImportoTotaleDocumento>1.53</ImportoTotaleDocumento>
7171
<Art73>SI</Art73>
7272
</DatiGeneraliDocumento>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2023 Simone Rubino - Aion Tech
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon
5+
6+
7+
class Common(FatturaPACommon):
8+
def setUp(self):
9+
super().setUp()
10+
11+
# XXX - a company named "YourCompany" alread exists
12+
# we move it out of the way but we should do better here
13+
self.env.company.sudo().search([("name", "=", "YourCompany")]).write(
14+
{"name": "YourCompany_"}
15+
)
16+
17+
self.env.company.name = "YourCompany"
18+
self.env.company.vat = "IT06363391001"
19+
self.env.company.fatturapa_art73 = True
20+
self.env.company.partner_id.street = "Via Milano, 1"
21+
self.env.company.partner_id.city = "Roma"
22+
self.env.company.partner_id.state_id = self.env.ref("base.state_us_2").id
23+
self.env.company.partner_id.zip = "00100"
24+
self.env.company.partner_id.phone = "06543534343"
25+
self.env.company.email = "[email protected]"
26+
self.env.company.partner_id.country_id = self.env.ref("base.it").id
27+
self.env.company.fatturapa_fiscal_position_id = self.env.ref(
28+
"l10n_it_fatturapa.fatturapa_RF01"
29+
).id
30+
31+
self.env["decimal.precision"].search(
32+
[("name", "=", "Product Unit of Measure")]
33+
).digits = 3
34+
self.env["uom.uom"].search([("name", "=", "Units")]).name = "Unit(s)"
35+
36+
def getFile(self, filename, module_name=None):
37+
if module_name is None:
38+
module_name = "l10n_it_fatturapa_out_triple_discount"
39+
return super().getFile(filename, module_name=module_name)
Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,50 @@
11
# Copyright 2019 Simone Rubino - Agile Business Group
2+
# Copyright 2023 Simone Rubino - Aion Tech
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34

4-
import codecs
5+
import base64
56

6-
from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon
7+
from odoo.tests import Form, tagged
78

9+
from .fatturapa_common import Common
810

9-
class TestInvoiceTripleDiscount(FatturaPACommon):
10-
def setUp(self):
11-
super(TestInvoiceTripleDiscount, self).setUp()
1211

12+
@tagged("post_install", "-at_install")
13+
class TestEInvoiceTripleDiscount(Common):
1314
def test_xml_export_triple_discount(self):
14-
self.set_sequences(13, "2016-01-07")
15-
invoice = self.invoice_model.create(
16-
{
17-
"date_invoice": "2016-01-07",
18-
"partner_id": self.res_partner_fatturapa_0.id,
19-
"journal_id": self.sales_journal.id,
20-
"account_id": self.a_recv.id,
21-
"payment_term_id": self.account_payment_term.id,
22-
"user_id": self.user_demo.id,
23-
"type": "out_invoice",
24-
"currency_id": self.EUR.id,
25-
"invoice_line_ids": [
26-
(
27-
0,
28-
0,
29-
{
30-
"account_id": self.a_sale.id,
31-
"product_id": self.product_product_10.id,
32-
"name": "Mouse\nOptical",
33-
"quantity": 1,
34-
"uom_id": self.product_uom_unit.id,
35-
"price_unit": 10,
36-
"discount": 50,
37-
"discount2": 50,
38-
"discount3": 50,
39-
"invoice_line_tax_ids": [(6, 0, {self.tax_22.id})],
40-
},
41-
)
42-
],
43-
}
15+
partner = self.res_partner_fatturapa_0
16+
partner.vat = "IT00146089990"
17+
partner.fiscalcode = "00146089990"
18+
invoice = self.init_invoice(
19+
"out_invoice",
20+
invoice_date="2016-01-07",
21+
partner=partner,
22+
products=self.product_product_10,
23+
taxes=self.tax_22,
4424
)
45-
invoice.action_invoice_open()
25+
invoice_form = Form(invoice)
26+
invoice_form.invoice_payment_term_id = self.account_payment_term
27+
with invoice_form.invoice_line_ids.edit(0) as line:
28+
line.name = "Mouse\nOptical"
29+
line.price_unit = 10
30+
line.discount = 50
31+
line.discount2 = 50
32+
line.discount3 = 50
33+
invoice = invoice_form.save()
34+
invoice.action_post()
4635
res = self.run_wizard(invoice.id)
4736

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

5241
# XML doc to be validated
53-
xml_content = codecs.decode(attachment.datas, "base64")
54-
self.check_content(
55-
xml_content,
56-
"IT06363391001_00001.xml",
57-
module_name="l10n_it_fatturapa_out_triple_discount",
42+
xml_content = base64.decodebytes(attachment.datas)
43+
xml_tree = self.get_xml_tree_from_string(xml_content)
44+
expected_xml = self.getFile("IT06363391001_00001.xml")[1]
45+
expected_xml_content = base64.decodebytes(expected_xml)
46+
expected_xml_tree = self.get_xml_tree_from_string(expected_xml_content)
47+
self.assertXmlTreeEqual(
48+
xml_tree,
49+
expected_xml_tree,
5850
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
13
from . import wizard_export_fatturapa
Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,56 @@
11
# Copyright 2019 Simone Rubino - Agile Business Group
2+
# Copyright 2023 Simone Rubino - Aion Tech
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34

45
from odoo import models
5-
from odoo.tools.float_utils import float_round
6+
from odoo.tools import float_is_zero
67

7-
from odoo.addons.l10n_it_fatturapa.bindings.fatturapa import ScontoMaggiorazioneType
88

9-
10-
class WizardExportFatturapa(models.TransientModel):
9+
class WizardExportFatturaPA(models.TransientModel):
1110
_inherit = "wizard.export.fatturapa"
1211

13-
def setDettaglioLinea(self, line_no, line, body, price_precision, uom_precision):
14-
res = super(WizardExportFatturapa, self).setDettaglioLinea(
15-
line_no, line, body, price_precision, uom_precision
16-
)
17-
if line.discount2 or line.discount3:
18-
DettaglioLinea = body.DatiBeniServizi.DettaglioLinee[-1]
19-
if line.discount2:
20-
DettaglioLinea.ScontoMaggiorazione.append(
21-
ScontoMaggiorazioneType(
22-
Tipo="SC", Percentuale="%.2f" % float_round(line.discount2, 8)
23-
)
24-
)
25-
if line.discount3:
26-
DettaglioLinea.ScontoMaggiorazione.append(
27-
ScontoMaggiorazioneType(
28-
Tipo="SC", Percentuale="%.2f" % float_round(line.discount3, 8)
12+
def _get_efattura_class(self):
13+
efattura_class = super()._get_efattura_class()
14+
15+
class EInvoiceOutTripleDiscount(efattura_class):
16+
def get_template_values(self):
17+
template_values = super().get_template_values()
18+
19+
format_numbers_two = template_values["format_numbers_two"]
20+
21+
def get_triple_ScontoMaggiorazione_values_list(line):
22+
ScontoMaggiorazione_values_list = []
23+
24+
discount_fields = line._get_multiple_discount_field_names()
25+
26+
discounts_digits = line.fields_get(
27+
allfields=discount_fields,
28+
attributes=[
29+
"digits",
30+
],
2931
)
30-
)
31-
return res
32+
for discount_field in discount_fields:
33+
discount_perc = line[discount_field]
34+
all_digits, precision_digits = discounts_digits[discount_field][
35+
"digits"
36+
]
37+
is_discount_zero = float_is_zero(
38+
discount_perc,
39+
precision_digits=precision_digits,
40+
)
41+
if not is_discount_zero:
42+
ScontoMaggiorazione_values = {
43+
"Tipo": "SC",
44+
"Percentuale": format_numbers_two(discount_perc),
45+
}
46+
ScontoMaggiorazione_values_list.append(
47+
ScontoMaggiorazione_values
48+
)
49+
return ScontoMaggiorazione_values_list
50+
51+
template_values[
52+
"get_triple_ScontoMaggiorazione_values_list"
53+
] = get_triple_ScontoMaggiorazione_values_list
54+
return template_values
55+
56+
return EInvoiceOutTripleDiscount

0 commit comments

Comments
 (0)