-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14.0][MIG] Migration to 14.0 l10n_it_fatturapa_out_fd
- Loading branch information
1 parent
ec94f19
commit 9fafba4
Showing
8 changed files
with
82 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
32
l10n_it_fatturapa_out_fd/wizards/wizard_export_fatturapa.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
setup/l10n_it_fatturapa_out_fd/odoo/addons/l10n_it_fatturapa_out_fd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../l10n_it_fatturapa_out_fd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |