Skip to content

Commit aa8db53

Browse files
committed
[IMP] l10n_it_fatturapa_in: Create intermediary contact by VAT
This commit contains refactorings and module improvements to include intermediary search depending by vat in e-invoice [IMP] l10n_it_fatturapa_in: better partner search [IMP] l10n_it_fatturapa_in: commercial partner search improvement
1 parent 54792f5 commit aa8db53

File tree

10 files changed

+383
-144
lines changed

10 files changed

+383
-144
lines changed

l10n_it_fatturapa_in/README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
=====================================
62
ITA - Fattura elettronica - Ricezione
73
=====================================
@@ -17,7 +13,7 @@ ITA - Fattura elettronica - Ricezione
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github

l10n_it_fatturapa_in/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"views/partner_view.xml",
2626
"wizard/wizard_import_fatturapa_view.xml",
2727
"wizard/link_to_existing_invoice.xml",
28+
"wizard/wizard_check_intermediary_vat.xml",
2829
"views/company_view.xml",
2930
"security/ir.model.access.csv",
3031
"security/rules.xml",

l10n_it_fatturapa_in/security/ir.model.access.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ access_einvoice_line_other_data,access_einvoice_line_other_data,model_einvoice_l
66
access_wizard_import_fatturapa,access_wizard_import_fatturapa,model_wizard_import_fatturapa,account.group_account_invoice,1,1,1,1
77
access_wizard_link_to_invoice,access_wizard_link_to_invoice,model_wizard_link_to_invoice,account.group_account_invoice,1,1,1,1
88
access_wizard_link_to_invoice_line,access_wizard_link_to_invoice_line,model_wizard_link_to_invoice_line,account.group_account_invoice,1,1,1,1
9+
access_wizard_check_intermediary_all,access_wizard_check_intermediary_all,model_wizard_check_intermediary,account.group_account_invoice,1,1,1,1
10+
access_wizard_check_intermediary_all_line,access_wizard_check_intermediary_all_line,model_wizard_check_intermediary_line,account.group_account_invoice,1,1,1,1
911
fatturapa_in_decimal_precision_access_manager,fatturapa_in_decimal_precision_access_manager,base.model_decimal_precision,account.group_account_manager,1,1,0,0
1012
fatturapa_in_decimal_precision_access_billing,fatturapa_in_decimal_precision_access_billing,base.model_decimal_precision,account.group_account_invoice,1,1,0,0
1113
fatturapa_in_mail_followers_access_manager,fatturapa_in_mail_followers_access_manager,mail.model_mail_followers,account.group_account_manager,1,1,0,0

