diff --git a/l10n_it_fatturapa_import_zip/models/attachment.py b/l10n_it_fatturapa_import_zip/models/attachment.py index 4ecc28574cd9..cb09cb28d8e7 100644 --- a/l10n_it_fatturapa_import_zip/models/attachment.py +++ b/l10n_it_fatturapa_import_zip/models/attachment.py @@ -200,6 +200,40 @@ def action_import(self): self.state = "done" + def action_import_no_invoice(self): + self.ensure_one() + company_partner = self.env.company.partner_id + with tempfile.TemporaryDirectory() as tmp_dir_path: + tmp_dir = Path(tmp_dir_path) + _extract_zip_file(tmp_dir, self.datas) + original_in_invoice_registration_date = ( + self.env.company.in_invoice_registration_date + ) + # we don't have the received date + self.env.company.in_invoice_registration_date = "inv_date" + + for xml_file in tmp_dir.rglob("*"): + # Process only files skipping non-XML/P7M files + if xml_file.is_file() and ( + _is_xml_file(xml_file) or _has_p7m_extension(xml_file) + ): + content = xml_file.read_bytes() + attach_vals = { + "name": xml_file.name, + "datas": base64.encodebytes(content), + "attachment_import_zip_id": self.id, + } + attachment = self.env["fatturapa.attachment.in"].create(attach_vals) + if attachment.xml_supplier_id == company_partner: + attachment.unlink() + attach_vals["state"] = "validated" + attachment = self.env["fatturapa.attachment.out"].create( + attach_vals + ) + else: + _logger.info(f"Skipping {xml_file}, not an XML/P7M file") + self.state = "done" + class FatturaPAAttachmentIn(models.Model): _inherit = "fatturapa.attachment.in" diff --git a/l10n_it_fatturapa_import_zip/views/attachment_views.xml b/l10n_it_fatturapa_import_zip/views/attachment_views.xml index a811872a81ec..f203cffb739f 100644 --- a/l10n_it_fatturapa_import_zip/views/attachment_views.xml +++ b/l10n_it_fatturapa_import_zip/views/attachment_views.xml @@ -7,13 +7,20 @@
-
@@ -173,4 +180,13 @@ + + Import Electronic Invoice Out + wizard.import.fatturapa + + form + new + + + diff --git a/l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py b/l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py index 2b9c3a352c0c..beda30156b14 100644 --- a/l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py @@ -114,3 +114,13 @@ def set_payments_data(self, FatturaBody, invoice, partner_id): ) else: return super().set_payments_data(FatturaBody, invoice, partner_id) + + def _get_payment_term(self, partner): + payment_term_id = False + if self._is_import_attachment_out(): + if partner.property_payment_term_id: + payment_term_id = partner.property_payment_term_id.id + else: + if partner.property_supplier_payment_term_id: + payment_term_id = partner.property_supplier_payment_term_id.id + return payment_term_id