Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa_in: replace UserError with log_inconsistency …
Browse files Browse the repository at this point in the history
…and return False from getPartnerBase method
  • Loading branch information
fredzamoabg committed May 2, 2022
1 parent a2f9668 commit d27d9e0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions l10n_it_fatturapa_in/models/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class FatturaPAAttachmentIn(models.Model):
"Contains self invoices", compute="_compute_xml_data", store=True
)

inconsistencies = fields.Text(compute="_compute_xml_data", store=True)

_sql_constraints = [
(
"ftpa_attachment_in_name_uniq",
Expand Down Expand Up @@ -123,6 +125,8 @@ def _compute_xml_data(self):
if dgd.TipoDocumento in SELF_INVOICE_TYPES:
att.is_self_invoice = True
att.invoices_date = " ".join(invoices_date)
inconsistencies = wiz_obj.env.context.get("inconsistencies", False)
att.inconsistencies = inconsistencies

@api.depends("in_invoice_ids")
def _compute_registered(self):
Expand Down
6 changes: 5 additions & 1 deletion l10n_it_fatturapa_in/tests/fatturapa_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def run_wizard(
attach_form = Form(self.attach_model)
attach_form.name = name
attach_form.datas = self.getFile(file_name, module_name=module_name)[1]
attach_id = attach_form.save().id
attach = attach_form.save()
attach_id = attach.id
if mode == "import":
wizard_form = Form(
self.wizard_model.with_context(
Expand All @@ -163,6 +164,9 @@ def run_wizard(
if wiz_values:
wiz_values.wizard_id = wizard
return wizard.link()
if not mode:
# return created fatturapa.attachment.in record in case no mode provided
return attach

def run_wizard_multi(self, file_name_list, module_name=None):
if module_name is None:
Expand Down
11 changes: 11 additions & 0 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,17 @@ def test_e_invoice_field_compute(self):
invoices = self.invoice_model.create([{}, {}])
self.assertEqual(invoices.mapped("e_invoice_validation_error"), [False, False])

def test_duplicated_vat_on_partners(self):
supplier = self.env["res.partner"].search(
[("vat", "=", "IT05979361218")], limit=1
)

duplicated_supplier = supplier.copy()
self.assertEqual(supplier.vat, duplicated_supplier.vat)
attach = self.run_wizard("duplicated_vat", "IT05979361218_012.xml", mode=False)
self.assertFalse(attach.xml_supplier_id)
self.assertTrue(attach.inconsistencies)


class TestFatturaPAEnasarco(FatturapaCommon):
def setUp(self):
Expand Down
11 changes: 6 additions & 5 deletions l10n_it_fatturapa_in/views/account_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
<field name="model">fatturapa.attachment.in</field>
<field name="arch" type="xml">
<form string="Import e-bill" duplicate="false">
<field name="inconsistencies" invisible="1" />
<div
class="alert alert-info"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('e_invoice_validation_error','=',False)]}"
attrs="{'invisible': [('e_invoice_validation_error','=',False), ('inconsistencies','=',False)]}"
>
<bold><field
name="e_invoice_validation_message"
nolabel="1"
/></bold>
<bold>
<field name="e_invoice_validation_message" nolabel="1" />
<field name="inconsistencies" nolabel="1" />
</bold>
</div>
<field name="e_invoice_validation_error" invisible="1" />
<div>
Expand Down
3 changes: 2 additions & 1 deletion l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ def getPartnerBase(self, DatiAnagrafici): # noqa: C901
commercial_partner_id
and partner.commercial_partner_id.id != commercial_partner_id
):
raise UserError(
self.log_inconsistency(
_(
"Two distinct partners with "
"VAT number %s or Fiscal Code %s already "
"present in db." % (vat, cf)
)
)
return False
commercial_partner_id = partner.commercial_partner_id.id
if partners:
if not commercial_partner_id:
Expand Down

0 comments on commit d27d9e0

Please sign in to comment.