l10n_it_fatturapa_in/static/description/index.html

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>ITA - Fattura elettronica - Ricezione</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="ita-fattura-elettronica-ricezione">
364+
<h1 class="title">ITA - Fattura elettronica - Ricezione</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="ita-fattura-elettronica-ricezione">
370-
<h1>ITA - Fattura elettronica - Ricezione</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:7c451f2c248991f81d741164a1b8f6f04f708e655f32ae61d9e148284381aed0
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_fatturapa_in"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_fatturapa_in"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_fatturapa_in"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_fatturapa_in"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p><strong>Italiano</strong></p>
379374
<p>Questo modulo consente di importare i file XML della fattura elettronica versione 1.2</p>
380375
<p><a class="reference external" href="http://www.fatturapa.gov.it/export/fatturazione/it/normativa/f-2.htm">http://www.fatturapa.gov.it/export/fatturazione/it/normativa/f-2.htm</a></p>
@@ -402,7 +397,7 @@ <h1>ITA - Fattura elettronica - Ricezione</h1>
402397
</ul>
403398
</div>
404399
<div class="section" id="installation">
405-
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
400+
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
406401
<p><strong>Italiano</strong></p>
407402
<p>Questo modulo richiede asn1crypto</p>
408403
<p><a class="reference external" href="https://github.com/wbond/asn1crypto">https://github.com/wbond/asn1crypto</a></p>
@@ -411,7 +406,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
411406
<p><a class="reference external" href="https://github.com/wbond/asn1crypto">https://github.com/wbond/asn1crypto</a></p>
412407
</div>
413408
<div class="section" id="configuration">
414-
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
409+
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
415410
<p><strong>Italiano</strong></p>
416411
<p>Consultare anche il file README del modulo l10n_it_fatturapa.</p>
417412
<p>Per ciascun fornitore è possibile impostare il “Livello dettaglio e-fatture”:</p>
@@ -440,7 +435,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
440435
<p>If supplier specifies a known code in XML, the system will use it to retrieve the correct product to be used in bill line, setting the related tax and account.</p>
441436
</div>
442437
<div class="section" id="usage">
443-
<h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2>
438+
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
444439
<p><strong>Italiano</strong></p>
445440
<blockquote>
446441
<ul class="simple">
@@ -463,7 +458,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2>
463458
<p>In the incoming electronic bill files list you will see, by default, files to be registered. These are files not yet linked to one or more bills.</p>
464459
</div>
465460
<div class="section" id="known-issues-roadmap">
466-
<h2><a class="toc-backref" href="#toc-entry-4">Known issues / Roadmap</a></h2>
461+
<h1><a class="toc-backref" href="#toc-entry-4">Known issues / Roadmap</a></h1>
467462
<p>Il modulo contiene un cambiamento alla firma di un metodo in <tt class="docutils literal">models/account.py</tt>
468463
il quale cambia da</p>
469464
<p><tt class="docutils literal">compute_xml_amount_untaxed(self, DatiRiepilogo)</tt></p>
@@ -479,24 +474,24 @@ <h2><a class="toc-backref" href="#toc-entry-4">Known issues / Roadmap</a></h2>
479474
dovranno adeguare la chiamata al metodo stesso preoccupandosi di utilizzare come primo parametro l’oggetto <tt class="docutils literal">FatturaElettronicaBody</tt>.</p>
480475
</div>
481476
<div class="section" id="bug-tracker">
482-
<h2><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h2>
477+
<h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
483478
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/l10n-italy/issues">GitHub Issues</a>.
484479
In case of trouble, please check there if your issue has already been reported.
485480
If you spotted it first, help us to smash it by providing a detailed and welcomed
486481
<a class="reference external" href="https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_fatturapa_in%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
487482
<p>Do not contact contributors directly about support or help with technical issues.</p>
488483
</div>
489484
<div class="section" id="credits">
490-
<h2><a class="toc-backref" href="#toc-entry-6">Credits</a></h2>
485+
<h1><a class="toc-backref" href="#toc-entry-6">Credits</a></h1>
491486
<div class="section" id="authors">
492-
<h3><a class="toc-backref" href="#toc-entry-7">Authors</a></h3>
487+
<h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
493488
<ul class="simple">
494489
<li>Agile Business Group</li>
495490
<li>Innoviu</li>
496491
</ul>
497492
</div>
498493
<div class="section" id="contributors">
499-
<h3><a class="toc-backref" href="#toc-entry-8">Contributors</a></h3>
494+
<h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
500495
<ul class="simple">
501496
<li>Lorenzo Battistini &lt;<a class="reference external" href="mailto:lorenzo.battistini&#64;agilebg.com">lorenzo.battistini&#64;agilebg.com</a>&gt;</li>
502497
<li>Roberto Onnis</li>
@@ -513,7 +508,7 @@ <h3><a class="toc-backref" href="#toc-entry-8">Contributors</a></h3>
513508
</ul>
514509
</div>
515510
<div class="section" id="maintainers">
516-
<h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3>
511+
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
517512
<p>This module is maintained by the OCA.</p>
518513
<a class="reference external image-reference" href="https://odoo-community.org">
519514
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -526,6 +521,5 @@ <h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3>
526521
</div>
527522
</div>
528523
</div>
529-
</div>
530524
</body>
531525
</html>

l10n_it_fatturapa_in/tests/fatturapa_common.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,13 @@ def create_attachment(self, name, file_name, module_name=None):
277277
return attach
278278

