From f9afdbccc168c3a4687bdcc464dd17e29032b35a Mon Sep 17 00:00:00 2001 From: "andrea.m.piovesana" Date: Wed, 31 Jul 2024 12:31:07 +0200 Subject: [PATCH] [IMP] l10n_it_fatturapa_import_zip: set the right account for customer invoices --- .../wizards/wizard_import_fatturapa.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) 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 beda30156b14..8adcbf20d3d5 100644 --- a/l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_import_zip/wizards/wizard_import_fatturapa.py @@ -124,3 +124,48 @@ def _get_payment_term(self, partner): if partner.property_supplier_payment_term_id: payment_term_id = partner.property_supplier_payment_term_id.id 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"] + + 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 = ( + self.env["ir.property"] + .with_company(company) + ._get("property_account_income_categ_id", "product.category") + ) + + if not debit_account: + raise UserError( + _( + "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