diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000000000000000000000000000000000..bfd7ac53df9f103f6dc8853738c63fd364445fde --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# Configuration for known file extensions +[*.{css,js,json,less,md,py,rst,sass,scss,xml,yaml,yml}] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,yml,yaml,rst,md}] +indent_size = 2 + +# Do not configure editor for libs and autogenerated content +[{*/static/{lib,src/lib}/**,*/static/description/index.html,*/readme/../README.rst}] +charset = unset +end_of_line = unset +indent_size = unset +indent_style = unset +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000000000000000000000000000000000000..d4cc423ccda9db9691205c9da83307af97b2670f --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,187 @@ +env: + browser: true + es6: true + +# See https://github.com/OCA/odoo-community.org/issues/37#issuecomment-470686449 +parserOptions: + ecmaVersion: 2017 + +overrides: + - files: + - "**/*.esm.js" + parserOptions: + sourceType: module + +# Globals available in Odoo that shouldn't produce errorings +globals: + _: readonly + $: readonly + fuzzy: readonly + jQuery: readonly + moment: readonly + odoo: readonly + openerp: readonly + owl: readonly + +# Styling is handled by Prettier, so we only need to enable AST rules; +# see https://github.com/OCA/maintainer-quality-tools/pull/618#issuecomment-558576890 +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 + valid-jsdoc: + - warn + - prefer: + arg: param + argument: param + augments: extends + constructor: class + exception: throws + func: function + method: function + prop: property + return: returns + virtual: abstract + yield: yields + preferType: + array: Array + bool: Boolean + boolean: Boolean + number: Number + object: Object + str: String + string: String + requireParamDescription: false + requireReturn: false + requireReturnDescription: false + requireReturnType: false + valid-typeof: warn + yoda: warn diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000000000000000000000000000000000..e397e8ed4e3e7f7fe7785dd391bb80aa6d85575e --- /dev/null +++ b/.flake8 @@ -0,0 +1,12 @@ +[flake8] +max-line-length = 88 +max-complexity = 16 +# B = bugbear +# B9 = bugbear opinionated (incl line length) +select = C,E,F,W,B,B9 +# E203: whitespace before ':' (black behaviour) +# E501: flake8 line length (covered by bugbear B950) +# W503: line break before binary operator (black behaviour) +ignore = E203,E501,W503 +per-file-ignores= + __init__.py:F401 diff --git a/.gitignore b/.gitignore index 75bb2042901930f807a588241612a29dd75e34d5..818770fb1bdc0a144e924c9a5940f0b035df8a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,75 @@ -.* -*.pyc -!.gitignore +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +/.venv +/.pytest_cache + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +*.eggs + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Pycharm +.idea + +# Eclipse +.settings + +# Visual Studio cache/options directory +.vs/ +.vscode + +# OSX Files +.DS_Store + +# Django stuff: +*.log + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Sphinx documentation +docs/_build/ + +# Backup files +*~ +*.swp + +# OCA rules +!static/lib/ diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000000000000000000000000000000000000..0ec187efd1bf802844749f508cda0c8f138970f9 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,13 @@ +[settings] +; see https://github.com/psf/black +multi_line_output=3 +include_trailing_comma=True +force_grid_wrap=0 +combine_as_imports=True +use_parentheses=True +line_length=88 +known_odoo=odoo +known_odoo_addons=odoo.addons +sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER +default_section=THIRDPARTY +ensure_newline_before_comments = True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1c6434bfc2274c73d98dbf62b6de9baccdc353ce --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,127 @@ +exclude: | + (?x) + # NOT INSTALLABLE ADDONS + # END NOT INSTALLABLE ADDONS + # Files and folders generated by bots, to avoid loops + ^setup/|/static/description/index\.html$| + # We don't want to mess with tool-generated files + .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/| + # Maybe reactivate this when all README files include prettier ignore tags? + ^README\.md$| + # Library files can have extraneous formatting (even minimized) + /static/(src/)?lib/| + # Repos using Sphinx to generate docs don't need prettying + ^docs/_templates/.*\.html$| + # You don't usually want a bot to modify your legal texts + (LICENSE.*|COPYING.*) +default_language_version: + python: python3 + node: "14.13.0" +repos: + - repo: local + hooks: + # These files are most likely copier diff rejection junks; if found, + # review them manually, fix the problem (if needed) and remove them + - id: forbidden-files + name: forbidden files + entry: found forbidden files; remove them + language: fail + files: "\\.rej$" + - repo: https://github.com/oca/maintainer-tools + rev: ab1d7f6 + hooks: + # update the NOT INSTALLABLE ADDONS section above + - id: oca-update-pre-commit-excluded-addons + - id: oca-fix-manifest-website + args: ["https://le-filament.com"] + - repo: https://github.com/myint/autoflake + rev: v1.4 + hooks: + - id: autoflake + args: + - --expand-star-imports + - --ignore-init-module-imports + - --in-place + - --remove-all-unused-imports + - --remove-duplicate-keys + - --remove-unused-variables + - repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.1.2 + hooks: + - id: prettier + name: prettier (with plugin-xml) + additional_dependencies: + - "prettier@2.1.2" + - "@prettier/plugin-xml@0.12.0" + args: + - --plugin=@prettier/plugin-xml + files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$ + - repo: https://github.com/pre-commit/mirrors-eslint + rev: v7.8.1 + hooks: + - id: eslint + verbose: true + args: + - --color + - --fix + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + # exclude autogenerated files + exclude: /README\.rst$|\.pot?$ + - id: end-of-file-fixer + # exclude autogenerated files + exclude: /README\.rst$|\.pot?$ + - id: debug-statements + - id: fix-encoding-pragma + args: ["--remove"] + - id: check-case-conflict + - id: check-docstring-first + - id: check-executables-have-shebangs + - id: check-merge-conflict + # exclude files where underlines are not distinguishable from merge conflicts + exclude: /README\.rst$|^docs/.*\.rst$ + - id: check-symlinks + - id: check-xml + - id: mixed-line-ending + args: ["--fix=lf"] + - repo: https://github.com/asottile/pyupgrade + rev: v2.7.2 + hooks: + - id: pyupgrade + args: ["--keep-percent-format"] + - repo: https://github.com/PyCQA/isort + rev: 5.5.1 + hooks: + - id: isort + name: isort except __init__.py + args: + - --settings=. + exclude: /__init__\.py$ + - repo: https://gitlab.com/PyCQA/flake8 + rev: 3.8.3 + hooks: + - id: flake8 + name: flake8 + additional_dependencies: ["flake8-bugbear==20.1.4"] + - repo: https://github.com/PyCQA/pylint + rev: pylint-2.5.3 + hooks: + - id: pylint + name: pylint with optional checks + args: + - --rcfile=.pylintrc + - --exit-zero + verbose: true + additional_dependencies: &pylint_deps + - pylint-odoo==3.5.0 + - id: pylint + name: pylint with mandatory checks + args: + - --rcfile=.pylintrc-mandatory + additional_dependencies: *pylint_deps diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b6d4b361ace92f3877993bf2848fac190d8fab6 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,8 @@ +# Defaults for all prettier-supported languages. +# Prettier will complete this with settings from .editorconfig file. +bracketSpacing: false +printWidth: 88 +proseWrap: always +semi: true +trailingComma: "es5" +xmlWhitespaceSensitivity: "strict" diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000000000000000000000000000000000000..dc6270e15be0c08da00e768a570f27c785d8630e --- /dev/null +++ b/.pylintrc @@ -0,0 +1,87 @@ +[MASTER] +load-plugins=pylint_odoo +score=n + +[ODOOLINT] +readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" +manifest_required_authors=Le Filament +manifest_required_keys=license +manifest_deprecated_keys=description,active +license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 +valid_odoo_versions=14.0 + +[MESSAGES CONTROL] +disable=all + +# This .pylintrc contains optional AND mandatory checks and is meant to be +# loaded in an IDE to have it check everything, in the hope this will make +# optional checks more visible to contributors who otherwise never look at a +# green travis to see optional checks that failed. +# .pylintrc-mandatory containing only mandatory checks is used the pre-commit +# config as a blocking check. + +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, + eval-used, + incoherent-interpreter-exec-perm, + license-allowed, + manifest-author-string, + manifest-deprecated-key, + manifest-required-author, + manifest-required-key, + manifest-version-format, + method-compute, + 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, + # 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, + no-utf8-coding-comment, + odoo-addons-relative-import, + old-api7-method-defined, + redefined-builtin, + too-complex, + unnecessary-utf8-coding-comment + + +[REPORTS] +msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} +output-format=colorized +reports=no diff --git a/.pylintrc-mandatory b/.pylintrc-mandatory new file mode 100644 index 0000000000000000000000000000000000000000..43ea23947166ff8080219007cfae43ec54a28f8e --- /dev/null +++ b/.pylintrc-mandatory @@ -0,0 +1,64 @@ +[MASTER] +load-plugins=pylint_odoo +score=n + +[ODOOLINT] +readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" +manifest_required_authors=Le Filament +manifest_required_keys=license +manifest_deprecated_keys=description,active +license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 +valid_odoo_versions=14.0 + +[MESSAGES CONTROL] +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, + eval-used, + incoherent-interpreter-exec-perm, + license-allowed, + manifest-author-string, + manifest-deprecated-key, + manifest-required-author, + manifest-required-key, + manifest-version-format, + method-compute, + 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 + +[REPORTS] +msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} +output-format=colorized +reports=no diff --git a/LICENSE b/LICENSE index 3ffc5678936860cc15a4d2d2e2c8db1dbb5ff219..eb37cafa97f50fd1f5768033d3652165b5810e75 100755 --- a/LICENSE +++ b/LICENSE @@ -617,45 +617,3 @@ Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -<http://www.gnu.org/licenses/>. \ No newline at end of file diff --git a/README.rst b/README.rst old mode 100755 new mode 100644 index 9ddc0a1c1d9efb9862a1bada3e55a1ad27721b9d..6cd110f6561b61d133e0d7ace35266eeed2073ec --- a/README.rst +++ b/README.rst @@ -3,22 +3,29 @@ :alt: License: AGPL-3 -=========================== -CG Scop - Partner Dashboard -=========================== +==================================== +CG SCOP - Gestion Dashboard Contacts +==================================== -Description -=========== +Ce module ajoute une vue dashboard pour faciliter la gestion des coopératives et des contacts. -Ajoute un tableau de bord au menu contact pour les UR. Credits ======= +Funders +------------ + +The development of this module has been financially supported by: + + Confédération Générale des SCOP (https://www.les-scop.coop) + + Contributors ------------ * Hervé Silvant <hsilvant@scop.coop> +* Benjamin Rivier <benjamin@le-filament.com> Maintainer diff --git a/__init__.py b/__init__.py index 5ea0fdc7b5b17460f4470c015275932cebb49ec3..5c6cd321bfe94af65a4134836fd50d27ae7ccb01 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- +# © 2020 Le Filament (<https://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import models -from . import controllers -from . import wizard \ No newline at end of file +from . import controllers, report, wizard diff --git a/__manifest__.py b/__manifest__.py index abce1aaf532bae9c7a08a344f0180979dc136580..51528da5a0ba30e7ec7079210c693434daeff662 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -1,17 +1,21 @@ +# © 2020 Le Filament (<https://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': "CGSCOP Partner Dashboard", - 'summary': "Dashboard coopératives", - 'author': "CGSCOP", - 'version': '12.0.0.0', - 'depends': ["cgscop_partner","cgscop_partner_crm","cgscop_timesheet"], - 'data': [ + "name": "CGSCOP Partner Dashboard", + "summary": "Dashboard coopératives", + "author": "Le Filament, Confédération Générale des Scop", + "license": "AGPL-3", + "version": "14.0.1.0.0", + "depends": ["cgscop_partner", "cgscop_partner_crm", "cgscop_timesheet"], + "data": [ "security/ir.model.access.csv", "security/security_rules.xml", - 'views/partner_dashboard_ur.xml', - 'views/partner_dashboard_dlg.xml', + "report/partner_dashboard_ur.xml", + "report/partner_dashboard_dlg.xml", "templates/header_dlg_template.xml", "wizard/partner_dashboard_dlg_selection_wizard.xml", - 'views/res_partner.xml', + "views/res_partner.xml", ], - 'demo': [], + "demo": [], } diff --git a/controllers/__init__.py b/controllers/__init__.py index a7a226b9e317f3d5f70642297b533f0e1390e5f2..e706c2f8da521b21b86e357e64dde1e4cc94d279 100644 --- a/controllers/__init__.py +++ b/controllers/__init__.py @@ -1 +1,5 @@ +# © 2020 Le Filament (<https://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from . import banner_dash_dlg diff --git a/controllers/banner_dash_dlg.py b/controllers/banner_dash_dlg.py index 90e89150717d080e2d7f093d4f1ee8f13412eed0..a431f306a7ce0f57d518970766e32e5d76572438 100644 --- a/controllers/banner_dash_dlg.py +++ b/controllers/banner_dash_dlg.py @@ -1,4 +1,5 @@ -# © 2020 Le Filament (<http://www.le-filament.com>) +# © 2020 Le Filament (<https://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import http @@ -6,10 +7,10 @@ from odoo.http import request class BannerDashDlgController(http.Controller): - - @http.route(['/cgscop_partner_dashboard/header_dlg'], type="json", auth="user") + @http.route(["/cgscop_partner_dashboard/header_dlg"], type="json", auth="user") def lm_header(self): return { - 'html': request.env.ref( - 'cgscop_partner_dashboard.header_dlg_template').render({}) + "html": request.env.ref( + "cgscop_partner_dashboard.header_dlg_template" + ).render({}) } diff --git a/data/union_regionale_data.xml b/data/union_regionale_data.xml deleted file mode 100644 index 7d94789ea8ed839856dd05e2c1f0c36533618e24..0000000000000000000000000000000000000000 --- a/data/union_regionale_data.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0"?> -<odoo> - <data> - <record id="cgscop" model="union.regionale"> - <field name="long_name">Confédération générale des scop</field> - <field name="name">CgScop</field> - </record> - </data> -</odoo> diff --git a/models/partner_dashboard_ur.py b/models/partner_dashboard_ur.py deleted file mode 100644 index 579c215927cbcd3074a52ba62fc2e28a18875e5c..0000000000000000000000000000000000000000 --- a/models/partner_dashboard_ur.py +++ /dev/null @@ -1,727 +0,0 @@ -# © 2020 Le Filament (<http://www.le-filament.com>) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -import json - -from odoo import fields, models, api, tools, exceptions -import datetime - - -class ScopPartnerDashboardUr(models.Model): - _name = 'scop.partner.dashboard.ur' - _description = 'Dashboard coopératives UR' - _order = 'dash_type asc' - _auto = False - - current_user_ur_id = fields.Many2one( - 'union.regionale', - string="Union Régionale de l'utilisateur", - compute='_compute_current_user_ur_id', - search='_search_current_user_ur_id') - - # Vue - ur_id = fields.Many2one('union.regionale', string='Union Régionale') - name = fields.Char() - dash_type = fields.Integer("Type de dashboard") - all_ur = fields.Boolean("Affichage de toutes les UR") - - nb_prj_info = fields.Integer("Information") - nb_prj_pdiag = fields.Integer("Pre-diag") - nb_prj_accomp = fields.Integer("Accompagnement") - nb_prj_adh = fields.Integer("Adhésion") - nb_prj_soumis = fields.Integer("Soumis") - nb_prj_tot = fields.Integer("Projets en cours") - - nb_fc_scop = fields.Integer("Nombre de scop") - nb_fc_scic = fields.Integer("Nombre de scic") - nb_fc_co47 = fields.Integer("Nombre de coop 47") - nb_coop_cae = fields.Integer("Nombre de CAE") - nb_coop_adh = fields.Integer("Nombre d'adhésion pour l'année") - nb_coop_tot = fields.Integer("Total coop adhérentes") - - rev_todo = fields.Integer("A réviser") - rev_done = fields.Integer("Révisées") - rev_total = fields.Integer("Total révisions") - rev_1y = fields.Integer("Annuelle") - rev_5y = fields.Integer("Quinquennale") - rev_5ys = fields.Integer("Quinquennale séquencée (annuel)") - rev_5ys23 = fields.Integer("Quinquennale séquencée (2 ans et 3 ans)") - rev_percent_done = fields.Float( - "Réalisés", - compute="_compute_percent_rev") - - act_dev = fields.Integer("Développement (hrs)") - act_acc = fields.Integer("Suivi (hrs)") - act_rev = fields.Integer("Révision (hrs)") - act_for = fields.Integer("Formation (hrs)") - act_acc_theo = fields.Integer("Acc. théorique (hrs)") - act_acc_percent_done = fields.Float( - "Réalisés", - compute="_compute_act_acc") - - graph_values = fields.Text(compute="_compute_graph_values") - - # ------------------------------------------------------ - # Construction de la requete - # ------------------------------------------------------ - @api.model - def _select(self): - # On récupere l'id de la cgscop - cgids = self.env['union.regionale'].search([('name','ilike','CGSCOP')]) - if (len(cgids)!=1): - cgscop_id = 0 - else: - cgscop_id = cgids[0].id - - # On constitue les requetes - qy_projet = self._select_projet(cgscop_id) - qy_coop = self._select_coop(cgscop_id) - qy_rev = self._select_rev(cgscop_id) - qy_act = self._select_act(cgscop_id) - - qy = qy_projet + " UNION ALL " + qy_coop + " UNION ALL " + qy_rev + " UNION ALL " + qy_act - - return qy - - - # ------------------------------------------------------ - # Dashboard projets - # ------------------------------------------------------ - @api.model - def _select_projet(self, cgscop_id): - query = """ - SELECT - CONCAT('1', ur_id) AS id, - org.ur_id as ur_id, - 'Prospects en cours' AS name, - '1' as dash_type, - 0 as all_ur, - SUM(case when substring(org.project_status,1,1) = '1' then 1 else 0 end) AS nb_prj_info, - SUM(case when substring(org.project_status,1,1) = '2' then 1 else 0 end) AS nb_prj_pdiag, - SUM(case when substring(org.project_status,1,1) = '3' then 1 else 0 end) AS nb_prj_accomp, - SUM(case when substring(org.project_status,1,1) = '4' then 1 else 0 end) AS nb_prj_adh, - SUM(case when substring(org.project_status,1,1) = '5' then 1 else 0 end) AS nb_prj_soumis, - count(org.id) as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 as rev_5y, - 0 as rev_5ys, - 0 as rev_5ys23, - 0 as rev_todo, - 0 as rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM res_partner org - where - (org.ur_id <> %d) and - (org.active=TRUE) and - (org.is_cooperative = TRUE)and - substring(org.project_status,1,1) in ('1','2','3','4','5') - group by - org.ur_id - UNION ALL - SELECT - '1CGSCOP' AS id, - '%d' as ur_id, - 'Prospects en cours' AS name, - '1' as dash_type, - 1 as all_ur, - SUM(case when substring(org.project_status,1,1) = '1' then 1 else 0 end) AS nb_prj_info, - SUM(case when substring(org.project_status,1,1) = '2' then 1 else 0 end) AS nb_prj_pdiag, - SUM(case when substring(org.project_status,1,1) = '3' then 1 else 0 end) AS nb_prj_accomp, - SUM(case when substring(org.project_status,1,1) = '4' then 1 else 0 end) AS nb_prj_adh, - SUM(case when substring(org.project_status,1,1) = '5' then 1 else 0 end) AS nb_prj_soumis, - count(org.id) as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 as rev_5y, - 0 as rev_5ys, - 0 as rev_5ys23, - 0 as rev_todo, - 0 as rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM res_partner org - where - (org.active=TRUE) and - (org.is_cooperative = TRUE)and - substring(org.project_status,1,1) in ('1','2','3','4','5') - """ % (cgscop_id, cgscop_id) - - return query - - # ------------------------------------------------------ - # Dashboard cooperative - # ------------------------------------------------------ - @api.model - def _select_coop(self, cgscop_id): - - try: - form_scop = self.env.ref('cgscop_partner.form_scop').id - except: - form_scop = 0 - try: - form_scic = self.env.ref('cgscop_partner.form_scic').id - except: - form_scic = 0 - try: - form_co47 = self.env.ref('cgscop_partner.form_coop47').id - except: - form_co47 = 0 - - query = """ - SELECT - CONCAT('2', ur_id) AS id, - org.ur_id as ur_id, - 'Coopératives adhérentes' AS name, - '2' as dash_type, - 0 as all_ur, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_scop, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_scic, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_co47, - SUM(case when org.cae is true then 1 else 0 end) AS nb_coop_cae, - SUM(case when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1 else 0 end) AS nb_coop_adh, - count(org.id) as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 as rev_5y, - 0 as rev_5ys, - 0 as rev_5ys23, - 0 as rev_todo, - 0 as rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM res_partner org - left join scop_membership_period as adh - on adh.partner_id = org.id - and adh.start=(select max(start) from scop_membership_period where partner_id=org.id and type_id=1) - and type_id=1 - where - (org.ur_id <> %d) and - (org.active=TRUE) and - (org.is_cooperative = TRUE) and - (org.membership_status = 'member') - group by - org.ur_id - UNION ALL - SELECT - '2CGSCOP' AS id, - '%d' as ur_id, - 'Coopératives adhérentes' AS name, - '2' as dash_type, - 1 as all_ur, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_scop, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_scic, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_co47, - SUM(case when org.cae is true then 1 else 0 end) AS nb_coop_cae, - SUM(case when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1 else 0 end) AS nb_coop_adh, - count(org.id) as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 as rev_5y, - 0 as rev_5ys, - 0 as rev_5ys23, - 0 as rev_todo, - 0 as rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM res_partner org - left join scop_membership_period as adh - on adh.partner_id = org.id - and adh.start=(select max(start) from scop_membership_period where partner_id=org.id and type_id=1) - and type_id=1 - where - (org.active=TRUE) and - (org.is_cooperative = TRUE) and - (org.membership_status = 'member') - """ % (form_scop,form_scic,form_co47,cgscop_id, - cgscop_id,form_scop,form_scic,form_co47) - - return query - - - # ------------------------------------------------------ - # Dashboard revision - # ------------------------------------------------------ - @api.model - def _select_rev(self, cgscop_id): - - query = """ - SELECT - id, - ur_id, - CONCAT('Révisions année ',date_part('year', CURRENT_DATE)) AS name, - '3' as dash_type, - 0 as all_ur, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - SUM(wrev.rev_done) as rev_done, - SUM(wrev.rev_1y) AS rev_1y, - SUM(wrev.rev_5y) AS rev_5y, - SUM(wRev.rev_5ys) AS rev_5ys, - SUM(wrev.rev_5ys23) AS rev_5ys23, - SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_todo, - SUM(wrev.rev_done) + SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM - ( - SELECT - CONCAT(org.ur_id, org.revision_next_year) AS id, - org.ur_id as ur_id, - 0 AS rev_done, - case when org.revision_type = '1y' then 1 else 0 end AS rev_1y, - case when org.revision_type = '5y' then 1 else 0 end AS rev_5y, - case when org.revision_type = '5ys' then 1 else 0 end AS rev_5ys, - case when org.revision_type = '5ys23' then 1 else 0 end AS rev_5ys23 - FROM res_partner as org - WHERE (org.revision_next_year = date_part('year', CURRENT_DATE)) - UNION ALL - SELECT - CONCAT(org.ur_id, date_part('year', rev.date)) as id, - org.ur_id as ur_id, - 1 AS rev_done, - 0 AS rev_1y, - 0 AS rev_5y, - 0 AS rev_5ys, - 0 AS rev_5ys23 - FROM scop_revision as rev - JOIN res_partner as org ON (org.id = rev.partner_id) - WHERE (date_part('year', rev.date) = date_part('year', CURRENT_DATE)) - ) AS wRev - GROUP BY wrev.id, wrev.ur_id - """ - return query - - - # ------------------------------------------------------ - # Dashboard activité - # ------------------------------------------------------ - @api.model - def _select_act(self, cgscop_id): - - query = """ - SELECT - CONCAT('4', ur_id) as id, - ur_id, - CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name, - '4' as dash_type, - 0 as all_ur, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 AS rev_5y, - 0 AS rev_5ys, - 0 AS rev_5ys23, - 0 AS rev_todo, - 0 AS rev_total, - sum(wrk.amount_dev) as act_dev, - sum(wrk.amount_acc) as act_acc, - sum(wrk.amount_rev) as act_rev, - sum(wrk.amount_for) as act_for, - sum(wrk.amount_theo) as act_acc_theo - FROM - ( - select - ac.ur_id as ur_id, - EXTRACT(YEAR FROM ac.date) as "year", - ac.unit_amount as amount_rev, - 0 as amount_dev, - 0 as amount_acc, - 0 as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'R' - union all - select - ac.ur_id as ur_id, - EXTRACT(YEAR FROM ac.date) as "year", - 0 as amount_rev, - ac.unit_amount as amount_dev, - 0 as amount_acc, - 0 as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'D' - union all - select - ac.ur_id as ur_id, - EXTRACT(YEAR FROM ac.date) as "year", - 0 as amount_rev, - 0 as amount_dev, - ac.unit_amount as amount_acc, - 0 as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'A' - union all - select - ac.ur_id as ur_id, - EXTRACT(YEAR FROM ac.date) as "year", - 0 as amount_rev, - 0 as amount_dev, - 0 as amount_acc, - ac.unit_amount as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'F' - union all - select - pa.ur_id as ur_id, - date_part('year', CURRENT_DATE) as "year", - 0 as amount_rev, - 0 as amount_dev, - 0 as amount_acc, - 0 as amount_for, - fo.duree as act_acc_theo - from - res_partner as pa - left join scop_followup_format as fo on fo.id = pa.followup_format_id - where pa.membership_status = 'member' - ) as wrk - group BY - wrk.ur_id, - wrk.year - """ - return query - - def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) - self.env.cr.execute("""CREATE or REPLACE VIEW %s as ( - %s - )""" % (self._table, self._select())) - - # ------------------------------------------------------ - # Récupère l'ur de l'utilisateur connecté - # ------------------------------------------------------ - @api.model - def _compute_current_user_ur_id(self): - for partner in self: - partner.current_user_ur_id = self.env.user.company_id.ur_id.id - - def _search_current_user_ur_id(self, operator, value): - return [('ur_id', '=', self.env.user.company_id.ur_id.id)] - - # ------------------------------------------------------ - # Calcule les données du graphique - # ------------------------------------------------------ - @api.multi - def _compute_graph_values(self): - for rec in self: - if (rec.dash_type == 1): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Information', 'value': rec.nb_prj_info}, - {'label': 'Pré-diag', 'value': rec.nb_prj_pdiag}, - {'label': 'Accompagnement', 'value': rec.nb_prj_accomp}, - {'label': 'Adhésion', 'value': rec.nb_prj_adh}, - {'label': 'Soumis CG', 'value': rec.nb_prj_soumis}], - 'area': True, - 'title': '', - 'key': 'Prospects en cours', - }]) - - if (rec.dash_type == 2): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Scop', 'value': rec.nb_fc_scop}, - {'label': 'Scic', 'value': rec.nb_fc_scic}, - {'label': 'Coop 47', 'value': rec.nb_fc_co47}], - 'area': True, - 'title': '', - 'key': 'Coopératives adhérentes', - }]) - - if (rec.dash_type == 3): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Annuelle', 'value': rec.rev_1y}, - {'label': 'Quinquennale', 'value': rec.rev_5y}, - {'label': 'Quinq. séq. (annuel)', 'value': rec.rev_5ys}, - {'label': 'Quinq. séq. (2 et 3)', 'value': rec.rev_5ys23} - ], - 'area': True, - 'title': '', - 'key': 'Nombre de révisions', - }]) - - if (rec.dash_type == 4): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Développement (hrs)', 'value': rec.act_dev}, - {'label': 'Suivi (hrs)', 'value': rec.act_acc}, - {'label': 'Révision (hrs)', 'value': rec.act_rev}, - {'label': 'Formation (hrs)', 'value': rec.act_for} - ], - 'area': True, - 'title': '', - 'key': "Découpage de l'activité" - }]) - - # ------------------------------------------------------ - # Calcul le % de révision réalisé - # ------------------------------------------------------ - @api.multi - def _compute_percent_rev(self): - for rec in self: - if rec.rev_total==0: - rec.rev_percent_done = 0 - else: - rec.rev_percent_done = rec.rev_done / rec.rev_total * 100 - - # ------------------------------------------------------ - # Calcul le % d'accompagnement réalisé - # ------------------------------------------------------ - @api.multi - def _compute_act_acc(self): - for rec in self: - if rec.act_acc_theo==0: - rec.act_acc_percent_done = 0 - else: - rec.act_acc_percent_done = rec.act_acc / rec.act_acc_theo * 100 - - # ------------------------------------------------------ - # Affichage des projets de l'ur - # ------------------------------------------------------ - def show_projets(self): - return { - 'name': "Prospects" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'view_type': 'form', - 'view_mode': 'kanban,tree,form', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_kanban').id, 'kanban'), - (self.env.ref('cgscop_partner.view_partner_prospect_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('project_status','in',('1_information','2_pre-diagnostic','3_accompagnement','4_adhesion','5_cg','7_abandonne')), - ('current_user_ur_id', '=', 'ur_id')], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'default_project_status': '1_information' - }, - } - - # ------------------------------------------------------ - # Affichage de tous les projets - # ------------------------------------------------------ - def show_all_projets(self): - return { - 'name': "Tous les Prospects" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'view_type': 'form', - 'view_mode': 'kanban,tree,form', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_kanban').id, 'kanban'), - (self.env.ref('cgscop_partner.view_partner_prospect_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('project_status', 'in', ('1_information','2_pre-diagnostic','3_accompagnement','4_adhesion','5_cg','7_abandonne'))], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'default_project_status': '1_information' - }, - } - - # ------------------------------------------------------ - # Affichage des coop adh de l'ur - # ------------------------------------------------------ - def show_coop(self): - return { - 'name': "Coopératives adhérentes" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'search_view_id': (self.env.ref('cgscop_partner.scop_partner_view_search').id,), - 'view_type': 'form', - 'view_mode': 'tree,form', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member'), - ('current_user_ur_id', '=', 'ur_id')], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } - - # ------------------------------------------------------ - # Affichage de toutes les coop adh - # ------------------------------------------------------ - def show_all_coop(self): - return { - 'name': "Toutes les coopératives adhérentes", - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'search_view_id': (self.env.ref('cgscop_partner.scop_partner_view_search').id,), - 'view_type': 'form', - 'view_mode': 'tree,form', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member')], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } - - # ------------------------------------------------------ - # Affichage des coop à réviser - # ------------------------------------------------------ - def show_rev(self): - - wyear = datetime.datetime.today().year - - return { - 'name': "Coopérative à réviser" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'view_type': 'form', - 'view_mode': 'tree', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member'), - ('current_user_ur_id', '=', 'ur_id'), - ('revision_next_year', '=', wyear)], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } - - # ------------------------------------------------------ - # Affichage des coop à suivre - # ------------------------------------------------------ - def show_acc(self): - - wyear = datetime.datetime.today().year - - return { - 'name': "Coopérative à suivre" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'search_view_id': (self.env.ref('cgscop_partner.scop_partner_view_search').id,), - 'view_type': 'form', - 'view_mode': 'tree', - 'views': [ - (self.env.ref('cgscop_partner_crm.scop_partner_crm_view_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member'), - ('current_user_ur_id', '=', 'ur_id')], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } \ No newline at end of file diff --git a/models/__init__.py b/report/__init__.py similarity index 79% rename from models/__init__.py rename to report/__init__.py index 9dd51d067ce759898cb62e0c0dbe34fc438f105f..69a8959c3d7ce63e09230f282ec3f44a9ba7d732 100644 --- a/models/__init__.py +++ b/report/__init__.py @@ -1,6 +1,6 @@ -# © 2020 Le Filament (<http://www.le-filament.com>) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - -from . import partner_dashboard_ur -from . import partner_dashboard_dlg \ No newline at end of file +# © 2020 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from . import partner_dashboard_ur +from . import partner_dashboard_dlg diff --git a/models/partner_dashboard_dlg.py b/report/partner_dashboard_dlg.py similarity index 50% rename from models/partner_dashboard_dlg.py rename to report/partner_dashboard_dlg.py index 1e0261a9a1e8aa3e84e605ca10dd8daa65020e26..d1254ff55885071986d911638088d973062b5474 100644 --- a/models/partner_dashboard_dlg.py +++ b/report/partner_dashboard_dlg.py @@ -1,572 +1,697 @@ -# © 2020 Le Filament (<http://www.le-filament.com>) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -import json - -from odoo import fields, models, api, tools, exceptions -import datetime - - -class ScopPartnerDashboardDlg(models.Model): - _name = 'scop.partner.dashboard.dlg' - _description = 'Dashboard coopératives délégués' - _order = 'dash_type asc' - _auto = False - - # Vue - dlg_id = fields.Many2one('res.users', string='Délégué') - name = fields.Char() - dash_type = fields.Integer("Type de dashboard") - - nb_prj_info = fields.Integer("Information") - nb_prj_pdiag = fields.Integer("Pre-diag") - nb_prj_accomp = fields.Integer("Accompagnement") - nb_prj_adh = fields.Integer("Adhésion") - nb_prj_soumis = fields.Integer("Soumis") - nb_prj_tot = fields.Integer("Projets en cours") - - nb_fc_scop = fields.Integer("Nombre de scop") - nb_fc_scic = fields.Integer("Nombre de scic") - nb_fc_co47 = fields.Integer("Nombre de coop 47") - nb_coop_cae = fields.Integer("Nombre de CAE") - nb_coop_adh = fields.Integer("Nombre d'adhésion pour l'année") - nb_coop_tot = fields.Integer("Total coop adhérentes") - - rev_todo = fields.Integer("A réviser") - rev_done = fields.Integer("Révisées") - rev_total = fields.Integer("Total révisions") - rev_1y = fields.Integer("Annuelle") - rev_5y = fields.Integer("Quinquennale") - rev_5ys = fields.Integer("Quinquennale séquencée (annuel)") - rev_5ys23 = fields.Integer("Quinquennale séquencée (2 ans et 3 ans)") - rev_percent_done = fields.Float( - "Réalisés", - compute="_compute_percent_rev") - - act_dev = fields.Integer("Développement (hrs)") - act_acc = fields.Integer("Accompagnement (hrs)") - act_rev = fields.Integer("Révision (hrs)") - act_for = fields.Integer("Formation (hrs)") - act_acc_theo = fields.Integer("Acc. théorique (hrs)") - - act_dev = fields.Integer("Développement (hrs)") - act_acc = fields.Integer("Suivi (hrs)") - act_rev = fields.Integer("Révision (hrs)") - act_for = fields.Integer("Formation (hrs)") - act_acc_theo = fields.Integer("Acc. théorique (hrs)") - act_acc_percent_done = fields.Float( - "Réalisés", - compute="_compute_act_acc") - - graph_values = fields.Text(compute="_compute_graph_values") - - # ------------------------------------------------------ - # Construction de la requete - # ------------------------------------------------------ - @api.model - def _select(self): - - # On constitue les requetes - qy_projet = self._select_projet() - qy_coop = self._select_coop() - qy_rev = self._select_rev() - qy_act = self._select_act() - - qy = qy_projet + " UNION ALL " + qy_coop + " UNION ALL " + qy_rev + " UNION ALL " + qy_act - - return qy - - # ------------------------------------------------------ - # Dashboard projets - # ------------------------------------------------------ - @api.model - def _select_projet(self): - query = """ - SELECT - CONCAT('1', org.creation_delegate_id) AS id, - org.creation_delegate_id as dlg_id, - 'Prospects en cours' AS name, - '1' as dash_type, - SUM(case when substring(org.project_status,1,1) = '1' then 1 else 0 end) AS nb_prj_info, - SUM(case when substring(org.project_status,1,1) = '2' then 1 else 0 end) AS nb_prj_pdiag, - SUM(case when substring(org.project_status,1,1) = '3' then 1 else 0 end) AS nb_prj_accomp, - SUM(case when substring(org.project_status,1,1) = '4' then 1 else 0 end) AS nb_prj_adh, - SUM(case when substring(org.project_status,1,1) = '5' then 1 else 0 end) AS nb_prj_soumis, - count(org.id) as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 as rev_5y, - 0 as rev_5ys, - 0 as rev_5ys23, - 0 as rev_todo, - 0 as rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM res_partner org - where - (org.active=TRUE) and - (org.is_cooperative = TRUE)and - substring(org.project_status,1,1) in ('1','2','3','4','5') - group by - org.creation_delegate_id - """ - return query - - # ------------------------------------------------------ - # Dashboard cooperative - # ------------------------------------------------------ - @api.model - def _select_coop(self,): - - try: - form_scop = self.env.ref('cgscop_partner.form_scop').id - except: - form_scop = 0 - try: - form_scic = self.env.ref('cgscop_partner.form_scic').id - except: - form_scic = 0 - try: - form_co47 = self.env.ref('cgscop_partner.form_coop47').id - except: - form_co47 = 0 - - query = """ - SELECT - CONCAT('2', org.followup_delegate_id) AS id, - org.followup_delegate_id as dlg_id, - 'Coopératives suivies' AS name, - '2' as dash_type, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_scop, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_scic, - SUM(case when org.cooperative_form_id = %d then 1 else 0 end) AS nb_fc_co47, - SUM(case when org.cae is true then 1 else 0 end) AS nb_coop_cae, - SUM(case when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1 else 0 end) AS nb_coop_adh, - count(org.id) as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 as rev_5y, - 0 as rev_5ys, - 0 as rev_5ys23, - 0 as rev_todo, - 0 as rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM res_partner org - left join scop_membership_period as adh - on adh.partner_id = org.id - and adh.start=(select max(start) from scop_membership_period where partner_id=org.id and type_id=1) - and type_id=1 - where - (org.active=TRUE) and - (org.is_cooperative = TRUE) and - (org.membership_status = 'member') - group by - org.followup_delegate_id - """ % (form_scop,form_scic,form_co47) - - return query - - # ------------------------------------------------------ - # Dashboard revision - # ------------------------------------------------------ - @api.model - def _select_rev(self): - - query = """ - SELECT - id, - dlg_id, - CONCAT('Révisions année ',date_part('year', CURRENT_DATE)) AS name, - '3' as dash_type, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - SUM(wrev.rev_done) as rev_done, - SUM(wrev.rev_1y) AS rev_1y, - SUM(wrev.rev_5y) AS rev_5y, - SUM(wRev.rev_5ys) AS rev_5ys, - SUM(wrev.rev_5ys23) AS rev_5ys23, - SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_todo, - SUM(wrev.rev_done) + SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_total, - 0 as act_dev, - 0 as act_acc, - 0 as act_rev, - 0 as act_for, - 0 as act_acc_theo - FROM - ( - SELECT - CONCAT(org.revision_person_id, org.revision_next_year) AS id, - org.revision_person_id as dlg_id, - 0 AS rev_done, - case when org.revision_type = '1y' then 1 else 0 end AS rev_1y, - case when org.revision_type = '5y' then 1 else 0 end AS rev_5y, - case when org.revision_type = '5ys' then 1 else 0 end AS rev_5ys, - case when org.revision_type = '5ys23' then 1 else 0 end AS rev_5ys23 - FROM res_partner as org - WHERE (org.revision_next_year = date_part('year', CURRENT_DATE)) - UNION ALL - SELECT - CONCAT(org.revision_person_id, date_part('year', rev.date)) as id, - org.revision_person_id as dlg_id, - 1 AS rev_done, - 0 AS rev_1y, - 0 AS rev_5y, - 0 AS rev_5ys, - 0 AS rev_5ys23 - FROM scop_revision as rev - JOIN res_partner as org ON (org.id = rev.partner_id) - WHERE (date_part('year', rev.date) = date_part('year', CURRENT_DATE)) - ) AS wRev - GROUP BY wrev.id, wrev.dlg_id - """ - return query - - # ------------------------------------------------------ - # Dashboard activité - # ------------------------------------------------------ - @api.model - def _select_act(self): - - query = """ - SELECT - CONCAT('4', wrk.dlg_id) as id, - dlg_id, - CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name, - '4' as dash_type, - 0 as nb_prj_info, - 0 as nb_prj_pdiag, - 0 as nb_prj_accomp, - 0 as nb_prj_adh, - 0 as nb_prj_soumis, - 0 as nb_prj_tot, - 0 as nb_fc_scop, - 0 as nb_fc_scic, - 0 as nb_fc_co47, - 0 as nb_coop_cae, - 0 as nb_coop_adh, - 0 as nb_coop_tot, - 0 as rev_done, - 0 as rev_1y, - 0 AS rev_5y, - 0 AS rev_5ys, - 0 AS rev_5ys23, - 0 AS rev_todo, - 0 AS rev_total, - sum(wrk.amount_dev) as act_dev, - sum(wrk.amount_acc) as act_acc, - sum(wrk.amount_rev) as act_rev, - sum(wrk.amount_for) as act_for, - sum(wrk.amount_theo) as act_acc_theo - FROM - ( - select - ac.user_id as dlg_id, - EXTRACT(YEAR FROM ac.date) as "year", - ac.unit_amount as amount_rev, - 0 as amount_dev, - 0 as amount_acc, - 0 as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'R' - union all - select - ac.user_id as dlg_id, - EXTRACT(YEAR FROM ac.date) as "year", - 0 as amount_rev, - ac.unit_amount as amount_dev, - 0 as amount_acc, - 0 as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'D' - union all - select - ac.user_id as dlg_id, - EXTRACT(YEAR FROM ac.date) as "year", - 0 as amount_rev, - 0 as amount_dev, - ac.unit_amount as amount_acc, - 0 as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'A' - union all - select - ac.user_id as dlg_id, - EXTRACT(YEAR FROM ac.date) as "year", - 0 as amount_rev, - 0 as amount_dev, - 0 as amount_acc, - ac.unit_amount as amount_for, - 0 as amount_theo - from - account_analytic_line as ac - left join project_project as pu on pu.id = ac.project_id - left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id - where - (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) - and pn.domain = 'F' - union all - select - pa.followup_delegate_id as dlg_id, - date_part('year', CURRENT_DATE) as "year", - 0 as amount_rev, - 0 as amount_dev, - 0 as amount_acc, - 0 as amount_for, - fo.duree as act_acc_theo - from - res_partner as pa - left join scop_followup_format as fo on fo.id = pa.followup_format_id - where pa.membership_status = 'member' - ) as wrk - group BY - wrk.dlg_id, - wrk.year - """ - return query - - def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) - self.env.cr.execute("""CREATE or REPLACE VIEW %s as ( - %s - )""" % (self._table, self._select())) - - # ------------------------------------------------------ - # Calcule les données du graphique - # ------------------------------------------------------ - @api.multi - def _compute_graph_values(self): - for rec in self: - - if (rec.dash_type == 1): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Information', 'value': rec.nb_prj_info}, - {'label': 'Pré-diag', 'value': rec.nb_prj_pdiag}, - {'label': 'Accompagnement', 'value': rec.nb_prj_accomp}, - {'label': 'Adhésion', 'value': rec.nb_prj_adh}, - {'label': 'Soumis CG', 'value': rec.nb_prj_soumis} - ], - 'area': True, - 'title': '', - 'key': 'Prospects en cours', - }]) - - if (rec.dash_type == 2): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Scop', 'value': rec.nb_fc_scop}, - {'label': 'Scic', 'value': rec.nb_fc_scic}, - {'label': 'Coop 47', 'value': rec.nb_fc_co47} - ], - 'area': True, - 'title': '', - 'key': 'Coopératives adhérentes', - }]) - - if (rec.dash_type == 3): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Annuelle', 'value': rec.rev_1y}, - {'label': 'Quinquennale', 'value': rec.rev_5y}, - {'label': 'Quinq. séq. (annuel)', 'value': rec.rev_5ys}, - {'label': 'Quinq. séq. (2 et 3)', 'value': rec.rev_5ys23} - ], - 'area': True, - 'title': '', - 'key': 'Nombre de révisions', - }]) - - if (rec.dash_type == 4): - rec.graph_values = json.dumps([{ - 'values': [ - {'label': 'Développement (hrs)', 'value': rec.act_dev}, - {'label': 'Suivi (hrs)', 'value': rec.act_acc}, - {'label': 'Révision (hrs)', 'value': rec.act_rev}, - {'label': 'Formation (hrs)', 'value': rec.act_for} - ], - 'area': True, - 'title': '', - 'key': "Découpage de l'activité" - }]) - - # ------------------------------------------------------ - # Calcul le % de révision réalisé - # ------------------------------------------------------ - @api.multi - def _compute_percent_rev(self): - for rec in self: - if rec.rev_total==0: - rec.rev_percent_done = 0 - else: - rec.rev_percent_done = rec.rev_done / rec.rev_total * 100 - - # ------------------------------------------------------ - # Calcul le % d'accompagnement réalisé - # ------------------------------------------------------ - @api.multi - def _compute_act_acc(self): - for rec in self: - if rec.act_acc_theo==0: - rec.act_acc_percent_done = 0 - else: - rec.act_acc_percent_done = rec.act_acc / rec.act_acc_theo * 100 - - # ------------------------------------------------------ - # Affichage des projets - # ------------------------------------------------------ - def show_projets(self): - return { - 'name': "Prospects" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'view_type': 'form', - 'view_mode': 'kanban,tree,form,activity', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_kanban').id, 'kanban'), - (self.env.ref('cgscop_partner.view_partner_prospect_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('project_status','in',('1_information','2_pre-diagnostic','3_accompagnement','4_adhesion','5_cg','7_abandonne')), - ('creation_delegate_id', '=', self.env.user.id)], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'default_project_status': '1_information' - }, - } - - # ------------------------------------------------------ - # Affichage des coop adh - # ------------------------------------------------------ - def show_coop(self): - return { - 'name': "Coopératives adhérentes" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'search_view_id' : self.env.ref('cgscop_partner.scop_partner_view_search').id, - 'view_type': 'form', - 'view_mode': 'tree,form,activity', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member'), - ('followup_delegate_id', '=', self.env.user.id)], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } - - # ------------------------------------------------------ - # Affichage des coop à réviser - # ------------------------------------------------------ - def show_rev(self): - - wyear = datetime.datetime.today().year - - return { - 'name': "Coopérative à réviser" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'view_type': 'form', - 'view_mode': 'tree,form,activity', - 'views': [ - (self.env.ref('cgscop_partner.view_partner_cooperative_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member'), - ('revision_person_id', '=', self.env.user.id), - ('revision_next_year', '=', wyear) - ], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } - - # ------------------------------------------------------ - # Affichage des coop à suivre - # ------------------------------------------------------ - def show_acc(self): - - return { - 'name': "Coopérative à suivre" , - 'type': 'ir.actions.act_window', - 'res_model': 'res.partner', - 'search_view_id': (self.env.ref('cgscop_partner.scop_partner_view_search').id,), - 'view_type': 'form', - 'view_mode': 'tree,form,activity', - 'views': [ - (self.env.ref('cgscop_partner_crm.scop_partner_crm_view_tree').id, 'tree'), - (self.env.ref('cgscop_partner.scop_contact_view_form').id, 'form')], - 'target': 'current', - 'domain': [ - ('is_cooperative', '=', True), - ('membership_status', '=', 'member'), - ('followup_delegate_id', '=', self.env.user.id)], - 'context': { - 'default_is_company': True, - 'default_is_cooperative': True, - 'default_company_type': 'company', - 'create': False, - }, - } \ No newline at end of file +# © 2020 Le Filament (<https://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import datetime +import json + +from psycopg2.extensions import AsIs + +from odoo import api, fields, models, tools + + +class ScopPartnerDashboardDlg(models.Model): + _name = "scop.partner.dashboard.dlg" + _description = "Dashboard coopératives délégués" + _order = "dash_type asc" + _auto = False + + # Vue + dlg_id = fields.Many2one("res.users", string="Délégué") + name = fields.Char() + dash_type = fields.Integer("Type de dashboard") + + nb_prj_info = fields.Integer("Information") + nb_prj_pdiag = fields.Integer("Pre-diag") + nb_prj_accomp = fields.Integer("Accompagnement") + nb_prj_adh = fields.Integer("Adhésion") + nb_prj_soumis = fields.Integer("Soumis") + nb_prj_tot = fields.Integer("Projets en cours") + + nb_fc_scop = fields.Integer("Nombre de scop") + nb_fc_scic = fields.Integer("Nombre de scic") + nb_fc_co47 = fields.Integer("Nombre de coop 47") + nb_coop_cae = fields.Integer("Nombre de CAE") + nb_coop_adh = fields.Integer("Nombre d'adhésion pour l'année") + nb_coop_tot = fields.Integer("Total coop adhérentes") + + rev_todo = fields.Integer("A réviser") + rev_done = fields.Integer("Révisées") + rev_total = fields.Integer("Total révisions") + rev_1y = fields.Integer("Annuelle") + rev_5y = fields.Integer("Quinquennale") + rev_5ys = fields.Integer("Quinquennale séquencée (annuel)") + rev_5ys23 = fields.Integer("Quinquennale séquencée (2 ans et 3 ans)") + rev_percent_done = fields.Float("Réalisés", compute="_compute_percent_rev") + + act_dev = fields.Integer("Développement (hrs)") + act_acc = fields.Integer("Accompagnement (hrs)") + act_rev = fields.Integer("Révision (hrs)") + act_for = fields.Integer("Formation (hrs)") + act_acc_theo = fields.Integer("Acc. théorique (hrs)") + + act_dev = fields.Integer("Développement (hrs)") + act_acc = fields.Integer("Suivi (hrs)") + act_rev = fields.Integer("Révision (hrs)") + act_for = fields.Integer("Formation (hrs)") + act_acc_theo = fields.Integer("Acc. théorique (hrs)") + act_acc_percent_done = fields.Float("Réalisés", compute="_compute_act_acc") + + graph_values = fields.Text(compute="_compute_graph_values") + + # ------------------------------------------------------ + # Construction de la requete + # ------------------------------------------------------ + @api.model + def _select(self): + + # On constitue les requetes + qy_projet = self._select_projet() + qy_coop = self._select_coop() + qy_rev = self._select_rev() + qy_act = self._select_act() + + qy = ( + qy_projet + + " UNION ALL " + + qy_coop + + " UNION ALL " + + qy_rev + + " UNION ALL " + + qy_act + ) + + return qy + + # ------------------------------------------------------ + # Dashboard projets + # ------------------------------------------------------ + @api.model + def _select_projet(self): + query = """ + SELECT + CONCAT('1', org.creation_delegate_id) AS id, + org.creation_delegate_id as dlg_id, + 'Prospects en cours' AS name, + '1' as dash_type, + SUM(case + when substring(org.project_status,1,1) = '1' then 1 + else 0 end) AS nb_prj_info, + SUM(case + when substring(org.project_status,1,1) = '2' then 1 + else 0 end) AS nb_prj_pdiag, + SUM(case + when substring(org.project_status,1,1) = '3' then 1 + else 0 end) AS nb_prj_accomp, + SUM(case + when substring(org.project_status,1,1) = '4' then 1 + else 0 end) AS nb_prj_adh, + SUM(case + when substring(org.project_status,1,1) = '5' then 1 + else 0 end) AS nb_prj_soumis, + count(org.id) as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 as rev_5y, + 0 as rev_5ys, + 0 as rev_5ys23, + 0 as rev_todo, + 0 as rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM + res_partner org + WHERE + (org.active=TRUE) and + (org.is_cooperative = TRUE)and + substring(org.project_status,1,1) in ('1','2','3','4','5') + GROUP BY + org.creation_delegate_id + """ + return query + + # ------------------------------------------------------ + # Dashboard cooperative + # ------------------------------------------------------ + @api.model + def _select_coop(self): + try: + form_scop = self.env.ref("cgscop_partner.form_scop").id + except Exception: + form_scop = 0 + try: + form_scic = self.env.ref("cgscop_partner.form_scic").id + + except Exception: + form_scic = 0 + try: + form_co47 = self.env.ref("cgscop_partner.form_coop47").id + except Exception: + form_co47 = 0 + + query = """ + SELECT + CONCAT('2', org.followup_delegate_id) AS id, + org.followup_delegate_id as dlg_id, + 'Coopératives suivies' AS name, + '2' as dash_type, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_scop, + SUM(case when + org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_scic, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_co47, + SUM(case + when org.cae is true then 1 + else 0 end) AS nb_coop_cae, + SUM(case + when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1 + else 0 end) AS nb_coop_adh, + count(org.id) as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 as rev_5y, + 0 as rev_5ys, + 0 as rev_5ys23, + 0 as rev_todo, + 0 as rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM res_partner org + LEFT JOIN + scop_membership_period as adh on adh.partner_id = org.id + and adh.start=(select max(start) + from scop_membership_period where partner_id=org.id and type_id=1) + and type_id=1 + WHERE + (org.active=TRUE) and + (org.is_cooperative = TRUE) and + (org.membership_status = 'member') + GROUP BY + org.followup_delegate_id + """ % ( + form_scop, + form_scic, + form_co47, + ) + + return query + + # ------------------------------------------------------ + # Dashboard revision + # ------------------------------------------------------ + @api.model + def _select_rev(self): + + query = """ + SELECT + id, + dlg_id, + CONCAT('Révisions année ',date_part('year', CURRENT_DATE)) AS name, + '3' as dash_type, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + SUM(wrev.rev_done) as rev_done, + SUM(wrev.rev_1y) AS rev_1y, + SUM(wrev.rev_5y) AS rev_5y, + SUM(wRev.rev_5ys) AS rev_5ys, + SUM(wrev.rev_5ys23) AS rev_5ys23, + (SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) + + SUM(wrev.rev_5ys23)) AS rev_todo, + SUM(wrev.rev_done) + SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + + SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM + ( + SELECT + CONCAT(org.revision_person_id, org.revision_next_year) AS id, + org.revision_person_id as dlg_id, + 0 AS rev_done, + case when org.revision_type = '1y' then 1 else 0 end AS rev_1y, + case when org.revision_type = '5y' then 1 else 0 end AS rev_5y, + case when org.revision_type = '5ys' then 1 else 0 end AS rev_5ys, + case when org.revision_type = '5ys23' then 1 else 0 end AS rev_5ys23 + FROM res_partner as org + WHERE (org.revision_next_year = date_part('year', CURRENT_DATE)) + UNION ALL + SELECT + CONCAT(org.revision_person_id, date_part('year', rev.date)) as id, + org.revision_person_id as dlg_id, + 1 AS rev_done, + 0 AS rev_1y, + 0 AS rev_5y, + 0 AS rev_5ys, + 0 AS rev_5ys23 + FROM scop_revision as rev + JOIN res_partner as org ON (org.id = rev.partner_id) + WHERE (date_part('year', rev.date) = date_part('year', CURRENT_DATE)) + ) AS wRev + GROUP BY wrev.id, wrev.dlg_id + """ + return query + + # ------------------------------------------------------ + # Dashboard activité + # ------------------------------------------------------ + @api.model + def _select_act(self): + + query = """ + SELECT + CONCAT('4', wrk.dlg_id) as id, + dlg_id, + CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name, + '4' as dash_type, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 AS rev_5y, + 0 AS rev_5ys, + 0 AS rev_5ys23, + 0 AS rev_todo, + 0 AS rev_total, + sum(wrk.amount_dev) as act_dev, + sum(wrk.amount_acc) as act_acc, + sum(wrk.amount_rev) as act_rev, + sum(wrk.amount_for) as act_for, + sum(wrk.amount_theo) as act_acc_theo + FROM + ( + select + ac.user_id as dlg_id, + EXTRACT(YEAR FROM ac.date) as "year", + ac.unit_amount as amount_rev, + 0 as amount_dev, + 0 as amount_acc, + 0 as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'R' + union all + select + ac.user_id as dlg_id, + EXTRACT(YEAR FROM ac.date) as "year", + 0 as amount_rev, + ac.unit_amount as amount_dev, + 0 as amount_acc, + 0 as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'D' + union all + select + ac.user_id as dlg_id, + EXTRACT(YEAR FROM ac.date) as "year", + 0 as amount_rev, + 0 as amount_dev, + ac.unit_amount as amount_acc, + 0 as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'A' + union all + select + ac.user_id as dlg_id, + EXTRACT(YEAR FROM ac.date) as "year", + 0 as amount_rev, + 0 as amount_dev, + 0 as amount_acc, + ac.unit_amount as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'F' + union all + select + pa.followup_delegate_id as dlg_id, + date_part('year', CURRENT_DATE) as "year", + 0 as amount_rev, + 0 as amount_dev, + 0 as amount_acc, + 0 as amount_for, + fo.duree as act_acc_theo + from + res_partner as pa + left join scop_followup_format as fo on fo.id = pa.followup_format_id + where pa.membership_status = 'member' + ) as wrk + group BY + wrk.dlg_id, + wrk.year + """ + return query + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute( + "CREATE or REPLACE VIEW %s as (%s)", + (AsIs(self._table), AsIs(self._select())), + ) + + # ------------------------------------------------------ + # Calcule les données du graphique + # ------------------------------------------------------ + def _compute_graph_values(self): + for rec in self: + + if rec.dash_type == 1: + rec.graph_values = json.dumps( + [ + { + "values": [ + { + "label": "Information", + "value": rec.nb_prj_info, + }, + { + "label": "Pré-diag", + "value": rec.nb_prj_pdiag, + }, + { + "label": "Accompagnement", + "value": rec.nb_prj_accomp, + }, + {"label": "Adhésion", "value": rec.nb_prj_adh}, + { + "label": "Soumis CG", + "value": rec.nb_prj_soumis, + }, + ], + "area": True, + "title": "", + "key": "Prospects en cours", + } + ] + ) + + if rec.dash_type == 2: + rec.graph_values = json.dumps( + [ + { + "values": [ + {"label": "Scop", "value": rec.nb_fc_scop}, + {"label": "Scic", "value": rec.nb_fc_scic}, + {"label": "Coop 47", "value": rec.nb_fc_co47}, + ], + "area": True, + "title": "", + "key": "Coopératives adhérentes", + } + ] + ) + + if rec.dash_type == 3: + rec.graph_values = json.dumps( + [ + { + "values": [ + {"label": "Annuelle", "value": rec.rev_1y}, + {"label": "Quinquennale", "value": rec.rev_5y}, + { + "label": "Quinq. séq. (annuel)", + "value": rec.rev_5ys, + }, + { + "label": "Quinq. séq. (2 et 3)", + "value": rec.rev_5ys23, + }, + ], + "area": True, + "title": "", + "key": "Nombre de révisions", + } + ] + ) + + if rec.dash_type == 4: + rec.graph_values = json.dumps( + [ + { + "values": [ + { + "label": "Développement (hrs)", + "value": rec.act_dev, + }, + {"label": "Suivi (hrs)", "value": rec.act_acc}, + { + "label": "Révision (hrs)", + "value": rec.act_rev, + }, + { + "label": "Formation (hrs)", + "value": rec.act_for, + }, + ], + "area": True, + "title": "", + "key": "Découpage de l'activité", + } + ] + ) + + # ------------------------------------------------------ + # Calcul le % de révision réalisé + # ------------------------------------------------------ + def _compute_percent_rev(self): + for rec in self: + if rec.rev_total == 0: + rec.rev_percent_done = 0 + else: + rec.rev_percent_done = rec.rev_done / rec.rev_total * 100 + + # ------------------------------------------------------ + # Calcul le % d'accompagnement réalisé + # ------------------------------------------------------ + def _compute_act_acc(self): + for rec in self: + if rec.act_acc_theo == 0: + rec.act_acc_percent_done = 0 + else: + rec.act_acc_percent_done = rec.act_acc / rec.act_acc_theo * 100 + + # ------------------------------------------------------ + # Affichage des projets + # ------------------------------------------------------ + def show_projets(self): + return { + "name": "Prospects", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "view_type": "form", + "view_mode": "kanban,tree,form,activity", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_kanban").id, + "kanban", + ), + ( + self.env.ref("cgscop_partner.view_partner_prospect_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ( + "project_status", + "in", + ( + "1_information", + "2_pre-diagnostic", + "3_accompagnement", + "4_adhesion", + "5_cg", + "7_abandonne", + ), + ), + ("creation_delegate_id", "=", self.env.user.id), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "default_project_status": "1_information", + }, + } + + # ------------------------------------------------------ + # Affichage des coop adh + # ------------------------------------------------------ + def show_coop(self): + return { + "name": "Coopératives adhérentes", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "search_view_id": self.env.ref( + "cgscop_partner.scop_partner_view_search" + ).id, + "view_type": "form", + "view_mode": "tree,form,activity", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ("followup_delegate_id", "=", self.env.user.id), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } + + # ------------------------------------------------------ + # Affichage des coop à réviser + # ------------------------------------------------------ + def show_rev(self): + + wyear = datetime.datetime.today().year + + return { + "name": "Coopérative à réviser", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "view_type": "form", + "view_mode": "tree,form,activity", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ("revision_person_id", "=", self.env.user.id), + ("revision_next_year", "=", wyear), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } + + # ------------------------------------------------------ + # Affichage des coop à suivre + # ------------------------------------------------------ + def show_acc(self): + + return { + "name": "Coopérative à suivre", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "search_view_id": ( + self.env.ref("cgscop_partner.scop_partner_view_search").id, + ), + "view_type": "form", + "view_mode": "tree,form,activity", + "views": [ + ( + self.env.ref("cgscop_partner_crm.scop_partner_crm_view_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ("followup_delegate_id", "=", self.env.user.id), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } diff --git a/views/partner_dashboard_dlg.xml b/report/partner_dashboard_dlg.xml similarity index 57% rename from views/partner_dashboard_dlg.xml rename to report/partner_dashboard_dlg.xml index 9e61ffc4fe1c0642a3588e21088c6c00c858a6c2..1db4fa9e5f50f80204588d895e8069f546cc8e39 100644 --- a/views/partner_dashboard_dlg.xml +++ b/report/partner_dashboard_dlg.xml @@ -1,178 +1,236 @@ -<?xml version="1.0" encoding="utf-8"?> -<odoo> - <data> - - <record id="scop_partner_dashboard_dlg_kanban_view" model="ir.ui.view"> - <field name="name">scop.partner.dashboard.dlg.kanban</field> - <field name="model">scop.partner.dashboard.dlg</field> - <field name="arch" type="xml"> - <kanban create="false" class="oe_background_grey o_kanban_dashboard o_account_kanban" banner_route="/cgscop_partner_dashboard/header_dlg" > - <field name="name"/> - <field name="dlg_id"/> - <field name="dash_type"/> - <field name="nb_prj_tot"/> - <field name="nb_prj_accomp"/> - <field name="nb_prj_adh"/> - <field name="nb_prj_soumis"/> - <templates> - <t t-name="kanban-box"> - <div class="container o_kanban_card_content"> - <div class="row"> - <div class="col"> - <h2 class="mt16"><field name="name"/></h2> - <hr/> - <p>Délégué : <field name="dlg_id"/></p> - </div> - </div> - - <!-- Affiche Dashboard type 1 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 1)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_projets" class="btn btn-info">Voir mes prospects</button> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Prospects en cours :</td> - <td><field name="nb_prj_tot"/></td> - </tr> - <tr> - <td>dont phase d'accompagnement :</td> - <td><field name="nb_prj_accomp"/></td> - </tr> - <tr> - <td>dont phase d'adhésion :</td> - <td><field name="nb_prj_adh"/></td> - </tr> - <tr> - <td>dont soumis CG :</td> - <td><field name="nb_prj_soumis"/></td> - </tr> - </tbody> - </table> - </div> - </div> - - - <!-- Affiche Dashboard type 2 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 2)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_coop" class="btn btn-info" >Voir mes coopératives<br/>suivies</button> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Coopératives suivies :</td> - <td><field name="nb_coop_tot"/></td> - </tr> - <tr> - <td>dont SCOP :</td> - <td><field name="nb_fc_scop"/></td> - </tr> - <tr> - <td>dont SCIC :</td> - <td><field name="nb_fc_scic"/></td> - </tr> - <tr> - <td>dont CAE :</td> - <td><field name="nb_coop_cae"/></td> - </tr> - </tbody> - </table> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Adhésions de l'année :</td> - <td><field name="nb_coop_adh"/></td> - </tr> - </tbody> - </table> - </div> - </div> - - <!-- Affiche Dashboard type 3 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 3)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_rev" class="btn btn-info">Voir mes coopératives<br/> à réviser</button> - </div> - <div class="text-center"> - <field name="rev_percent_done" widget="percentpie"/> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>A réaliser :</td> - <td><field name="rev_todo"/></td> - </tr> - <tr> - <td>Réalisées :</td> - <td><field name="rev_done"/></td> - </tr><tr> - <td><strong>Total :</strong></td> - <td><strong><field name="rev_total"/></strong></td> - </tr> - </tbody> - </table> - </div> - </div> - - <!-- Affiche Dashboard type 4 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 4)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_acc" class="btn btn-info">Voir les coopératives<br/> à suivre</button> - </div> - <div class="text-center"> - <field name="act_acc_percent_done" widget="percentpie"/> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Suivi à réaliser (hrs) :</td> - <td><field name="act_acc_theo"/></td> - </tr> - <tr> - <td>Suivi réalisés (hrs) :</td> - <td><field name="act_acc"/></td> - </tr> - </tbody> - </table> - </div> - </div> - - - <!-- Affiche le graph --> - <div class="row"> - <div class="col"> - <field name="graph_values" widget="dashboard_graph" graph_type="bar"/> - </div> - </div> - </div> - </t> - </templates> - </kanban> - </field> - </record> - - <record model="ir.actions.act_window" id="coop_partner_dashboard_dlg_act" > - <field name="name">Dashboard coopératives (Délégué)</field> - <field name="type">ir.actions.act_window</field> - <field name="res_model">scop.partner.dashboard.dlg</field> - <field name="view_type">form</field> - <field name="view_mode">kanban</field> - <field name="domain">[('dlg_id', '=', uid)]</field> - </record> - - </data> -</odoo> \ No newline at end of file +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <data> + + <record id="scop_partner_dashboard_dlg_kanban_view" model="ir.ui.view"> + <field name="name">scop.partner.dashboard.dlg.kanban</field> + <field name="model">scop.partner.dashboard.dlg</field> + <field name="arch" type="xml"> + <kanban + create="false" + class="oe_background_grey o_kanban_dashboard o_account_kanban" + banner_route="/cgscop_partner_dashboard/header_dlg" + > + <field name="name" /> + <field name="dlg_id" /> + <field name="dash_type" /> + <field name="nb_prj_tot" /> + <field name="nb_prj_accomp" /> + <field name="nb_prj_adh" /> + <field name="nb_prj_soumis" /> + <templates> + <t t-name="kanban-box"> + <div class="container o_kanban_card_content"> + <div class="row"> + <div class="col"> + <h2 class="mt16"><field name="name" /></h2> + <hr /> + <p>Délégué : <field name="dlg_id" /></p> + </div> + </div> + + <!-- Affiche Dashboard type 1 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 1)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_projets" + class="btn btn-info" + >Voir mes prospects</button> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Prospects en cours :</td> + <td><field name="nb_prj_tot" /></td> + </tr> + <tr> + <td + >dont phase d'accompagnement :</td> + <td><field + name="nb_prj_accomp" + /></td> + </tr> + <tr> + <td>dont phase d'adhésion :</td> + <td><field name="nb_prj_adh" /></td> + </tr> + <tr> + <td>dont soumis CG :</td> + <td><field + name="nb_prj_soumis" + /></td> + </tr> + </tbody> + </table> + </div> + </div> + + + <!-- Affiche Dashboard type 2 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 2)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_coop" + class="btn btn-info" + >Voir mes coopératives<br />suivies</button> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Coopératives suivies :</td> + <td><field + name="nb_coop_tot" + /></td> + </tr> + <tr> + <td>dont SCOP :</td> + <td><field name="nb_fc_scop" /></td> + </tr> + <tr> + <td>dont SCIC :</td> + <td><field name="nb_fc_scic" /></td> + </tr> + <tr> + <td>dont CAE :</td> + <td><field + name="nb_coop_cae" + /></td> + </tr> + </tbody> + </table> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Adhésions de l'année :</td> + <td><field + name="nb_coop_adh" + /></td> + </tr> + </tbody> + </table> + </div> + </div> + + <!-- Affiche Dashboard type 3 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 3)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_rev" + class="btn btn-info" + >Voir mes coopératives<br + /> à réviser</button> + </div> + <div class="text-center"> + <field + name="rev_percent_done" + widget="percentpie" + /> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>A réaliser :</td> + <td><field name="rev_todo" /></td> + </tr> + <tr> + <td>Réalisées :</td> + <td><field name="rev_done" /></td> + </tr><tr> + <td><strong>Total :</strong></td> + <td><strong><field + name="rev_total" + /></strong></td> + </tr> + </tbody> + </table> + </div> + </div> + + <!-- Affiche Dashboard type 4 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 4)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_acc" + class="btn btn-info" + >Voir les coopératives<br + /> à suivre</button> + </div> + <div class="text-center"> + <field + name="act_acc_percent_done" + widget="percentpie" + /> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Suivi à réaliser (hrs) :</td> + <td><field + name="act_acc_theo" + /></td> + </tr> + <tr> + <td>Suivi réalisés (hrs) :</td> + <td><field name="act_acc" /></td> + </tr> + </tbody> + </table> + </div> + </div> + + + <!-- Affiche le graph --> + <div class="row"> + <div class="col"> + <field + name="graph_values" + widget="dashboard_graph" + graph_type="bar" + /> + </div> + </div> + </div> + </t> + </templates> + </kanban> + </field> + </record> + + <record model="ir.actions.act_window" id="coop_partner_dashboard_dlg_act"> + <field name="name">Dashboard coopératives (Délégué)</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">scop.partner.dashboard.dlg</field> + <field name="view_mode">kanban</field> + <field name="domain">[('dlg_id', '=', uid)]</field> + </record> + + </data> +</odoo> diff --git a/report/partner_dashboard_ur.py b/report/partner_dashboard_ur.py new file mode 100644 index 0000000000000000000000000000000000000000..7fbb43108fd053661d635a541a4662e41220de2f --- /dev/null +++ b/report/partner_dashboard_ur.py @@ -0,0 +1,914 @@ +# © 2020 Le Filament (<https://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import datetime +import json + +from psycopg2.extensions import AsIs + +from odoo import api, fields, models, tools + + +class ScopPartnerDashboardUr(models.Model): + _name = "scop.partner.dashboard.ur" + _description = "Dashboard coopératives UR" + _order = "dash_type asc" + _auto = False + + current_user_ur_id = fields.Many2one( + "union.regionale", + string="Union Régionale de l'utilisateur", + compute="_compute_current_user_ur_id", + search="_search_current_user_ur_id", + ) + + # Vue + ur_id = fields.Many2one("union.regionale", string="Union Régionale") + name = fields.Char() + dash_type = fields.Integer("Type de dashboard") + all_ur = fields.Boolean("Affichage de toutes les UR") + + nb_prj_info = fields.Integer("Information") + nb_prj_pdiag = fields.Integer("Pre-diag") + nb_prj_accomp = fields.Integer("Accompagnement") + nb_prj_adh = fields.Integer("Adhésion") + nb_prj_soumis = fields.Integer("Soumis") + nb_prj_tot = fields.Integer("Projets en cours") + + nb_fc_scop = fields.Integer("Nombre de scop") + nb_fc_scic = fields.Integer("Nombre de scic") + nb_fc_co47 = fields.Integer("Nombre de coop 47") + nb_coop_cae = fields.Integer("Nombre de CAE") + nb_coop_adh = fields.Integer("Nombre d'adhésion pour l'année") + nb_coop_tot = fields.Integer("Total coop adhérentes") + + rev_todo = fields.Integer("A réviser") + rev_done = fields.Integer("Révisées") + rev_total = fields.Integer("Total révisions") + rev_1y = fields.Integer("Annuelle") + rev_5y = fields.Integer("Quinquennale") + rev_5ys = fields.Integer("Quinquennale séquencée (annuel)") + rev_5ys23 = fields.Integer("Quinquennale séquencée (2 ans et 3 ans)") + rev_percent_done = fields.Float("Réalisés", compute="_compute_percent_rev") + + act_dev = fields.Integer("Développement (hrs)") + act_acc = fields.Integer("Suivi (hrs)") + act_rev = fields.Integer("Révision (hrs)") + act_for = fields.Integer("Formation (hrs)") + act_acc_theo = fields.Integer("Acc. théorique (hrs)") + act_acc_percent_done = fields.Float("Réalisés", compute="_compute_act_acc") + + graph_values = fields.Text(compute="_compute_graph_values") + + # ------------------------------------------------------ + # Construction de la requete + # ------------------------------------------------------ + @api.model + def _select(self): + # On récupere l'id de la cgscop + cgids = self.env["union.regionale"].search([("name", "ilike", "CGSCOP")]) + if len(cgids) != 1: + cgscop_id = 0 + else: + cgscop_id = cgids[0].id + + # On constitue les requetes + qy_projet = self._select_projet(cgscop_id) + qy_coop = self._select_coop(cgscop_id) + qy_rev = self._select_rev(cgscop_id) + qy_act = self._select_act(cgscop_id) + + qy = ( + qy_projet + + " UNION ALL " + + qy_coop + + " UNION ALL " + + qy_rev + + " UNION ALL " + + qy_act + ) + + return qy + + # ------------------------------------------------------ + # Dashboard projets + # ------------------------------------------------------ + @api.model + def _select_projet(self, cgscop_id): + query = """ + SELECT + CONCAT('1', ur_id) AS id, + org.ur_id as ur_id, + 'Prospects en cours' AS name, + '1' as dash_type, + 0 as all_ur, + SUM(case + when substring(org.project_status,1,1) = '1' then 1 + else 0 end) AS nb_prj_info, + SUM(case + when substring(org.project_status,1,1) = '2' then 1 + else 0 end) AS nb_prj_pdiag, + SUM(case + when substring(org.project_status,1,1) = '3' then 1 + else 0 end) AS nb_prj_accomp, + SUM(case + when substring(org.project_status,1,1) = '4' then 1 + else 0 end) AS nb_prj_adh, + SUM(case when + substring(org.project_status,1,1) = '5' then 1 + else 0 end) AS nb_prj_soumis, + count(org.id) as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 as rev_5y, + 0 as rev_5ys, + 0 as rev_5ys23, + 0 as rev_todo, + 0 as rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM res_partner org + where + (org.ur_id <> %d) and + (org.active=TRUE) and + (org.is_cooperative = TRUE)and + substring(org.project_status,1,1) in ('1','2','3','4','5') + group by + org.ur_id + UNION ALL + SELECT + '1CGSCOP' AS id, + '%d' as ur_id, + 'Prospects en cours' AS name, + '1' as dash_type, + 1 as all_ur, + SUM(case + when substring(org.project_status,1,1) = '1' then 1 + else 0 end) AS nb_prj_info, + SUM(case + when substring(org.project_status,1,1) = '2' then 1 + else 0 end) AS nb_prj_pdiag, + SUM(case + when substring(org.project_status,1,1) = '3' then 1 + else 0 end) AS nb_prj_accomp, + SUM(case + when substring(org.project_status,1,1) = '4' then 1 + else 0 end) AS nb_prj_adh, + SUM(case + when substring(org.project_status,1,1) = '5' then 1 + else 0 end) AS nb_prj_soumis, + count(org.id) as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 as rev_5y, + 0 as rev_5ys, + 0 as rev_5ys23, + 0 as rev_todo, + 0 as rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM res_partner org + where + (org.active=TRUE) and + (org.is_cooperative = TRUE)and + substring(org.project_status,1,1) in ('1','2','3','4','5') + """ % ( + cgscop_id, + cgscop_id, + ) + + return query + + # ------------------------------------------------------ + # Dashboard cooperative + # ------------------------------------------------------ + @api.model + def _select_coop(self, cgscop_id): + + try: + form_scop = self.env.ref("cgscop_partner.form_scop").id + except Exception: + form_scop = 0 + + try: + form_scic = self.env.ref("cgscop_partner.form_scic").id + except Exception: + form_scic = 0 + + try: + form_co47 = self.env.ref("cgscop_partner.form_coop47").id + except Exception: + form_co47 = 0 + + query = """ + SELECT + CONCAT('2', ur_id) AS id, + org.ur_id as ur_id, + 'Coopératives adhérentes' AS name, + '2' as dash_type, + 0 as all_ur, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_scop, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_scic, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_co47, + SUM(case + when org.cae is true then 1 + else 0 end) AS nb_coop_cae, + SUM(case + when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1 + else 0 end) AS nb_coop_adh, + count(org.id) as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 as rev_5y, + 0 as rev_5ys, + 0 as rev_5ys23, + 0 as rev_todo, + 0 as rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM res_partner org + left join scop_membership_period as adh + on adh.partner_id = org.id + and adh.start=(select max(start) + from scop_membership_period where partner_id=org.id and type_id=1) + and type_id=1 + where + (org.ur_id <> %d) and + (org.active=TRUE) and + (org.is_cooperative = TRUE) and + (org.membership_status = 'member') + group by + org.ur_id + UNION ALL + SELECT + '2CGSCOP' AS id, + '%d' as ur_id, + 'Coopératives adhérentes' AS name, + '2' as dash_type, + 1 as all_ur, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_scop, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_scic, + SUM(case + when org.cooperative_form_id = %d then 1 + else 0 end) AS nb_fc_co47, + SUM(case + when org.cae is true then 1 + else 0 end) AS nb_coop_cae, + SUM(case + when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1 + else 0 end) AS nb_coop_adh, + count(org.id) as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 as rev_5y, + 0 as rev_5ys, + 0 as rev_5ys23, + 0 as rev_todo, + 0 as rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM res_partner org + left join scop_membership_period as adh + on adh.partner_id = org.id + and adh.start=(select max(start) + from scop_membership_period where partner_id=org.id and type_id=1) + and type_id=1 + where + (org.active=TRUE) and + (org.is_cooperative = TRUE) and + (org.membership_status = 'member') + """ % ( + form_scop, + form_scic, + form_co47, + cgscop_id, + cgscop_id, + form_scop, + form_scic, + form_co47, + ) + + return query + + # ------------------------------------------------------ + # Dashboard revision + # ------------------------------------------------------ + @api.model + def _select_rev(self, cgscop_id): + + query = """ + SELECT + id, + ur_id, + CONCAT('Révisions année ',date_part('year', CURRENT_DATE)) AS name, + '3' as dash_type, + 0 as all_ur, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + SUM(wrev.rev_done) as rev_done, + SUM(wrev.rev_1y) AS rev_1y, + SUM(wrev.rev_5y) AS rev_5y, + SUM(wRev.rev_5ys) AS rev_5ys, + SUM(wrev.rev_5ys23) AS rev_5ys23, + SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) + + SUM(wrev.rev_5ys23) AS rev_todo, + SUM(wrev.rev_done) + SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + + SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_total, + 0 as act_dev, + 0 as act_acc, + 0 as act_rev, + 0 as act_for, + 0 as act_acc_theo + FROM + ( + SELECT + CONCAT(org.ur_id, org.revision_next_year) AS id, + org.ur_id as ur_id, + 0 AS rev_done, + case when org.revision_type = '1y' then 1 else 0 end AS rev_1y, + case when org.revision_type = '5y' then 1 else 0 end AS rev_5y, + case when org.revision_type = '5ys' then 1 else 0 end AS rev_5ys, + case when org.revision_type = '5ys23' then 1 else 0 end AS rev_5ys23 + FROM res_partner as org + WHERE (org.revision_next_year = date_part('year', CURRENT_DATE)) + UNION ALL + SELECT + CONCAT(org.ur_id, date_part('year', rev.date)) as id, + org.ur_id as ur_id, + 1 AS rev_done, + 0 AS rev_1y, + 0 AS rev_5y, + 0 AS rev_5ys, + 0 AS rev_5ys23 + FROM scop_revision as rev + JOIN res_partner as org ON (org.id = rev.partner_id) + WHERE (date_part('year', rev.date) = date_part('year', CURRENT_DATE)) + ) AS wRev + GROUP BY wrev.id, wrev.ur_id + """ + return query + + # ------------------------------------------------------ + # Dashboard activité + # ------------------------------------------------------ + @api.model + def _select_act(self, cgscop_id): + + query = """ + SELECT + CONCAT('4', ur_id) as id, + ur_id, + CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name, + '4' as dash_type, + 0 as all_ur, + 0 as nb_prj_info, + 0 as nb_prj_pdiag, + 0 as nb_prj_accomp, + 0 as nb_prj_adh, + 0 as nb_prj_soumis, + 0 as nb_prj_tot, + 0 as nb_fc_scop, + 0 as nb_fc_scic, + 0 as nb_fc_co47, + 0 as nb_coop_cae, + 0 as nb_coop_adh, + 0 as nb_coop_tot, + 0 as rev_done, + 0 as rev_1y, + 0 AS rev_5y, + 0 AS rev_5ys, + 0 AS rev_5ys23, + 0 AS rev_todo, + 0 AS rev_total, + sum(wrk.amount_dev) as act_dev, + sum(wrk.amount_acc) as act_acc, + sum(wrk.amount_rev) as act_rev, + sum(wrk.amount_for) as act_for, + sum(wrk.amount_theo) as act_acc_theo + FROM + ( + select + ac.ur_id as ur_id, + EXTRACT(YEAR FROM ac.date) as "year", + ac.unit_amount as amount_rev, + 0 as amount_dev, + 0 as amount_acc, + 0 as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'R' + union all + select + ac.ur_id as ur_id, + EXTRACT(YEAR FROM ac.date) as "year", + 0 as amount_rev, + ac.unit_amount as amount_dev, + 0 as amount_acc, + 0 as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'D' + union all + select + ac.ur_id as ur_id, + EXTRACT(YEAR FROM ac.date) as "year", + 0 as amount_rev, + 0 as amount_dev, + ac.unit_amount as amount_acc, + 0 as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'A' + union all + select + ac.ur_id as ur_id, + EXTRACT(YEAR FROM ac.date) as "year", + 0 as amount_rev, + 0 as amount_dev, + 0 as amount_acc, + ac.unit_amount as amount_for, + 0 as amount_theo + from + account_analytic_line as ac + left join project_project as pu on pu.id = ac.project_id + left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id + where + (date_part('year', ac.date) = date_part('year', CURRENT_DATE)) + and pn.domain = 'F' + union all + select + pa.ur_id as ur_id, + date_part('year', CURRENT_DATE) as "year", + 0 as amount_rev, + 0 as amount_dev, + 0 as amount_acc, + 0 as amount_for, + fo.duree as act_acc_theo + from + res_partner as pa + left join scop_followup_format as fo on fo.id = pa.followup_format_id + where pa.membership_status = 'member' + ) as wrk + group BY + wrk.ur_id, + wrk.year + """ + return query + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute( + "CREATE or REPLACE VIEW %s as (%s)", + (AsIs(self._table), AsIs(self._select())), + ) + + # ------------------------------------------------------ + # Récupère l'ur de l'utilisateur connecté + # ------------------------------------------------------ + @api.model + def _compute_current_user_ur_id(self): + for partner in self: + partner.current_user_ur_id = self.env.user.company_id.ur_id.id + + def _search_current_user_ur_id(self, operator, value): + return [("ur_id", "=", self.env.user.company_id.ur_id.id)] + + # ------------------------------------------------------ + # Calcule les données du graphique + # ------------------------------------------------------ + def _compute_graph_values(self): + for rec in self: + if rec.dash_type == 1: + rec.graph_values = json.dumps( + [ + { + "values": [ + { + "label": "Information", + "value": rec.nb_prj_info, + }, + { + "label": "Pré-diag", + "value": rec.nb_prj_pdiag, + }, + { + "label": "Accompagnement", + "value": rec.nb_prj_accomp, + }, + {"label": "Adhésion", "value": rec.nb_prj_adh}, + { + "label": "Soumis CG", + "value": rec.nb_prj_soumis, + }, + ], + "area": True, + "title": "", + "key": "Prospects en cours", + } + ] + ) + + if rec.dash_type == 2: + rec.graph_values = json.dumps( + [ + { + "values": [ + {"label": "Scop", "value": rec.nb_fc_scop}, + {"label": "Scic", "value": rec.nb_fc_scic}, + {"label": "Coop 47", "value": rec.nb_fc_co47}, + ], + "area": True, + "title": "", + "key": "Coopératives adhérentes", + } + ] + ) + + if rec.dash_type == 3: + rec.graph_values = json.dumps( + [ + { + "values": [ + {"label": "Annuelle", "value": rec.rev_1y}, + {"label": "Quinquennale", "value": rec.rev_5y}, + { + "label": "Quinq. séq. (annuel)", + "value": rec.rev_5ys, + }, + { + "label": "Quinq. séq. (2 et 3)", + "value": rec.rev_5ys23, + }, + ], + "area": True, + "title": "", + "key": "Nombre de révisions", + } + ] + ) + + if rec.dash_type == 4: + rec.graph_values = json.dumps( + [ + { + "values": [ + { + "label": "Développement (hrs)", + "value": rec.act_dev, + }, + {"label": "Suivi (hrs)", "value": rec.act_acc}, + { + "label": "Révision (hrs)", + "value": rec.act_rev, + }, + { + "label": "Formation (hrs)", + "value": rec.act_for, + }, + ], + "area": True, + "title": "", + "key": "Découpage de l'activité", + } + ] + ) + + # ------------------------------------------------------ + # Calcul le % de révision réalisé + # ------------------------------------------------------ + def _compute_percent_rev(self): + for rec in self: + if rec.rev_total == 0: + rec.rev_percent_done = 0 + else: + rec.rev_percent_done = rec.rev_done / rec.rev_total * 100 + + # ------------------------------------------------------ + # Calcul le % d'accompagnement réalisé + # ------------------------------------------------------ + def _compute_act_acc(self): + for rec in self: + if rec.act_acc_theo == 0: + rec.act_acc_percent_done = 0 + else: + rec.act_acc_percent_done = rec.act_acc / rec.act_acc_theo * 100 + + # ------------------------------------------------------ + # Affichage des projets de l'ur + # ------------------------------------------------------ + def show_projets(self): + return { + "name": "Prospects", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "view_type": "form", + "view_mode": "kanban,tree,form", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_kanban").id, + "kanban", + ), + ( + self.env.ref("cgscop_partner.view_partner_prospect_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ( + "project_status", + "in", + ( + "1_information", + "2_pre-diagnostic", + "3_accompagnement", + "4_adhesion", + "5_cg", + "7_abandonne", + ), + ), + ("current_user_ur_id", "=", "ur_id"), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "default_project_status": "1_information", + }, + } + + # ------------------------------------------------------ + # Affichage de tous les projets + # ------------------------------------------------------ + def show_all_projets(self): + return { + "name": "Tous les Prospects", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "view_type": "form", + "view_mode": "kanban,tree,form", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_kanban").id, + "kanban", + ), + ( + self.env.ref("cgscop_partner.view_partner_prospect_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ( + "project_status", + "in", + ( + "1_information", + "2_pre-diagnostic", + "3_accompagnement", + "4_adhesion", + "5_cg", + "7_abandonne", + ), + ), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "default_project_status": "1_information", + }, + } + + # ------------------------------------------------------ + # Affichage des coop adh de l'ur + # ------------------------------------------------------ + def show_coop(self): + return { + "name": "Coopératives adhérentes", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "search_view_id": ( + self.env.ref("cgscop_partner.scop_partner_view_search").id, + ), + "view_type": "form", + "view_mode": "tree,form", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ("current_user_ur_id", "=", "ur_id"), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } + + # ------------------------------------------------------ + # Affichage de toutes les coop adh + # ------------------------------------------------------ + def show_all_coop(self): + return { + "name": "Toutes les coopératives adhérentes", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "search_view_id": ( + self.env.ref("cgscop_partner.scop_partner_view_search").id, + ), + "view_type": "form", + "view_mode": "tree,form", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } + + # ------------------------------------------------------ + # Affichage des coop à réviser + # ------------------------------------------------------ + def show_rev(self): + + wyear = datetime.datetime.today().year + + return { + "name": "Coopérative à réviser", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "view_type": "form", + "view_mode": "tree", + "views": [ + ( + self.env.ref("cgscop_partner.view_partner_cooperative_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ("current_user_ur_id", "=", "ur_id"), + ("revision_next_year", "=", wyear), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } + + # ------------------------------------------------------ + # Affichage des coop à suivre + # ------------------------------------------------------ + def show_acc(self): + + datetime.datetime.today().year + + return { + "name": "Coopérative à suivre", + "type": "ir.actions.act_window", + "res_model": "res.partner", + "search_view_id": ( + self.env.ref("cgscop_partner.scop_partner_view_search").id, + ), + "view_type": "form", + "view_mode": "tree", + "views": [ + ( + self.env.ref("cgscop_partner_crm.scop_partner_crm_view_tree").id, + "tree", + ), + ( + self.env.ref("cgscop_partner.scop_contact_view_form").id, + "form", + ), + ], + "target": "current", + "domain": [ + ("is_cooperative", "=", True), + ("membership_status", "=", "member"), + ("current_user_ur_id", "=", "ur_id"), + ], + "context": { + "default_is_company": True, + "default_is_cooperative": True, + "default_company_type": "company", + "create": False, + }, + } diff --git a/views/partner_dashboard_ur.xml b/report/partner_dashboard_ur.xml similarity index 54% rename from views/partner_dashboard_ur.xml rename to report/partner_dashboard_ur.xml index 48e10fe21cd5b5a4bb325caf3c88c93c9db03d26..fb29a193a4b4e7812b3ba0d8471b19ac8d2f6b0a 100644 --- a/views/partner_dashboard_ur.xml +++ b/report/partner_dashboard_ur.xml @@ -1,185 +1,256 @@ -<?xml version="1.0" encoding="utf-8"?> -<odoo> - <data> - - <record id="scop_partner_dashboard_ur_kanban_view" model="ir.ui.view"> - <field name="name">scop.partner.dashboard.ur.kanban</field> - <field name="model">scop.partner.dashboard.ur</field> - <field name="arch" type="xml"> - <kanban create="false" class="oe_background_grey o_kanban_dashboard o_account_kanban" > - <field name="name"/> - <field name="ur_id"/> - <field name="dash_type"/> - <field name="nb_prj_tot"/> - <field name="nb_prj_accomp"/> - <field name="nb_prj_adh"/> - <field name="nb_prj_soumis"/> - <field name="all_ur"/> - <templates> - <t t-name="kanban-box"> - <div class="container o_kanban_card_content"> - <div class="row"> - <div class="col"> - <h2 class="mt16"><field name="name"/></h2> - <hr/> - <p>Union régionale : <field name="ur_id"/></p> - </div> - </div> - - <!-- Affiche Dashboard type 1 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 1)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_projets" class="btn btn-info" attrs="{'invisible': [('all_ur', '=', True)]}">Voir les prospects</button> - </div> - <div class="text-center mb32"> - <button type="object" name="show_all_projets" class="btn btn-info" attrs="{'invisible': [('all_ur', '!=', True)]}">Voir tous les prospects</button> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Prospects en cours :</td> - <td><field name="nb_prj_tot"/></td> - </tr> - <tr> - <td>dont phase d'accompagnement :</td> - <td><field name="nb_prj_accomp"/></td> - </tr> - <tr> - <td>dont phase d'adhésion :</td> - <td><field name="nb_prj_adh"/></td> - </tr> - <tr> - <td>dont soumis CG :</td> - <td><field name="nb_prj_soumis"/></td> - </tr> - </tbody> - </table> - </div> - </div> - - - <!-- Affiche Dashboard type 2 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 2)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_coop" class="btn btn-info" attrs="{'invisible': [('all_ur', '=', True)]}">Voir les coopératives<br/> adhérentes</button> - </div> - <div class="text-center mb32"> - <button type="object" name="show_all_coop" class="btn btn-info" attrs="{'invisible': [('all_ur', '!=', True)]}">Voir toutes les coopératives<br/> adhérentes</button> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Coopératives adhérentes :</td> - <td><field name="nb_coop_tot"/></td> - </tr> - <tr> - <td>dont SCOP :</td> - <td><field name="nb_fc_scop"/></td> - </tr> - <tr> - <td>dont SCIC :</td> - <td><field name="nb_fc_scic"/></td> - </tr> - <tr> - <td>dont CAE :</td> - <td><field name="nb_coop_cae"/></td> - </tr> - </tbody> - </table> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Adhésions de l'année :</td> - <td><field name="nb_coop_adh"/></td> - </tr> - </tbody> - </table> - </div> - </div> - - <!-- Affiche Dashboard type 3 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 3)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_rev" class="btn btn-info">Voir les coopératives<br/> à réviser</button> - </div> - <div class="text-center"> - <field name="rev_percent_done" widget="percentpie"/> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>A réaliser :</td> - <td><field name="rev_todo"/></td> - </tr> - <tr> - <td>Réalisées :</td> - <td><field name="rev_done"/></td> - </tr><tr> - <td><strong>Total :</strong></td> - <td><strong><field name="rev_total"/></strong></td> - </tr> - </tbody> - </table> - </div> - </div> - - <!-- Affiche Dashboard type 4 --> - <div class="row" attrs="{'invisible': [('dash_type', '!=', 4)]}"> - <div class="col-6"> - <div class="text-center mb32"> - <button type="object" name="show_acc" class="btn btn-info">Voir les coopératives<br/> à suivre</button> - </div> - <div class="text-center"> - <field name="act_acc_percent_done" widget="percentpie"/> - </div> - </div> - <div class="col-6"> - <table class="table table-bordered"> - <tbody> - <tr> - <td>Suivi à réaliser (hrs) :</td> - <td><field name="act_acc_theo"/></td> - </tr> - <tr> - <td>Suivi réalisés (hrs) :</td> - <td><field name="act_acc"/></td> - </tr> - </tbody> - </table> - </div> - </div> - - - <!-- Affiche le graph --> - <div class="row"> - <div class="col"> - <field name="graph_values" widget="dashboard_graph" graph_type="bar"/> - </div> - </div> - </div> - </t> - </templates> - </kanban> - </field> - </record> - - <record model="ir.actions.act_window" id="coop_partner_dashboard_ur_act" > - <field name="name">Dashboard coopératives (Union régionale)</field> - <field name="type">ir.actions.act_window</field> - <field name="res_model">scop.partner.dashboard.ur</field> - <field name="view_type">form</field> - <field name="view_mode">kanban</field> - <field name="domain" eval="[('current_user_ur_id', '=', 'ur_id')]"/> - </record> - - </data> -</odoo> \ No newline at end of file +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <data> + + <record id="scop_partner_dashboard_ur_kanban_view" model="ir.ui.view"> + <field name="name">scop.partner.dashboard.ur.kanban</field> + <field name="model">scop.partner.dashboard.ur</field> + <field name="arch" type="xml"> + <kanban + create="false" + class="oe_background_grey o_kanban_dashboard o_account_kanban" + > + <field name="name" /> + <field name="ur_id" /> + <field name="dash_type" /> + <field name="nb_prj_tot" /> + <field name="nb_prj_accomp" /> + <field name="nb_prj_adh" /> + <field name="nb_prj_soumis" /> + <field name="all_ur" /> + <templates> + <t t-name="kanban-box"> + <div class="container o_kanban_card_content"> + <div class="row"> + <div class="col"> + <h2 class="mt16"><field name="name" /></h2> + <hr /> + <p>Union régionale : <field name="ur_id" /></p> + </div> + </div> + + <!-- Affiche Dashboard type 1 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 1)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_projets" + class="btn btn-info" + attrs="{'invisible': [('all_ur', '=', True)]}" + >Voir les prospects</button> + </div> + <div class="text-center mb32"> + <button + type="object" + name="show_all_projets" + class="btn btn-info" + attrs="{'invisible': [('all_ur', '!=', True)]}" + >Voir tous les prospects</button> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Prospects en cours :</td> + <td><field name="nb_prj_tot" /></td> + </tr> + <tr> + <td + >dont phase d'accompagnement :</td> + <td><field + name="nb_prj_accomp" + /></td> + </tr> + <tr> + <td>dont phase d'adhésion :</td> + <td><field name="nb_prj_adh" /></td> + </tr> + <tr> + <td>dont soumis CG :</td> + <td><field + name="nb_prj_soumis" + /></td> + </tr> + </tbody> + </table> + </div> + </div> + + + <!-- Affiche Dashboard type 2 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 2)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_coop" + class="btn btn-info" + attrs="{'invisible': [('all_ur', '=', True)]}" + >Voir les coopératives<br + /> adhérentes</button> + </div> + <div class="text-center mb32"> + <button + type="object" + name="show_all_coop" + class="btn btn-info" + attrs="{'invisible': [('all_ur', '!=', True)]}" + >Voir toutes les coopératives<br + /> adhérentes</button> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Coopératives adhérentes :</td> + <td><field + name="nb_coop_tot" + /></td> + </tr> + <tr> + <td>dont SCOP :</td> + <td><field name="nb_fc_scop" /></td> + </tr> + <tr> + <td>dont SCIC :</td> + <td><field name="nb_fc_scic" /></td> + </tr> + <tr> + <td>dont CAE :</td> + <td><field + name="nb_coop_cae" + /></td> + </tr> + </tbody> + </table> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Adhésions de l'année :</td> + <td><field + name="nb_coop_adh" + /></td> + </tr> + </tbody> + </table> + </div> + </div> + + <!-- Affiche Dashboard type 3 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 3)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_rev" + class="btn btn-info" + >Voir les coopératives<br + /> à réviser</button> + </div> + <div class="text-center"> + <field + name="rev_percent_done" + widget="percentpie" + /> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>A réaliser :</td> + <td><field name="rev_todo" /></td> + </tr> + <tr> + <td>Réalisées :</td> + <td><field name="rev_done" /></td> + </tr><tr> + <td><strong>Total :</strong></td> + <td><strong><field + name="rev_total" + /></strong></td> + </tr> + </tbody> + </table> + </div> + </div> + + <!-- Affiche Dashboard type 4 --> + <div + class="row" + attrs="{'invisible': [('dash_type', '!=', 4)]}" + > + <div class="col-6"> + <div class="text-center mb32"> + <button + type="object" + name="show_acc" + class="btn btn-info" + >Voir les coopératives<br + /> à suivre</button> + </div> + <div class="text-center"> + <field + name="act_acc_percent_done" + widget="percentpie" + /> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Suivi à réaliser (hrs) :</td> + <td><field + name="act_acc_theo" + /></td> + </tr> + <tr> + <td>Suivi réalisés (hrs) :</td> + <td><field name="act_acc" /></td> + </tr> + </tbody> + </table> + </div> + </div> + + + <!-- Affiche le graph --> + <div class="row"> + <div class="col"> + <field + name="graph_values" + widget="dashboard_graph" + graph_type="bar" + /> + </div> + </div> + </div> + </t> + </templates> + </kanban> + </field> + </record> + + <record model="ir.actions.act_window" id="coop_partner_dashboard_ur_act"> + <field name="name">Dashboard coopératives (Union régionale)</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">scop.partner.dashboard.ur</field> + <field name="view_mode">kanban</field> + <field name="domain" eval="[('current_user_ur_id', '=', 'ur_id')]" /> + </record> + + </data> +</odoo> diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index fa51d84fb26d3f893934d8db21d101b8011c2fd6..f2d434b1ab6ec8d40b9a3442d7f5b98d081b1c7a 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -1,5 +1,6 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_scop_partner_dashboard_ur,access_scop_partner_dashboard_ur,model_scop_partner_dashboard_ur,base.group_user,1,0,0,0 -admin_access_scop_partner_dashboard_ur,admin_scop_partner_dashboard_ur,model_scop_partner_dashboard_ur,cgscop_partner.group_cg_administrator,1,1,1,1 -access_scop_partner_dashboard_dlg,access_scop_partner_dashboard_dlg,model_scop_partner_dashboard_dlg,base.group_user,1,0,0,0 -admin_access_scop_partner_dashboard_dlg,admin_scop_partner_dashboard_dlg,model_scop_partner_dashboard_dlg,cgscop_partner.group_cg_administrator,1,1,1,1 \ No newline at end of file +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_scop_partner_dashboard_ur,access_scop_partner_dashboard_ur,model_scop_partner_dashboard_ur,base.group_user,1,0,0,0 +admin_access_scop_partner_dashboard_ur,admin_scop_partner_dashboard_ur,model_scop_partner_dashboard_ur,cgscop_partner.group_cg_administrator,1,1,1,1 +access_scop_partner_dashboard_dlg,access_scop_partner_dashboard_dlg,model_scop_partner_dashboard_dlg,base.group_user,1,0,0,0 +admin_access_scop_partner_dashboard_dlg,admin_scop_partner_dashboard_dlg,model_scop_partner_dashboard_dlg,cgscop_partner.group_cg_administrator,1,1,1,1 +access_scop_partner_dashboard_dlg_selection_wizard,access_scop_partner_dashboard_dlg_selection_wizard,model_scop_partner_dashboard_dlg_selection_wizard,base.group_user,1,1,1,1 diff --git a/security/security_rules.xml b/security/security_rules.xml index 82d5c9dba402e9df0c4fc9613fb3cb119e315153..dd7f42085383c2bbe10ca85bb54f499c86c53289 100644 --- a/security/security_rules.xml +++ b/security/security_rules.xml @@ -1,8 +1,7 @@ <odoo> - <data noupdate="0"> - <record model="res.groups" id="partner_dashboard_dlg_selection_group" > + <data> + <record model="res.groups" id="partner_dashboard_dlg_selection_group"> <field name="name">Dashboard coopératives, choix du délégué</field> </record> - </data> </odoo> diff --git a/static/description/icon.png b/static/description/icon.png index 7c4b282f22fa37ed748c5e23f644205ad340af1f..9002f6179b6459cee4ea49e69e8b5114e2f5d3d0 100644 Binary files a/static/description/icon.png and b/static/description/icon.png differ diff --git a/templates/header_dlg_template.xml b/templates/header_dlg_template.xml index 14038e691e40c275d769a88feb88394900e18de4..10bf3dfcd073ec76b2f29955026cdb354f98f95d 100644 --- a/templates/header_dlg_template.xml +++ b/templates/header_dlg_template.xml @@ -1,12 +1,19 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8" ?> <odoo> - <template id="header_dlg_template" name="cgscop_partner_dashboard.header_dlg_template"> + <template + id="header_dlg_template" + name="cgscop_partner_dashboard.header_dlg_template" + > <div id="dash" style="background-color: #fff; padding: 16px "> - <div > + <div> <div class="row"> <div class="col-12"> - <a type="action" data-method="action_open_wizard_selection" data-model="scop.partner.dashboard.dlg.selection.wizard" - class="btn btn-secondary"> + <a + type="action" + data-method="action_open_wizard_selection" + data-model="scop.partner.dashboard.dlg.selection.wizard" + class="btn btn-secondary" + > Sélectionner un collaborateur </a> </div> @@ -14,4 +21,4 @@ </div> </div> </template> -</odoo> \ No newline at end of file +</odoo> diff --git a/views/res_partner.xml b/views/res_partner.xml index b7e935cc6d1402ac695e16a6ad61d7a3bfffdbcf..2342af86b5496417c607a739a9f51efd0eccc0aa 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -1,28 +1,34 @@ -<?xml version="1.0"?> -<!-- Copyright 2020 Le Filament - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> - -<odoo> - <data> - <menuitem id="contacts.menu_contacts" - action="coop_partner_dashboard_ur_act" - /> - - <menuitem id="res_partner_menu_dashboard" - name="Dashboard" - parent="contacts.menu_contacts" - sequence="05"/> - - <menuitem id="res_partner_menu_dashboard_ur" - name="Dashboard union régionale" - parent="res_partner_menu_dashboard" - action="coop_partner_dashboard_ur_act" - sequence="10"/> - - <menuitem id="res_partner_menu_dashboard_dlg" - name="Dashboard délégué" - parent="res_partner_menu_dashboard" - action="coop_partner_dashboard_dlg_act" - sequence="20"/> - </data> -</odoo> +<?xml version="1.0" ?> +<!-- Copyright 2020 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> +<odoo> + <data> + <menuitem + id="contacts.menu_contacts" + action="coop_partner_dashboard_ur_act" + /> + + <menuitem + id="res_partner_menu_dashboard" + name="Dashboard" + parent="contacts.menu_contacts" + sequence="05" + /> + + <menuitem + id="res_partner_menu_dashboard_ur" + name="Dashboard union régionale" + parent="res_partner_menu_dashboard" + action="coop_partner_dashboard_ur_act" + sequence="10" + /> + + <menuitem + id="res_partner_menu_dashboard_dlg" + name="Dashboard délégué" + parent="res_partner_menu_dashboard" + action="coop_partner_dashboard_dlg_act" + sequence="20" + /> + </data> +</odoo> diff --git a/wizard/partner_dashboard_dlg_selection_wizard.py b/wizard/partner_dashboard_dlg_selection_wizard.py index 25cb0032df4ad694ca950bbfd7de43d53c60a5e9..1e38b04699209690afc6d28a234aba31497be69a 100644 --- a/wizard/partner_dashboard_dlg_selection_wizard.py +++ b/wizard/partner_dashboard_dlg_selection_wizard.py @@ -1,49 +1,51 @@ # © 2019 Le Filament (<http://www.le-filament.com>) +# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import fields, models, api +from odoo import api, fields, models class ScopPartnerDashboardDlgSelectiontWizard(models.TransientModel): - _name = 'scop.partner.dashboard.dlg.selection.wizard' + _name = "scop.partner.dashboard.dlg.selection.wizard" _description = "Wizard de sélection du délégué" @api.model def _getUserDomain(self): - if self.env.user.has_group('cgscop_partner_dashboard.partner_dashboard_dlg_selection_group'): - return [('ur_id', '=', self.env.user.company_id.ur_id.id)] + if self.env.user.has_group( + "cgscop_partner_dashboard.partner_dashboard_dlg_selection_group" + ): + return [("ur_id", "=", self.env.user.company_id.ur_id.id)] else: - return [('id', '=', self.env.user.id)] + return [("id", "=", self.env.user.id)] # Fields common dlg_id = fields.Many2one( - comodel_name='res.users', - domain=_getUserDomain, - string='Collaborateur') + comodel_name="res.users", domain=_getUserDomain, string="Collaborateur" + ) - - #.................................................................................... + # .................................................................................... # Affichage du wizard - #.................................................................................... + # .................................................................................... @api.model def action_open_wizard_selection(self): action = self.env.ref( - 'cgscop_partner_dashboard.scop_partner_dashboard_dlg_selection_act').read()[ - 0] + "cgscop_partner_dashboard.scop_partner_dashboard_dlg_selection_act" + ).read()[0] return action - #.................................................................................... + # .................................................................................... # Affichage de la demande - #.................................................................................... + # .................................................................................... def valid_wizard(self): form_id = self.env.ref( - "cgscop_partner_dashboard.scop_partner_dashboard_dlg_kanban_view") + "cgscop_partner_dashboard.scop_partner_dashboard_dlg_kanban_view" + ) return { - 'name': 'Dashboard coopératives : '+self.dlg_id.name, - 'type': 'ir.actions.act_window', - 'res_model': 'scop.partner.dashboard.dlg', - 'view_mode': 'kanban', - 'views': [[form_id.id, 'kanban']], - 'target': 'main', - 'domain': [('dlg_id', '=', self.dlg_id.id)] - } \ No newline at end of file + "name": "Dashboard coopératives : " + self.dlg_id.name, + "type": "ir.actions.act_window", + "res_model": "scop.partner.dashboard.dlg", + "view_mode": "kanban", + "views": [[form_id.id, "kanban"]], + "target": "main", + "domain": [("dlg_id", "=", self.dlg_id.id)], + } diff --git a/wizard/partner_dashboard_dlg_selection_wizard.xml b/wizard/partner_dashboard_dlg_selection_wizard.xml index 5ef687251d26fdde021db49517abcb203f54dd17..5970f87e145843ad4bff85744e15d69d8629c0f7 100644 --- a/wizard/partner_dashboard_dlg_selection_wizard.xml +++ b/wizard/partner_dashboard_dlg_selection_wizard.xml @@ -1,28 +1,41 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8" ?> <odoo> <!-- WIZARD FORM --> - <record model="ir.ui.view" id="scop_partner_dashboard_dlg_selection_wizard" > + <record model="ir.ui.view" id="scop_partner_dashboard_dlg_selection_wizard"> <field name="name">scop_partner_dashboard_dlg_selection_wizard</field> <field name="model">scop.partner.dashboard.dlg.selection.wizard</field> <field name="arch" type="xml"> <form string="Sélection du collaborateur"> <group string="Collaborateur" col="2"> - <field name="dlg_id" options="{'no_create_edit': True, 'no_open': True}" required="1"/> + <field + name="dlg_id" + options="{'no_create_edit': True, 'no_open': True}" + required="1" + /> </group> <footer> - <button class="btn btn-sm btn-primary" name="valid_wizard" string="Validation" type="object"/> - <button class="btn btn-sm btn-default" special="cancel" string="Close"/> + <button + class="btn btn-sm btn-primary" + name="valid_wizard" + string="Validation" + type="object" + /> + <button + class="btn btn-sm btn-default" + special="cancel" + string="Close" + /> </footer> </form> </field> </record> - <record model="ir.actions.act_window" id="scop_partner_dashboard_dlg_selection_act" > + <record model="ir.actions.act_window" id="scop_partner_dashboard_dlg_selection_act"> <field name="name">Sélection du collaborateur</field> <field name="type">ir.actions.act_window</field> <field name="res_model">scop.partner.dashboard.dlg.selection.wizard</field> <field name="view_mode">form</field> - <field name="view_id" ref="scop_partner_dashboard_dlg_selection_wizard"/> + <field name="view_id" ref="scop_partner_dashboard_dlg_selection_wizard" /> <field name="target">new</field> </record>