Browse Source

[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.
pull/1180/merge
Jairo Llopis 8 years ago
committed by Jairo Llopis
parent
commit
0e76aae7c8
  1. 2
      datetime_formatter/README.rst
  2. 4
      datetime_formatter/__init__.py
  3. 8
      datetime_formatter/__manifest__.py
  4. 12
      datetime_formatter/exceptions.py
  5. 3
      datetime_formatter/models/__init__.py
  6. 16
      datetime_formatter/models/res_lang.py
  7. 2
      datetime_formatter/tests/__init__.py
  8. 10
      datetime_formatter/tests/test_best_matcher.py
  9. 14
      datetime_formatter/tests/test_formatter.py

2
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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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 Bug Tracker
=========== ===========

4
datetime_formatter/__init__.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models from . import models
# Make these easily available for submodules
from .models.res_lang import MODE_DATE, MODE_DATETIME, MODE_TIME

8
datetime_formatter/__openerp__.py → datetime_formatter/__manifest__.py

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*- # -*- 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 <jairo.llopis@tecnativa.com>
# Copyright 2016 Tecnativa, S.L. - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Date & Time Formatter", "name": "Date & Time Formatter",
"summary": "Helper functions to give correct format to date[time] fields", "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", "category": "Tools",
"website": "https://tecnativa.com",
"website": "https://www.tecnativa.com",
"author": "Grupo ESOC Ingeniería de Servicios, " "author": "Grupo ESOC Ingeniería de Servicios, "
"Tecnativa," "Tecnativa,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",

12
datetime_formatter/exceptions.py

@ -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

3
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

16
datetime_formatter/models.py → datetime_formatter/models/res_lang.py

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*- # -*- 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 <jairo.llopis@tecnativa.com>
# Copyright 2016 Tecnativa, S.L. - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime, timedelta 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` # Available modes for :param:`.ResLang.datetime_formatter.template`
MODE_DATETIME = "MODE_DATETIME" MODE_DATETIME = "MODE_DATETIME"
@ -56,7 +56,9 @@ class ResLang(models.Model):
record.ensure_one() record.ensure_one()
except ValueError: except ValueError:
if not failure_safe: if not failure_safe:
raise ex.BestMatchedLanguageNotFoundError(lang)
raise UserError(
_("Best matched language (%s) not found.") % lang
)
else: else:
record = first_installed record = first_installed

2
datetime_formatter/tests/__init__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*- # -*- 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_best_matcher, test_formatter from . import test_best_matcher, test_formatter

10
datetime_formatter/tests/test_best_matcher.py

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- 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 <jairo.llopis@tecnativa.com>
# Copyright 2016 Tecnativa, S.L. - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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): class BasicCase(TransactionCase):
@ -72,5 +72,5 @@ class BasicCase(TransactionCase):
self.assertEqual(self.rl.best_match("fake_LANG").code, first.code) self.assertEqual(self.rl.best_match("fake_LANG").code, first.code)
# Unsafe mode # Unsafe mode
with self.assertRaises(exceptions.BestMatchedLanguageNotFoundError):
with self.assertRaises(UserError):
self.rl.best_match("fake_LANG", failure_safe=False) self.rl.best_match("fake_LANG", failure_safe=False)

14
datetime_formatter/tests/test_formatter.py

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*- # -*- 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 <jairo.llopis@tecnativa.com>
# Copyright 2016 Tecnativa, S.L. - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import datetime import datetime
from random import random 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): class FormatterCase(TransactionCase):

Loading…
Cancel
Save