Skip to content

Commit 2f2ce53

Browse files
committed
[IMP] l10n_it_fatturapa_in: intermediary contact creation depending by vat
1 parent 45bbecf commit 2f2ce53

File tree

7 files changed

+148
-4
lines changed

7 files changed

+148
-4
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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
910
fatturapa_in_decimal_precision_access_manager,fatturapa_in_decimal_precision_access_manager,base.model_decimal_precision,account.group_account_manager,1,1,0,0
1011
fatturapa_in_decimal_precision_access_billing,fatturapa_in_decimal_precision_access_billing,base.model_decimal_precision,account.group_account_invoice,1,1,0,0
1112
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/tests/test_import_fatturapa_xml.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,43 @@ def test_11_xml_import(self):
325325

326326
def test_12_xml_import(self):
327327
res = self.run_wizard("test12", "IT05979361218_008.xml")
328-
invoice_id = res.get("domain")[0][2][0]
329-
invoice = self.invoice_model.browse(invoice_id)
328+
329+
# Case where the confirmation wizard is shown
330+
if res.get("res_model") == "wizard.check.intermediary":
331+
# Simulate opening the wizard and retrieving values from the context
332+
context = res.get("context", {})
333+
intermediary_id = context.get("intermediary_id")
334+
invoice_id = context.get("invoice_id")
335+
336+
# Check that the wizard was opened with the correct values
337+
self.assertTrue(intermediary_id, "intermediary_id not present in context")
338+
self.assertTrue(invoice_id, "invoice_id not present in context")
339+
340+
# Simulate the wizard
341+
wizard = (
342+
self.env["wizard.check.intermediary"]
343+
.with_context(context)
344+
.create(
345+
{
346+
"message": context.get("default_message"),
347+
"intermediary_id": intermediary_id,
348+
"invoice_id": invoice_id,
349+
}
350+
)
351+
)
352+
353+
# Simulate user confirmation
354+
wizard.action_confirm()
355+
356+
# After confirmation, retrieve the invoice and check the intermediary partner
357+
invoice = self.env["account.move"].browse(invoice_id)
358+
359+
else:
360+
# Standard flow without wizard
361+
invoice_id = res.get("domain")[0][2][0]
362+
invoice = self.env["account.move"].browse(invoice_id)
363+
364+
# Final assertions regardless of the path
330365
self.assertEqual(invoice.payment_reference, "FT/2015/0012")
331366
self.assertEqual(invoice.sender, "TZ")
332367
self.assertEqual(invoice.intermediary.name, "MARIO ROSSI")
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from odoo import fields, models
2+
3+
4+
class WizardCheckIntermediaryVat(models.TransientModel):
5+
_name = "wizard.check.intermediary"
6+
_description = "Intermediary VAT Check"
7+
8+
message = fields.Text(string="Message", readonly=True)
9+
# intermediary_id = fields.Integer(string="Intermediary", readonly=True)
10+
invoice_id = fields.Many2one(
11+
"account.move", string="Invoice", readonly=True
12+
) # contains the invoice object
13+
name = fields.Char()
14+
vat = fields.Char()
15+
16+
def action_confirm(self):
17+
partner = self.env["res.partner"].create(
18+
{
19+
"name": self.name,
20+
"vat": self.vat,
21+
}
22+
)
23+
24+
self.invoice_id.write({"intermediary": partner.id})
25+
26+
return {"type": "ir.actions.act_window_close"}
27+
28+
def action_cancel(self):
29+
return {"type": "ir.actions.act_window_close"}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
<field name="message" nolabel="1" />
11+
</group>
12+
<footer>
13+
<button
14+
string="Confirm"
15+
type="object"
16+
name="action_confirm"
17+
class="btn-primary"
18+
/>
19+
<button
20+
string="No"
21+
type="object"
22+
name="action_cancel"
23+
class="btn-secondary"
24+
/>
25+
</footer>
26+
</sheet>
27+
</form>
28+
</field>
29+
</record>
30+
</odoo>

l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,55 @@ def importFatturaPA(self):
19241924
)
19251925
invoice.write({"tax_representative_id": tax_partner_id})
19261926
if Intermediary:
1927-
Intermediary_id = self.getPartnerBase(Intermediary.DatiAnagrafici)
1928-
invoice.write({"intermediary": Intermediary_id})
1927+
vat = False
1928+
if Intermediary.DatiAnagrafici.IdFiscaleIVA:
1929+
id_paese = (
1930+
Intermediary.DatiAnagrafici.IdFiscaleIVA.IdPaese.upper()
1931+
)
1932+
id_codice = re.sub(
1933+
r"\W+",
1934+
"",
1935+
Intermediary.DatiAnagrafici.IdFiscaleIVA.IdCodice,
1936+
).upper()
1937+
# Format Italian VAT ID to always have 11 char
1938+
# to avoid validation error when creating the given partner
1939+
if id_paese == "IT" and not id_codice.startswith("IT"):
1940+
vat = "IT{}".format(id_codice.rjust(11, "0")[:11])
1941+
# XXX maybe San Marino needs special formatting too?
1942+
else:
1943+
vat = id_codice
1944+
1945+
vat_check = self.env["res.partner"].search(
1946+
[("vat", "=", vat)], limit=1
1947+
)
1948+
1949+
if vat_check:
1950+
invoice.write({"intermediary": vat_check.id})
1951+
else:
1952+
name = Intermediary.DatiAnagrafici.Anagrafica.Denominazione
1953+
1954+
res = self.env["wizard.check.intermediary"].create(
1955+
{
1956+
"name": name,
1957+
"vat": vat,
1958+
"invoice_id": invoice.id,
1959+
"message": _(
1960+
"The contact intermediary %(name)s "
1961+
"does not exists in the system. Do you want to create it?"
1962+
)
1963+
% {"name": name},
1964+
}
1965+
)
1966+
1967+
return {
1968+
"type": "ir.actions.act_window",
1969+
"name": "Confirm action",
1970+
"res_model": "wizard.check.intermediary",
1971+
"res_id": res.id,
1972+
"view_mode": "form",
1973+
"target": "new",
1974+
}
1975+
19291976
new_invoices.append(invoice.id)
19301977
self.check_invoice_amount(invoice, fattura)
19311978

0 commit comments

Comments
 (0)