This commit fixes two bugs with payment_test: First: Before, payment test would create token without a name. When you tried to pay your subscription on the portal with these, the following error would occurs: ``` Error to render compiling AST AttributeError: 'bool' object has no attribute 'replace' Template: sale_subscription.subscription Path: /t/t[2]/div/t/t[2]/ul/li[1]/div[3]/t Node: <t t-esc="account.payment_token_id.short_name"/> The error occured while rendering the template sale_subscription.subscription and evaluating the following expression: <t t-esc="account.payment_token_id.short_name"/> ``` This commit add a distinct name for these token to avoid errors and confusion. Secondly, Before this commit when user tried to make a payment with the payment_test acquirer, the callback method was never called. This had an impact on module where the callback method is used (mostly subscription). closes odoo/odoo#61888 Taskid: 2367508 X-original-commit: a0e012f1578b6257816dfb1a508781d054b95198 Related: odoo/enterprise#14814 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
# coding: utf-8
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from datetime import datetime
|
|
from uuid import uuid4
|
|
|
|
from odoo import api, exceptions, fields, models, _
|
|
|
|
|
|
class PaymentAcquirerTest(models.Model):
|
|
_inherit = 'payment.acquirer'
|
|
|
|
provider = fields.Selection(selection_add=[
|
|
('test', 'Test')
|
|
], ondelete={'test': 'set default'})
|
|
|
|
@api.model
|
|
def create(self, values):
|
|
if values.get('provider') == 'test' and 'state' in values and values.get('state') not in ('test', 'disabled'):
|
|
raise exceptions.UserError(_('This acquirer should not be used for other purposes than testing.'))
|
|
return super(PaymentAcquirerTest, self).create(values)
|
|
|
|
def write(self, values):
|
|
if any(rec.provider == 'test' for rec in self) and 'state' in values and values.get('state') not in ('test', 'disabled'):
|
|
raise exceptions.UserError(_('This acquirer should not be used for other purposes than testing.'))
|
|
return super(PaymentAcquirerTest, self).write(values)
|
|
|
|
@api.model
|
|
def test_s2s_form_process(self, data):
|
|
""" Return a minimal token to allow proceeding to transaction creation. """
|
|
ref = uuid4()
|
|
payment_token = self.env['payment.token'].sudo().create({
|
|
'name': 'Test - %s' % str(ref)[:4],
|
|
'acquirer_ref': ref,
|
|
'acquirer_id': int(data['acquirer_id']),
|
|
'partner_id': int(data['partner_id']),
|
|
'name': 'XXXXXXXXXXXX%s - %s' % (data['cc_number'][-4:], data['cc_holder_name'])
|
|
})
|
|
return payment_token
|
|
|
|
|
|
class PaymentTransactionTest(models.Model):
|
|
_inherit = 'payment.transaction'
|
|
|
|
def test_create(self, values):
|
|
"""Automatically set the transaction as successful upon creation. """
|
|
return {'date': datetime.now(), 'state': 'done'}
|
|
|
|
def test_s2s_do_transaction(self, **kwargs):
|
|
self.execute_callback()
|