[IMP] iap, various: implement _neutralize method
An overridable model method was added in a previous commit in order to neutralize a database. This commit adds the implementation of this method on the `iap.account` model. A _get_iap_config_paremeters method is also added on this model. Each iap service must override this method to extend the list of `ir.config_parameter` that need to be neutralized. Part-of: odoo/odoo#67825
This commit is contained in:
@@ -118,3 +118,26 @@ class IapAccount(models.Model):
|
||||
credit = -1
|
||||
|
||||
return credit
|
||||
|
||||
def _neutralize(self):
|
||||
super()._neutralize()
|
||||
self.flush()
|
||||
self.invalidate_cache()
|
||||
|
||||
self.env.cr.execute("""
|
||||
INSERT INTO ir_config_parameter(key, value)
|
||||
VALUES ('iap.endpoint', 'https://iap-sandbox.odoo.com')
|
||||
ON CONFLICT (key) DO UPDATE SET value = 'https://iap-sandbox.odoo.com'
|
||||
""")
|
||||
|
||||
iap_service_endpoints = self._get_iap_config_parameters()
|
||||
if iap_service_endpoints:
|
||||
self.env.cr.execute("""
|
||||
UPDATE ir_config_parameter
|
||||
SET value = 'https://iap-services-test.odoo.com'
|
||||
WHERE key IN %s
|
||||
""", [tuple(iap_service_endpoints)])
|
||||
|
||||
def _get_iap_config_parameters(self):
|
||||
"""override this method to extend the list with each parameter"""
|
||||
return []
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import iap_account
|
||||
from . import iap_autocomplete_api
|
||||
from . import ir_http
|
||||
from . import res_partner
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class IapAccount(models.Model):
|
||||
_inherit = 'iap.account'
|
||||
|
||||
def _get_iap_config_parameters(self):
|
||||
return super()._get_iap_config_parameters() + ['iap.partner_autocomplete.endpoint']
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_neutralize
|
||||
from . import test_res_company
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestPartnerAutocompleteNeutralize(TransactionCase):
|
||||
|
||||
def test_partner_autocomplete_neutralize(self):
|
||||
iap_key = 'iap.partner_autocomplete.endpoint'
|
||||
self.env['ir.config_parameter'].create({
|
||||
'key': iap_key,
|
||||
'value': 'fake test iap partner autocomplete endpoint'
|
||||
})
|
||||
|
||||
self.env['iap.account']._neutralize()
|
||||
self.assertEqual(self.env['ir.config_parameter'].get_param(iap_key), 'https://iap-services-test.odoo.com')
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import iap_account
|
||||
from . import ir_actions
|
||||
from . import ir_model
|
||||
from . import mail_followers
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class IapAccount(models.Model):
|
||||
_inherit = 'iap.account'
|
||||
|
||||
def _get_iap_config_parameters(self):
|
||||
return super()._get_iap_config_parameters() + ['sms.endpoint']
|
||||
@@ -2,4 +2,5 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import common
|
||||
from . import test_neutralize
|
||||
from . import test_sms_template
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestSmsNeutralize(TransactionCase):
|
||||
|
||||
def test_sms_neutralize(self):
|
||||
sms_key = 'sms.endpoint'
|
||||
self.env['ir.config_parameter'].create({
|
||||
'key': sms_key,
|
||||
'value': 'fake test sms endpoint'
|
||||
})
|
||||
|
||||
self.env['iap.account']._neutralize()
|
||||
self.assertEqual(self.env['ir.config_parameter'].get_param(sms_key), 'https://iap-services-test.odoo.com')
|
||||
@@ -1,10 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import res_company
|
||||
from . import res_partner
|
||||
from . import res_config_settings
|
||||
from . import mail_notification
|
||||
from . import snailmail_letter
|
||||
from . import iap_account
|
||||
from . import ir_actions_report
|
||||
from . import ir_qweb_fields
|
||||
from . import mail_message
|
||||
from . import mail_notification
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import res_partner
|
||||
from . import snailmail_letter
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class IapAccount(models.Model):
|
||||
_inherit = 'iap.account'
|
||||
|
||||
def _get_iap_config_parameters(self):
|
||||
return super()._get_iap_config_parameters() + ['snailmail.endpoint']
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_neutralize
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestSnailMailNeutralize(TransactionCase):
|
||||
|
||||
def test_snailmail_neutralize(self):
|
||||
key = 'snailmail.endpoint'
|
||||
self.env['ir.config_parameter'].create({
|
||||
'key': key,
|
||||
'value': 'fake test snailmail endpoint'
|
||||
})
|
||||
|
||||
self.env['iap.account']._neutralize()
|
||||
self.assertEqual(self.env['ir.config_parameter'].get_param(key), 'https://iap-services-test.odoo.com')
|
||||
@@ -4,4 +4,5 @@
|
||||
from . import crm_lead
|
||||
from . import crm_reveal_rule
|
||||
from . import crm_reveal_view
|
||||
from . import iap_account
|
||||
from . import ir_http
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class IapAccount(models.Model):
|
||||
_inherit = 'iap.account'
|
||||
|
||||
def _get_iap_config_parameters(self):
|
||||
return super()._get_iap_config_parameters() + ['reveal.endpoint']
|
||||
@@ -2,3 +2,4 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_lead_reveal
|
||||
from . import test_neutralize
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestIapLeadWebsiteNeutralize(TransactionCase):
|
||||
|
||||
def test_iap_lead_website_neutralize(self):
|
||||
ICP = self.env['ir.config_parameter']
|
||||
key = 'reveal.endpoint'
|
||||
ICP.set_param(key, 'Fake test reveal endpoint')
|
||||
|
||||
self.env['iap.account']._neutralize()
|
||||
self.assertEqual(ICP.get_param(key), 'https://iap-services-test.odoo.com')
|
||||
Reference in New Issue
Block a user