Files
odoo_source/addons/payment_test/models/payment_acquirer.py
T
Adrian Torres 1daf8eb127 [FIX] *: set ondelete policy of required Selection fields
With this commit, Selection fields with `required=True` which are
extended via `selection_add` are given proper ondelete policies to
ensure the cleanup of records containing these extended options during
uninstall of the extending module.

This commit also cleans up leftover uninstall hooks that were being used
to handle the same set of problems prior to the ondelete mechanism being
implemented for Selection fields.

closes odoo/odoo#46325

Related: odoo/enterprise#9117
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-03-30 13:42:04 +00:00

45 lines
1.7 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. """
payment_token = self.env['payment.token'].sudo().create({
'acquirer_ref': uuid4(),
'acquirer_id': int(data['acquirer_id']),
'partner_id': int(data['partner_id'])
})
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'}