diff --git a/addons/payment_transfer/__init__.py b/addons/payment_transfer/__init__.py index 81ea421d..96f1329b 100644 --- a/addons/payment_transfer/__init__.py +++ b/addons/payment_transfer/__init__.py @@ -3,3 +3,4 @@ from . import models from . import controllers +from flectra.addons.payment.models.payment_acquirer import create_missing_journal_for_acquirers diff --git a/addons/payment_transfer/__manifest__.py b/addons/payment_transfer/__manifest__.py index 61b36bea..a26b289e 100644 --- a/addons/payment_transfer/__manifest__.py +++ b/addons/payment_transfer/__manifest__.py @@ -15,4 +15,5 @@ ], 'installable': True, 'auto_install': True, + 'post_init_hook': 'create_missing_journal_for_acquirers', } diff --git a/addons/payment_transfer/models/payment.py b/addons/payment_transfer/models/payment.py index 5c942f1d..09741c15 100644 --- a/addons/payment_transfer/models/payment.py +++ b/addons/payment_transfer/models/payment.py @@ -15,6 +15,19 @@ class TransferPaymentAcquirer(models.Model): provider = fields.Selection(selection_add=[('transfer', 'Wire Transfer')], default='transfer') + @api.model + def _create_missing_journal_for_acquirers(self, company=None): + # By default, the wire transfer method uses the default Bank journal. + company = company or self.env.user.company_id + acquirers = self.env['payment.acquirer'].search( + [('provider', '=', 'transfer'), ('journal_id', '=', False), ('company_id', '=', company.id)]) + + bank_journal = self.env['account.journal'].search( + [('type', '=', 'bank'), ('company_id', '=', company.id)], limit=1) + if bank_journal: + acquirers.write({'journal_id': bank_journal.id}) + return super(TransferPaymentAcquirer, self)._create_missing_journal_for_acquirers(company=company) + def transfer_get_form_action_url(self): return '/payment/transfer/feedback'