Skip to content

Commit

Permalink
🚑 Fix odoo core addon taking priority over extra version
Browse files Browse the repository at this point in the history
#84 introduced a regression that violated [the addon priority table](https://github.com/Tecnativa/docker-odoo-base#optodoocustomsrcaddonsyaml). This fixes the regression and tests it.
  • Loading branch information
yajo committed Oct 16, 2017
1 parent 2ff6186 commit 47509e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
38 changes: 15 additions & 23 deletions lib/odoobaselib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
def addons_config():
"""Yield addon name and path from ``ADDONS_YAML``."""
config = dict()
private_done = False
core_done = False
special_missing = {PRIVATE, CORE}
try:
with open(ADDONS_YAML) as addons_file:
for doc in yaml.load_all(addons_file):
Expand All @@ -53,11 +52,8 @@ def addons_config():
continue
# Flatten all sections in a single dict
for repo, addons in doc.items():
if repo == PRIVATE:
private_done = True
elif repo == CORE:
core_done = True
logging.debug("Processing %s repo", repo)
special_missing.discard(repo)
for glob in addons:
logging.debug("Expanding glob %s", glob)
for addon in iglob(os.path.join(SRC_DIR, repo, glob)):
Expand All @@ -66,31 +62,27 @@ def addons_config():
config.setdefault(addon, set())
config[addon].add(repo)
except IOError:
logging.debug('Could not find addons configuration yml.')
logging.debug('Could not find addons configuration yaml.')
# By default, all private and core addons are enabled
if not private_done:
logging.debug("Auto-adding all private repo addons")
config.update({
os.path.basename(addon): {PRIVATE}
for addon in iglob(os.path.join(SRC_DIR, PRIVATE, "*"))
})
if not core_done:
logging.debug("Auto-adding all core repo addons")
config.update({
os.path.basename(addon): {CORE}
for addon in iglob(os.path.join(SRC_DIR, CORE, "*"))
})
for repo in special_missing:
logging.debug("Auto-adding all addons from %s", repo)
for addon in iglob(os.path.join(SRC_DIR, repo, "*")):
addon = os.path.basename(addon)
config.setdefault(addon, set())
config[addon].add(repo)
logging.debug("Resulting configuration: %r", config)
for addon, repos in config.items():
# Private addons are most important
if PRIVATE in repos:
yield addon, PRIVATE
continue
# Odoo core addons are least important
elif repos == {CORE}:
if repos == {CORE}:
yield addon, CORE
continue
repos.discard(CORE)
# Other addons fall in between
elif len(repos) != 1:
if len(repos) != 1:
logging.error("Addon %s defined in several repos %s", addon, repos)
raise Exception
else:
yield addon, repos.pop()
yield addon, repos.pop()
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def test_dotd(self):
("test", "-d", "custom/src/private/private_addon"),
("test", "-f", "custom/src/private/private_addon/__init__.py"),
("test", "-e", "auto/addons/private_addon"),
# Addon from extra repo takes higher priority than core version
("realpath", "auto/addons/product"),
("bash", "-c", 'test "$(realpath auto/addons/product)" == '
'/opt/odoo/custom/src/dummy_repo/product'),
# ``odoo`` command works
("odoo", "--version"),
# Implicit ``odoo`` command also works
Expand Down
1 change: 1 addition & 0 deletions tests/scaffoldings/dotd/custom/src/addons.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dummy_repo:
- dummy_addon
- product

---
ONLY:
Expand Down
Empty file.

0 comments on commit 47509e7

Please sign in to comment.