Skip to content

Commit

Permalink
[14.0][MIG] Migration to 14.0 l10n_it_fatturapa_out_fd
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Oct 24, 2024
1 parent 0a9db37 commit 420f135
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 31 deletions.
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_fd/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "ITA - Fattura elettronica - Emissione - Sconto fisso",
"version": "12.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Localization/Italy",
"summary": "Emissione di fattura elettronica con sconto fisso",
"author": "TAKOBI, Odoo Community Association (OCA)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2020-01-01</Data>
<Numero>INV/2020/0001</Numero>
<Numero>INV/2020/01/0001</Numero>
<ImportoTotaleDocumento>1195.60</ImportoTotaleDocumento>
<Art73>SI</Art73>
</DatiGeneraliDocumento>
Expand Down
57 changes: 44 additions & 13 deletions l10n_it_fatturapa_out_fd/tests/test_xml_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,79 @@

import base64

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

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

class TestXMLGeneration (FatturaPACommon):

@tagged("post_install", "-at_install")
class TestXMLGeneration(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 = "[email protected]"
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 test_fixed_discount(self):
"""Generate an e-invoice for an invoice having a fixed discount.
Check that the ScontoMaggiorazione is present in the generated e-invoice.
"""
# Setup for fixing date and sequence of new invoices
date_invoice = '2020-01-01'
date_invoice = "2020-01-01"
self.set_sequences(1, date_invoice)

# Arrange: Create an invoice with one line costing 100
# and fixed discount of 20
invoice_form = Form(self.env['account.invoice'])
invoice_form = Form(
self.env["account.move"].with_context(default_move_type="out_invoice")
)
invoice_form.name = "INV/2020/01/0001"
invoice_form.partner_id = self.res_partner_fatturapa_2
invoice_form.date_invoice = date_invoice
invoice_form.invoice_date = date_invoice
with invoice_form.invoice_line_ids.new() as line:
line.name = "Test fixed discount"
line.price_unit = 1000
line.quantity = 1
line.discount_fixed = 20
line.invoice_line_tax_ids.clear()
line.invoice_line_tax_ids.add(self.tax_22)
line.account_id = self.a_sale
line.tax_ids.clear()
line.tax_ids.add(self.tax_22)
invoice = invoice_form.save()
invoice.action_invoice_open()
invoice._post()
# pre-condition: Check invoice totals
self.assertEqual(invoice.amount_untaxed, 980)
self.assertEqual(invoice.amount_tax, 215.6)
self.assertEqual(invoice.amount_total, 1195.6)
self.assertAlmostEqual(invoice.amount_total, 1195.6, 2)

# Act: Generate the e-invoice
action = self.run_wizard(invoice.id)
e_invoice = self.env[action['res_model']].browse(action['res_id'])
e_invoice = self.env[action["res_model"]].browse(action["res_id"])

# Assert: The E-invoice matches the XML in tests data
file_name = 'IT06363391001_00001.xml'
file_name = "IT06363391001_00001.xml"
self.set_e_invoice_file_id(e_invoice, file_name)
xml_content = base64.decodebytes(e_invoice.datas)
self.check_content(
xml_content,
file_name,
module_name='l10n_it_fatturapa_out_fd',
module_name="l10n_it_fatturapa_out_fd",
)
32 changes: 16 additions & 16 deletions l10n_it_fatturapa_out_fd/wizards/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Copyright 2023 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.addons.l10n_it_fatturapa.bindings.fatturapa import (
ScontoMaggiorazioneType,
TipoScontoMaggiorazioneType,
)
from odoo.tools import float_round
from odoo import api, models


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

def setScontoMaggiorazione(self, line):
res = super().setScontoMaggiorazione(line)
@staticmethod
def get_importo(line):
discount_fixed = line.discount_fixed
if discount_fixed:
res.append(
ScontoMaggiorazioneType(
Tipo=TipoScontoMaggiorazioneType.SC,
Importo='%.2f' % float_round(discount_fixed, 8),
)
)
return res
return discount_fixed
str_number = str(line.discount)
number = str_number[::-1].find(".")
if number <= 2:
return False
return line.price_unit * line.discount / 100

@api.model
def getTemplateValues(self, template_values):
template_values = super().getTemplateValues(template_values)
template_values.update({"get_importo": self.get_importo})
return template_values
6 changes: 6 additions & 0 deletions setup/l10n_it_fatturapa_out_fd/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 420f135

Please sign in to comment.