279279
def run_wizard(
280-
self, name, file_name, mode="import", wiz_values=None, module_name=None
280+
self,
281+
name,
282+
file_name,
283+
mode="import",
284+
wiz_values=None,
285+
module_name=None,
286+
wizard_check_action="action_confirm",
281287
):
282288
if module_name is None:
283289
module_name = "l10n_it_fatturapa_in"
@@ -294,7 +300,22 @@ def run_wizard(
294300
for wiz_field, wiz_value in wiz_values.items():
295301
setattr(wizard_form, wiz_field, wiz_value)
296302
wizard = wizard_form.save()
297-
return wizard.importFatturaPA()
303+
res = wizard.importFatturaPA()
304+
305+
# NEW WIZARD INTERMEDIARY CREATION BASED ON VAT CHECK
306+
# Case where the confirmation wizard is shown
307+
if res.get("res_model") == "wizard.check.intermediary":
308+
309+
wizard = self.env["wizard.check.intermediary"].browse(res["res_id"])
310+
311+
if wizard_check_action == "action_confirm":
312+
res = wizard.action_confirm()
313+
else:
314+
res = wizard.action_cancel()
315+
return res
316+
else:
317+
return res
318+
298319
if mode == "link":
299320
wizard_form = Form(
300321
self.wizard_link_model.with_context(

l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,33 @@ def test_05_xml_import(self):
174174
self.assertEqual(invoice.amount_tax, 0)
175175
self.assertEqual(invoice.amount_total, 9)
176176

177+
def test_xml_import_with_action_cancel(self):
178+
partner_record = self.env["res.partner"].search([("name", "=", "MARIO ROSSI")])
179+
180+
if partner_record:
181+
partner_record.unlink()
182+
183+
res = self.run_wizard(
184+
"test5.2",
185+
"IT05979361218_003.xml",
186+
wizard_check_action="action_cancel",
187+
)
188+
invoice_id = res.get("domain")[0][2][0]
189+
invoice = self.invoice_model.browse(invoice_id)
190+
self.assertEqual(invoice.ref, "FT/2015/0008")
191+
self.assertEqual(invoice.payment_reference, "FT/2015/0008")
192+
self.assertEqual(invoice.sender, "TZ")
193+
self.assertFalse(invoice.intermediary)
194+
self.assertEqual(
195+
invoice.e_invoice_line_ids[0].discount_rise_price_ids[0].name, "SC"
196+
)
197+
self.assertEqual(
198+
invoice.e_invoice_line_ids[0].discount_rise_price_ids[0].percentage, 10
199+
)
200+
self.assertEqual(invoice.amount_untaxed, 9)
201+
self.assertEqual(invoice.amount_tax, 0)
202+
self.assertEqual(invoice.amount_total, 9)
203+
177204
def test_06_import_except(self):
178205
# File not exist Exception
179206
self.assertRaises(Exception, self.run_wizard, "test6_Exception", "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import wizard_import_fatturapa
2+
from . import wizard_check_intermediary_vat
23
from . import link_to_existing_invoice
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
3+
from odoo import fields, models
4+
5+
6+
class WizardCheckIntermediaryVat(models.TransientModel):
7+
_name = "wizard.check.intermediary"
8+
_description = "Intermediary VAT Check"
9+
10+
line_ids = fields.One2many(
11+
comodel_name="wizard.check.intermediary.line", inverse_name="wizard_id"
12+
)
13+
invoice_ids = fields.Many2many(comodel_name="account.move")
14+
15+
def action_confirm(self):
16+
for line in self.line_ids:
17+
data = json.loads(line.intermediary_data_json)
18+
if isinstance(data, str):
19+
data = json.loads(data)
20+
partner = self.env["res.partner"].create(data)
21+
line.invoice_id.write({"intermediary": partner.id})
22+
23+
return self.action()
24+
25+
def action_cancel(self):
26+
return self.action()
27+
28+
def action(self):
29+
return {
30+
"view_type": "form",
31+
"name": "Electronic Bills",
32+
"view_mode": "tree,form",
33+
"res_model": "account.move",
34+
"type": "ir.actions.act_window",
35+
"domain": [("id", "in", self.invoice_ids.ids)],
36+
}
37+
38+
39+
class WizardCheckIntermediaryVatLine(models.TransientModel):
40+
_name = "wizard.check.intermediary.line"
41+
_description = "Intermediary VAT Check Line"
42+
43+
invoice_id = fields.Many2one("account.move", string="Invoice", readonly=True)
44+
firstname = fields.Char()
45+
lastname = fields.Char()
46+
vat = fields.Char()
47+
intermediary_data_json = fields.Text()
48+
wizard_id = fields.Many2one("wizard.check.intermediary")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="view_check_intermediary_vat" model="ir.ui.view">
4+
<field name="name">check.intermediary.vat.form</field>
5+
<field name="model">wizard.check.intermediary</field>
6+
<field name="arch" type="xml">
7+
<form string="Verify Intermediary">
8+
<sheet>
9+
<group>
10+
<group>
11+
<p
12+
>These intermediaries do not exist on the system. Do you want to create them?</p>
13+
</group>
14+
<field name="line_ids" nolabel="1">
15+
<tree create="0">
16+
<field name="firstname" />
17+
<field name="lastname" />
18+
<field name="vat" />
19+
<field name="invoice_id" />
20+
<field name="intermediary_data_json" invisible="1" />
21+
</tree>
22+
</field>
23+
</group>
24+
<footer>
25+
<button
26+
string="Confirm"
27+
type="object"
28+
name="action_confirm"
29+
class="btn-primary"
30+
/>
31+
<button
32+
string="No"
33+
type="object"
34+
name="action_cancel"
35+
class="btn-secondary"
36+
/>
37+
</footer>
38+
</sheet>
39+
</form>
40+
</field>
41+
</record>
42+
</odoo>

0 commit comments

Comments
 (0)