Skip to content

Commit bc9aaee

Browse files
committed
[IMP] l10n_it_fatturapa_in: intermediary contact creation depending by vat
1 parent ea8d2f5 commit bc9aaee

File tree

7 files changed

+118
-3
lines changed

7 files changed

+118
-3
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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="Intermediario", readonly=True)
10+
invoice_id = fields.Many2one("account.move", string="Fattura", readonly=True)
11+
12+
def action_confirm(self):
13+
if self._context.get("intermediary_id"):
14+
self.env["account.move"].browse(self._context.get("invoice_id")).write(
15+
{"intermediary": self._context.get("intermediary_id")}
16+
)
17+
18+
return {"type": "ir.actions.act_window_close"}
19+
20+
def action_cancel(self):
21+
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="Verifica intermediario">
8+
<sheet>
9+
<group>
10+
<field name="message" nolabel="1" />
11+
</group>
12+
<footer>
13+
<button
14+
string=""
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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,33 @@ def importFatturaPA(self):
19251925
invoice.write({"tax_representative_id": tax_partner_id})
19261926
if Intermediary:
19271927
Intermediary_id = self.getPartnerBase(Intermediary.DatiAnagrafici)
1928-
invoice.write({"intermediary": Intermediary_id})
1928+
vat_check = (
1929+
self.env["res.partner"]
1930+
.search([("id", "=", Intermediary_id)])
1931+
.vat
1932+
)
1933+
if vat_check:
1934+
invoice.write({"intermediary": Intermediary_id})
1935+
else:
1936+
name = (
1937+
self.env["res.partner"]
1938+
.search([("id", "=", Intermediary_id)])
1939+
.name
1940+
)
1941+
return {
1942+
"type": "ir.actions.act_window",
1943+
"name": "Confirm action",
1944+
"res_model": "wizard.check.intermediary",
1945+
"view_mode": "form",
1946+
"target": "new",
1947+
"context": {
1948+
"default_message": f'Il contatto intermediario "{name}" '
1949+
"non esiste nel sistema. Confermi di volerlo creare?",
1950+
"intermediary_id": Intermediary_id,
1951+
"invoice_id": invoice.id,
1952+
},
1953+
}
1954+
19291955
new_invoices.append(invoice.id)
19301956
self.check_invoice_amount(invoice, fattura)
19311957

0 commit comments

Comments
 (0)