From 8380d182b7b3fae761ee8cc22bea4eb1d13d9d89 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 22 Jun 2017 12:42:48 +0200 Subject: [PATCH] [MIG][10.0][datetime_formatter] Migration Special highlights: - Fixed some license headers. - Adhered to normal addon structure. - Removed `exceptions.py` and use `UserError` instead. - Allow submodules to import some constants from main namespace. The rest is basically a standard migration. --- datetime_formatter/README.rst | 2 +- datetime_formatter/__init__.py | 4 ++-- .../{__openerp__.py => __manifest__.py} | 8 ++++---- datetime_formatter/exceptions.py | 12 ------------ datetime_formatter/models/__init__.py | 3 +++ .../{models.py => models/res_lang.py} | 16 +++++++++------- datetime_formatter/tests/__init__.py | 2 -- datetime_formatter/tests/test_best_matcher.py | 10 +++++----- datetime_formatter/tests/test_formatter.py | 14 +++++++------- 9 files changed, 31 insertions(+), 40 deletions(-) rename datetime_formatter/{__openerp__.py => __manifest__.py} (70%) delete mode 100644 datetime_formatter/exceptions.py create mode 100644 datetime_formatter/models/__init__.py rename datetime_formatter/{models.py => models/res_lang.py} (90%) diff --git a/datetime_formatter/README.rst b/datetime_formatter/README.rst index bf5e28101..9c777e60f 100644 --- a/datetime_formatter/README.rst +++ b/datetime_formatter/README.rst @@ -37,7 +37,7 @@ If you are a developer, to use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/149/9.0 + :target: https://runbot.odoo-community.org/runbot/149/10.0 Bug Tracker =========== diff --git a/datetime_formatter/__init__.py b/datetime_formatter/__init__.py index e2c3bb8f2..491851786 100644 --- a/datetime_formatter/__init__.py +++ b/datetime_formatter/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models +# Make these easily available for submodules +from .models.res_lang import MODE_DATE, MODE_DATETIME, MODE_TIME diff --git a/datetime_formatter/__openerp__.py b/datetime_formatter/__manifest__.py similarity index 70% rename from datetime_formatter/__openerp__.py rename to datetime_formatter/__manifest__.py index 659b241b2..ac84cc5b3 100644 --- a/datetime_formatter/__openerp__.py +++ b/datetime_formatter/__manifest__.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells +# Copyright 2015, 2017 Jairo Llopis +# Copyright 2016 Tecnativa, S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Date & Time Formatter", "summary": "Helper functions to give correct format to date[time] fields", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "category": "Tools", - "website": "https://tecnativa.com", + "website": "https://www.tecnativa.com", "author": "Grupo ESOC Ingeniería de Servicios, " "Tecnativa," "Odoo Community Association (OCA)", diff --git a/datetime_formatter/exceptions.py b/datetime_formatter/exceptions.py deleted file mode 100644 index 42b5f2850..000000000 --- a/datetime_formatter/exceptions.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, exceptions - - -class BestMatchedLanguageNotFoundError(exceptions.MissingError): - def __init__(self, lang): - msg = (_("Best matched language (%s) not found.") % lang) - super(BestMatchedLanguageNotFoundError, self).__init__(msg) - self.lang = lang diff --git a/datetime_formatter/models/__init__.py b/datetime_formatter/models/__init__.py new file mode 100644 index 000000000..30cac48d5 --- /dev/null +++ b/datetime_formatter/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import res_lang diff --git a/datetime_formatter/models.py b/datetime_formatter/models/res_lang.py similarity index 90% rename from datetime_formatter/models.py rename to datetime_formatter/models/res_lang.py index 90816df38..9d3ced04a 100644 --- a/datetime_formatter/models.py +++ b/datetime_formatter/models/res_lang.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells +# Copyright 2015, 2017 Jairo Llopis +# Copyright 2016 Tecnativa, S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from datetime import datetime, timedelta -from openerp import api, fields, models -from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, - DEFAULT_SERVER_TIME_FORMAT) -from . import exceptions as ex +from odoo import _, api, fields, models +from odoo.tools import (DEFAULT_SERVER_DATE_FORMAT, + DEFAULT_SERVER_TIME_FORMAT) +from odoo.exceptions import UserError # Available modes for :param:`.ResLang.datetime_formatter.template` MODE_DATETIME = "MODE_DATETIME" @@ -56,7 +56,9 @@ class ResLang(models.Model): record.ensure_one() except ValueError: if not failure_safe: - raise ex.BestMatchedLanguageNotFoundError(lang) + raise UserError( + _("Best matched language (%s) not found.") % lang + ) else: record = first_installed diff --git a/datetime_formatter/tests/__init__.py b/datetime_formatter/tests/__init__.py index e1f602d5d..0192d242f 100644 --- a/datetime_formatter/tests/__init__.py +++ b/datetime_formatter/tests/__init__.py @@ -1,5 +1,3 @@ # -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import test_best_matcher, test_formatter diff --git a/datetime_formatter/tests/test_best_matcher.py b/datetime_formatter/tests/test_best_matcher.py index e022dfd18..790c70d58 100644 --- a/datetime_formatter/tests/test_best_matcher.py +++ b/datetime_formatter/tests/test_best_matcher.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells +# Copyright 2015, 2017 Jairo Llopis +# Copyright 2016 Tecnativa, S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.tests.common import TransactionCase -from .. import exceptions +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError class BasicCase(TransactionCase): @@ -72,5 +72,5 @@ class BasicCase(TransactionCase): self.assertEqual(self.rl.best_match("fake_LANG").code, first.code) # Unsafe mode - with self.assertRaises(exceptions.BestMatchedLanguageNotFoundError): + with self.assertRaises(UserError): self.rl.best_match("fake_LANG", failure_safe=False) diff --git a/datetime_formatter/tests/test_formatter.py b/datetime_formatter/tests/test_formatter.py index cd3833dca..1fa451202 100644 --- a/datetime_formatter/tests/test_formatter.py +++ b/datetime_formatter/tests/test_formatter.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- -# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis -# © 2016 Tecnativa, S.L. - Vicent Cubells +# Copyright 2015, 2017 Jairo Llopis +# Copyright 2016 Tecnativa, S.L. - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import datetime from random import random -from openerp.tests.common import TransactionCase -from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, - DEFAULT_SERVER_TIME_FORMAT, - DEFAULT_SERVER_DATETIME_FORMAT) -from ..models import MODE_DATE, MODE_TIME, MODE_DATETIME +from odoo.tests.common import TransactionCase +from odoo.tools import (DEFAULT_SERVER_DATE_FORMAT, + DEFAULT_SERVER_TIME_FORMAT, + DEFAULT_SERVER_DATETIME_FORMAT) +from ..models.res_lang import MODE_DATE, MODE_TIME, MODE_DATETIME class FormatterCase(TransactionCase):