Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] l10n_it_fatturapa_import_zip: import only xml + enable customer xml import + manage payment for customer invoice + set debit account for customer invoice #4300

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions l10n_it_fatturapa_import_zip/models/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
),
)

def action_import(self):
def action_import(self, with_invoice=True):
self.ensure_one()
company_partner = self.env.company.partner_id
with tempfile.TemporaryDirectory() as tmp_dir_path:
Expand Down Expand Up @@ -182,16 +182,17 @@
attachment = self.env["fatturapa.attachment.out"].create(
attach_vals
)
wizard = (
self.env["wizard.import.fatturapa"]
.with_context(
active_ids=attachment.ids,
active_model=attachment._name,
if with_invoice:
wizard = (
self.env["wizard.import.fatturapa"]
.with_context(
active_ids=attachment.ids,
active_model=attachment._name,
)
.create({})
)
.create({})
)
_logger.info(f"Importing {xml_file}")
wizard.importFatturaPA()
_logger.info(f"Importing {xml_file}")
wizard.importFatturaPA()
else:
_logger.info(f"Skipping {xml_file}, not an XML/P7M file")
self.env.company.in_invoice_registration_date = (
Expand All @@ -200,6 +201,14 @@

self.state = "done"

def action_import_with_invoice(self):
self.ensure_one()
self.action_import(with_invoice=True)

Check warning on line 206 in l10n_it_fatturapa_import_zip/models/attachment.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_import_zip/models/attachment.py#L205-L206

Added lines #L205 - L206 were not covered by tests

def action_import_no_invoice(self):
self.ensure_one()
self.action_import(with_invoice=False)

Check warning on line 210 in l10n_it_fatturapa_import_zip/models/attachment.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_import_zip/models/attachment.py#L209-L210

Added lines #L209 - L210 were not covered by tests


class FatturaPAAttachmentIn(models.Model):
_inherit = "fatturapa.attachment.in"
Expand Down
26 changes: 24 additions & 2 deletions 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
name="action_import"
<button
name="action_import_with_invoice"
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,19 @@
</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>
54 changes: 54 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,57 @@
)
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

Check warning on line 122 in l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py#L122

Added line #L122 was not covered by tests
else:
payment_term_id = super()._get_payment_term(partner=partner)
return payment_term_id

def get_credit_account(self, product=None):
if self._is_import_attachment_out():
ret = self.get_debit_account(product=product)
else:
ret = super().get_credit_account(product=product)
return ret

# function to mimics get_credit_account() for outgoing invoices
def get_debit_account(self, product=None):
debit_account = self.env["account.account"]

if product:
template = product.product_tmpl_id
accounts_dict = template.get_product_accounts()
debit_account = accounts_dict["income"]

Check warning on line 141 in l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py#L139-L141

Added lines #L139 - L141 were not covered by tests

company = self.env.company
# Search in journal
journal = self.get_journal(company)
if not debit_account:
debit_account = journal.default_account_id

# Search in company defaults
if not debit_account:
debit_account = (

Check warning on line 151 in l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py#L151

Added line #L151 was not covered by tests
self.env["ir.property"]
.with_company(company)
._get("property_account_income_categ_id", "product.category")
)

if not debit_account:
raise UserError(

Check warning on line 158 in l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py#L158

Added line #L158 was not covered by tests
_(
"Please configure Default Debit Account "
"in Journal '{journal}' "
"or check default income account "
"for company '{company}'."
).format(
journal=journal.display_name,
company=company.display_name,
)
)

return debit_account
9 changes: 8 additions & 1 deletion l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,12 @@
received_date = received_date.date()
return received_date

def _get_payment_term(self, partner):
payment_term_id = False
if partner.property_supplier_payment_term_id:
payment_term_id = partner.property_supplier_payment_term_id.id

Check warning on line 1173 in l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py#L1173

Added line #L1173 was not covered by tests
return payment_term_id

def _prepare_invoice_values(self, fatt, fatturapa_attachment, FatturaBody, partner):
company = self.env.company
currency = self._get_currency(FatturaBody)
Expand Down Expand Up @@ -1197,6 +1203,7 @@
partner,
delivery=delivery_partner,
)
payment_term_id = self._get_payment_term(partner)

invoice_data = {
"e_invoice_received_date": e_invoice_received_date,
Expand All @@ -1212,7 +1219,7 @@
"journal_id": purchase_journal.id,
# 'origin': xmlData.datiOrdineAcquisto,
"fiscal_position_id": fiscal_position.id,
"invoice_payment_term_id": partner.property_supplier_payment_term_id.id,
"invoice_payment_term_id": payment_term_id,
"company_id": company.id,
"fatturapa_attachment_in_id": fatturapa_attachment.id,
"narration": comment,
Expand Down
Loading