Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa_import_zip: set the right account for custome…
Browse files Browse the repository at this point in the history
…r invoices
  • Loading branch information
andreampiovesana committed Sep 5, 2024
1 parent fddaefe commit 546a1a9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 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 @@ -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

Check warning on line 125 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#L125

Added line #L125 was not covered by tests
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 142 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#L140-L142

Added lines #L140 - L142 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 152 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#L152

Added line #L152 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 159 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#L159

Added line #L159 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

0 comments on commit 546a1a9

Please sign in to comment.