Compare commits
2 Commits
16.0
...
63e5e6da4f
| Author | SHA1 | Date | |
|---|---|---|---|
| 63e5e6da4f | |||
| e49803baca |
@@ -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:
|
||||
- "16.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:
|
||||
- "16.0*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: odoo-ci
|
||||
container:
|
||||
image: docker.0k.io/mirror/odoo:rc_16.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/
|
||||
|
||||
@@ -49,9 +49,12 @@ 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"
|
||||
--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
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# survey_dropdown_simple_choice
|
||||
|
||||
Ajoute une option « Afficher en liste déroulante » aux questions
|
||||
« Choix multiple : une seule réponse » des sondages : les réponses sont
|
||||
proposées dans une liste déroulante au lieu de boutons radio.
|
||||
|
||||
Pratique pour les longues listes (pays, départements…).
|
||||
|
||||
## Utilisation
|
||||
|
||||
Dans le sondage, éditez la question → onglet **Options** → cochez
|
||||
**« Afficher en liste déroulante »**.
|
||||
|
||||
L'option « Autre » (commentaire) et les questions conditionnelles
|
||||
fonctionnent comme d'habitude.
|
||||
|
||||
## Limites
|
||||
|
||||
- Si une réponse proposée contient une image, la question reste affichée
|
||||
en boutons radio.
|
||||
- À l'impression et dans la revue des réponses (« Consulter vos réponses »),
|
||||
seule la réponse choisie est affichée, ainsi que la bonne réponse pour
|
||||
un sondage noté.
|
||||
@@ -1 +0,0 @@
|
||||
from . import models
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"name": "Survey Dropdown Simple Choice",
|
||||
"summary": "Display some single choice survey questions as a dropdown list",
|
||||
"description": "Adds a boolean on survey.question to display a "
|
||||
"\"Multiple choice: only one answer\" question as a dropdown list "
|
||||
"instead of radio buttons, with support for conditional questions "
|
||||
"and \"Other\" comments.",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
"category": "Marketing/Surveys",
|
||||
"license": "AGPL-3",
|
||||
"version": "16.0.1.0.0",
|
||||
"depends": ["survey"],
|
||||
"data": [
|
||||
"views/survey_question_views.xml",
|
||||
"views/survey_templates.xml",
|
||||
],
|
||||
"assets": {
|
||||
"survey.survey_assets": [
|
||||
"survey_dropdown_simple_choice/static/src/scss/survey_dropdown.scss",
|
||||
"survey_dropdown_simple_choice/static/src/js/survey_form_dropdown.js",
|
||||
],
|
||||
},
|
||||
"installable": True,
|
||||
"application": False,
|
||||
"auto_install": True,
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * survey_dropdown_simple_choice
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 16.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-10-20 17:08+0000\n"
|
||||
"PO-Revision-Date: 2026-10-20 17:08+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: survey_dropdown_simple_choice
|
||||
#: model:ir.model.fields,field_description:survey_dropdown_simple_choice.field_survey_question__display_dropdown
|
||||
msgid "Display as dropdown list"
|
||||
msgstr "Afficher en liste déroulante"
|
||||
|
||||
#. module: survey_dropdown_simple_choice
|
||||
#: model:ir.model.fields,help:survey_dropdown_simple_choice.field_survey_question__display_dropdown
|
||||
msgid ""
|
||||
"Display this single choice question as a dropdown list instead of radio "
|
||||
"buttons. Ignored if the suggested answers contain images."
|
||||
msgstr ""
|
||||
"Affiche cette question à choix unique sous la forme d'une liste déroulante "
|
||||
"au lieu de boutons radio. Ignoré si les réponses proposées contiennent des "
|
||||
"images."
|
||||
|
||||
#. module: survey_dropdown_simple_choice
|
||||
#: model:ir.model.fields,field_description:survey_dropdown_simple_choice.field_survey_question__smart_search
|
||||
msgid "Smart Search"
|
||||
msgstr "Recherche intelligente"
|
||||
|
||||
#. module: survey_dropdown_simple_choice
|
||||
#: model:ir.model,name:survey_dropdown_simple_choice.model_survey_question
|
||||
msgid "Survey Question"
|
||||
msgstr "Question du sondage"
|
||||
@@ -1 +0,0 @@
|
||||
from . import survey_question
|
||||
@@ -1,11 +0,0 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SurveyQuestion(models.Model):
|
||||
_inherit = 'survey.question'
|
||||
|
||||
display_dropdown = fields.Boolean(
|
||||
string="Display as dropdown list",
|
||||
help="Display this single choice question as a dropdown list instead "
|
||||
"of radio buttons. Ignored if the suggested answers contain images.",
|
||||
)
|
||||
@@ -1,55 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import SurveyFormWidget from "survey.form";
|
||||
|
||||
// The dropdown only drives the native radios (hidden by CSS): choosing an
|
||||
// option clicks the matching radio, so validation, conditional questions,
|
||||
// "Other" comment, auto-submit and AJAX submit are all handled natively.
|
||||
SurveyFormWidget.include({
|
||||
events: Object.assign({}, SurveyFormWidget.prototype.events, {
|
||||
'change select.o_survey_dropdown_choice': '_onDropdownChoiceChange',
|
||||
'change [data-survey-dropdown="edit"] .o_survey_form_choice_item': '_onDropdownRadioChange',
|
||||
}),
|
||||
|
||||
/**
|
||||
* A focused dropdown is handled like a text input: its keys (letters,
|
||||
* arrows, enter) must not trigger the survey shortcuts.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
_onKeyDown: function (event) {
|
||||
if (event.target.matches?.('select.o_survey_dropdown_choice')
|
||||
&& !((event.ctrlKey || event.metaKey) && event.key === 'Enter')) {
|
||||
return;
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Click the radio of the chosen option, or the checked one to untick it
|
||||
* when the empty option is chosen (native untick behavior).
|
||||
*/
|
||||
_onDropdownChoiceChange: function (ev) {
|
||||
if (this.readonly) {
|
||||
return;
|
||||
}
|
||||
const select = ev.currentTarget;
|
||||
const group = select.closest('.o_survey_form_choice');
|
||||
const radio = select.value
|
||||
? group.querySelector(`.o_survey_form_choice_item[value="${select.value}"]`)
|
||||
: group.querySelector('.o_survey_form_choice_item:checked');
|
||||
if (radio && !(select.value && radio.checked)) {
|
||||
radio.click();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Keep the dropdown in sync when a radio changes by other means
|
||||
* (A-Z keyboard shortcuts).
|
||||
*/
|
||||
_onDropdownRadioChange: function (ev) {
|
||||
const group = ev.currentTarget.closest('.o_survey_form_choice');
|
||||
const checked = group.querySelector('.o_survey_form_choice_item:checked');
|
||||
group.querySelector('select.o_survey_dropdown_choice').value = checked ? checked.value : '';
|
||||
},
|
||||
});
|
||||
@@ -1,19 +0,0 @@
|
||||
.o_survey_form {
|
||||
select.o_survey_dropdown_choice {
|
||||
min-height: 44px;
|
||||
|
||||
option {
|
||||
color: initial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Native radios still carry the answer but are replaced by the dropdown
|
||||
.o_survey_form_choice[data-survey-dropdown="edit"] .o_survey_choice_btn {
|
||||
display: none;
|
||||
}
|
||||
|
||||
// Review / print: only show the selected and correct answers
|
||||
.o_survey_form_choice[data-survey-dropdown="review"] .o_survey_choice_btn:not(.o_survey_selected):not(.bg-success) {
|
||||
display: none;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="survey_question_form_dropdown" model="ir.ui.view">
|
||||
<field name="name">survey.question.form.dropdown</field>
|
||||
<field name="model">survey.question</field>
|
||||
<field name="inherit_id" ref="survey.survey_question_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='comments_allowed']" position="before">
|
||||
<field name="display_dropdown" attrs="{'invisible': [('question_type', '!=', 'simple_choice')]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- Add a dropdown on top of the native radios when the display_dropdown
|
||||
flag is set. The radios are kept (hidden by CSS) and still carry the
|
||||
answer: the dropdown only clicks them (see survey_form_dropdown.js).
|
||||
In readonly mode (review / print), the radios are shown but only the
|
||||
selected and correct answers are kept visible (data-survey-dropdown
|
||||
"review"). The native rendering is kept when a suggestion carries an
|
||||
image. -->
|
||||
<template id="question_simple_choice" inherit_id="survey.question_simple_choice" name="Question: simple choice (dropdown)">
|
||||
<xpath expr="//t[@t-set='comment_line']" position="after">
|
||||
<t t-set="dropdown_enabled" t-value="question.display_dropdown and not any(a.value_image for a in question.suggested_answer_ids)"/>
|
||||
<t t-set="use_dropdown" t-value="dropdown_enabled and not survey_form_readonly"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('o_survey_form_choice')]" position="attributes">
|
||||
<attribute name="t-att-data-survey-dropdown">('review' if survey_form_readonly else 'edit') if dropdown_enabled else None</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('o_survey_form_choice')]/t[@t-set='item_idx']" position="after">
|
||||
<div t-if="use_dropdown" class="col-lg-12 mb-2 o_survey_dropdown_select">
|
||||
<select class="form-select o_survey_dropdown_choice" t-att-aria-label="question.title">
|
||||
<option value=""/>
|
||||
<option t-foreach="question.suggested_answer_ids" t-as="label"
|
||||
t-att-value="label.id"
|
||||
t-att-selected="'selected' if answer_line.suggested_answer_id == label else None"
|
||||
t-out="label.value"/>
|
||||
<option t-if="question.comments_allowed and question.comment_count_as_answer" value="-1"
|
||||
t-att-selected="'selected' if comment_line else None"
|
||||
t-out="question.comments_message or default_comments_message"/>
|
||||
</select>
|
||||
</div>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
@@ -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": "16.0.1.0.4",
|
||||
"version": "16.0.1.0.3",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
|
||||
@@ -61,11 +61,6 @@ class SurveyUserInput(models.Model):
|
||||
)
|
||||
field_name: str = field_value.field_id.name
|
||||
|
||||
if value is None:
|
||||
# No value (e.g. question not displayed or skipped):
|
||||
# keep the default/computed value of the field, and
|
||||
# let another question fill up the same field.
|
||||
continue
|
||||
vals[field_name] = value
|
||||
|
||||
existing_record = self.find_existing_record(record_creation, vals)
|
||||
@@ -165,9 +160,8 @@ class SurveyUserInput(models.Model):
|
||||
elif field_value.value_origin == "question":
|
||||
value = self.get_value_from_user_answer(field_value, user_input)
|
||||
elif field_value.value_origin == "other_record":
|
||||
# if the other record is already created, get it
|
||||
# (or raise if it is not created yet and the field is required)
|
||||
value = self.get_value_from_other_record(
|
||||
# if the other_record value is a required field, get it or raise
|
||||
value = self.get_required_value_from_other_record(
|
||||
model, created_records, field_value
|
||||
)
|
||||
# otherwise, we update the record later (out of this for loop)
|
||||
@@ -200,34 +194,39 @@ class SurveyUserInput(models.Model):
|
||||
if unique_fields:
|
||||
uniq_domain = []
|
||||
for uniq_field in unique_fields:
|
||||
uniq_domain.append((uniq_field, "=", vals.get(uniq_field, False)))
|
||||
uniq_domain.append((uniq_field, "=", vals[uniq_field]))
|
||||
duplicate = self.env[model].search(uniq_domain, limit=1)
|
||||
return duplicate
|
||||
|
||||
def get_value_from_other_record(
|
||||
def get_required_value_from_other_record(
|
||||
self,
|
||||
model: str,
|
||||
created_records: dict[Any, Any],
|
||||
field_value: "SurveyRecordCreationFieldValues",
|
||||
) -> Any:
|
||||
linked_record = created_records.get(field_value.other_created_record_id.id)
|
||||
if linked_record:
|
||||
# The other record is already created: link it right away.
|
||||
return self.get_value_for_relational_field(field_value, linked_record)
|
||||
if self.env[model]._fields[field_value.field_id.name].required:
|
||||
raise UserError(
|
||||
_(
|
||||
"The field %(field)s is mandatory for model %(model)s. "
|
||||
"In Record Creation tab, drag %(record)s "
|
||||
"on top of the model %(model)s."
|
||||
model_class = self.env[model]
|
||||
if model_class._fields[field_value.field_id.name].required:
|
||||
# check if the other record is already created,
|
||||
# if yes add it to vals, else raise
|
||||
if (
|
||||
len(created_records) > 0
|
||||
and created_records[field_value.other_created_record_id.id]
|
||||
):
|
||||
linked_record = created_records[field_value.other_created_record_id.id]
|
||||
return self.get_value_for_relational_field(field_value, linked_record)
|
||||
else:
|
||||
raise UserError(
|
||||
_(
|
||||
"The field %(field)s is mandatory for model %(model)s. "
|
||||
"In Record Creation tab, drag %(record)s "
|
||||
"on top of the model %(model)s."
|
||||
)
|
||||
% {
|
||||
"field": field_value.field_id.display_name,
|
||||
"model": model,
|
||||
"record": field_value.other_created_record_id.name,
|
||||
}
|
||||
)
|
||||
% {
|
||||
"field": field_value.field_id.display_name,
|
||||
"model": model,
|
||||
"record": field_value.other_created_record_id.name,
|
||||
}
|
||||
)
|
||||
return None
|
||||
|
||||
def get_value_from_user_answer(
|
||||
self,
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
from . import test_survey_record_creation
|
||||
from . import test_end_migration_16_0_1_0_3
|
||||
from . import test_computed_fields
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SurveyRecordGenerationFakeParent(models.Model):
|
||||
_name = "survey.record.generation.fake.parent"
|
||||
_description = "Fake parent record (tests only)"
|
||||
|
||||
name = fields.Char()
|
||||
price = fields.Float()
|
||||
|
||||
|
||||
class SurveyRecordGenerationFakeLine(models.Model):
|
||||
"""Line whose price is computed from its parent, like the price of a
|
||||
subscription line (subscription_oca).
|
||||
|
||||
Pattern reproduced: the survey creates a parent, then a line linked to
|
||||
it, with a price answered by the user. The user's price must be kept,
|
||||
the parent's price only applies when the user gave none.
|
||||
"""
|
||||
|
||||
_name = "survey.record.generation.fake.line"
|
||||
_description = "Fake line record (tests only)"
|
||||
|
||||
parent_id = fields.Many2one("survey.record.generation.fake.parent")
|
||||
price_unit = fields.Float(
|
||||
compute="_compute_price_unit", store=True, readonly=False
|
||||
)
|
||||
|
||||
@api.depends("parent_id.price")
|
||||
def _compute_price_unit(self):
|
||||
for line in self:
|
||||
if line.parent_id:
|
||||
line.price_unit = line.parent_id.price
|
||||
@@ -1,120 +0,0 @@
|
||||
from odoo_test_helper import FakeModelLoader
|
||||
|
||||
from odoo.addons.survey.tests.common import SurveyCase
|
||||
|
||||
|
||||
class TestComputedFields(SurveyCase):
|
||||
"""User's answers must not be overridden by computed fields depending on
|
||||
a link to another generated record.
|
||||
|
||||
Use case: a membership form creating a subscription and a subscription
|
||||
line whose price is typed by the participant (free amount), while the
|
||||
line price is computed from the subscription.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.loader = FakeModelLoader(cls.env, cls.__module__)
|
||||
cls.loader.backup_registry()
|
||||
from .fake_models import (
|
||||
SurveyRecordGenerationFakeLine,
|
||||
SurveyRecordGenerationFakeParent,
|
||||
)
|
||||
|
||||
cls.loader.update_registry(
|
||||
(SurveyRecordGenerationFakeParent, SurveyRecordGenerationFakeLine)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.loader.restore_registry()
|
||||
super().tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.survey = self.env["survey.survey"].create({"title": "Join us"})
|
||||
self.question_amount = self._add_question(
|
||||
page=None,
|
||||
name="Free amount",
|
||||
qtype="numerical_box",
|
||||
survey_id=self.survey.id,
|
||||
sequence=1,
|
||||
)
|
||||
|
||||
# Parent, with a default price of 20
|
||||
self.parent_creation = self._add_record_creation(
|
||||
"Parent", "survey.record.generation.fake.parent", 0
|
||||
)
|
||||
self._add_field_value(
|
||||
self.parent_creation, "name", value_origin="fixed",
|
||||
fixed_value_char="Membership",
|
||||
)
|
||||
self._add_field_value(
|
||||
self.parent_creation, "price", value_origin="fixed",
|
||||
fixed_value_float=20.0,
|
||||
)
|
||||
|
||||
# Line, linked to the parent, with the price answered by the user
|
||||
self.line_creation = self._add_record_creation(
|
||||
"Line", "survey.record.generation.fake.line", 1
|
||||
)
|
||||
self._add_field_value(
|
||||
self.line_creation, "parent_id", value_origin="other_record",
|
||||
other_created_record_id=self.parent_creation.id,
|
||||
)
|
||||
self._add_field_value(
|
||||
self.line_creation, "price_unit", value_origin="question",
|
||||
question_id=self.question_amount.id,
|
||||
)
|
||||
|
||||
def _add_record_creation(self, name, model, sequence):
|
||||
return self.env["survey.record.creation"].create(
|
||||
{
|
||||
"name": name,
|
||||
"survey_id": self.survey.id,
|
||||
"model_id": self.env["ir.model"]._get(model).id,
|
||||
"sequence": sequence,
|
||||
}
|
||||
)
|
||||
|
||||
def _add_field_value(self, record_creation, field_name, **vals):
|
||||
field = self.env["ir.model.fields"]._get(
|
||||
record_creation.model_id.model, field_name
|
||||
)
|
||||
return self.env["survey.record.creation.field.values"].create(
|
||||
{
|
||||
"survey_record_creation_id": record_creation.id,
|
||||
"survey_id": self.survey.id,
|
||||
"model_id": record_creation.model_id.id,
|
||||
"field_id": field.id,
|
||||
**vals,
|
||||
}
|
||||
)
|
||||
|
||||
def _submit(self, amount=None):
|
||||
answer = self._add_answer(
|
||||
survey=self.survey, partner=False, email="jean@test.fr"
|
||||
)
|
||||
if amount is not None:
|
||||
self._add_answer_line(
|
||||
question=self.question_amount, answer=answer, answer_value=amount
|
||||
)
|
||||
answer._mark_done()
|
||||
return self.env["survey.record.generation.fake.line"].search(
|
||||
[("parent_id.name", "=", "Membership")]
|
||||
)
|
||||
|
||||
def test_answer_is_not_overridden_by_computed_field(self):
|
||||
line = self._submit(amount=33)
|
||||
|
||||
self.assertEqual(len(line), 1)
|
||||
self.assertEqual(line.price_unit, 33.0)
|
||||
|
||||
def test_computed_field_applies_when_question_is_not_displayed(self):
|
||||
# E.g. the "free amount" question is only displayed when the user
|
||||
# chose "Other amount": otherwise the line keeps the computed price.
|
||||
line = self._submit()
|
||||
|
||||
self.assertEqual(len(line), 1)
|
||||
self.assertEqual(line.price_unit, 20.0)
|
||||
@@ -1096,82 +1096,3 @@ class TestSurveyRecordCreation(SurveyCase):
|
||||
self.assertEqual(self.answer.partner_id, jean)
|
||||
self.assertNotEqual(self.answer.partner_id, jeanne)
|
||||
self.assertEqual(self.answer.email, jean.email)
|
||||
|
||||
def test_question_not_displayed_does_not_override_default_value(self):
|
||||
# When a question is not displayed to the user (e.g. a conditional
|
||||
# question), the field must keep its default (or computed) value
|
||||
# instead of being emptied.
|
||||
question_type = self._add_question(
|
||||
page=None,
|
||||
name="Type",
|
||||
qtype="simple_choice",
|
||||
labels=[{"value": "contact"}, {"value": "other"}],
|
||||
survey_id=self.survey.id,
|
||||
sequence=2,
|
||||
answer_values_type="value",
|
||||
)
|
||||
for suggested_answer in question_type.suggested_answer_ids:
|
||||
suggested_answer.value_char = suggested_answer.value
|
||||
type_field = self.env["ir.model.fields"]._get("res.partner", "type")
|
||||
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": type_field.id,
|
||||
"value_origin": "question",
|
||||
"question_id": question_type.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.answer = self._add_answer(
|
||||
survey=self.survey, partner=False, email="jean@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(partner.type, "contact")
|
||||
|
||||
def test_several_conditional_questions_on_the_same_field(self):
|
||||
# Several questions can fill up the same field (e.g. one list of
|
||||
# amounts per periodicity, displayed conditionally): the answered
|
||||
# question wins, the questions not displayed are ignored.
|
||||
street_field = self.env["ir.model.fields"]._get("res.partner", "street")
|
||||
questions = self.env["survey.question"]
|
||||
for sequence, name in enumerate(["Street (France)", "Street (abroad)"], 2):
|
||||
question = self._add_question(
|
||||
page=None,
|
||||
name=name,
|
||||
qtype="char_box",
|
||||
survey_id=self.survey.id,
|
||||
sequence=sequence,
|
||||
)
|
||||
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": street_field.id,
|
||||
"value_origin": "question",
|
||||
"question_id": question.id,
|
||||
}
|
||||
)
|
||||
questions |= question
|
||||
|
||||
self.answer = self._add_answer(
|
||||
survey=self.survey, partner=False, email="jean@test.fr"
|
||||
)
|
||||
self._add_answer_line(
|
||||
question=self.question_name, answer=self.answer, answer_value="Jean"
|
||||
)
|
||||
# Only the first question is displayed and answered
|
||||
self._add_answer_line(
|
||||
question=questions[0], answer=self.answer, answer_value="1 rue de Paris"
|
||||
)
|
||||
self.answer._mark_done()
|
||||
|
||||
partner = self.env["res.partner"].search([("name", "=", "Jean")])
|
||||
self.assertEqual(partner.street, "1 rue de Paris")
|
||||
|
||||
Reference in New Issue
Block a user