mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 23:32:03 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
|
|
@ -1,48 +1,36 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import logging
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from lxml import objectify
|
||||
|
||||
from odoo.fields import Command
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.fields import Command, Domain
|
||||
from odoo.tools.misc import hmac as hmac_tool
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PaymentCommon(TransactionCase):
|
||||
class PaymentCommon(BaseCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
cls.currency_euro = cls._prepare_currency('EUR')
|
||||
cls.currency_usd = cls._prepare_currency('USD')
|
||||
cls.currency_euro = cls._enable_currency('EUR')
|
||||
cls.currency_usd = cls._enable_currency('USD')
|
||||
|
||||
cls.country_belgium = cls.env.ref('base.be')
|
||||
cls.country_france = cls.env.ref('base.fr')
|
||||
cls.europe = cls.env.ref('base.europe')
|
||||
cls.country_belgium = cls.quick_ref('base.be')
|
||||
cls.country_france = cls.quick_ref('base.fr')
|
||||
cls.europe = cls.quick_ref('base.europe')
|
||||
|
||||
cls.group_user = cls.env.ref('base.group_user')
|
||||
cls.group_portal = cls.env.ref('base.group_portal')
|
||||
cls.group_public = cls.env.ref('base.group_public')
|
||||
|
||||
cls.admin_user = cls.env.ref('base.user_admin')
|
||||
cls.internal_user = cls.env['res.users'].create({
|
||||
'name': 'Internal User (Test)',
|
||||
'login': 'internal',
|
||||
'password': 'internal',
|
||||
'groups_id': [Command.link(cls.group_user.id)]
|
||||
})
|
||||
cls.portal_user = cls.env['res.users'].create({
|
||||
'name': 'Portal User (Test)',
|
||||
'login': 'payment_portal',
|
||||
'password': 'payment_portal',
|
||||
'groups_id': [Command.link(cls.group_portal.id)]
|
||||
})
|
||||
cls.public_user = cls.env.ref('base.public_user')
|
||||
cls.admin_user = cls.quick_ref('base.user_admin')
|
||||
cls.internal_user = cls._create_new_internal_user()
|
||||
cls.portal_user = cls._create_new_portal_user()
|
||||
cls.public_user = cls.quick_ref('base.public_user')
|
||||
|
||||
cls.admin_partner = cls.admin_user.partner_id
|
||||
cls.internal_partner = cls.internal_user.partner_id
|
||||
|
|
@ -72,16 +60,30 @@ class PaymentCommon(TransactionCase):
|
|||
'arch': arch,
|
||||
})
|
||||
|
||||
cls.pm_unknown = cls.quick_ref('payment.payment_method_unknown')
|
||||
cls.dummy_provider = cls.env['payment.provider'].create({
|
||||
'name': "Dummy Provider",
|
||||
'code': 'none',
|
||||
'state': 'test',
|
||||
'is_published': True,
|
||||
'payment_method_ids': [Command.set([cls.pm_unknown.id])],
|
||||
'allow_tokenization': True,
|
||||
'redirect_form_view_id': redirect_form.id,
|
||||
'available_currency_ids': [Command.set(
|
||||
(cls.currency_euro + cls.currency_usd + cls.env.company.currency_id).ids
|
||||
)],
|
||||
})
|
||||
# Activate pm
|
||||
cls.pm_unknown.write({
|
||||
'active': True,
|
||||
'support_tokenization': True,
|
||||
})
|
||||
|
||||
cls.provider = cls.dummy_provider
|
||||
cls.payment_methods = cls.provider.payment_method_ids
|
||||
cls.payment_method = cls.payment_methods[:1]
|
||||
cls.payment_method_id = cls.payment_method.id
|
||||
cls.payment_method_code = cls.payment_method.code
|
||||
cls.amount = 1111.11
|
||||
cls.company = cls.env.company
|
||||
cls.company_id = cls.company.id
|
||||
|
|
@ -91,65 +93,57 @@ class PaymentCommon(TransactionCase):
|
|||
|
||||
account_payment_module = cls.env['ir.module.module']._get('account_payment')
|
||||
cls.account_payment_installed = account_payment_module.state in ('installed', 'to upgrade')
|
||||
cls.enable_reconcile_after_done_patcher = True
|
||||
cls.enable_post_process_patcher = True
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
if self.account_payment_installed and self.enable_reconcile_after_done_patcher:
|
||||
if self.account_payment_installed and self.enable_post_process_patcher:
|
||||
# disable account payment generation if account_payment is installed
|
||||
# because the accounting setup of providers is not managed in this common
|
||||
self.reconcile_after_done_patcher = patch(
|
||||
'odoo.addons.account_payment.models.payment_transaction.PaymentTransaction._reconcile_after_done',
|
||||
self.post_process_patcher = patch(
|
||||
'odoo.addons.account_payment.models.payment_transaction.PaymentTransaction._post_process',
|
||||
)
|
||||
self.startPatcher(self.reconcile_after_done_patcher)
|
||||
self.startPatcher(self.post_process_patcher)
|
||||
|
||||
#=== Utils ===#
|
||||
|
||||
@classmethod
|
||||
def _prepare_currency(cls, currency_code):
|
||||
currency = cls.env['res.currency'].with_context(active_test=False).search(
|
||||
[('name', '=', currency_code.upper())]
|
||||
)
|
||||
currency.action_unarchive()
|
||||
return currency
|
||||
|
||||
@classmethod
|
||||
def _prepare_provider(cls, code='none', company=None, update_values=None):
|
||||
""" Prepare and return the first provider matching the given provider and company.
|
||||
|
||||
If no provider is found in the given company, we duplicate the one from the base company.
|
||||
def _prepare_provider(cls, code, company=None, update_values=None, **kwargs):
|
||||
""" Prepare and return the first active provider matching the given code and company.
|
||||
|
||||
All other providers belonging to the same company are disabled to avoid any interferences.
|
||||
|
||||
:param str 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
|
||||
:param dict kwargs: The keyword arguments passed as-is to the called function.
|
||||
:return: The provider to prepare, if found
|
||||
:rtype: recordset of `payment.provider`
|
||||
"""
|
||||
assert code != 'none', "Code 'none' should not be passed to _prepare_provider"
|
||||
|
||||
company = company or cls.env.company
|
||||
update_values = update_values or {}
|
||||
provider_domain = cls._get_provider_domain(code, **kwargs)
|
||||
|
||||
provider = cls.env['payment.provider'].sudo().search(
|
||||
[('code', '=', code), ('company_id', '=', company.id)], limit=1
|
||||
Domain.AND([provider_domain, [('company_id', '=', company.id)]]), limit=1
|
||||
)
|
||||
if not provider:
|
||||
base_provider = cls.env['payment.provider'].sudo().search(
|
||||
[('code', '=', code)], limit=1
|
||||
)
|
||||
if not base_provider:
|
||||
_logger.error("no payment.provider found for code %s", code)
|
||||
return cls.env['payment.provider']
|
||||
else:
|
||||
provider = base_provider.copy({'company_id': company.id})
|
||||
_logger.error("No payment.provider found for code %s in company %s", code, company.name)
|
||||
return cls.env['payment.provider']
|
||||
|
||||
update_values['state'] = 'test'
|
||||
provider.write(update_values)
|
||||
return provider
|
||||
|
||||
@classmethod
|
||||
def _get_provider_domain(cls, code, **kwargs):
|
||||
return [('code', '=', code)]
|
||||
|
||||
@classmethod
|
||||
def _prepare_user(cls, user, group_xmlid):
|
||||
user.groups_id = [Command.link(cls.env.ref(group_xmlid).id)]
|
||||
user.group_ids = [Command.link(cls.env.ref(group_xmlid).id)]
|
||||
# Flush and invalidate the cache to allow checking access rights.
|
||||
user.flush_recordset()
|
||||
user.invalidate_recordset()
|
||||
|
|
@ -157,6 +151,7 @@ class PaymentCommon(TransactionCase):
|
|||
|
||||
def _create_transaction(self, flow, sudo=True, **values):
|
||||
default_values = {
|
||||
'payment_method_id': self.payment_method_id,
|
||||
'amount': self.amount,
|
||||
'currency_id': self.currency.id,
|
||||
'provider_id': self.provider.id,
|
||||
|
|
@ -168,8 +163,9 @@ class PaymentCommon(TransactionCase):
|
|||
|
||||
def _create_token(self, sudo=True, **values):
|
||||
default_values = {
|
||||
'payment_details': "1234",
|
||||
'provider_id': self.provider.id,
|
||||
'payment_method_id': self.payment_method_id,
|
||||
'payment_details': "1234",
|
||||
'partner_id': self.partner.id,
|
||||
'provider_ref': "provider Ref (TEST)",
|
||||
'active': True,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue