Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa_import_zip: enable to import only xml for bil…
Browse files Browse the repository at this point in the history
…ls and invoices
  • Loading branch information
andreampiovesana committed Sep 5, 2024
1 parent 43f1a7b commit fddaefe
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
34 changes: 34 additions & 0 deletions l10n_it_fatturapa_import_zip/models/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion l10n_it_fatturapa_import_zip/views/attachment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
<field name="arch" type="xml">
<form string="Import e-bill ZIP" duplicate="false">
<header>
<button
<button
name="action_import"
type="object"
states="draft"
string="Import invoices"
class="oe_highlight"
/>
<button
name="action_import_no_invoice"
type="object"
states="draft"
string="Import Files (No Invoices)"
class="oe_highlight"
/>
<field name="state" widget="statusbar" />
</header>
<sheet string="Import e-bill ZIP">
Expand Down Expand Up @@ -173,4 +180,13 @@
</field>
</record>

<record id="action_wizard_import_fatturapa_out" model="ir.actions.act_window">
<field name="name">Import Electronic Invoice Out</field>
<field name="res_model">wizard.import.fatturapa</field>
<field name="binding_model_id" ref="l10n_it_fatturapa_out.model_fatturapa_attachment_out" />
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="l10n_it_fatturapa_in.wizard_import_fatturapa_form_view" />
</record>

</odoo>
10 changes: 10 additions & 0 deletions l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fddaefe

Please sign in to comment.