[FIX] microsoft_calendar: keep sync_stopped status

Before this commit, if you stopped sync with microsoft, and
refereshed the calendar, it would change the button back to
synced status.

opw-3382311

closes odoo/odoo#126706

X-original-commit: 1e0e4e8a792513ddecc27ab42d76be0c5873c8bc
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
pedrambiria
2023-06-28 19:08:54 +02:00
committed by Pedram (PEBR)
parent a5e9d411ad
commit dc91f30008
2 changed files with 33 additions and 0 deletions
@@ -41,6 +41,13 @@ class MicrosoftCalendarController(http.Controller):
}
# If App authorized, and user access accepted, We launch the synchronization
need_refresh = request.env.user.sudo()._sync_microsoft_calendar()
# If synchronization has been stopped
if not need_refresh and request.env.user.microsoft_synchronization_stopped:
return {
"status": "sync_stopped",
"url": ''
}
return {
"status": "need_refresh" if need_refresh else "no_new_event_from_microsoft",
"url": ''
@@ -6,6 +6,9 @@ from odoo.addons.microsoft_calendar.utils.microsoft_event import MicrosoftEvent
from odoo.addons.microsoft_calendar.models.res_users import User
from odoo.addons.microsoft_calendar.utils.event_id_storage import combine_ids
from odoo.addons.microsoft_calendar.tests.common import TestCommon, mock_get_token, _modified_date_in_the_future, patch_api
from odoo.tests import users
import json
@patch.object(User, '_get_microsoft_calendar_token', mock_get_token)
@@ -154,3 +157,26 @@ class TestAnswerEvents(TestCommon):
('partner_id', '=', self.attendee_user.partner_id.id)
])
self.assertEqual(attendee.state, "declined")
@users('admin')
def test_sync_data_with_stopped_sync(self):
self.authenticate(self.env.user.login, self.env.user.login)
self.env['ir.config_parameter'].sudo().set_param(
'microsoft_calendar_client_id',
'test_microsoft_calendar_client_id'
)
self.env.user.sudo().microsoft_calendar_rtoken = 'test_microsoft_calendar_rtoken'
self.env.user.stop_microsoft_synchronization()
payload = {
'params': {
'model': 'calendar.event'
}
}
# Sending the request to the sync_data
response = self.url_open(
'/microsoft_calendar/sync_data',
data=json.dumps(payload),
headers={'Content-Type': 'application/json'}
).json()
# the status must be sync_stopped
self.assertEqual(response['result']['status'], 'sync_stopped')