diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index ed53255b2c1..12b8e52db44 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -126,7 +126,7 @@ class AccountJournal(models.Model): copy=False, check_company=True, help="Manual: Get paid by any method outside of Odoo.\n" - "Payment Acquirers: Each payment acquirer has its own Payment Method. Request a transaction on/to a card thanks to a payment token saved by the partner when buying or subscribing online.\n" + "Payment Providers: Each payment provider has its own Payment Method. Request a transaction on/to a card thanks to a payment token saved by the partner when buying or subscribing online.\n" "Batch Deposit: Collect several customer checks at once generating and submitting a batch deposit to your bank. Module account_batch_payment is necessary.\n" "SEPA Direct Debit: Get paid in the SEPA zone thanks to a mandate your partner will have granted to you. Module account_sepa is necessary.\n" ) @@ -901,7 +901,7 @@ class AccountJournal(models.Model): This getter is here to allow filtering the payment method lines if needed in other modules. It does NOT serve as a general getter to get the lines. - For example, it'll be extended to filter out lines from inactive payment acquirers in the payment module. + For example, it'll be extended to filter out lines from inactive payment providers in the payment module. :param payment_type: either inbound or outbound, used to know which lines to return :return: Either the inbound or outbound payment method lines """ diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 12c376990e3..764d16a60b4 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -47,7 +47,7 @@ class AccountPayment(models.Model): compute='_compute_payment_method_line_id', domain="[('id', 'in', available_payment_method_line_ids)]", help="Manual: Pay or Get paid by any method outside of Odoo.\n" - "Payment Acquirers: Each payment acquirer has its own Payment Method. Request a transaction on/to a card thanks to a payment token saved by the partner when buying or subscribing online.\n" + "Payment Providers: Each payment provider has its own Payment Method. Request a transaction on/to a card thanks to a payment token saved by the partner when buying or subscribing online.\n" "Check: Pay bills by check and print it from Odoo.\n" "Batch Deposit: Collect several customer checks at once generating and submitting a batch deposit to your bank. Module account_batch_payment is necessary.\n" "SEPA Credit Transfer: Pay in the SEPA zone by submitting a SEPA Credit Transfer file to your bank. Module account_sepa is necessary.\n" diff --git a/addons/account/models/account_payment_method.py b/addons/account/models/account_payment_method.py index 16577338b80..1f7bde0b5f7 100644 --- a/addons/account/models/account_payment_method.py +++ b/addons/account/models/account_payment_method.py @@ -67,7 +67,7 @@ class AccountPaymentMethod(models.Model): """ Contains details about how to initialize a payment method with the code x. The contained info are: - mode: Either unique if we only want one of them at a single time (payment acquirers for example) + mode: Either unique if we only want one of them at a single time (payment providers for example) or multi if we want the method on each journal fitting the domain. domain: The domain defining the eligible journals. currency_id: The id of the currency necessary on the journal (or company) for it to be eligible. diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 61bdb338293..1cf17d753db 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -224,7 +224,7 @@ class ResCompany(models.Model): # YTI FIXME: Define only one method that returns {'account': [], 'sale': [], ...} def get_account_invoice_onboarding_steps_states_names(self): - """ Necessary to add/edit steps from other modules (payment acquirer in this case). """ + """ Necessary to add/edit steps from other modules (payment provider in this case). """ return [ 'base_onboarding_company_state', 'account_onboarding_invoice_layout_state', diff --git a/addons/account/wizard/account_payment_register.py b/addons/account/wizard/account_payment_register.py index 162264ad9e5..934f414fbb9 100644 --- a/addons/account/wizard/account_payment_register.py +++ b/addons/account/wizard/account_payment_register.py @@ -88,7 +88,7 @@ class AccountPaymentRegister(models.TransientModel): compute='_compute_payment_method_line_id', domain="[('id', 'in', available_payment_method_line_ids)]", help="Manual: Pay or Get paid by any method outside of Odoo.\n" - "Payment Acquirers: Each payment acquirer has its own Payment Method. Request a transaction on/to a card thanks to a payment token saved by the partner when buying or subscribing online.\n" + "Payment Providers: Each payment provider has its own Payment Method. Request a transaction on/to a card thanks to a payment token saved by the partner when buying or subscribing online.\n" "Check: Pay bills by check and print it from Odoo.\n" "Batch Deposit: Collect several customer checks at once generating and submitting a batch deposit to your bank. Module account_batch_payment is necessary.\n" "SEPA Credit Transfer: Pay in the SEPA zone by submitting a SEPA Credit Transfer file to your bank. Module account_sepa is necessary.\n" diff --git a/addons/account_payment/__init__.py b/addons/account_payment/__init__.py index c722f591c88..c8b4631d454 100644 --- a/addons/account_payment/__init__.py +++ b/addons/account_payment/__init__.py @@ -10,16 +10,16 @@ from odoo import api, SUPERUSER_ID def post_init_hook(cr, registry): """ Create `account.payment.method` records for the installed payment providers. """ env = api.Environment(cr, SUPERUSER_ID, {}) - PaymentAcquirer = env['payment.acquirer'] - installed_providers = PaymentAcquirer.search([('module_id.state', '=', 'installed')]) - for provider_code in set(installed_providers.mapped('provider')): - PaymentAcquirer._setup_payment_method(provider_code) + PaymentProvider = env['payment.provider'] + installed_providers = PaymentProvider.search([('module_id.state', '=', 'installed')]) + for code in set(installed_providers.mapped('code')): + PaymentProvider._setup_payment_method(code) def uninstall_hook(cr, registry): """ Delete `account.payment.method` records created for the installed payment providers. """ env = api.Environment(cr, SUPERUSER_ID, {}) - installed_providers = env['payment.acquirer'].search([('module_id.state', '=', 'installed')]) + installed_providers = env['payment.provider'].search([('module_id.state', '=', 'installed')]) env['account.payment.method'].search([ ('code', 'in', installed_providers.mapped('provider')), ('payment_type', '=', 'inbound'), diff --git a/addons/account_payment/__manifest__.py b/addons/account_payment/__manifest__.py index 91f8825b3b0..ddd1d153e14 100644 --- a/addons/account_payment/__manifest__.py +++ b/addons/account_payment/__manifest__.py @@ -17,7 +17,7 @@ 'views/account_move_views.xml', 'views/account_journal_views.xml', 'views/account_payment_views.xml', - 'views/payment_acquirer_views.xml', + 'views/payment_provider_views.xml', 'views/payment_transaction_views.xml', 'wizards/account_payment_register_views.xml', diff --git a/addons/account_payment/controllers/portal.py b/addons/account_payment/controllers/portal.py index 9cb61da274d..e0d6876ae04 100644 --- a/addons/account_payment/controllers/portal.py +++ b/addons/account_payment/controllers/portal.py @@ -22,23 +22,23 @@ class PortalAccount(portal.PortalAccount): invoice_company = invoice.company_id or request.env.company PaymentPortal._ensure_matching_companies(partner, invoice_company) - acquirers_sudo = request.env['payment.acquirer'].sudo()._get_compatible_acquirers( + providers_sudo = request.env['payment.provider'].sudo()._get_compatible_providers( invoice_company.id, partner.id, invoice.amount_total, currency_id=invoice.currency_id.id - ) # In sudo mode to read the fields of acquirers and partner (if not logged in) + ) # In sudo mode to read the fields of providers and partner (if not logged in) tokens = request.env['payment.token'].search( - [('acquirer_id', 'in', acquirers_sudo.ids), ('partner_id', '=', partner.id)] + [('provider_id', 'in', providers_sudo.ids), ('partner_id', '=', partner.id)] ) # Tokens are cleared at the end if the user is not logged in - fees_by_acquirer = { - acq_sudo: acq_sudo._compute_fees( + fees_by_provider = { + pro_sudo: pro_sudo._compute_fees( invoice.amount_total, invoice.currency_id, invoice.partner_id.country_id - ) for acq_sudo in acquirers_sudo.filtered('fees_active') + ) for pro_sudo in providers_sudo.filtered('fees_active') } values.update({ - 'acquirers': acquirers_sudo, + 'providers': providers_sudo, 'tokens': tokens, - 'fees_by_acquirer': fees_by_acquirer, + 'fees_by_provider': fees_by_provider, 'show_tokenize_input': PaymentPortal._compute_show_tokenize_input_mapping( - acquirers_sudo, logged_in=logged_in + providers_sudo, logged_in=logged_in ), 'amount': invoice.amount_residual, 'currency': invoice.currency_id, diff --git a/addons/account_payment/models/__init__.py b/addons/account_payment/models/__init__.py index 034d2f7c8b0..1a548501a06 100644 --- a/addons/account_payment/models/__init__.py +++ b/addons/account_payment/models/__init__.py @@ -5,5 +5,5 @@ from . import account_move from . import account_payment from . import account_payment_method from . import account_payment_method_line -from . import payment_acquirer +from . import payment_provider from . import payment_transaction diff --git a/addons/account_payment/models/account_journal.py b/addons/account_payment/models/account_journal.py index e9ebcbf8e81..ed56e2ed200 100644 --- a/addons/account_payment/models/account_journal.py +++ b/addons/account_payment/models/account_journal.py @@ -11,50 +11,52 @@ class AccountJournal(models.Model): @api.constrains('inbound_payment_method_line_ids') def _check_inbound_payment_method_line_ids(self): """ - Check and ensure that the user do not remove a apml that is linked to an acquirer in the test or enabled state. + Check and ensure that the user do not remove a apml that is linked to a provider in the test or enabled state. """ if not self.company_id: return self.env['account.payment.method'].flush_model(['code', 'payment_type']) self.env['account.payment.method.line'].flush_model(['payment_method_id']) - self.env['payment.acquirer'].flush_model(['provider', 'state']) + self.env['payment.provider'].flush_model(['code', 'state']) self._cr.execute(''' - SELECT acquirer.id - FROM payment_acquirer acquirer + SELECT provider.id + FROM payment_provider provider JOIN account_payment_method apm - ON apm.code = acquirer.provider + ON apm.code = provider.code LEFT JOIN account_payment_method_line apml ON apm.id = apml.payment_method_id AND apml.journal_id IS NOT NULL - WHERE acquirer.state IN ('enabled', 'test') - AND acquirer.provider != 'custom' + WHERE provider.state IN ('enabled', 'test') + AND provider.code != 'custom' AND apm.payment_type = 'inbound' AND apml.id IS NULL - AND acquirer.company_id IN %(company_ids)s + AND provider.company_id IN %(company_ids)s ''', {'company_ids': tuple(self.company_id.ids)}) ids = [r[0] for r in self._cr.fetchall()] if ids: - acquirers = self.env['payment.acquirer'].sudo().browse(ids) - raise UserError(_("You can't delete a payment method that is linked to an acquirer in the enabled or test state.\n" - "Linked acquirer(s): %s", ', '.join(a.display_name for a in acquirers))) + providers = self.env['payment.provider'].sudo().browse(ids) + raise UserError( + _("You can't delete a payment method that is linked to a provider in the enabled or test state.\n" + "Linked provider(s): %s", ', '.join(p.display_name for p in providers)) + ) def _get_available_payment_method_lines(self, payment_type): lines = super()._get_available_payment_method_lines(payment_type) - return lines.filtered(lambda l: l.payment_acquirer_state != 'disabled') + return lines.filtered(lambda l: l.payment_provider_state != 'disabled') @api.depends('outbound_payment_method_line_ids', 'inbound_payment_method_line_ids') def _compute_available_payment_method_ids(self): super()._compute_available_payment_method_ids() - installed_acquirers = self.env['payment.acquirer'].sudo().search([]) + installed_providers = self.env['payment.provider'].sudo().search([]) method_information = self.env['account.payment.method']._get_payment_method_information() pay_methods = self.env['account.payment.method'].search([('code', 'in', list(method_information.keys()))]) pay_method_by_code = {x.code + x.payment_type: x for x in pay_methods} - # On top of the basic filtering, filter to hide unavailable acquirers. - # This avoid allowing payment method lines linked to an acquirer that has no record. + # On top of the basic filtering, filter to hide unavailable providers. + # This avoid allowing payment method lines linked to a provider that has no record. for code, vals in method_information.items(): payment_method = pay_method_by_code.get(code + 'inbound') @@ -64,9 +66,9 @@ class AccountJournal(models.Model): for journal in self: to_remove = [] - available_providers = installed_acquirers.filtered( - lambda a: a.company_id == journal.company_id - ).mapped('provider') + available_providers = installed_providers.filtered( + lambda p: p.company_id == journal.company_id + ).mapped('code') available = payment_method.code in available_providers if vals['mode'] == 'unique' and not available: diff --git a/addons/account_payment/models/account_move.py b/addons/account_payment/models/account_move.py index e14454a47a3..bf4b8e82772 100644 --- a/addons/account_payment/models/account_move.py +++ b/addons/account_payment/models/account_move.py @@ -45,13 +45,13 @@ class AccountMove(models.Model): def payment_action_capture(self): """ Capture all transactions linked to this invoice. """ payment_utils.check_rights_on_recordset(self) - # In sudo mode because we need to be able to read on acquirer fields. + # In sudo mode because we need to be able to read on provider fields. self.authorized_transaction_ids.sudo().action_capture() def payment_action_void(self): """ Void all transactions linked to this invoice. """ payment_utils.check_rights_on_recordset(self) - # In sudo mode because we need to be able to read on acquirer fields. + # In sudo mode because we need to be able to read on provider fields. self.authorized_transaction_ids.sudo().action_void() def action_view_payment_transactions(self): diff --git a/addons/account_payment/models/account_payment.py b/addons/account_payment/models/account_payment.py index 1ffbce501ca..d20871cc52b 100644 --- a/addons/account_payment/models/account_payment.py +++ b/addons/account_payment/models/account_payment.py @@ -18,7 +18,7 @@ class AccountPayment(models.Model): string="Saved Payment Token", comodel_name='payment.token', domain="""[ ('id', 'in', suitable_payment_token_ids), ]""", - help="Note that only tokens from acquirers allowing to capture the amount are available.") + help="Note that only tokens from providers allowing to capture the amount are available.") amount_available_for_refund = fields.Monetary(compute='_compute_amount_available_for_refund') # == Display purpose fields == @@ -48,7 +48,7 @@ class AccountPayment(models.Model): def _compute_amount_available_for_refund(self): for payment in self: tx_sudo = payment.payment_transaction_id.sudo() - if tx_sudo.acquirer_id.support_refund and tx_sudo.operation != 'refund': + if tx_sudo.provider_id.support_refund and tx_sudo.operation != 'refund': # Only consider refund transactions that are confirmed by summing the amounts of # payments linked to such refund transactions. Indeed, should a refund transaction # be stuck forever in a transient state (due to webhook failure, for example), the @@ -71,9 +71,9 @@ class AccountPayment(models.Model): if payment.use_electronic_payment_method: payment.suitable_payment_token_ids = self.env['payment.token'].sudo().search([ ('company_id', '=', payment.company_id.id), - ('acquirer_id.capture_manually', '=', False), + ('provider_id.capture_manually', '=', False), ('partner_id', 'in', related_partner_ids.ids), - ('acquirer_id', '=', payment.payment_method_line_id.payment_acquirer_id.id), + ('provider_id', '=', payment.payment_method_line_id.payment_provider_id.id), ]) else: payment.suitable_payment_token_ids = [Command.clear()] @@ -82,8 +82,8 @@ class AccountPayment(models.Model): def _compute_use_electronic_payment_method(self): for payment in self: # Get a list of all electronic payment method codes. - # These codes are comprised of 'electronic' and the providers of each payment acquirer. - codes = [key for key in dict(self.env['payment.acquirer']._fields['provider']._description_selection(self.env))] + # These codes are comprised of 'electronic' and the providers of each payment provider. + codes = [key for key in dict(self.env['payment.provider']._fields['code']._description_selection(self.env))] payment.use_electronic_payment_method = payment.payment_method_code in codes def _compute_refunds_count(self): @@ -103,7 +103,7 @@ class AccountPayment(models.Model): @api.onchange('partner_id', 'payment_method_line_id', 'journal_id') def _onchange_set_payment_token_id(self): - codes = [key for key in dict(self.env['payment.acquirer']._fields['provider']._description_selection(self.env))] + codes = [key for key in dict(self.env['payment.provider']._fields['code']._description_selection(self.env))] if not (self.payment_method_code in codes and self.partner_id and self.journal_id): self.payment_token_id = False return @@ -117,20 +117,20 @@ class AccountPayment(models.Model): self.payment_token_id = self.env['payment.token'].sudo().search([ ('company_id', '=', self.company_id.id), ('partner_id', 'in', related_partner_ids.ids), - ('acquirer_id.capture_manually', '=', False), - ('acquirer_id', '=', self.payment_method_line_id.payment_acquirer_id.id), + ('provider_id.capture_manually', '=', False), + ('provider_id', '=', self.payment_method_line_id.payment_provider_id.id), ], limit=1) #=== ACTION METHODS ===# def action_post(self): # Post the payments "normally" if no transactions are needed. - # If not, let the acquirer update the state. + # If not, let the provider update the state. payments_need_tx = self.filtered( lambda p: p.payment_token_id and not p.payment_transaction_id ) - # creating the transaction require to access data on payment acquirers, not always accessible to users + # creating the transaction require to access data on payment providers, not always accessible to users # able to create payments transactions = payments_need_tx.sudo()._create_payment_transaction() @@ -203,7 +203,7 @@ class AccountPayment(models.Model): def _prepare_payment_transaction_vals(self, **extra_create_values): self.ensure_one() return { - 'acquirer_id': self.payment_token_id.acquirer_id.id, + 'provider_id': self.payment_token_id.provider_id.id, 'reference': self.ref, 'amount': self.amount, 'currency_id': self.currency_id.id, diff --git a/addons/account_payment/models/account_payment_method.py b/addons/account_payment/models/account_payment_method.py index b6f35aefe8a..a269cc95c60 100644 --- a/addons/account_payment/models/account_payment_method.py +++ b/addons/account_payment/models/account_payment_method.py @@ -10,10 +10,10 @@ class AccountPaymentMethod(models.Model): @api.model def _get_payment_method_information(self): res = super()._get_payment_method_information() - for provider, _desc in self.env['payment.acquirer']._fields['provider'].selection: - if provider in ('none', 'transfer'): + for code, _desc in self.env['payment.provider']._fields['code'].selection: + if code in ('none', 'transfer'): continue - res[provider] = { + res[code] = { 'mode': 'unique', 'domain': [('type', '=', 'bank')], } diff --git a/addons/account_payment/models/account_payment_method_line.py b/addons/account_payment/models/account_payment_method_line.py index 1f17edcafe9..b141bc10365 100644 --- a/addons/account_payment/models/account_payment_method_line.py +++ b/addons/account_payment/models/account_payment_method_line.py @@ -8,35 +8,35 @@ from odoo.osv import expression class AccountPaymentMethodLine(models.Model): _inherit = "account.payment.method.line" - payment_acquirer_id = fields.Many2one( - comodel_name='payment.acquirer', - compute='_compute_payment_acquirer_id', + payment_provider_id = fields.Many2one( + comodel_name='payment.provider', + compute='_compute_payment_provider_id', store=True ) - payment_acquirer_state = fields.Selection( - related='payment_acquirer_id.state' + payment_provider_state = fields.Selection( + related='payment_provider_id.state' ) @api.depends('payment_method_id') - def _compute_payment_acquirer_id(self): - acquirers = self.env['payment.acquirer'].sudo().search([ - ('provider', 'in', self.mapped('code')), + def _compute_payment_provider_id(self): + providers = self.env['payment.provider'].sudo().search([ + ('code', 'in', self.mapped('code')), ('company_id', 'in', self.journal_id.company_id.ids), ]) - # Make sure to pick the active acquirer, if any. - acquirers_map = dict() - for acquirer in acquirers: - current_value = acquirers_map.get((acquirer.provider, acquirer.company_id), False) + # Make sure to pick the active provider, if any. + providers_map = dict() + for provider in providers: + current_value = providers_map.get((provider.code, provider.company_id), False) if current_value and current_value.state != 'disabled': continue - acquirers_map[(acquirer.provider, acquirer.company_id)] = acquirer + providers_map[(provider.code, provider.company_id)] = provider for line in self: code = line.payment_method_id.code company = line.journal_id.company_id - line.payment_acquirer_id = acquirers_map.get((code, company), False) + line.payment_provider_id = providers_map.get((code, company), False) @api.model def _get_payment_method_domain(self, code): @@ -46,19 +46,19 @@ class AccountPaymentMethodLine(models.Model): unique = information.get('mode') == 'unique' if unique: - company_ids = self.env['payment.acquirer'].sudo().search([('provider', '=', code)]).mapped('company_id') + company_ids = self.env['payment.provider'].sudo().search([('code', '=', code)]).mapped('company_id') if company_ids: domain = expression.AND([domain, [('company_id', 'in', company_ids.ids)]]) return domain - def action_open_acquirer_form(self): + def action_open_provider_form(self): self.ensure_one() return { 'type': 'ir.actions.act_window', - 'name': _('Acquirer'), + 'name': _('Provider'), 'view_mode': 'form', - 'res_model': 'payment.acquirer', + 'res_model': 'payment.provider', 'target': 'current', - 'res_id': self.payment_acquirer_id.id + 'res_id': self.payment_provider_id.id } diff --git a/addons/account_payment/models/payment_acquirer.py b/addons/account_payment/models/payment_provider.py similarity index 57% rename from addons/account_payment/models/payment_acquirer.py rename to addons/account_payment/models/payment_provider.py index 11031b7545c..9416db46380 100644 --- a/addons/account_payment/models/payment_acquirer.py +++ b/addons/account_payment/models/payment_provider.py @@ -3,8 +3,8 @@ from odoo import api, fields, models -class PaymentAcquirer(models.Model): - _inherit = 'payment.acquirer' +class Paymentprovider(models.Model): + _inherit = 'payment.provider' journal_id = fields.Many2one( string="Payment Journal", @@ -17,74 +17,74 @@ class PaymentAcquirer(models.Model): #=== COMPUTE METHODS ===# - @api.depends('provider') + @api.depends('code') def _compute_journal_id(self): - for acquirer in self: + for provider in self: payment_method = self.env['account.payment.method.line'].search([ - ('journal_id.company_id', '=', acquirer.company_id.id), - ('code', '=', acquirer.provider) + ('journal_id.company_id', '=', provider.company_id.id), + ('code', '=', provider.code) ], limit=1) if payment_method: - acquirer.journal_id = payment_method.journal_id + provider.journal_id = payment_method.journal_id else: - acquirer.journal_id = False + provider.journal_id = False def _inverse_journal_id(self): - for acquirer in self: + for provider in self: payment_method_line = self.env['account.payment.method.line'].search([ - ('journal_id.company_id', '=', acquirer.company_id.id), - ('code', '=', acquirer.provider), + ('journal_id.company_id', '=', provider.company_id.id), + ('code', '=', provider.code), ], limit=1) - if acquirer.journal_id: + if provider.journal_id: if not payment_method_line: - default_payment_method_id = acquirer._get_default_payment_method_id( - acquirer.provider + default_payment_method_id = provider._get_default_payment_method_id( + provider.code ) existing_payment_method_line = self.env['account.payment.method.line'].search([ ('payment_method_id', '=', default_payment_method_id), - ('journal_id', '=', acquirer.journal_id.id), + ('journal_id', '=', provider.journal_id.id), ], limit=1) if not existing_payment_method_line: self.env['account.payment.method.line'].create({ 'payment_method_id': default_payment_method_id, - 'journal_id': acquirer.journal_id.id, + 'journal_id': provider.journal_id.id, }) else: - payment_method_line.journal_id = acquirer.journal_id + payment_method_line.journal_id = provider.journal_id elif payment_method_line: payment_method_line.unlink() @api.model - def _get_default_payment_method_id(self, provider): - provider_payment_method = self._get_provider_payment_method(provider) + def _get_default_payment_method_id(self, code): + provider_payment_method = self._get_provider_payment_method(code) if provider_payment_method: return provider_payment_method.id return self.env.ref('account.account_payment_method_manual_in').id @api.model - def _get_provider_payment_method(self, provider): - return self.env['account.payment.method'].search([('code', '=', provider)], limit=1) + def _get_provider_payment_method(self, code): + return self.env['account.payment.method'].search([('code', '=', code)], limit=1) #=== BUSINESS METHODS ===# @api.model - def _setup_provider(self, provider_code): + def _setup_provider(self, code): """ Override of `payment` to create the payment method of the provider. """ - super()._setup_provider(provider_code) - self._setup_payment_method(provider_code) + super()._setup_provider(code) + self._setup_payment_method(code) @api.model - def _setup_payment_method(self, provider): - if provider not in ('none', 'transfer') and not self._get_provider_payment_method(provider): - providers_description = dict(self._fields['provider']._description_selection(self.env)) + def _setup_payment_method(self, code): + if code not in ('none', 'transfer') and not self._get_provider_payment_method(code): + providers_description = dict(self._fields['code']._description_selection(self.env)) self.env['account.payment.method'].create({ - 'name': providers_description[provider], - 'code': provider, + 'name': providers_description[code], + 'code': code, 'payment_type': 'inbound', }) @api.model - def _remove_provider(self, provider): + def _remove_provider(self, code): """ Override of `payment` to delete the payment method of the provider. """ - super()._remove_provider(provider) - self._get_provider_payment_method(provider).unlink() + super()._remove_provider(code) + self._get_provider_payment_method(code).unlink() diff --git a/addons/account_payment/models/payment_transaction.py b/addons/account_payment/models/payment_transaction.py index e06d935b080..1018cb61e95 100644 --- a/addons/account_payment/models/payment_transaction.py +++ b/addons/account_payment/models/payment_transaction.py @@ -64,7 +64,7 @@ class PaymentTransaction(models.Model): #=== BUSINESS METHODS - PAYMENT FLOW ===# @api.model - def _compute_reference_prefix(self, provider, separator, **values): + def _compute_reference_prefix(self, provider_code, separator, **values): """ Compute the reference prefix from the transaction values. If the `values` parameter has an entry with 'invoice_ids' as key and a list of (4, id, O) or @@ -73,7 +73,7 @@ class PaymentTransaction(models.Model): Note: This method should be called in sudo mode to give access to documents (INV, SO, ...). - :param str provider: The provider of the acquirer handling the transaction + :param str provider_code: The code of the provider handling the transaction :param str separator: The custom separator used to separate data references :param dict values: The transaction values used to compute the reference prefix. It should have the structure {'invoice_ids': [(X2M command), ...], ...}. @@ -87,7 +87,7 @@ class PaymentTransaction(models.Model): invoices = self.env['account.move'].browse(invoice_ids).exists() if len(invoices) == len(invoice_ids): # All ids are valid return separator.join(invoices.mapped('name')) - return super()._compute_reference_prefix(provider, separator, **values) + return super()._compute_reference_prefix(provider_code, separator, **values) def _set_canceled(self, state_message=None): """ Update the transactions' state to 'cancel'. @@ -134,16 +134,16 @@ class PaymentTransaction(models.Model): """ self.ensure_one() - payment_method_line = self.acquirer_id.journal_id.inbound_payment_method_line_ids\ - .filtered(lambda l: l.code == self.provider) + payment_method_line = self.provider_id.journal_id.inbound_payment_method_line_ids\ + .filtered(lambda l: l.code == self.provider_code) payment_values = { 'amount': abs(self.amount), # A tx may have a negative amount, but a payment must >= 0 'payment_type': 'inbound' if self.amount > 0 else 'outbound', 'currency_id': self.currency_id.id, 'partner_id': self.partner_id.commercial_partner_id.id, 'partner_type': 'customer', - 'journal_id': self.acquirer_id.journal_id.id, - 'company_id': self.acquirer_id.company_id.id, + 'journal_id': self.provider_id.journal_id.id, + 'company_id': self.provider_id.company_id.id, 'payment_method_line_id': payment_method_line.id, 'payment_token_id': self.token_id.id, 'payment_transaction_id': self.id, diff --git a/addons/account_payment/static/src/js/payment_form.js b/addons/account_payment/static/src/js/payment_form.js index 1680562384b..9fb04c83439 100644 --- a/addons/account_payment/static/src/js/payment_form.js +++ b/addons/account_payment/static/src/js/payment_form.js @@ -15,12 +15,12 @@ odoo.define('account_payment.payment_form', require => { * * @override method from payment.payment_form_mixin * @private - * @param {string} provider - The provider of the selected payment option's acquirer. + * @param {string} code - The provider code of the selected payment option. * @param {number} paymentOptionId - The id of the selected payment option. * @param {string} flow - The online payment flow of the selected payment option. * @return {object} The extended transaction route params. */ - _prepareTransactionRouteParams: function (provider, paymentOptionId, flow) { + _prepareTransactionRouteParams: function (code, paymentOptionId, flow) { const transactionRouteParams = this._super(...arguments); return { ...transactionRouteParams, diff --git a/addons/account_payment/tests/common.py b/addons/account_payment/tests/common.py index 3529aa7e274..0e44e646c71 100644 --- a/addons/account_payment/tests/common.py +++ b/addons/account_payment/tests/common.py @@ -28,7 +28,7 @@ class AccountPaymentCommon(PaymentCommon, AccountTestInvoicingCommon): 'payment_type': 'inbound' }) - cls.dummy_acquirer.journal_id = cls.company_data['default_journal_bank'].id, + cls.dummy_provider.journal_id = cls.company_data['default_journal_bank'].id, cls.account = cls.company.account_journal_payment_credit_account_id cls.invoice = cls.env['account.move'].create({ @@ -60,23 +60,23 @@ class AccountPaymentCommon(PaymentCommon, AccountTestInvoicingCommon): #=== Utils ===# @classmethod - def _prepare_acquirer(cls, provider='none', company=None, update_values=None): - """ Override of `payment` to prepare and return the first acquirer matching the given + def _prepare_provider(cls, provider_code='none', company=None, update_values=None): + """ Override of `payment` to prepare and return the first provider matching the given provider and company. - If no acquirer is found in the given company, we duplicate the one from the base company. - All other acquirers belonging to the same company are disabled to avoid any interferences. + If no provider is found in the given company, we duplicate the one from the base company. + All other providers belonging to the same company are disabled to avoid any interferences. - :param str provider: The provider of the acquirer to prepare. - :param recordset company: The company of the acquirer to prepare, as a `res.company` record. - :param dict update_values: The values used to update the acquirer. - :return: The acquirer to prepare, if found. - :rtype: recordset of `payment.acquirer` + :param str provider_code: The code of the provider to prepare. + :param recordset company: The company of the provider to prepare, as a `res.company` record. + :param dict update_values: The values used to update the provider. + :return: The provider to prepare, if found. + :rtype: recordset of `payment.provider` """ - acquirer = super()._prepare_acquirer(provider, company, update_values) - if not acquirer.journal_id: - acquirer.journal_id = cls.env['account.journal'].search( - [('company_id', '=', acquirer.company_id.id), ('type', '=', 'bank')], + provider = super()._prepare_provider(provider_code, company, update_values) + if not provider.journal_id: + provider.journal_id = cls.env['account.journal'].search( + [('company_id', '=', provider.company_id.id), ('type', '=', 'bank')], limit=1, ) - return acquirer + return provider diff --git a/addons/account_payment/tests/test_account_payment.py b/addons/account_payment/tests/test_account_payment.py index 1734eb2fd3a..4b8fc12a3b7 100644 --- a/addons/account_payment/tests/test_account_payment.py +++ b/addons/account_payment/tests/test_account_payment.py @@ -11,18 +11,18 @@ from odoo.addons.account_payment.tests.common import AccountPaymentCommon class TestAccountPayment(AccountPaymentCommon): def test_no_amount_available_for_refund_when_not_supported(self): - self.acquirer.support_refund = False + self.provider.support_refund = False tx = self._create_transaction('redirect', state='done') tx._reconcile_after_done() # Create the payment self.assertEqual( tx.payment_id.amount_available_for_refund, 0, - msg="The value of `amount_available_for_refund` should be 0 when the acquirer doesn't " + msg="The value of `amount_available_for_refund` should be 0 when the provider doesn't " "support refunds." ) def test_full_amount_available_for_refund_when_not_yet_refunded(self): - self.acquirer.support_refund = 'full_only' # Should simply not be False + self.provider.support_refund = 'full_only' # Should simply not be False tx = self._create_transaction('redirect', state='done') tx._reconcile_after_done() # Create the payment self.assertAlmostEqual( @@ -34,7 +34,7 @@ class TestAccountPayment(AccountPaymentCommon): ) def test_full_amount_available_for_refund_when_refunds_are_pending(self): - self.acquirer.write({ + self.provider.write({ 'support_refund': 'full_only', # Should simply not be False 'support_manual_capture': True, # To create transaction in the 'authorized' state }) @@ -58,7 +58,7 @@ class TestAccountPayment(AccountPaymentCommon): ) def test_no_amount_available_for_refund_when_fully_refunded(self): - self.acquirer.support_refund = 'full_only' # Should simply not be False + self.provider.support_refund = 'full_only' # Should simply not be False tx = self._create_transaction('redirect', state='done') tx._reconcile_after_done() # Create the payment self._create_transaction( @@ -77,7 +77,7 @@ class TestAccountPayment(AccountPaymentCommon): ) def test_no_full_amount_available_for_refund_when_partially_refunded(self): - self.acquirer.support_refund = 'partial' + self.provider.support_refund = 'partial' tx = self._create_transaction('redirect', state='done') tx._reconcile_after_done() # Create the payment self._create_transaction( @@ -98,7 +98,7 @@ class TestAccountPayment(AccountPaymentCommon): ) def test_refunds_count(self): - self.acquirer.support_refund = 'full_only' # Should simply not be False + self.provider.support_refund = 'full_only' # Should simply not be False tx = self._create_transaction('redirect', state='done') tx._reconcile_after_done() # Create the payment for reference_index, operation in enumerate( @@ -127,7 +127,7 @@ class TestAccountPayment(AccountPaymentCommon): 'date': '2019-01-01', 'currency_id': self.currency.id, 'partner_id': self.partner.id, - 'journal_id': self.acquirer.journal_id.id, + 'journal_id': self.provider.journal_id.id, 'payment_method_line_id': self.inbound_payment_method_line.id, }) payment_with_token = payment_without_token.copy() diff --git a/addons/account_payment/tests/test_payment_flows.py b/addons/account_payment/tests/test_payment_flows.py index b5c76706d1d..329cb26d8f7 100644 --- a/addons/account_payment/tests/test_payment_flows.py +++ b/addons/account_payment/tests/test_payment_flows.py @@ -34,7 +34,7 @@ class TestFlows(AccountPaymentCommon, PaymentHttpCommon): } route_values.update({ 'flow': 'direct', - 'payment_option_id': self.acquirer.id, + 'payment_option_id': self.provider.id, 'tokenization_requested': False, }) with mute_logger('odoo.addons.payment.models.payment_transaction'): diff --git a/addons/account_payment/views/account_journal_views.xml b/addons/account_payment/views/account_journal_views.xml index f110be226c4..50013f77036 100644 --- a/addons/account_payment/views/account_journal_views.xml +++ b/addons/account_payment/views/account_journal_views.xml @@ -7,17 +7,17 @@ - - -