Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_best_matcher, test_formatter

View file

@ -0,0 +1,72 @@
# Copyright 2015, 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2016 Tecnativa, S.L. - Vicent Cubells
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
class BasicCase(TransactionCase):
@classmethod
def setUpClass(cls):
super(BasicCase, cls).setUpClass()
cls.langs = (
cls.env.ref("base.lang_en"),
cls.env.ref("base.lang_es"),
cls.env.ref("base.lang_it"),
cls.env.ref("base.lang_pt"),
cls.env.ref("base.lang_zh_CN"),
)
cls.rl = cls.env["res.lang"]
for lang in cls.langs:
cls.rl._activate_lang(lang.code)
def test_explicit(self):
"""When an explicit lang is used."""
for lang in self.langs:
self.assertEqual(self.rl.best_match(lang.code).code, lang.code)
def test_record(self):
"""When called from a ``res.lang`` record."""
rl = self.rl.with_context(lang="it_IT")
rl.env.user.lang = "pt_PT"
for lang in self.langs:
self.assertEqual(
rl.search([("code", "=", lang.code)]).best_match().code, lang.code
)
def test_context(self):
"""When called with a lang in context."""
self.env.user.lang = "pt_PT"
for lang in self.langs:
self.assertEqual(
self.rl.with_context(lang=lang.code).best_match().code, lang.code
)
def test_user(self):
"""When lang not specified in context."""
for lang in self.langs:
self.env.user.lang = lang.code
# Lang is False in context
self.assertEqual(
self.rl.with_context(lang=False).best_match().code, lang.code
)
# Lang not found in context
self.assertEqual(self.rl.with_context(**{}).best_match().code, lang.code)
def test_first_installed(self):
"""When falling back to first installed language."""
first = self.rl.search([("active", "=", True)], limit=1)
self.env.user.lang = False
self.assertEqual(self.rl.with_context(lang=False).best_match().code, first.code)
def test_unavailable(self):
"""When matches to an unavailable language."""
self.env.user.lang = False
self.rl = self.rl.with_context(lang=False)
first = self.rl.search([("active", "=", True)], limit=1)
# Safe mode
self.assertEqual(self.rl.best_match("fake_LANG").code, first.code)
# Unsafe mode
with self.assertRaises(UserError):
self.rl.best_match("fake_LANG", failure_safe=False)

View file

@ -0,0 +1,83 @@
# Copyright 2015, 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2016 Tecnativa, S.L. - Vicent Cubells
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import datetime
from random import random
from odoo.tests.common import TransactionCase
from odoo.tools import (
DEFAULT_SERVER_DATE_FORMAT,
DEFAULT_SERVER_DATETIME_FORMAT,
DEFAULT_SERVER_TIME_FORMAT,
)
from ..models.res_lang import MODE_DATE, MODE_DATETIME, MODE_TIME
class FormatterCase(TransactionCase):
@classmethod
def setUpClass(cls):
super(FormatterCase, cls).setUpClass()
cls.rl = cls.env["res.lang"]
cls.bm = cls.rl.best_match()
cls.dt = datetime.datetime.now()
cls.d_fmt = cls.bm.date_format or DEFAULT_SERVER_DATE_FORMAT
cls.t_fmt = cls.bm.time_format or DEFAULT_SERVER_TIME_FORMAT
cls.kwargs = dict()
def tearDown(self):
# This should be returned
self.expected = self.dt.strftime(self.format)
# Pass a datetime object
self.assertEqual(
self.expected, self.rl.datetime_formatter(self.dt, **self.kwargs)
)
# When the date comes as a string
if isinstance(self.dt, datetime.datetime):
self.dt_str = self.dt.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
elif isinstance(self.dt, datetime.date):
self.dt_str = self.dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
elif isinstance(self.dt, datetime.time):
self.dt_str = self.dt.strftime(DEFAULT_SERVER_TIME_FORMAT)
# Pass a string
self.assertEqual(
self.expected, self.rl.datetime_formatter(self.dt_str, **self.kwargs)
)
# Pass a unicode
self.assertEqual(
self.expected, self.rl.datetime_formatter(str(self.dt_str), **self.kwargs)
)
super().tearDown()
def test_datetime(self):
"""Format a datetime."""
self.format = "{} {}".format(self.d_fmt, self.t_fmt)
self.kwargs = {"template": MODE_DATETIME}
def test_date(self):
"""Format a date."""
self.format = self.d_fmt
self.kwargs = {"template": MODE_DATE}
self.dt = self.dt.date()
def test_time(self):
"""Format times, including float ones."""
self.format = self.t_fmt
self.kwargs = {"template": MODE_TIME}
self.dt = self.dt.time()
# Test float times
for n in range(50):
n = n + random()
# Patch values with >= 24 hours
fmt = self.format.replace("%H", "%02d" % n)
time = (datetime.datetime.min + datetime.timedelta(hours=n)).time()
self.assertEqual(
time.strftime(fmt), self.rl.datetime_formatter(n, **self.kwargs)
)
def test_custom_separator(self):
"""Format a datetime with a custom separator."""
sep = "T"
self.format = "{}{}{}".format(self.d_fmt, sep, self.t_fmt)
self.kwargs = {"template": MODE_DATETIME, "separator": sep}