From 0222285869357e8ae00898b768673bc3765dac75 Mon Sep 17 00:00:00 2001 From: wan Date: Thu, 25 Nov 2021 11:08:47 +0000 Subject: [PATCH] [ADD] extensions: add a custom `example` admonition closes odoo/documentation#1506 X-original-commit: 434bb6649297d4ae9d7c0227f70917b4d075ec52 Signed-off-by: Antoine Vandevenne (anv) --- conf.py | 2 +- .../localizations/france.rst | 68 +++++++++---------- .../reporting/subscription_reports.rst | 20 +++--- .../developer/reference/backend/mixins.rst | 12 ++-- content/developer/reference/backend/orm.rst | 4 +- content/developer/reference/backend/views.rst | 2 +- .../__init__.py | 16 ++++- .../odoo_theme/static/scss/_variables.scss | 3 +- extensions/odoo_theme/static/style.scss | 17 ++++- extensions/odoo_theme/translator.py | 1 + 10 files changed, 86 insertions(+), 59 deletions(-) rename extensions/{exercise_admonition => custom_admonitions}/__init__.py (59%) diff --git a/conf.py b/conf.py index 2b0ce9b49..553d63cf5 100644 --- a/conf.py +++ b/conf.py @@ -116,7 +116,7 @@ extensions = [ # Youtube and Vimeo videos integration (youtube, vimeo directives) 'embedded_video', - 'exercise_admonition', + 'custom_admonitions', # Redirection generator 'redirects', diff --git a/content/applications/finance/accounting/fiscal_localizations/localizations/france.rst b/content/applications/finance/accounting/fiscal_localizations/localizations/france.rst index d72ade118..57079f4f8 100644 --- a/content/applications/finance/accounting/fiscal_localizations/localizations/france.rst +++ b/content/applications/finance/accounting/fiscal_localizations/localizations/france.rst @@ -149,10 +149,9 @@ This means that the account codes the trailing zeroes are right-trimmed, and tha between the account codes in the FEC file and the ones already existing in Odoo is performed only on the first six digits of the codes. -.. admonition:: Example - - The account code `65800000` in the file is matched against an existing `658000` account in - Odoo, and that account is used instead of creating a new one. +.. example:: + The account code `65800000` in the file is matched against an existing `658000` account in Odoo, + and that account is used instead of creating a new one. Reconcilable flag ***************** @@ -177,17 +176,17 @@ computed this way. The match is done with the left-most digits, starting by using all digits, then 3, then 2. -.. admonition:: Example +.. example:: - +------------+------------+-----------------+---------------------+---------------------+ - | Name | Code | Full comparison | 3-digits comparison | 2-digits comparison | - +============+============+=================+=====================+=====================+ - | Template | `400000` | `400000` | `400` | `40` | - +------------+------------+-----------------+---------------------+---------------------+ - | CompteNum | `40100000` | `40100000` | `401` | `40` | - +------------+------------+-----------------+---------------------+---------------------+ - | **Result** | | | | Match **found** | - +------------+------------+-----------------+---------------------+---------------------+ + +------------+------------+-----------------+---------------------+---------------------+ + | Name | Code | Full comparison | 3-digits comparison | 2-digits comparison | + +============+============+=================+=====================+=====================+ + | Template | `400000` | `400000` | `400` | `40` | + +------------+------------+-----------------+---------------------+---------------------+ + | CompteNum | `40100000` | `40100000` | `401` | `40` | + +------------+------------+-----------------+---------------------+---------------------+ + | **Result** | | | | Match **found** | + +------------+------------+-----------------+---------------------+---------------------+ The type of the account is then flagged as *payable* and *reconcilable* as per the account template. @@ -202,9 +201,8 @@ creating a new one. New journals have their name prefixed by the string ``FEC-``. -.. admonition:: Example - - `ACHATS` -> `FEC-ACHATS` +.. example:: + `ACHATS` -> `FEC-ACHATS` The journals are *not* archived, the user is entitled to handle them as he wishes. @@ -233,24 +231,23 @@ moves and accounts: - A minimum of three moves is necessary for journal type identification. - A threshold of 70% of moves must correspond to a criteria for a journal type to be determined. -.. admonition:: Example +.. example:: + Suppose we are analyzing the moves that share a certain `journal_id`. - Suppose we are analyzing the moves that share a certain `journal_id` + +------------------------------------------------------------+-------+------------+ + | Moves | Count | Percentage | + +============================================================+=======+============+ + | that have a sale account line and no purchase account line | 0 | 0 | + +------------------------------------------------------------+-------+------------+ + | that have a purchase account line and no sale account line | 1 | 25% | + +------------------------------------------------------------+-------+------------+ + | that have a liquidity account line | 3 | **75%** | + +------------------------------------------------------------+-------+------------+ + | **Total** | 4 | 100% | + +------------------------------------------------------------+-------+------------+ - +------------------------------------------------------------+-------+------------+ - | Moves | Count | Percentage | - +============================================================+=======+============+ - | that have a sale account line and no purchase account line | 0 | 0 | - +------------------------------------------------------------+-------+------------+ - | that have a purchase account line and no sale account line | 1 | 25% | - +------------------------------------------------------------+-------+------------+ - | that have a liquidity account line | 3 | **75%** | - +------------------------------------------------------------+-------+------------+ - | **Total** | 4 | 100% | - +------------------------------------------------------------+-------+------------+ - - The journal `type` would be `bank`, because the bank moves percentage (75%) - exceeds the threshold (70%). + The journal `type` would be `bank`, because the bank moves percentage (75%) exceeds the threshold + (70%). Partners ******** @@ -299,9 +296,8 @@ One last attempt is made, grouping all lines from the same journal and date (`Jo `EcritureDate`). Should this grouping generate balanced moves (sum(credit) - sum(debit) = 0), then each different combination of journal and date creates a new move. -.. admonition:: Example - - `ACH` + `2021/05/01` --> new move on journal `ACH` with name `20210501`. +.. example:: + `ACH` + `2021/05/01` --> new move on journal `ACH` with name `20210501`. Should this attempt fail, the user is prompted an error message with all the move lines that are supposedly unbalanced. diff --git a/content/applications/sales/subscriptions/reporting/subscription_reports.rst b/content/applications/sales/subscriptions/reporting/subscription_reports.rst index c014c8317..81554b887 100644 --- a/content/applications/sales/subscriptions/reporting/subscription_reports.rst +++ b/content/applications/sales/subscriptions/reporting/subscription_reports.rst @@ -36,19 +36,19 @@ concepts to the proper understanding of the following reports: - **Revenue Churn**: It corresponds to the monthly recurring revenue loss rate. - .. admonition:: - Let's imagine a 2$ increase in a subscription service. + .. example:: + Let's imagine a 2$ increase in a subscription service. - - We lost 3 customers out of the initial 20, which generates a **Logo Churn** of 15%. - - | Therefore, the 56$ of MRR difference out of the initial 600$ causes a **Revenue Churn** - | of 9,33%. + - We lost 3 customers out of the initial 20, which generates a **Logo Churn** of 15%. + - | Therefore, the 56$ of MRR difference out of the initial 600$ causes a **Revenue Churn** + | of 9,33%. - .. image:: media/difference-between-logo-churn-and-revenue-churn.png - :align: center - :alt: Difference between logo churn and revenue churn in Odoo Subscriptions + .. image:: media/difference-between-logo-churn-and-revenue-churn.png + :align: center + :alt: Difference between logo churn and revenue churn in Odoo Subscriptions - Reminder: even though they seem to evolve in the same direction most of the time, it might not - be the case all the time. + Reminder: even though they seem to evolve in the same direction most of the time, it might + not be the case all the time. - **Customer Lifetime Value (CLV)**: Indicates how much revenue can be expected for a customer during his/her entire contract. This approach emphasizes the importance of customer retention, diff --git a/content/developer/reference/backend/mixins.rst b/content/developer/reference/backend/mixins.rst index f89e74596..2d91f9c1d 100644 --- a/content/developer/reference/backend/mixins.rst +++ b/content/developer/reference/backend/mixins.rst @@ -26,7 +26,7 @@ Integrating messaging features to your model is extremely easy. Simply inheritin the ``mail.thread`` model and adding the messaging fields (and their appropriate widgets) to your form view will get you up and running in no time. -.. admonition:: Example +.. example:: Let's create a simplistic model representing a business trip. Since organizing this kind of trip usually involves a lot of people and a lot of discussion, let's @@ -200,7 +200,7 @@ The ``mail`` module adds a powerful tracking system on fields, allowing you to log changes to specific fields in the record's chatter. To add tracking to a field, simple set the tracking attribute to True. -.. admonition:: Example +.. example:: Let's track changes on the name and responsible of our business trips: @@ -272,7 +272,7 @@ can override the ``_track_subtype()`` function: :returns: a subtype's full external id or False if no subtype is triggered -.. admonition:: Example +.. example:: Let's add a ``state`` field on our example class and trigger a notification with a specific subtype when this field change values. @@ -422,7 +422,7 @@ The urls in the actions list can be generated automatically by calling the :returns: link of the type selected for the record :rtype: str -.. admonition:: Example +.. example:: Let's add a custom button to the Business Trip state change notification; this button will reset the state to Draft and will be only visible to a member @@ -609,7 +609,7 @@ which means that while the alias is stored in another table, you have access to all these fields directly from your parent object. This allows you to make your alias easily configurable from the record's form view. -.. admonition:: Example +.. example:: Let's add aliases on our business trip class to create expenses on the fly via e-mail. @@ -738,7 +738,7 @@ and the specific widgets to display them (via the field ``activity_ids``) in the view and kanban view of your records (``mail_activity`` and ``kanban_activity`` widgets, respectively). -.. admonition:: Example +.. example:: Organizing a business trip is a tedious process and tracking needed activities like ordering plane tickets or a cab for the airport could be useful. To do so, diff --git a/content/developer/reference/backend/orm.rst b/content/developer/reference/backend/orm.rst index fba1e7c27..7bfcc271b 100644 --- a/content/developer/reference/backend/orm.rst +++ b/content/developer/reference/backend/orm.rst @@ -172,7 +172,7 @@ into a compatible type: * :func:`~odoo.fields.Date.to_date` will convert to a :class:`datetime.date` * :func:`~odoo.fields.Datetime.to_datetime` will convert to a :class:`datetime.datetime`. -.. admonition:: Example +.. example:: To parse date/datetimes coming from external sources:: @@ -866,7 +866,7 @@ Domain criteria can be combined using logical operators in *prefix* form: Individual criterion generally have a negative form (e.g. ``=`` -> ``!=``, ``<`` -> ``>=``) which is simpler than negating the positive. -.. admonition:: Example +.. example:: To search for partners named *ABC*, from belgium or germany, whose language is not english:: diff --git a/content/developer/reference/backend/views.rst b/content/developer/reference/backend/views.rst index 94ac5f4e9..1cf96d0ce 100644 --- a/content/developer/reference/backend/views.rst +++ b/content/developer/reference/backend/views.rst @@ -1015,7 +1015,7 @@ take the following attributes: * ``plan``: If enabled and ``edit`` enabled, a "magnifying glass" button will be displayed on time slots to plan unassigned records into that time slot. - .. admonition:: Example + .. example:: When you do not want to create records on the gantt view and the beginning and end dates are required on the model, the planning feature should be disabled diff --git a/extensions/exercise_admonition/__init__.py b/extensions/custom_admonitions/__init__.py similarity index 59% rename from extensions/exercise_admonition/__init__.py rename to extensions/custom_admonitions/__init__.py index 82be4d755..9c5c13d17 100644 --- a/extensions/exercise_admonition/__init__.py +++ b/extensions/custom_admonitions/__init__.py @@ -1,10 +1,18 @@ -""" Add a new "exercise" admonition directive. """ +""" Add new custom admonition directives. """ from docutils import nodes from docutils.parsers.rst.directives import admonitions from sphinx.locale import admonitionlabels +class example(nodes.Admonition, nodes.Element): + pass + + +class Example(admonitions.BaseAdmonition): + node_class = example + + class exercise(nodes.Admonition, nodes.Element): pass @@ -14,6 +22,11 @@ class Exercise(admonitions.BaseAdmonition): def setup(app): + app.add_directive('example', Example) + app.add_node(example, html=( + lambda self, node: self.visit_admonition(node, 'example'), + lambda self, node: self.depart_admonition(node), + )) app.add_directive('exercise', Exercise) app.add_node(exercise, html=( lambda self, node: self.visit_admonition(node, 'exercise'), @@ -26,4 +39,5 @@ def setup(app): } +admonitionlabels['example'] = 'Example' admonitionlabels['exercise'] = 'Exercise' diff --git a/extensions/odoo_theme/static/scss/_variables.scss b/extensions/odoo_theme/static/scss/_variables.scss index 2990b90bd..e442fcb6e 100644 --- a/extensions/odoo_theme/static/scss/_variables.scss +++ b/extensions/odoo_theme/static/scss/_variables.scss @@ -217,6 +217,7 @@ $brand-danger : #D9534F; $doc_paper_dark: $gray-lighter; $doc_paper: #ffffff; +$doc_example: #519161; $doc_exercise: #938E94; $doc_code-bg: #F8F8F8; $doc_lime: #CDDC39; @@ -255,4 +256,4 @@ $padding-m: 2rem; $padding-l: 3rem; $margin-s: $padding-s; $margin-m: $padding-m; -$margin-l: $padding-l; \ No newline at end of file +$margin-l: $padding-l; diff --git a/extensions/odoo_theme/static/style.scss b/extensions/odoo_theme/static/style.scss index d6c93d39e..dc4fb4113 100644 --- a/extensions/odoo_theme/static/style.scss +++ b/extensions/odoo_theme/static/style.scss @@ -938,13 +938,28 @@ header.o_main_header { border-color: $danger; > .alert-title, > h3 { - color: darken($brand-danger,20%); + color: darken($brand-danger, 20%); + &:before { content: '#{$i-danger}'; } } } + &.alert-example { + border-color: tint-color($doc_example, 30%); + background-color: tint-color($doc_example, 90%); + color: shade-color($doc_example, 35%); + + > .alert-title, > h3 { + color: shade-color($doc_example, 35%); + } + + > .alert-title:before, > h3:before { + content: '#{$i-knowledge}'; + } + } + &.alert-exercise { border-color: tint-color($doc_exercise, 30%); background-color: tint-color($doc_exercise, 90%); diff --git a/extensions/odoo_theme/translator.py b/extensions/odoo_theme/translator.py index 4d5cc4ce7..a62ac8924 100644 --- a/extensions/odoo_theme/translator.py +++ b/extensions/odoo_theme/translator.py @@ -34,6 +34,7 @@ ADMONITION_MAPPING = { 'danger': 'alert-danger', 'error': 'alert-danger', + 'example': 'alert-example', 'exercise': 'alert-exercise', }