diff options
| author | Laurent Smet <las@odoo.com> | 2018-03-27 14:33:12 +0200 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2018-04-26 11:26:22 +0200 |
| commit | 5439e72a4ebd7716b813c7ec24fd59058151568f (patch) | |
| tree | 033fd10b4e2c82b4bc6639f7e4725a449dba6a1a /addons/payment_transfer | |
| parent | 5588c2e02bf7d96b3a07f2d8160e2a531f00d467 (diff) | |
[IMP] payment*: auto-create journal for payment.acquirer
This commit adds the auto-creation journal for installed acquirers.
This is not easy because:
- The acquirers are created on the 'payment' module but are enabled only when the specific module
is installed. E.g. Paypal is enabled with 'payment_paypal'.
- To create a journal, a chart of accounts is required. However, the post_init_hook on the
'account' module makes the installation order harder. E.g install payment_paypal directly:
The module are installed in the order: account -> payment -> payment_paypal -> l10n_generic_coa.
To fix the problem, the journals are created at two moments:
- During the installation of the chart of accounts.
- At the installation of an acquirer module. E.g. payment_paypal.
Was PR #23904
Was task: 1831620
Diffstat (limited to 'addons/payment_transfer')
| -rw-r--r-- | addons/payment_transfer/__init__.py | 1 | ||||
| -rw-r--r-- | addons/payment_transfer/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/payment_transfer/models/payment.py | 13 |
3 files changed, 15 insertions, 0 deletions
diff --git a/addons/payment_transfer/__init__.py b/addons/payment_transfer/__init__.py index 8c67f893b37..f2ff55f0433 100644 --- a/addons/payment_transfer/__init__.py +++ b/addons/payment_transfer/__init__.py @@ -3,3 +3,4 @@ from . import models from . import controllers +from odoo.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 9f8704467dc..530fe49ede4 100644 --- a/addons/payment_transfer/__manifest__.py +++ b/addons/payment_transfer/__manifest__.py @@ -14,4 +14,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 00a34ac0ad4..18c74d2246d 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' |
