Compare commits
2 Commits
18.0
...
c940289d40
| Author | SHA1 | Date | |
|---|---|---|---|
| c940289d40 | |||
| 9d1cd2746a |
@@ -1,42 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Run the Python tests of the given Odoo modules.
|
||||
#
|
||||
# This script is meant to be executed *inside* an Elabore doodba image
|
||||
# (docker.0k.io/mirror/odoo:rc_<version>-ELABORE-LIGHT), with a
|
||||
# PostgreSQL service reachable at $PGHOST. The modules under test are
|
||||
# read from the current working directory (the checked-out repository),
|
||||
# which is prepended to the addons path so that the PR's code takes
|
||||
# precedence over the modules already baked in the image.
|
||||
#
|
||||
# Usage: odoo-tests.sh <module1,module2,...>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
modules="${1:?usage: odoo-tests.sh <module1,module2,...>}"
|
||||
|
||||
export PGHOST=postgres
|
||||
export PGUSER=odoo
|
||||
export PGPASSWORD=odoopassword
|
||||
export PGDATABASE="test_$(basename "$PWD" | tr '.-' '__')"
|
||||
export WITHOUT_DEMO=all
|
||||
export DB_FILTER='.*'
|
||||
|
||||
# Generate /opt/odoo/auto/odoo.conf from the environment and wait for
|
||||
# the database to accept connections.
|
||||
/opt/odoo/common/entrypoint
|
||||
|
||||
# Odoo test-tags format: "/module1,/module2" (one leading slash).
|
||||
tags="/$(echo "$modules" | tr ',' ',/')"
|
||||
|
||||
exec odoo \
|
||||
--config=/opt/odoo/auto/odoo.conf \
|
||||
--max-cron-threads=0 \
|
||||
--limit-time-real=10000 \
|
||||
--workers=0 \
|
||||
--test-enable \
|
||||
--stop-after-init \
|
||||
--addons-path="$PWD,/opt/odoo/auto/addons" \
|
||||
-d "$PGDATABASE" \
|
||||
-i "$modules" \
|
||||
--test-tags "$tags"
|
||||
@@ -2,6 +2,8 @@ name: pre-commit
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "18.0*"
|
||||
|
||||
jobs:
|
||||
pre-commit:
|
||||
@@ -13,10 +15,10 @@ jobs:
|
||||
python-version: "3.11"
|
||||
- name: Get python version
|
||||
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
|
||||
- uses: https://gitea.com/actions/cache@v3
|
||||
with:
|
||||
path: ~/.cache/pre-commit
|
||||
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
||||
# - uses: actions/cache@v4
|
||||
# with:
|
||||
# path: ~/.cache/pre-commit
|
||||
# key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
||||
- name: Install pre-commit
|
||||
run: pip install pre-commit
|
||||
- name: Run pre-commit
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
name: tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "18.0*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: odoo-ci
|
||||
container:
|
||||
image: docker.0k.io/mirror/odoo:rc_18.0-ELABORE-LIGHT
|
||||
services:
|
||||
postgres:
|
||||
image: docker.0k.io/postgres:17.2.0-myc
|
||||
env:
|
||||
POSTGRES_USER: odoo
|
||||
POSTGRES_PASSWORD: odoopassword
|
||||
POSTGRES_DB: postgres
|
||||
steps:
|
||||
# The doodba image ships no Node.js, so actions/checkout@v4 cannot
|
||||
# run here. The repository is private, so the job token is required.
|
||||
- name: Checkout
|
||||
env:
|
||||
SECRET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
token="${GITEA_TOKEN:-${GITHUB_TOKEN:-${SECRET_GITEA_TOKEN:-${SECRET_GITHUB_TOKEN:-}}}}"
|
||||
if [ -z "$token" ]; then
|
||||
echo "::error::No job token available to clone the repository"
|
||||
exit 1
|
||||
fi
|
||||
server="${GITHUB_SERVER_URL:-https://git.elabore.coop}"
|
||||
repo="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is not set}"
|
||||
ref="${GITHUB_REF:-${GITHUB_SHA:?neither GITHUB_REF nor GITHUB_SHA is set}}"
|
||||
auth_url="$(printf '%s' "${server%/}/${repo}.git" |
|
||||
sed -E "s#^https://#https://${token}@#")"
|
||||
git init -q .
|
||||
git config --global --add safe.directory "$PWD"
|
||||
git remote add origin "$auth_url"
|
||||
git fetch -q --depth=1 origin "$ref"
|
||||
git checkout -q FETCH_HEAD
|
||||
|
||||
- name: Detect changed modules
|
||||
id: changed
|
||||
run: |
|
||||
set -eu
|
||||
if [ -n "${GITHUB_BASE_REF:-}" ]; then
|
||||
git fetch -q --depth=1 origin "refs/heads/$GITHUB_BASE_REF"
|
||||
base_rev="FETCH_HEAD"
|
||||
scope="diff against $GITHUB_BASE_REF"
|
||||
else
|
||||
base_rev=""
|
||||
scope="all installable modules (manual run)"
|
||||
fi
|
||||
if [ -n "$base_rev" ]; then
|
||||
modules="$(
|
||||
git diff --name-only "$base_rev" HEAD |
|
||||
awk -F/ '{print $1}' | sort -u |
|
||||
while read -r dir; do
|
||||
[ -f "$dir/__manifest__.py" ] && echo "$dir"
|
||||
done | paste -sd, -
|
||||
)"
|
||||
else
|
||||
modules="$(
|
||||
for dir in */; do
|
||||
dir="${dir%/}"
|
||||
[ -f "$dir/__manifest__.py" ] && echo "$dir"
|
||||
done | paste -sd, -
|
||||
)"
|
||||
fi
|
||||
echo "modules=$modules" >> "$GITHUB_OUTPUT"
|
||||
echo "Modules to test ($scope): ${modules:-<none>}"
|
||||
|
||||
- name: Run Odoo tests
|
||||
if: steps.changed.outputs.modules != ''
|
||||
run: bash .gitea/scripts/odoo-tests.sh "${{ steps.changed.outputs.modules }}"
|
||||
161
.gitignore
vendored
161
.gitignore
vendored
@@ -1,42 +1,40 @@
|
||||
*.docx
|
||||
|
||||
.~*
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
/.venv
|
||||
/.pytest_cache
|
||||
/.ruff_cache
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
*.eggs
|
||||
MANIFEST
|
||||
|
||||
# Windows installers
|
||||
*.msi
|
||||
|
||||
# Debian packages
|
||||
*.deb
|
||||
|
||||
# Redhat packages
|
||||
*.rpm
|
||||
|
||||
# MacOS packages
|
||||
*.dmg
|
||||
*.pkg
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
@@ -45,44 +43,123 @@ pip-delete-this-directory.txt
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Pycharm
|
||||
.idea
|
||||
|
||||
# Eclipse
|
||||
.settings
|
||||
|
||||
# Visual Studio cache/options directory
|
||||
.vs/
|
||||
.vscode
|
||||
|
||||
# OSX Files
|
||||
.DS_Store
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Rope
|
||||
.ropeproject
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# Backup files
|
||||
*~
|
||||
*.swp
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# OCA rules
|
||||
!static/lib/
|
||||
|
||||
@@ -22,7 +22,7 @@ exclude: |
|
||||
(LICENSE.*|COPYING.*)
|
||||
default_language_version:
|
||||
python: python3
|
||||
node: "22.9.0"
|
||||
node: "16.17.0"
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
@@ -38,12 +38,8 @@ repos:
|
||||
entry: found a en.po file
|
||||
language: fail
|
||||
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
|
||||
- repo: https://github.com/sbidoul/whool
|
||||
rev: v1.3
|
||||
hooks:
|
||||
- id: whool-init
|
||||
- repo: https://github.com/oca/maintainer-tools
|
||||
rev: b89f767503be6ab2b11e4f50a7557cb20066e667
|
||||
rev: f9b919b9868143135a9c9cb03021089cabba8223
|
||||
hooks:
|
||||
# update the NOT INSTALLABLE ADDONS section above
|
||||
- id: oca-update-pre-commit-excluded-addons
|
||||
@@ -53,13 +49,16 @@ repos:
|
||||
$(git rev-parse --show-toplevel))"'
|
||||
- id: oca-gen-addon-readme
|
||||
entry:
|
||||
bash -c 'oca-gen-addon-readme --addons-dir=. --branch=$(git symbolic-ref
|
||||
bash -c 'oca-gen-addon-readme
|
||||
--addons-dir=.
|
||||
--branch=$(git symbolic-ref
|
||||
refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")
|
||||
--repo-name=$(basename $(git rev-parse --show-toplevel)) --org-name="Elabore"
|
||||
--if-source-changed --keep-source-digest --convert-fragments-to-markdown'
|
||||
- id: oca-gen-external-dependencies
|
||||
--repo-name=$(basename $(git rev-parse --show-toplevel))
|
||||
--org-name="Elabore"
|
||||
--if-source-changed --keep-source-digest'
|
||||
|
||||
- repo: https://github.com/OCA/odoo-pre-commit-hooks
|
||||
rev: v0.0.33
|
||||
rev: v0.1.4
|
||||
hooks:
|
||||
- id: oca-checks-odoo-module
|
||||
- id: oca-checks-po
|
||||
@@ -78,8 +77,8 @@ repos:
|
||||
files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$
|
||||
language: node
|
||||
additional_dependencies:
|
||||
- "prettier@3.3.3"
|
||||
- "@prettier/plugin-xml@3.4.1"
|
||||
- "prettier@2.7.1"
|
||||
- "@prettier/plugin-xml@2.2.0"
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: eslint
|
||||
@@ -92,11 +91,10 @@ repos:
|
||||
types: [javascript]
|
||||
language: node
|
||||
additional_dependencies:
|
||||
- "eslint@9.12.0"
|
||||
- "eslint-plugin-jsdoc@50.3.1"
|
||||
- "globals@16.0.0"
|
||||
- "eslint@8.24.0"
|
||||
- "eslint-plugin-jsdoc@"
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
# exclude autogenerated files
|
||||
@@ -117,8 +115,23 @@ repos:
|
||||
- id: check-xml
|
||||
- id: mixed-line-ending
|
||||
args: ["--fix=lf"]
|
||||
- repo: https://github.com/PyCQA/docformatter
|
||||
rev: v1.7.7
|
||||
hooks:
|
||||
- id: docformatter
|
||||
args: [
|
||||
"--in-place", # modify the files
|
||||
"--recursive", # run on all the files
|
||||
"--wrap-summaries",
|
||||
"88", # max length of 1st line
|
||||
"--wrap-descriptions",
|
||||
"88", # max length of other lines
|
||||
"--pre-summary-newline", # new line before a long summary
|
||||
"--make-summary-multi-line", # force summary on multilines
|
||||
]
|
||||
additional_dependencies: ["tomli"] # if Python <3.11
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.6.8
|
||||
rev: v0.12.0
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--fix, --exit-non-zero-on-fix]
|
||||
|
||||
71
.pylintrc
71
.pylintrc
@@ -25,25 +25,19 @@ disable=all
|
||||
enable=anomalous-backslash-in-string,
|
||||
api-one-deprecated,
|
||||
api-one-multi-together,
|
||||
assignment-from-none,
|
||||
attribute-deprecated,
|
||||
class-camelcase,
|
||||
dangerous-default-value,
|
||||
dangerous-view-replace-wo-priority,
|
||||
development-status-allowed,
|
||||
duplicate-id-csv,
|
||||
duplicate-key,
|
||||
duplicate-xml-fields,
|
||||
duplicate-xml-record-id,
|
||||
eval-referenced,
|
||||
incoherent-interpreter-exec-perm,
|
||||
openerp-exception-warning,
|
||||
redundant-modulename-xml,
|
||||
relative-import,
|
||||
rst-syntax-error,
|
||||
wrong-tabs-instead-of-spaces,
|
||||
xml-syntax-error,
|
||||
assignment-from-none,
|
||||
attribute-deprecated,
|
||||
dangerous-default-value,
|
||||
development-status-allowed,
|
||||
duplicate-key,
|
||||
eval-used,
|
||||
incoherent-interpreter-exec-perm,
|
||||
license-allowed,
|
||||
manifest-author-string,
|
||||
manifest-deprecated-key,
|
||||
@@ -54,68 +48,73 @@ enable=anomalous-backslash-in-string,
|
||||
method-inverse,
|
||||
method-required-super,
|
||||
method-search,
|
||||
openerp-exception-warning,
|
||||
pointless-statement,
|
||||
pointless-string-statement,
|
||||
print-used,
|
||||
redundant-keyword-arg,
|
||||
redundant-modulename-xml,
|
||||
reimported,
|
||||
relative-import,
|
||||
return-in-init,
|
||||
rst-syntax-error,
|
||||
sql-injection,
|
||||
too-few-format-args,
|
||||
translation-field,
|
||||
translation-required,
|
||||
unreachable,
|
||||
use-vim-comment,
|
||||
wrong-tabs-instead-of-spaces,
|
||||
xml-syntax-error,
|
||||
attribute-string-redundant,
|
||||
character-not-valid-in-resource-link,
|
||||
consider-merging-classes-inherited,
|
||||
context-overridden,
|
||||
create-user-wo-reset-password,
|
||||
dangerous-filter-wo-user,
|
||||
dangerous-qweb-replace-wo-priority,
|
||||
deprecated-data-xml-node,
|
||||
deprecated-openerp-xml-node,
|
||||
duplicate-po-message-definition,
|
||||
file-not-used,
|
||||
missing-newline-extrafiles,
|
||||
old-api7-method-defined,
|
||||
po-msgstr-variables,
|
||||
po-syntax-error,
|
||||
str-format-used,
|
||||
unnecessary-utf8-coding-comment,
|
||||
xml-attribute-translatable,
|
||||
xml-deprecated-qweb-directive,
|
||||
xml-deprecated-tree-attribute,
|
||||
attribute-string-redundant,
|
||||
consider-merging-classes-inherited,
|
||||
context-overridden,
|
||||
except-pass,
|
||||
file-not-used,
|
||||
invalid-commit,
|
||||
manifest-maintainers-list,
|
||||
missing-newline-extrafiles,
|
||||
missing-readme,
|
||||
missing-return,
|
||||
odoo-addons-relative-import,
|
||||
old-api7-method-defined,
|
||||
po-msgstr-variables,
|
||||
po-syntax-error,
|
||||
renamed-field-parameter,
|
||||
resource-not-exist,
|
||||
str-format-used,
|
||||
test-folder-imported,
|
||||
translation-contains-variable,
|
||||
translation-positional-used,
|
||||
website-manifest-key-not-valid-uri,
|
||||
external-request-timeout,
|
||||
missing-manifest-dependency,
|
||||
too-complex,,
|
||||
create-user-wo-reset-password,
|
||||
dangerous-filter-wo-user,
|
||||
file-not-used,
|
||||
missing-newline-extrafiles,
|
||||
no-utf8-coding-comment,
|
||||
old-api7-method-defined,
|
||||
unnecessary-utf8-coding-comment,
|
||||
website-manifest-key-not-valid-uri,
|
||||
xml-attribute-translatable,
|
||||
xml-deprecated-qweb-directive,
|
||||
xml-deprecated-tree-attribute,
|
||||
external-request-timeout,
|
||||
# messages that do not cause the lint step to fail
|
||||
consider-merging-classes-inherited,
|
||||
create-user-wo-reset-password,
|
||||
dangerous-filter-wo-user,
|
||||
deprecated-module,
|
||||
file-not-used,
|
||||
invalid-commit,
|
||||
missing-manifest-dependency,
|
||||
missing-newline-extrafiles,
|
||||
missing-readme,
|
||||
no-utf8-coding-comment,
|
||||
odoo-addons-relative-import,
|
||||
old-api7-method-defined,
|
||||
redefined-builtin,
|
||||
manifest-external-assets
|
||||
too-complex,
|
||||
unnecessary-utf8-coding-comment
|
||||
|
||||
|
||||
[REPORTS]
|
||||
|
||||
@@ -17,25 +17,19 @@ disable=all
|
||||
enable=anomalous-backslash-in-string,
|
||||
api-one-deprecated,
|
||||
api-one-multi-together,
|
||||
assignment-from-none,
|
||||
attribute-deprecated,
|
||||
class-camelcase,
|
||||
dangerous-default-value,
|
||||
dangerous-view-replace-wo-priority,
|
||||
development-status-allowed,
|
||||
duplicate-id-csv,
|
||||
duplicate-key,
|
||||
duplicate-xml-fields,
|
||||
duplicate-xml-record-id,
|
||||
eval-referenced,
|
||||
incoherent-interpreter-exec-perm,
|
||||
openerp-exception-warning,
|
||||
redundant-modulename-xml,
|
||||
relative-import,
|
||||
rst-syntax-error,
|
||||
wrong-tabs-instead-of-spaces,
|
||||
xml-syntax-error,
|
||||
assignment-from-none,
|
||||
attribute-deprecated,
|
||||
dangerous-default-value,
|
||||
development-status-allowed,
|
||||
duplicate-key,
|
||||
eval-used,
|
||||
incoherent-interpreter-exec-perm,
|
||||
license-allowed,
|
||||
manifest-author-string,
|
||||
manifest-deprecated-key,
|
||||
@@ -46,50 +40,56 @@ enable=anomalous-backslash-in-string,
|
||||
method-inverse,
|
||||
method-required-super,
|
||||
method-search,
|
||||
openerp-exception-warning,
|
||||
pointless-statement,
|
||||
pointless-string-statement,
|
||||
print-used,
|
||||
redundant-keyword-arg,
|
||||
redundant-modulename-xml,
|
||||
reimported,
|
||||
relative-import,
|
||||
return-in-init,
|
||||
rst-syntax-error,
|
||||
sql-injection,
|
||||
too-few-format-args,
|
||||
translation-field,
|
||||
translation-required,
|
||||
unreachable,
|
||||
use-vim-comment,
|
||||
wrong-tabs-instead-of-spaces,
|
||||
xml-syntax-error,
|
||||
attribute-string-redundant,
|
||||
character-not-valid-in-resource-link,
|
||||
consider-merging-classes-inherited,
|
||||
context-overridden,
|
||||
create-user-wo-reset-password,
|
||||
dangerous-filter-wo-user,
|
||||
dangerous-qweb-replace-wo-priority,
|
||||
deprecated-data-xml-node,
|
||||
deprecated-openerp-xml-node,
|
||||
duplicate-po-message-definition,
|
||||
file-not-used,
|
||||
missing-newline-extrafiles,
|
||||
old-api7-method-defined,
|
||||
po-msgstr-variables,
|
||||
po-syntax-error,
|
||||
str-format-used,
|
||||
unnecessary-utf8-coding-comment,
|
||||
xml-attribute-translatable,
|
||||
xml-deprecated-qweb-directive,
|
||||
xml-deprecated-tree-attribute,
|
||||
attribute-string-redundant,
|
||||
consider-merging-classes-inherited,
|
||||
context-overridden,
|
||||
except-pass,
|
||||
file-not-used,
|
||||
invalid-commit,
|
||||
manifest-maintainers-list,
|
||||
missing-newline-extrafiles,
|
||||
missing-readme,
|
||||
missing-return,
|
||||
odoo-addons-relative-import,
|
||||
old-api7-method-defined,
|
||||
po-msgstr-variables,
|
||||
po-syntax-error,
|
||||
renamed-field-parameter,
|
||||
resource-not-exist,
|
||||
str-format-used,
|
||||
test-folder-imported,
|
||||
translation-contains-variable,
|
||||
translation-positional-used,
|
||||
unnecessary-utf8-coding-comment,
|
||||
website-manifest-key-not-valid-uri,
|
||||
xml-attribute-translatable,
|
||||
xml-deprecated-qweb-directive,
|
||||
xml-deprecated-tree-attribute,
|
||||
external-request-timeout
|
||||
|
||||
[REPORTS]
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
var globals = require('globals');
|
||||
jsdoc = require("eslint-plugin-jsdoc");
|
||||
|
||||
const config = [{
|
||||
plugins: {
|
||||
jsdoc,
|
||||
},
|
||||
|
||||
languageOptions: {
|
||||
globals: {
|
||||
_: "readonly",
|
||||
$: "readonly",
|
||||
fuzzy: "readonly",
|
||||
jQuery: "readonly",
|
||||
moment: "readonly",
|
||||
odoo: "readonly",
|
||||
openerp: "readonly",
|
||||
owl: "readonly",
|
||||
luxon: "readonly",
|
||||
QUnit: "readonly",
|
||||
...globals.browser,
|
||||
},
|
||||
|
||||
ecmaVersion: 2024,
|
||||
sourceType: "script",
|
||||
},
|
||||
|
||||
rules: {
|
||||
"accessor-pairs": "warn",
|
||||
"array-callback-return": "warn",
|
||||
"callback-return": "warn",
|
||||
"capitalized-comments": ["warn", "always", {
|
||||
ignoreConsecutiveComments: true,
|
||||
ignoreInlineComments: true,
|
||||
}],
|
||||
complexity: ["warn", 15],
|
||||
"constructor-super": "warn",
|
||||
"dot-notation": "warn",
|
||||
eqeqeq: "warn",
|
||||
"global-require": "warn",
|
||||
"handle-callback-err": "warn",
|
||||
"id-blacklist": "warn",
|
||||
"id-match": "warn",
|
||||
"init-declarations": "error",
|
||||
"max-depth": "warn",
|
||||
"max-nested-callbacks": "warn",
|
||||
"max-statements-per-line": "warn",
|
||||
"no-alert": "warn",
|
||||
"no-array-constructor": "warn",
|
||||
"no-caller": "warn",
|
||||
"no-case-declarations": "warn",
|
||||
"no-class-assign": "warn",
|
||||
"no-cond-assign": "error",
|
||||
"no-const-assign": "error",
|
||||
"no-constant-condition": "warn",
|
||||
"no-control-regex": "warn",
|
||||
"no-debugger": "error",
|
||||
"no-delete-var": "warn",
|
||||
"no-div-regex": "warn",
|
||||
"no-dupe-args": "error",
|
||||
"no-dupe-class-members": "error",
|
||||
"no-dupe-keys": "error",
|
||||
"no-duplicate-case": "error",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-else-return": "warn",
|
||||
"no-empty-character-class": "warn",
|
||||
"no-empty-function": "error",
|
||||
"no-empty-pattern": "error",
|
||||
"no-empty": "warn",
|
||||
"no-eq-null": "error",
|
||||
"no-eval": "error",
|
||||
"no-ex-assign": "error",
|
||||
"no-extend-native": "warn",
|
||||
"no-extra-bind": "warn",
|
||||
"no-extra-boolean-cast": "warn",
|
||||
"no-extra-label": "warn",
|
||||
"no-fallthrough": "warn",
|
||||
"no-func-assign": "error",
|
||||
"no-global-assign": "error",
|
||||
"no-implicit-coercion": ["warn", {
|
||||
allow: ["~"],
|
||||
}],
|
||||
"no-implicit-globals": "warn",
|
||||
"no-implied-eval": "warn",
|
||||
"no-inline-comments": "warn",
|
||||
"no-inner-declarations": "warn",
|
||||
"no-invalid-regexp": "warn",
|
||||
"no-irregular-whitespace": "warn",
|
||||
"no-iterator": "warn",
|
||||
"no-label-var": "warn",
|
||||
"no-labels": "warn",
|
||||
"no-lone-blocks": "warn",
|
||||
"no-lonely-if": "error",
|
||||
"no-mixed-requires": "error",
|
||||
"no-multi-str": "warn",
|
||||
"no-native-reassign": "error",
|
||||
"no-negated-condition": "warn",
|
||||
"no-negated-in-lhs": "error",
|
||||
"no-new-func": "warn",
|
||||
"no-new-object": "warn",
|
||||
"no-new-require": "warn",
|
||||
"no-new-symbol": "warn",
|
||||
"no-new-wrappers": "warn",
|
||||
"no-new": "warn",
|
||||
"no-obj-calls": "warn",
|
||||
"no-octal-escape": "warn",
|
||||
"no-octal": "warn",
|
||||
"no-param-reassign": "warn",
|
||||
"no-path-concat": "warn",
|
||||
"no-process-env": "warn",
|
||||
"no-process-exit": "warn",
|
||||
"no-proto": "warn",
|
||||
"no-prototype-builtins": "warn",
|
||||
"no-redeclare": "warn",
|
||||
"no-regex-spaces": "warn",
|
||||
"no-restricted-globals": "warn",
|
||||
"no-restricted-imports": "warn",
|
||||
"no-restricted-modules": "warn",
|
||||
"no-restricted-syntax": "warn",
|
||||
"no-return-assign": "error",
|
||||
"no-script-url": "warn",
|
||||
"no-self-assign": "warn",
|
||||
"no-self-compare": "warn",
|
||||
"no-sequences": "warn",
|
||||
"no-shadow-restricted-names": "warn",
|
||||
"no-shadow": "warn",
|
||||
"no-sparse-arrays": "warn",
|
||||
"no-sync": "warn",
|
||||
"no-this-before-super": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"no-undef-init": "warn",
|
||||
"no-undef": "error",
|
||||
"no-unmodified-loop-condition": "warn",
|
||||
"no-unneeded-ternary": "error",
|
||||
"no-unreachable": "error",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unused-expressions": "error",
|
||||
"no-unused-labels": "error",
|
||||
"no-unused-vars": "error",
|
||||
"no-use-before-define": "error",
|
||||
"no-useless-call": "warn",
|
||||
"no-useless-computed-key": "warn",
|
||||
"no-useless-concat": "warn",
|
||||
"no-useless-constructor": "warn",
|
||||
"no-useless-escape": "warn",
|
||||
"no-useless-rename": "warn",
|
||||
"no-void": "warn",
|
||||
"no-with": "warn",
|
||||
"operator-assignment": ["error", "always"],
|
||||
"prefer-const": "warn",
|
||||
radix: "warn",
|
||||
"require-yield": "warn",
|
||||
"sort-imports": "warn",
|
||||
"spaced-comment": ["error", "always"],
|
||||
strict: ["error", "function"],
|
||||
"use-isnan": "error",
|
||||
|
||||
"jsdoc/check-tag-names": "warn",
|
||||
"jsdoc/check-types": "warn",
|
||||
"jsdoc/require-param-description": "off",
|
||||
"jsdoc/require-return": "off",
|
||||
"jsdoc/require-return-description": "off",
|
||||
"jsdoc/require-return-type": "off",
|
||||
|
||||
"valid-typeof": "warn",
|
||||
yoda: "warn",
|
||||
},
|
||||
|
||||
settings: {
|
||||
jsdoc: {
|
||||
tagNamePreference: {
|
||||
arg: "param",
|
||||
argument: "param",
|
||||
augments: "extends",
|
||||
constructor: "class",
|
||||
exception: "throws",
|
||||
func: "function",
|
||||
method: "function",
|
||||
prop: "property",
|
||||
return: "returns",
|
||||
virtual: "abstract",
|
||||
yield: "yields",
|
||||
},
|
||||
preferredTypes: {
|
||||
array: "Array",
|
||||
bool: "Boolean",
|
||||
boolean: "Boolean",
|
||||
number: "Number",
|
||||
object: "Object",
|
||||
str: "String",
|
||||
string: "String",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
}, {
|
||||
files: ["**/*.esm.js", "**/*test.js"],
|
||||
|
||||
languageOptions: {
|
||||
ecmaVersion: 2024,
|
||||
sourceType: "module",
|
||||
},
|
||||
}];
|
||||
|
||||
module.exports = config
|
||||
@@ -1,14 +0,0 @@
|
||||
/** @type {import('prettier').Config} */
|
||||
|
||||
const config = {
|
||||
// https://github.com/prettier/prettier/issues/15388#issuecomment-1717746872
|
||||
plugins: [require.resolve("@prettier/plugin-xml")],
|
||||
bracketSpacing: false,
|
||||
printWidth: 88,
|
||||
proseWrap: "always",
|
||||
semi: true,
|
||||
trailingComma: "es5",
|
||||
xmlWhitespaceSensitivity: "preserve",
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
@@ -11,7 +11,7 @@ Allow to create record of any model when sending the form :
|
||||
* Associate question with fields
|
||||
* For x2m fields : Associate values to questions
|
||||
""",
|
||||
"version": "18.0.1.0.1",
|
||||
"version": "18.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
"""Relink survey.user_input.partner_id/email to the contact that actually
|
||||
matches each participant's own answers.
|
||||
|
||||
Before this version, survey.user_input.partner_id/email were only updated
|
||||
when _mark_done() created a *new* res.partner. If the answer already had a
|
||||
partner_id/email (e.g. inherited from the Odoo user who was logged in when
|
||||
the /survey/start link was opened, or from some other unidentified cause),
|
||||
_mark_done() silently kept that value even when the survey_record_creation
|
||||
config found or created a different, correct contact from the participant's
|
||||
own answers. This backfill re-runs that resolution for every already-done
|
||||
answer and fixes partner_id/email accordingly.
|
||||
|
||||
It never re-triggers the other survey.user_input._mark_done() overrides
|
||||
(crm lead / event registration / notification modules, ...): it only calls
|
||||
the res.partner-matching helpers directly, so it can't create duplicate
|
||||
leads, registrations, etc. for historical submissions.
|
||||
|
||||
A res.partner is expected to already exist for every done submission (it
|
||||
was necessarily found or created the first time _mark_done() ran), so this
|
||||
backfill never creates one. It first looks for the survey.generated.record
|
||||
row _mark_done() logged when it created that partner, and falls back to
|
||||
re-deriving the match through find_existing_record()/
|
||||
find_duplicate_if_there_are_fields_with_unicity_check() when there is no
|
||||
such row (existing partner matched instead of created) or it points to a
|
||||
partner that has since been deleted (e.g. merged into another contact). If
|
||||
neither approach finds anything, the record is left untouched and logged
|
||||
for manual review instead.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from odoo import SUPERUSER_ID, api
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
user_input_model = env["survey.user_input"]
|
||||
|
||||
surveys_with_partner_creation = env["survey.record.creation"].search(
|
||||
[("model_id.model", "=", "res.partner")]
|
||||
).survey_id
|
||||
|
||||
user_inputs = user_input_model.search(
|
||||
[
|
||||
("survey_id", "in", surveys_with_partner_creation.ids),
|
||||
("state", "=", "done"),
|
||||
]
|
||||
)
|
||||
|
||||
_logger.info(
|
||||
"survey_record_generation: relinking partner_id/email on %d done "
|
||||
"survey.user_input records",
|
||||
len(user_inputs),
|
||||
)
|
||||
|
||||
fixed_count = 0
|
||||
not_found_count = 0
|
||||
|
||||
for user_input in user_inputs:
|
||||
record_creations = user_input.survey_id.survey_record_creation_ids.filtered(
|
||||
lambda rc: rc.model_id.model == "res.partner"
|
||||
).sorted("sequence")
|
||||
|
||||
record_creation = record_creations[:1]
|
||||
if not record_creation:
|
||||
continue
|
||||
|
||||
# 1) Prefer the res.partner this very submission created, if any
|
||||
# (the first one, by id, in the rare case there is more than one):
|
||||
# it's the exact record _mark_done() produced for this answer, no
|
||||
# guessing involved. This is also the only option for surveys whose
|
||||
# record creation has neither update_existing_records nor any
|
||||
# unicity_check field configured, since find_existing_record()/
|
||||
# find_duplicate...() can then never find anything (nothing to
|
||||
# search on).
|
||||
record = False
|
||||
for generated in user_input.generated_record_ids.sorted("id"):
|
||||
if (
|
||||
generated.survey_record_creation_id == record_creation
|
||||
and generated.created_record_id
|
||||
and generated.created_record_id._name == "res.partner"
|
||||
and generated.created_record_id.exists()
|
||||
):
|
||||
# The referenced partner may have since been deleted (e.g.
|
||||
# merged into another contact): in that case it's not usable
|
||||
# and we fall through to the search-based lookup below.
|
||||
record = generated.created_record_id
|
||||
break
|
||||
|
||||
# 2) Otherwise, this submission matched an already-existing partner
|
||||
# instead of creating one (find_existing_record()/find_duplicate...()
|
||||
# branch of _mark_done()): re-derive it the same way.
|
||||
if not record:
|
||||
# Only compute the fields find_existing_record()/find_duplicate...()
|
||||
# actually read (the search field, and any unicity_check field),
|
||||
# not every field of the record creation: other fields (e.g. a
|
||||
# "record" reference to a model defined in a module that depends
|
||||
# on this one) may not be loadable yet at this point of the
|
||||
# upgrade, and are useless here anyway since this backfill never
|
||||
# writes to res.partner.
|
||||
needed_field_names = set()
|
||||
if (
|
||||
record_creation.update_existing_records
|
||||
and record_creation.field_to_retrieve_existing_records
|
||||
):
|
||||
needed_field_names.add(
|
||||
record_creation.field_to_retrieve_existing_records.name
|
||||
)
|
||||
unicity_field_values = record_creation.field_values_ids.filtered(
|
||||
lambda field_value: field_value.unicity_check
|
||||
)
|
||||
needed_field_names.update(unicity_field_values.mapped("field_id.name"))
|
||||
|
||||
vals = {}
|
||||
for field_value in record_creation.field_values_ids:
|
||||
if field_value.field_id.name not in needed_field_names:
|
||||
continue
|
||||
value, __ = user_input_model.get_value_based_on_value_origin(
|
||||
field_value=field_value,
|
||||
user_input=user_input,
|
||||
created_records={},
|
||||
model="res.partner",
|
||||
other_record_fields_to_update=[],
|
||||
)
|
||||
vals[field_value.field_id.name] = value
|
||||
|
||||
existing_record = user_input_model.find_existing_record(
|
||||
record_creation, vals
|
||||
)
|
||||
duplicate = (
|
||||
user_input_model.find_duplicate_if_there_are_fields_with_unicity_check(
|
||||
"res.partner", record_creation, vals
|
||||
)
|
||||
)
|
||||
record = duplicate or existing_record
|
||||
|
||||
if not record:
|
||||
_logger.warning(
|
||||
"survey_record_generation: no existing res.partner found for "
|
||||
"survey.user_input %s while backfilling partner_id/email, "
|
||||
"leaving it untouched",
|
||||
user_input.id,
|
||||
)
|
||||
not_found_count += 1
|
||||
continue
|
||||
|
||||
if user_input.partner_id != record or user_input.email != record.email:
|
||||
user_input.partner_id = record.id
|
||||
user_input.email = record.email
|
||||
fixed_count += 1
|
||||
|
||||
_logger.info(
|
||||
"survey_record_generation: fixed %d survey.user_input records "
|
||||
"(%d without a matching res.partner)",
|
||||
fixed_count,
|
||||
not_found_count,
|
||||
)
|
||||
@@ -39,7 +39,6 @@ class SurveyUserInput(models.Model):
|
||||
for user_input in self:
|
||||
created_records = {}
|
||||
other_record_fields_to_update: list[SurveyRecordCreationFieldValues] = []
|
||||
partner_linked_in_this_run = False
|
||||
|
||||
record_creation: SurveyRecordCreation
|
||||
for (
|
||||
@@ -86,6 +85,8 @@ class SurveyUserInput(models.Model):
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
record = self.env[model].create(vals)
|
||||
if model == "res.partner" and not self.partner_id:
|
||||
self.partner_id = record.id
|
||||
except Exception:
|
||||
# This a broad exception because it could be IntegrityError,
|
||||
# EmptyNamesError in case partner_firstname is installed etc...
|
||||
@@ -102,17 +103,6 @@ class SurveyUserInput(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
if model == "res.partner" and not partner_linked_in_this_run:
|
||||
# Always reflect the partner actually matched/created from
|
||||
# this participant's own answers, even if partner_id/email
|
||||
# were already set on the answer (e.g. inherited from the
|
||||
# logged-in user when the survey link was opened). Only the
|
||||
# first res.partner record creation of this run wins, in
|
||||
# case several are configured on the same survey.
|
||||
user_input.partner_id = record.id
|
||||
user_input.email = record.email
|
||||
partner_linked_in_this_run = True
|
||||
|
||||
created_records[record_creation.id] = record
|
||||
|
||||
# update linked record
|
||||
@@ -325,44 +315,28 @@ class SurveyUserInput(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _get_boolean_true_values(self):
|
||||
"""Tokens interpreted as true, normalized to lowercase.
|
||||
|
||||
Instance method so that a third-party module or a localization can
|
||||
extend the list without rewriting get_boolean_value.
|
||||
"""
|
||||
return {"1", "true", "vrai", "yes", "y", "oui", "o", "on", "x"}
|
||||
|
||||
def _get_boolean_false_values(self):
|
||||
"""Tokens interpreted as false, normalized to lowercase."""
|
||||
return {"0", "false", "faux", "no", "n", "non", "off", ""}
|
||||
|
||||
def get_boolean_value(self, answer_value_char: str, question_title: str) -> bool:
|
||||
"""Convert the technical value of an answer into a boolean.
|
||||
|
||||
Allows a boolean field to be filled from a "simple_choice" question
|
||||
whose suggested answers carry yes/no values.
|
||||
"""
|
||||
if not answer_value_char:
|
||||
# Empty answer: an unset boolean is false, this is not a
|
||||
# configuration error.
|
||||
return False
|
||||
|
||||
token = str(answer_value_char).strip().casefold()
|
||||
|
||||
if token in self._get_boolean_true_values():
|
||||
return True
|
||||
if token in self._get_boolean_false_values():
|
||||
return False
|
||||
|
||||
raise UserError(
|
||||
_(
|
||||
"[Survey record generation] The boolean value %(value)s is not "
|
||||
"supported (for question %(question)s)"
|
||||
@staticmethod
|
||||
def get_boolean_value(answer_value_char: str, question_title: str) -> bool:
|
||||
# Below code is a trick to be able to use "simple_choice" question
|
||||
# with values 'yes' and 'no' and transform it to boolean.
|
||||
if boolean_value := answer_value_char in [
|
||||
"1",
|
||||
"True",
|
||||
"true",
|
||||
"Oui",
|
||||
"oui",
|
||||
"Yes",
|
||||
"yes",
|
||||
]:
|
||||
return boolean_value
|
||||
else:
|
||||
raise UserError(
|
||||
_(
|
||||
"[Survey record generation] The boolean value %s(value)s "
|
||||
"is not supported (for question %(question)s)."
|
||||
)
|
||||
% {
|
||||
"value": answer_value_char,
|
||||
"question": question_title,
|
||||
}
|
||||
)
|
||||
% {
|
||||
"value": answer_value_char,
|
||||
"question": question_title,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
from . import test_survey_record_creation
|
||||
from . import test_end_migration_18_0_1_0_1
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
import importlib.util
|
||||
import os
|
||||
|
||||
from odoo.addons.survey.tests.common import SurveyCase
|
||||
|
||||
|
||||
def _load_end_migration():
|
||||
migration_path = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
||||
"migrations",
|
||||
"18.0.1.0.1",
|
||||
"end-migration.py",
|
||||
)
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"survey_record_generation_end_migration_18_0_1_0_1", migration_path
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class TestEndMigration180101(SurveyCase):
|
||||
"""Covers the use cases the 18.0.1.0.1 end-migration backfill must
|
||||
handle: relinking survey.user_input.partner_id/email to the contact
|
||||
that actually matches each participant's own answers, for submissions
|
||||
whose partner_id/email were left wrong before the fix in this version.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.migration = _load_end_migration()
|
||||
|
||||
self.survey = self.env["survey.survey"].create({"title": "Test Survey"})
|
||||
self.question_name = self._add_question(
|
||||
page=None,
|
||||
name="Name",
|
||||
qtype="char_box",
|
||||
survey_id=self.survey.id,
|
||||
sequence=1,
|
||||
)
|
||||
self.res_partner_model = self.env["ir.model"]._get("res.partner")
|
||||
self.survey_record_creation = self.env["survey.record.creation"].create(
|
||||
{
|
||||
"name": "Contact",
|
||||
"survey_id": self.survey.id,
|
||||
"model_id": self.res_partner_model.id,
|
||||
}
|
||||
)
|
||||
self.name_field = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "res.partner"), ("name", "=", "name")]
|
||||
)
|
||||
self.env["survey.record.creation.field.values"].create(
|
||||
{
|
||||
"survey_record_creation_id": self.survey_record_creation.id,
|
||||
"survey_id": self.survey.id,
|
||||
"model_id": self.res_partner_model.id,
|
||||
"field_id": self.name_field.id,
|
||||
"value_origin": "question",
|
||||
"question_id": self.question_name.id,
|
||||
}
|
||||
)
|
||||
|
||||
def _submit_answer(self, name):
|
||||
answer = self._add_answer(survey=self.survey, partner=False, email=False)
|
||||
self._add_answer_line(
|
||||
question=self.question_name, answer=answer, answer_value=name
|
||||
)
|
||||
answer._mark_done()
|
||||
return answer
|
||||
|
||||
def _corrupt_with_wrong_partner(self, answer):
|
||||
# Simulate a pre-fix record: partner_id/email point to someone
|
||||
# unrelated to this participant's own answers.
|
||||
wrong_partner = self.env["res.partner"].create({"name": "Wrong Partner"})
|
||||
answer.write({"partner_id": wrong_partner.id, "email": "wrong@test.fr"})
|
||||
return wrong_partner
|
||||
|
||||
def test_migrate_uses_generated_record_when_available(self):
|
||||
# The submission created its own res.partner: the migration must
|
||||
# relink partner_id/email to that exact contact.
|
||||
answer = self._submit_answer("Jean")
|
||||
jean = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
self._corrupt_with_wrong_partner(answer)
|
||||
|
||||
self.migration.migrate(self.cr, "18.0.1.0.0")
|
||||
answer.invalidate_recordset()
|
||||
|
||||
self.assertEqual(answer.partner_id, jean)
|
||||
self.assertEqual(answer.email, jean.email)
|
||||
|
||||
def test_migrate_falls_back_to_search_when_no_generated_record(self):
|
||||
# The submission matched an already-existing partner instead of
|
||||
# creating one: no survey.generated.record row exists for it, so the
|
||||
# migration must fall back to re-deriving the match through search.
|
||||
jean = self.env["res.partner"].create(
|
||||
{"name": "Jean", "email": "jean@test.fr"}
|
||||
)
|
||||
self.survey_record_creation.write(
|
||||
{
|
||||
"update_existing_records": True,
|
||||
"field_to_retrieve_existing_records": self.name_field.id,
|
||||
}
|
||||
)
|
||||
|
||||
answer = self._submit_answer("Jean")
|
||||
self.assertFalse(answer.generated_record_ids)
|
||||
self._corrupt_with_wrong_partner(answer)
|
||||
|
||||
self.migration.migrate(self.cr, "18.0.1.0.0")
|
||||
answer.invalidate_recordset()
|
||||
|
||||
self.assertEqual(answer.partner_id, jean)
|
||||
self.assertEqual(answer.email, jean.email)
|
||||
|
||||
def test_migrate_falls_back_to_search_when_generated_partner_was_deleted(self):
|
||||
# The res.partner the submission created has since been deleted
|
||||
# (e.g. merged into another contact): the migration must not crash
|
||||
# on the stale reference and must fall back to search instead.
|
||||
self.survey_record_creation.write(
|
||||
{
|
||||
"update_existing_records": True,
|
||||
"field_to_retrieve_existing_records": self.name_field.id,
|
||||
}
|
||||
)
|
||||
|
||||
answer = self._submit_answer("Jean")
|
||||
first_jean = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
first_jean.unlink()
|
||||
|
||||
# A new contact with the same name takes over.
|
||||
second_jean = self.env["res.partner"].create(
|
||||
{"name": "Jean", "email": "jean2@test.fr"}
|
||||
)
|
||||
self._corrupt_with_wrong_partner(answer)
|
||||
|
||||
self.migration.migrate(self.cr, "18.0.1.0.0")
|
||||
answer.invalidate_recordset()
|
||||
|
||||
self.assertEqual(answer.partner_id, second_jean)
|
||||
self.assertEqual(answer.email, second_jean.email)
|
||||
|
||||
def test_migrate_leaves_answer_untouched_when_no_partner_can_be_found(self):
|
||||
# No survey.generated.record row (e.g. historical data predating
|
||||
# that log) and no way to search (neither update_existing_records
|
||||
# nor unicity_check configured): the migration must leave
|
||||
# partner_id/email as they are instead of guessing or crashing.
|
||||
answer = self._submit_answer("Jean")
|
||||
answer.generated_record_ids.unlink()
|
||||
wrong_partner = self._corrupt_with_wrong_partner(answer)
|
||||
|
||||
self.migration.migrate(self.cr, "18.0.1.0.0")
|
||||
answer.invalidate_recordset()
|
||||
|
||||
self.assertEqual(answer.partner_id, wrong_partner)
|
||||
self.assertEqual(answer.email, "wrong@test.fr")
|
||||
@@ -906,71 +906,6 @@ class TestSurveyRecordCreation(SurveyCase):
|
||||
partner = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
self.assertEqual(self.answer.partner_id, partner)
|
||||
|
||||
def test_partner_id_and_email_are_corrected_when_creating_a_new_partner(self):
|
||||
# A wrong partner_id/email is already set on the answer (e.g.
|
||||
# inherited from the Odoo user who was logged in when the
|
||||
# /survey/start link was opened). The record creation must still
|
||||
# fill partner_id/email with the contact actually created from the
|
||||
# participant's own answers, overriding that wrong value.
|
||||
wrong_partner = self.env["res.partner"].create({"name": "Wrong Partner"})
|
||||
|
||||
self.answer = self._add_answer(
|
||||
survey=self.survey, partner=wrong_partner, email="wrong@test.fr"
|
||||
)
|
||||
self._add_answer_line(
|
||||
question=self.question_name, answer=self.answer, answer_value="Jean"
|
||||
)
|
||||
self.answer._mark_done()
|
||||
|
||||
partner = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
self.assertEqual(self.answer.partner_id, partner)
|
||||
self.assertNotEqual(self.answer.partner_id, wrong_partner)
|
||||
self.assertEqual(self.answer.email, partner.email)
|
||||
|
||||
def test_partner_id_and_email_are_corrected_when_matching_an_existing_partner(self):
|
||||
# Same as above, but this time the record creation matches an
|
||||
# already-existing partner (via update_existing_records) instead of
|
||||
# creating a new one: partner_id/email must still be corrected to
|
||||
# that matched partner, not left as the wrong pre-existing value.
|
||||
jean = self.env["res.partner"].create({"name": "Jean", "email": "jean@test.fr"})
|
||||
wrong_partner = self.env["res.partner"].create({"name": "Wrong Partner"})
|
||||
|
||||
self.survey_record_creation.write(
|
||||
{
|
||||
"update_existing_records": True,
|
||||
"field_to_retrieve_existing_records": self.name_field.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.answer = self._add_answer(
|
||||
survey=self.survey, partner=wrong_partner, email="wrong@test.fr"
|
||||
)
|
||||
self._add_answer_line(
|
||||
question=self.question_name, answer=self.answer, answer_value="Jean"
|
||||
)
|
||||
self.answer._mark_done()
|
||||
|
||||
self.assertEqual(self.answer.partner_id, jean)
|
||||
self.assertEqual(self.answer.email, jean.email)
|
||||
|
||||
def test_partner_id_and_email_are_corrected_when_matching_a_duplicate(self):
|
||||
# Same as above, but through the unicity_check/find_duplicate branch
|
||||
# instead of update_existing_records.
|
||||
self.name_survey_record_creation_field_values.unicity_check = True
|
||||
jean = self.env["res.partner"].create({"name": "Jean", "email": "jean@test.fr"})
|
||||
wrong_partner = self.env["res.partner"].create({"name": "Wrong Partner"})
|
||||
|
||||
self.answer = self._add_answer(
|
||||
survey=self.survey, partner=wrong_partner, email="wrong@test.fr"
|
||||
)
|
||||
self._add_answer_line(
|
||||
question=self.question_name, answer=self.answer, answer_value="Jean"
|
||||
)
|
||||
self.answer._mark_done()
|
||||
|
||||
self.assertEqual(self.answer.partner_id, jean)
|
||||
self.assertEqual(self.answer.email, jean.email)
|
||||
|
||||
def test_partner_id_in_survey_input_is_filled_up_by_first_contact_record_creation(self):
|
||||
# In this test, we verify that when creating several contacts with the same survey,
|
||||
# the 1st created contact is used to fill up survey_input.partner_id
|
||||
@@ -1017,58 +952,3 @@ class TestSurveyRecordCreation(SurveyCase):
|
||||
|
||||
partner = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
self.assertEqual(self.answer.partner_id, partner)
|
||||
|
||||
def test_partner_id_is_not_overridden_by_second_contact_record_creation(self):
|
||||
# When several res.partner record creations run on the same survey,
|
||||
# partner_id/email must be corrected to match the first contact
|
||||
# created, and the second contact created must not override that
|
||||
# choice, even though the answer started with a wrong
|
||||
# partner_id/email.
|
||||
self.second_question_name = self._add_question(
|
||||
page=None,
|
||||
name="Name of second person",
|
||||
qtype="char_box",
|
||||
survey_id=self.survey.id,
|
||||
sequence=1,
|
||||
)
|
||||
|
||||
self.second_contact_creation = self.env["survey.record.creation"].create(
|
||||
{
|
||||
"name": "Contact 2",
|
||||
"survey_id": self.survey.id,
|
||||
"model_id": self.res_partner_model.id,
|
||||
}
|
||||
)
|
||||
self.env["survey.record.creation.field.values"].create(
|
||||
{
|
||||
"survey_record_creation_id": self.second_contact_creation.id,
|
||||
"survey_id": self.survey.id,
|
||||
"model_id": self.res_partner_model.id,
|
||||
"field_id": self.name_field.id,
|
||||
"value_origin": "question",
|
||||
"question_id": self.second_question_name.id,
|
||||
}
|
||||
)
|
||||
|
||||
wrong_partner = self.env["res.partner"].create({"name": "Wrong Partner"})
|
||||
|
||||
self.answer = self._add_answer(
|
||||
survey=self.survey, partner=wrong_partner, email="wrong@test.fr"
|
||||
)
|
||||
self._add_answer_line(
|
||||
question=self.question_name,
|
||||
answer=self.answer,
|
||||
answer_value="Jean",
|
||||
)
|
||||
self._add_answer_line(
|
||||
question=self.second_question_name,
|
||||
answer=self.answer,
|
||||
answer_value="Jeanne",
|
||||
)
|
||||
self.answer._mark_done()
|
||||
|
||||
jean = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
jeanne = self.env["res.partner"].search([("name", "=", "Jeanne")])
|
||||
self.assertEqual(self.answer.partner_id, jean)
|
||||
self.assertNotEqual(self.answer.partner_id, jeanne)
|
||||
self.assertEqual(self.answer.email, jean.email)
|
||||
|
||||
Reference in New Issue
Block a user