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 13, 2024
1 parent fddaefe commit 39e4581
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
10 changes: 8 additions & 2 deletions l10n_it_fatturapa_import_zip/views/attachment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,16 @@
<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="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" />
<field
name="view_id"
ref="l10n_it_fatturapa_in.wizard_import_fatturapa_form_view"
/>
</record>

</odoo>
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
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

0 comments on commit 39e4581

Please sign in to comment.