Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa_in: intermediary contact creation depending b…
Browse files Browse the repository at this point in the history
…y vat
  • Loading branch information
Chionne27 committed Feb 24, 2025
1 parent ea8d2f5 commit 718d373
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 3 deletions.
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"views/partner_view.xml",
"wizard/wizard_import_fatturapa_view.xml",
"wizard/link_to_existing_invoice.xml",
"wizard/wizard_check_intermediary_vat.xml",
"views/company_view.xml",
"security/ir.model.access.csv",
"security/rules.xml",
Expand Down
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ access_einvoice_line_other_data,access_einvoice_line_other_data,model_einvoice_l
access_wizard_import_fatturapa,access_wizard_import_fatturapa,model_wizard_import_fatturapa,account.group_account_invoice,1,1,1,1
access_wizard_link_to_invoice,access_wizard_link_to_invoice,model_wizard_link_to_invoice,account.group_account_invoice,1,1,1,1
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
access_wizard_check_intermediary_all,access_wizard_check_intermediary_all,model_wizard_check_intermediary,account.group_account_invoice,1,1,1,1
fatturapa_in_decimal_precision_access_manager,fatturapa_in_decimal_precision_access_manager,base.model_decimal_precision,account.group_account_manager,1,1,0,0
fatturapa_in_decimal_precision_access_billing,fatturapa_in_decimal_precision_access_billing,base.model_decimal_precision,account.group_account_invoice,1,1,0,0
fatturapa_in_mail_followers_access_manager,fatturapa_in_mail_followers_access_manager,mail.model_mail_followers,account.group_account_manager,1,1,0,0
Expand Down
39 changes: 37 additions & 2 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,43 @@ def test_11_xml_import(self):

def test_12_xml_import(self):
res = self.run_wizard("test12", "IT05979361218_008.xml")
invoice_id = res.get("domain")[0][2][0]
invoice = self.invoice_model.browse(invoice_id)

# Case where the confirmation wizard is shown
if res.get("res_model") == "wizard.check.intermediary":
# Simulate opening the wizard and retrieving values from the context
context = res.get("context", {})
intermediary_id = context.get("intermediary_id")
invoice_id = context.get("invoice_id")

# Check that the wizard was opened with the correct values
self.assertTrue(intermediary_id, "intermediary_id not present in context")
self.assertTrue(invoice_id, "invoice_id not present in context")

# Simulate the wizard
wizard = (
self.env["wizard.check.intermediary"]
.with_context(context)
.create(
{
"message": context.get("default_message"),
"intermediary_id": intermediary_id,
"invoice_id": invoice_id,
}
)
)

# Simulate user confirmation
wizard.action_confirm()

# After confirmation, retrieve the invoice and check the intermediary partner
invoice = self.env["account.move"].browse(invoice_id)

else:
# Standard flow without wizard
invoice_id = res.get("domain")[0][2][0]
invoice = self.env["account.move"].browse(invoice_id)

# Final assertions regardless of the path
self.assertEqual(invoice.payment_reference, "FT/2015/0012")
self.assertEqual(invoice.sender, "TZ")
self.assertEqual(invoice.intermediary.name, "MARIO ROSSI")
Expand Down
1 change: 1 addition & 0 deletions l10n_it_fatturapa_in/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import wizard_import_fatturapa
from . import wizard_check_intermediary_vat
from . import link_to_existing_invoice
21 changes: 21 additions & 0 deletions l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo import fields, models


class WizardCheckIntermediaryVat(models.TransientModel):
_name = "wizard.check.intermediary"
_description = "Intermediary VAT Check"

message = fields.Text(string="Message", readonly=True)
intermediary_id = fields.Integer(string="Intermediary", readonly=True)
invoice_id = fields.Many2one("account.move", string="Invoice", readonly=True)

def action_confirm(self):
if self._context.get("intermediary_id"):
self.env["account.move"].browse(self._context.get("invoice_id")).write(
{"intermediary": self._context.get("intermediary_id")}
)

return {"type": "ir.actions.act_window_close"}

def action_cancel(self):
return {"type": "ir.actions.act_window_close"}
30 changes: 30 additions & 0 deletions l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_check_intermediary_vat" model="ir.ui.view">
<field name="name">check.intermediary.vat.form</field>
<field name="model">wizard.check.intermediary</field>
<field name="arch" type="xml">
<form string="Verify Intermediary">
<sheet>
<group>
<field name="message" nolabel="1" />
</group>
<footer>
<button
string="Confirm"
type="object"
name="action_confirm"
class="btn-primary"
/>
<button
string="No"
type="object"
name="action_cancel"
class="btn-secondary"
/>
</footer>
</sheet>
</form>
</field>
</record>
</odoo>
28 changes: 27 additions & 1 deletion l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,33 @@ def importFatturaPA(self):
invoice.write({"tax_representative_id": tax_partner_id})
if Intermediary:
Intermediary_id = self.getPartnerBase(Intermediary.DatiAnagrafici)
invoice.write({"intermediary": Intermediary_id})
vat_check = (
self.env["res.partner"]
.search([("id", "=", Intermediary_id)])
.vat
)
if vat_check:
invoice.write({"intermediary": Intermediary_id})
else:
name = (
self.env["res.partner"]
.search([("id", "=", Intermediary_id)])
.name
)
return {
"type": "ir.actions.act_window",
"name": "Confirm action",
"res_model": "wizard.check.intermediary",
"view_mode": "form",
"target": "new",
"context": {
"default_message": f'The contact intermediary "{name}" '
"does not exists in the system. Do you want to create it?",
"intermediary_id": Intermediary_id,
"invoice_id": invoice.id,
},
}

new_invoices.append(invoice.id)
self.check_invoice_amount(invoice, fattura)

Expand Down

0 comments on commit 718d373

Please sign in to comment.