[12.0][MIG] base_user_role_history - migration from 9.0 to 12.0

This commit is contained in:
Benoit Aimont
2019-10-01 14:41:31 +02:00
parent f91a25e016
commit d1822fcab8
7 changed files with 40 additions and 28 deletions

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -6,7 +5,7 @@
'name': 'Base User Role History',
'summary': """
This module allows to track the changes on users roles.""",
'version': '9.0.1.0.0',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV, '
'Odoo Community Association (OCA)',

View File

@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models
from odoo import api, fields, models
class BaseUserRoleLineHistory(models.Model):

View File

@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models, _
from odoo import api, fields, models, _
class ResUsers(models.Model):
@@ -18,8 +17,8 @@ class ResUsers(models.Model):
return {
'user_id': role_line.user_id.id,
'role_id': role_line.role_id.id,
'date_from': fields.Date.from_string(role_line.date_from),
'date_to': fields.Date.from_string(role_line.date_to),
'date_from': role_line.date_from,
'date_to': role_line.date_to,
'is_enabled': role_line.is_enabled,
}
@@ -33,9 +32,10 @@ class ResUsers(models.Model):
self._prepare_role_line_history_dict(role_line)
return role_line_values_by_user
@api.model
def create(self, vals):
res = super(ResUsers, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
for vals in vals_list:
if 'role_line_ids' not in vals:
return res
new_role_line_values_by_user = res._get_role_line_values_by_user()
@@ -49,9 +49,9 @@ class ResUsers(models.Model):
@api.multi
def write(self, vals):
if 'role_line_ids' not in vals:
return super(ResUsers, self).write(vals)
return super().write(vals)
old_role_line_values_by_user = self._get_role_line_values_by_user()
res = super(ResUsers, self).write(vals)
res = super().write(vals)
new_role_line_values_by_user = self._get_role_line_values_by_user()
self.env['base.user.role.line.history'].create_from_vals(
old_role_line_values_by_user,

View File

@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).µ
from datetime import date, timedelta
from openerp import fields
from openerp.tests.common import SavepointCase
from odoo.tests.common import SavepointCase
class TestBaseUserRoleHistory(SavepointCase):
@@ -83,12 +81,12 @@ class TestBaseUserRoleHistory(SavepointCase):
self.assertEqual(history_lines_2.old_role_id, self.role_01)
self.assertEqual(history_lines_2.new_role_id, self.role_01)
self.assertFalse(history_lines_2.old_date_from)
self.assertEqual(history_lines_2.new_date_from,
fields.Date.to_string(date.today()))
self.assertEqual(history_lines_2.new_date_from, date.today())
self.assertFalse(history_lines_2.old_date_to)
self.assertEqual(history_lines_2.new_date_to,
fields.Date.to_string(
date.today() + timedelta(days=5)))
self.assertEqual(
history_lines_2.new_date_to,
date.today() + timedelta(days=5)
)
self.user_01.write({
'role_line_ids': [(1, self.user_01.role_line_ids[0].id, {})]
})
@@ -110,12 +108,15 @@ class TestBaseUserRoleHistory(SavepointCase):
self.assertEqual(history_lines_4.performed_action, 'unlink')
self.assertEqual(history_lines_4.old_role_id, self.role_01)
self.assertFalse(history_lines_4.new_role_id)
self.assertEqual(history_lines_4.old_date_from,
fields.Date.to_string(date.today()))
self.assertEqual(
history_lines_4.old_date_from,
date.today()
)
self.assertFalse(history_lines_4.new_date_from)
self.assertEqual(history_lines_4.old_date_to,
fields.Date.to_string(
date.today() + timedelta(days=5)))
self.assertEqual(
history_lines_4.old_date_to,
date.today() + timedelta(days=5)
)
self.assertFalse(history_lines_4.new_date_to)
def test_create_role_lines_on_new_user(self):

View File

@@ -0,0 +1,6 @@
This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins.
This directory caches those eggs to prevent repeated downloads.
However, it is safe to delete this directory.

View File

@@ -0,0 +1 @@
../../../../base_user_role_history

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)