diff --git a/base_comment_template/README.rst b/base_comment_template/README.rst
index cfb55db7..50a03023 100644
--- a/base_comment_template/README.rst
+++ b/base_comment_template/README.rst
@@ -25,12 +25,22 @@ Base Comments Templates
|badge1| |badge2| |badge3| |badge4| |badge5|
-Add a new model to define templates of comments to print on
-documents.
+Add a new mixin class to define templates of comments to print on documents.
+The comment templates can be defined like make templates, so you can use variables from linked models.
Two positions are available for the comments:
-* above document lines
-* below document lines
+
+* above document lines (before_lines)
+* below document lines (after_lines)
+
+The template are general, and can be attached to any Model and based on some domain defined in the template.
+You can define one default template per Model and domain, which can be overwritten for any company and partners.
+It has a priority field (smaller number = higher priority)
+
+In existing reports, if you add this line will get the comment template if you created one like
+
+* ( or without any parameter)
+
This module is the base module for following modules:
@@ -44,6 +54,53 @@ This module is the base module for following modules:
.. contents::
:local:
+Configuration
+=============
+
+Go to *Settings > Technical > Reporting > Comment Templates* and start designing you comment templates.
+
+This module is the base module for following modules:
+
+* sale_comment_template
+* purchase_comment_template
+* invoice_comment_template
+* stock_picking_comment_template
+
+Usage
+=====
+
+#. Go to *Settings* and activate the developer mode.
+#. Go to *Settings > Technical > Reporting > Comment Templates*.
+#. Create a new record.
+#. Define the Company the template is linked or leave default for all companies.
+#. Define the Partner the template is linked or leave default for all partners.
+#. Define the Model, Domain the template is linked.
+#. Define the Position where the template will be printed:
+
+ * above document lines
+ * below document lines
+
+You should have at least one template with Default field set, if you choose a Partner the template is deselected as a Default one.
+If you create a new template with the same configuration (Model, Domain, Position) and set it as Default, the previous one will be deselected as a default one.
+
+The template is a html field which will be rendered just like a mail template, so you can use variables like ${object}, ${user}, ${ctx} to add dynamic content.
+
+Change the report related to the model from configuration and add a statement like:
+
+
+
+
+
+
+
+
+
+
+
+
+
+You should always use t-if since the method returns False if no template is found.
+
Bug Tracker
===========
@@ -79,6 +136,15 @@ Contributors
* Iván Todorovich
* Pierre Verkest
+* `NextERP Romania `_:
+
+ * Fekete Mihai
+
+* `Tecnativa `_:
+
+ * Carlos Roca
+ * Víctor Martínez
+
Maintainers
~~~~~~~~~~~
diff --git a/base_comment_template/__manifest__.py b/base_comment_template/__manifest__.py
index 9a4af1bf..25656977 100644
--- a/base_comment_template/__manifest__.py
+++ b/base_comment_template/__manifest__.py
@@ -3,18 +3,19 @@
{
"name": "Base Comments Templates",
- "summary": "Comments templates on documents",
- "version": "14.0.1.0.0",
- "category": "Sale",
+ "summary": "Add conditional mako template to any report"
+ "on models that inherits comment.template.",
+ "version": "14.0.2.0.0",
+ "category": "Reporting",
"website": "https://github.com/OCA/reporting-engine",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
- "depends": ["base"],
+ "depends": ["base", "mail"],
"data": [
"security/ir.model.access.csv",
"security/security.xml",
- "views/comment_view.xml",
- "views/res_partner.xml",
+ "views/base_comment_template_view.xml",
+ "views/res_partner_view.xml",
],
}
diff --git a/base_comment_template/i18n/base_comment_template.pot b/base_comment_template/i18n/base_comment_template.pot
index 649f377d..cf594bd3 100644
--- a/base_comment_template/i18n/base_comment_template.pot
+++ b/base_comment_template/i18n/base_comment_template.pot
@@ -4,8 +4,10 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: Odoo Server 14.0\n"
+"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2021-02-09 09:55+0000\n"
+"PO-Revision-Date: 2021-02-09 09:55+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@@ -24,8 +26,8 @@ msgid "After lines"
msgstr ""
#. module: base_comment_template
-#: model:ir.model,name:base_comment_template.model_base_comment_template
-msgid "Base comment template"
+#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
+msgid "Archived"
msgstr ""
#. module: base_comment_template
@@ -34,21 +36,30 @@ msgid "Before lines"
msgstr ""
#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__text
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
msgid "Comment"
msgstr ""
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_ir_model__is_comment_template
+msgid "Comment Template"
+msgstr ""
+
#. module: base_comment_template
#: model:ir.actions.act_window,name:base_comment_template.action_base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_res_partner__base_comment_template_ids
+#: model:ir.model.fields,field_description:base_comment_template.field_res_users__base_comment_template_ids
+#: model:ir.ui.menu,name:base_comment_template.reports_base_comment_template_menuitem
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_search
+#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_tree
+#: model_terms:ir.ui.view,arch_db:base_comment_template.view_partner_form
msgid "Comment Templates"
msgstr ""
#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__name
-msgid "Comment summary"
+#: model:ir.model,name:base_comment_template.model_base_comment_template
+msgid "Comments Template"
msgstr ""
#. module: base_comment_template
@@ -56,12 +67,6 @@ msgstr ""
msgid "Company"
msgstr ""
-#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_res_partner__property_comment_template_id
-#: model:ir.model.fields,field_description:base_comment_template.field_res_users__property_comment_template_id
-msgid "Conditions template"
-msgstr ""
-
#. module: base_comment_template
#: model:ir.model,name:base_comment_template.model_res_partner
msgid "Contact"
@@ -79,24 +84,43 @@ msgstr ""
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__display_name
-#: model:ir.model.fields,field_description:base_comment_template.field_res_partner__display_name
+#: model:ir.model.fields,field_description:base_comment_template.field_comment_template__display_name
msgid "Display Name"
msgstr ""
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__domain
+msgid "Filter Domain"
+msgstr ""
+
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__id
-#: model:ir.model.fields,field_description:base_comment_template.field_res_partner__id
+#: model:ir.model.fields,field_description:base_comment_template.field_comment_template__id
msgid "ID"
msgstr ""
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__model_ids
+msgid "IR Model"
+msgstr ""
+
#. module: base_comment_template
#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__company_id
-msgid "If set, it'll only be available for this company"
+msgid ""
+"If set, the comment template will be available only for the selected "
+"company."
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__partner_ids
+msgid ""
+"If set, the comment template will be available only for the selected "
+"partner."
msgstr ""
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template____last_update
-#: model:ir.model.fields,field_description:base_comment_template.field_res_partner____last_update
+#: model:ir.model.fields,field_description:base_comment_template.field_comment_template____last_update
msgid "Last Modified on"
msgstr ""
@@ -111,16 +135,91 @@ msgid "Last Updated on"
msgstr ""
#. module: base_comment_template
+#: model:ir.model,name:base_comment_template.model_ir_model
+msgid "Models"
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__name
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
msgid "Name"
msgstr ""
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__name
+msgid "Name/description of this comment template"
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__partner_ids
+msgid "Partner"
+msgstr ""
+
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__position
-msgid "Position"
+msgid "Position on document"
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__priority
+msgid "Priority"
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_res_partner__base_comment_template_ids
+#: model:ir.model.fields,help:base_comment_template.field_res_users__base_comment_template_ids
+msgid "Specific partner comments that can be included in reports"
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__text
+msgid "Template"
+msgstr ""
+
+#. module: base_comment_template
+#: code:addons/base_comment_template/models/base_comment_template.py:0
+#, python-format
+msgid ""
+"There are other records with same models, priority, domain and position."
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__model_ids
+msgid ""
+"This comment template will be available on this models. You can see here "
+"only models allowed to set the coment template."
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__domain
+msgid ""
+"This comment template will be available only for objects that satisfy the "
+"condition"
msgstr ""
#. module: base_comment_template
#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__position
-msgid "Position on document"
+msgid "This field allows to select the position of the comment on reports."
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__text
+msgid "This is the text template that will be inserted into reports."
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_ir_model__is_comment_template
+msgid "Whether this model supports in reports to add comment templates."
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model,name:base_comment_template.model_comment_template
+msgid ""
+"base.comment.template to put header and footer in reports based on created "
+"comment templates"
+msgstr ""
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__priority
+msgid "the highest priority = the smallest number"
msgstr ""
diff --git a/base_comment_template/i18n/es.po b/base_comment_template/i18n/es.po
index 682c1f06..e5d06266 100644
--- a/base_comment_template/i18n/es.po
+++ b/base_comment_template/i18n/es.po
@@ -8,70 +8,73 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-01-05 01:40+0000\n"
-"PO-Revision-Date: 2018-01-05 01:40+0000\n"
-"Last-Translator: enjolras , 2018\n"
+"POT-Creation-Date: 2021-02-09 09:55+0000\n"
+"PO-Revision-Date: 2021-02-09 11:21+0100\n"
+"Last-Translator: Carlos \n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: \n"
+"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+"X-Generator: Poedit 2.0.6\n"
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__active
msgid "Active"
-msgstr ""
+msgstr "Activo"
#. module: base_comment_template
-#: selection:base.comment.template,position:0
+#: model:ir.model.fields.selection,name:base_comment_template.selection__base_comment_template__position__after_lines
msgid "After lines"
msgstr "Después de las líneas"
#. module: base_comment_template
-#: model:ir.model,name:base_comment_template.model_base_comment_template
-msgid "Base comment template"
-msgstr "Plantilla de comentario base"
+#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
+msgid "Archived"
+msgstr "Archivado"
#. module: base_comment_template
-#: selection:base.comment.template,position:0
+#: model:ir.model.fields.selection,name:base_comment_template.selection__base_comment_template__position__before_lines
msgid "Before lines"
msgstr "Antes de las líneas"
#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__text
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
msgid "Comment"
msgstr "Comentario"
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_ir_model__is_comment_template
+msgid "Comment Template"
+msgstr "Plantilla de comentario"
+
#. module: base_comment_template
#: model:ir.actions.act_window,name:base_comment_template.action_base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_res_partner__base_comment_template_ids
+#: model:ir.model.fields,field_description:base_comment_template.field_res_users__base_comment_template_ids
+#: model:ir.ui.menu,name:base_comment_template.reports_base_comment_template_menuitem
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_search
+#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_tree
+#: model_terms:ir.ui.view,arch_db:base_comment_template.view_partner_form
msgid "Comment Templates"
msgstr "Plantillas de comentarios"
#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__name
-msgid "Comment summary"
-msgstr "Índice de comentarios"
+#: model:ir.model,name:base_comment_template.model_base_comment_template
+msgid "Comments Template"
+msgstr "Plantillas de comentarios"
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__company_id
msgid "Company"
-msgstr ""
-
-#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_res_partner__property_comment_template_id
-#: model:ir.model.fields,field_description:base_comment_template.field_res_users__property_comment_template_id
-#, fuzzy
-msgid "Conditions template"
-msgstr "Plantillas de comentarios"
+msgstr "Compañía"
#. module: base_comment_template
#: model:ir.model,name:base_comment_template.model_res_partner
msgid "Contact"
-msgstr ""
+msgstr "Contacto"
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__create_uid
@@ -85,21 +88,45 @@ msgstr "Creado el"
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__display_name
+#: model:ir.model.fields,field_description:base_comment_template.field_comment_template__display_name
msgid "Display Name"
msgstr "Nombre mostrado"
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__domain
+msgid "Filter Domain"
+msgstr "Filtro de dominio"
+
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__id
+#: model:ir.model.fields,field_description:base_comment_template.field_comment_template__id
msgid "ID"
msgstr "ID"
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__model_ids
+msgid "IR Model"
+msgstr "Modelo"
+
#. module: base_comment_template
#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__company_id
-msgid "If set, it'll only be available for this company"
+msgid ""
+"If set, the comment template will be available only for the selected company."
msgstr ""
+"Si se define, la plantilla de comentario va a estar disponible para las "
+"compañías seleccionadas."
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__partner_ids
+msgid ""
+"If set, the comment template will be available only for the selected partner."
+msgstr ""
+"Si se define, la plantilla de comentario va a estar disponible para los "
+"contactos seleccionados."
#. module: base_comment_template
#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template____last_update
+#: model:ir.model.fields,field_description:base_comment_template.field_comment_template____last_update
msgid "Last Modified on"
msgstr "Última modificación el"
@@ -114,16 +141,112 @@ msgid "Last Updated on"
msgstr "Última modificación el"
#. module: base_comment_template
+#: model:ir.model,name:base_comment_template.model_ir_model
+msgid "Models"
+msgstr "Modelos"
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__name
#: model_terms:ir.ui.view,arch_db:base_comment_template.view_base_comment_template_form
msgid "Name"
-msgstr ""
+msgstr "Nombre"
#. module: base_comment_template
-#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__position
-msgid "Position"
-msgstr "Posició"
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__name
+msgid "Name/description of this comment template"
+msgstr "Nombre de la plantilla de comentario"
#. module: base_comment_template
-#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__position
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__partner_ids
+msgid "Partner"
+msgstr "Contacto"
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__position
msgid "Position on document"
msgstr "Posición en el documento"
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__priority
+msgid "Priority"
+msgstr "Prioridad"
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_res_partner__base_comment_template_ids
+#: model:ir.model.fields,help:base_comment_template.field_res_users__base_comment_template_ids
+msgid "Specific partner comments that can be included in reports"
+msgstr "Comentarios de contactos que se pueden incluir en informes"
+
+#. module: base_comment_template
+#: model:ir.model.fields,field_description:base_comment_template.field_base_comment_template__text
+msgid "Template"
+msgstr "Plantilla de comentario"
+
+#. module: base_comment_template
+#: code:addons/base_comment_template/models/base_comment_template.py:0
+#, python-format
+msgid ""
+"There are other records with same models, priority, domain and position."
+msgstr ""
+"Hay otros registros con los mismos datos en modelo, prioridad, dominio y "
+"posición."
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__model_ids
+msgid ""
+"This comment template will be available on this models. You can see here "
+"only models allowed to set the coment template."
+msgstr ""
+"Esta plantilla de comentarios estará disponible en estos modelos. Sólo vas a "
+"ver los modelos autorizados para configurar la plantilla de comentarios."
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__domain
+msgid ""
+"This comment template will be available only for objects that satisfy the "
+"condition"
+msgstr ""
+"Esta plantilla de comentarios estará disponible solo para objetos que "
+"satisfagan la condición"
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__position
+msgid "This field allows to select the position of the comment on reports."
+msgstr ""
+"Este campo permite seleccionar la posición del comentario en los informes."
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__text
+msgid "This is the text template that will be inserted into reports."
+msgstr "Esta es la plantilla de texto que se insertará en los informes."
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_ir_model__is_comment_template
+msgid "Whether this model supports in reports to add comment templates."
+msgstr ""
+"Si este modelo admite en los informes, añadir plantillas de comentarios."
+
+#. module: base_comment_template
+#: model:ir.model,name:base_comment_template.model_comment_template
+msgid ""
+"base.comment.template to put header and footer in reports based on created "
+"comment templates"
+msgstr ""
+"base.comment.template para poner cabecera y pie de página en los informes "
+"basados en las plantillas de comentarios creadas"
+
+#. module: base_comment_template
+#: model:ir.model.fields,help:base_comment_template.field_base_comment_template__priority
+msgid "the highest priority = the smallest number"
+msgstr "Mayor prioridad = número menor"
+
+#~ msgid "Comment summary"
+#~ msgstr "Índice de comentarios"
+
+#, fuzzy
+#~| msgid "Comment Templates"
+#~ msgid "Conditions template"
+#~ msgstr "Plantillas de comentarios"
+
+#~ msgid "Position"
+#~ msgstr "Posició"
diff --git a/base_comment_template/migrations/14.0.2.0.0/post-migration.py b/base_comment_template/migrations/14.0.2.0.0/post-migration.py
new file mode 100644
index 00000000..30414fe2
--- /dev/null
+++ b/base_comment_template/migrations/14.0.2.0.0/post-migration.py
@@ -0,0 +1,29 @@
+# Copyright 2021 Tecnativa - Víctor Martínez
+# Copyright 2021 Tecnativa - Pedro M. Baeza
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from openupgradelib import openupgrade
+
+from odoo.tools import parse_version
+
+
+@openupgrade.migrate()
+def migrate(env, version):
+ if parse_version(version) == parse_version("14.0.1.0.0"):
+ openupgrade.logged_query(
+ env.cr,
+ """
+ INSERT INTO base_comment_template_res_partner_rel
+ (res_partner_id, base_comment_template_id)
+ SELECT SPLIT_PART(ip.res_id, ',', 2)::int AS res_partner_id,
+ SPLIT_PART(ip.value_reference, ',', 2)::int AS base_comment_template_id
+ FROM ir_property ip
+ JOIN ir_model_fields imf ON ip.fields_id = imf.id
+ JOIN res_partner rp ON rp.id = SPLIT_PART(ip.res_id, ',', 2)::int
+ JOIN base_comment_template bct
+ ON bct.id = SPLIT_PART(ip.value_reference, ',', 2)::int
+ WHERE imf.name = 'property_comment_template_id'
+ AND imf.model = 'res.partner'
+ AND ip.res_id IS NOT NULL
+ ON CONFLICT DO NOTHING
+ """,
+ )
diff --git a/base_comment_template/migrations/14.0.2.0.0/pre-migration.py b/base_comment_template/migrations/14.0.2.0.0/pre-migration.py
new file mode 100644
index 00000000..75933bfd
--- /dev/null
+++ b/base_comment_template/migrations/14.0.2.0.0/pre-migration.py
@@ -0,0 +1,30 @@
+# Copyright 2021 Tecnativa - Víctor Martínez
+# Copyright 2021 Tecnativa - Pedro M: Baeza
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from openupgradelib import openupgrade
+
+from odoo.tools import parse_version
+
+field_renames = [
+ ("base.comment.template", "base_comment_template", "priority", "sequence"),
+]
+
+
+@openupgrade.migrate()
+def migrate(env, version):
+ if parse_version(version) == parse_version("14.0.1.0.0"):
+ openupgrade.rename_fields(env, field_renames)
+ if openupgrade.table_exists(env.cr, "base_comment_template_res_partner_rel"):
+ # Swap column names, as they were incorrect
+ env.cr.execute(
+ "ALTER TABLE base_comment_template_res_partner_rel "
+ "RENAME base_comment_template_id TO temp"
+ )
+ env.cr.execute(
+ "ALTER TABLE base_comment_template_res_partner_rel "
+ "RENAME res_partner_id TO base_comment_template_id"
+ )
+ env.cr.execute(
+ "ALTER TABLE base_comment_template_res_partner_rel "
+ "RENAME temp TO res_partner_id"
+ )
diff --git a/base_comment_template/models/__init__.py b/base_comment_template/models/__init__.py
index b62fbec1..d695c580 100644
--- a/base_comment_template/models/__init__.py
+++ b/base_comment_template/models/__init__.py
@@ -1,3 +1,4 @@
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from . import comment
+from . import base_comment_template
+from . import comment_template
from . import res_partner
+from . import ir_model
diff --git a/base_comment_template/models/base_comment_template.py b/base_comment_template/models/base_comment_template.py
new file mode 100644
index 00000000..6ae2e264
--- /dev/null
+++ b/base_comment_template/models/base_comment_template.py
@@ -0,0 +1,88 @@
+# Copyright 2014 Guewen Baconnier (Camptocamp SA)
+# Copyright 2013-2014 Nicolas Bessi (Camptocamp SA)
+# Copyright 2020 NextERP Romania SRL
+# Copyright 2021 Tecnativa - Víctor Martínez
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+from odoo import fields, models
+
+
+class BaseCommentTemplate(models.Model):
+ """Comment templates printed on reports"""
+
+ _name = "base.comment.template"
+ _description = "Comments Template"
+ _order = "sequence,id"
+
+ active = fields.Boolean(default=True)
+ position = fields.Selection(
+ string="Position on document",
+ selection=[("before_lines", "Top"), ("after_lines", "Bottom")],
+ required=True,
+ default="before_lines",
+ help="This field allows to select the position of the comment on reports.",
+ )
+ name = fields.Char(
+ string="Name",
+ translate=True,
+ required=True,
+ help="Name/description of this comment template",
+ )
+ text = fields.Html(
+ string="Template",
+ translate=True,
+ required=True,
+ sanitize=False,
+ help="This is the text template that will be inserted into reports.",
+ )
+ company_id = fields.Many2one(
+ comodel_name="res.company",
+ string="Company",
+ ondelete="cascade",
+ index=True,
+ help="If set, the comment template will be available only for the selected "
+ "company.",
+ )
+ partner_ids = fields.Many2many(
+ comodel_name="res.partner",
+ relation="base_comment_template_res_partner_rel",
+ column1="base_comment_template_id",
+ column2="res_partner_id",
+ string="Partner",
+ readonly=True,
+ help="If set, the comment template will be available only for the selected "
+ "partner.",
+ )
+ model_ids = fields.Many2many(
+ comodel_name="ir.model",
+ string="IR Model",
+ ondelete="cascade",
+ domain=[
+ ("is_comment_template", "=", True),
+ ("model", "!=", "comment.template"),
+ ],
+ required=True,
+ help="This comment template will be available on this models. "
+ "You can see here only models allowed to set the coment template.",
+ )
+ domain = fields.Char(
+ string="Filter Domain",
+ required=True,
+ default="[]",
+ help="This comment template will be available only for objects "
+ "that satisfy the condition",
+ )
+ sequence = fields.Integer(
+ required=True, default=10, help="The smaller number = The higher priority"
+ )
+
+ def name_get(self):
+ """Redefine the name_get method to show the template name with the position."""
+ res = []
+ for item in self:
+ name = "{} ({})".format(
+ item.name, dict(self._fields["position"].selection).get(item.position)
+ )
+ if self.env.context.get("comment_template_model_display"):
+ name += " (%s)" % ", ".join(item.model_ids.mapped("name"))
+ res.append((item.id, name))
+ return res
diff --git a/base_comment_template/models/comment.py b/base_comment_template/models/comment.py
deleted file mode 100644
index a8b6c85b..00000000
--- a/base_comment_template/models/comment.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright 2014 Guewen Baconnier (Camptocamp SA)
-# Copyright 2013-2014 Nicolas Bessi (Camptocamp SA)
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-
-from odoo import fields, models
-
-
-class BaseCommentTemplate(models.Model):
- _name = "base.comment.template"
- _description = "Base comment template"
-
- active = fields.Boolean(default=True)
-
- name = fields.Char(
- string="Comment summary",
- required=True,
- )
-
- position = fields.Selection(
- selection=[
- ("before_lines", "Before lines"),
- ("after_lines", "After lines"),
- ],
- required=True,
- default="before_lines",
- help="Position on document",
- )
-
- text = fields.Html(
- string="Comment",
- translate=True,
- required=True,
- )
-
- company_id = fields.Many2one(
- "res.company",
- string="Company",
- help="If set, it'll only be available for this company",
- ondelete="cascade",
- index=True,
- )
-
- def get_value(self, partner_id=False):
- self.ensure_one()
- lang = None
- if partner_id:
- lang = self.env["res.partner"].browse(partner_id).lang
- return self.with_context(lang=lang).text
diff --git a/base_comment_template/models/comment_template.py b/base_comment_template/models/comment_template.py
new file mode 100644
index 00000000..465e6ddc
--- /dev/null
+++ b/base_comment_template/models/comment_template.py
@@ -0,0 +1,45 @@
+# Copyright 2014 Guewen Baconnier (Camptocamp SA)
+# Copyright 2013-2014 Nicolas Bessi (Camptocamp SA)
+# Copyright 2020 NextERP Romania SRL
+# Copyright 2021 Tecnativa - Víctor Martínez
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+from odoo import api, fields, models
+from odoo.tools.safe_eval import safe_eval
+
+
+class CommentTemplate(models.AbstractModel):
+ _name = "comment.template"
+ _description = (
+ "base.comment.template to put header and footer "
+ "in reports based on created comment templates"
+ )
+ # This field allows to set any given field that determines the source partner for
+ # the comment templates downstream.
+ # E.g.: other models where the partner field is called customer_id.
+ _comment_template_partner_field_name = "partner_id"
+
+ comment_template_ids = fields.Many2many(
+ compute="_compute_comment_template_ids",
+ comodel_name="base.comment.template",
+ string="Comment Template",
+ domain=lambda self: [("model_ids.model", "=", self._name)],
+ store=True,
+ readonly=False,
+ )
+
+ @api.depends(_comment_template_partner_field_name)
+ def _compute_comment_template_ids(self):
+ for record in self:
+ partner = record[self._comment_template_partner_field_name]
+ record.comment_template_ids = [(5,)]
+ templates = self.env["base.comment.template"].search(
+ [
+ ("id", "in", partner.base_comment_template_ids.ids),
+ ("model_ids.model", "=", self._name),
+ ]
+ )
+ for template in templates:
+ if not template.domain or self in self.search(
+ safe_eval(template.domain)
+ ):
+ record.comment_template_ids = [(4, template.id)]
diff --git a/base_comment_template/models/ir_model.py b/base_comment_template/models/ir_model.py
new file mode 100644
index 00000000..b799732b
--- /dev/null
+++ b/base_comment_template/models/ir_model.py
@@ -0,0 +1,33 @@
+# Copyright 2020 NextERP Romania SRL
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from odoo import api, fields, models
+
+
+class IrModel(models.Model):
+ _inherit = "ir.model"
+
+ is_comment_template = fields.Boolean(
+ string="Comment Template",
+ default=False,
+ help="Whether this model supports in reports to add comment templates.",
+ )
+
+ def _reflect_model_params(self, model):
+ vals = super(IrModel, self)._reflect_model_params(model)
+ vals["is_comment_template"] = issubclass(
+ type(model), self.pool["comment.template"]
+ )
+ return vals
+
+ @api.model
+ def _instanciate(self, model_data):
+ model_class = super(IrModel, self)._instanciate(model_data)
+ if (
+ model_data.get("is_comment_template")
+ and model_class._name != "comment.template"
+ ):
+ parents = model_class._inherit or []
+ parents = [parents] if isinstance(parents, str) else parents
+ model_class._inherit = parents + ["comment.template"]
+ return model_class
diff --git a/base_comment_template/models/res_partner.py b/base_comment_template/models/res_partner.py
index 0a4cc9cc..cc06cbdc 100644
--- a/base_comment_template/models/res_partner.py
+++ b/base_comment_template/models/res_partner.py
@@ -1,3 +1,5 @@
+# Copyright 2020 NextERP Romania SRL
+# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
@@ -6,14 +8,16 @@ from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
- property_comment_template_id = fields.Many2one(
+ base_comment_template_ids = fields.Many2many(
comodel_name="base.comment.template",
- string="Conditions template",
- company_dependent=True,
+ relation="base_comment_template_res_partner_rel",
+ column1="res_partner_id",
+ column2="base_comment_template_id",
+ string="Comment Templates",
+ help="Specific partner comments that can be included in reports",
)
@api.model
def _commercial_fields(self):
- res = super(ResPartner, self)._commercial_fields()
- res += ["property_comment_template_id"]
- return res
+ """Add comment templates to commercial fields"""
+ return super()._commercial_fields() + ["base_comment_template_ids"]
diff --git a/base_comment_template/readme/CONFIGURE.rst b/base_comment_template/readme/CONFIGURE.rst
new file mode 100644
index 00000000..aa45ae16
--- /dev/null
+++ b/base_comment_template/readme/CONFIGURE.rst
@@ -0,0 +1,8 @@
+Go to *Settings > Technical > Reporting > Comment Templates* and start designing you comment templates.
+
+This module is the base module for following modules:
+
+* sale_comment_template
+* purchase_comment_template
+* invoice_comment_template
+* stock_picking_comment_template
diff --git a/base_comment_template/readme/CONTRIBUTORS.rst b/base_comment_template/readme/CONTRIBUTORS.rst
index b5394276..0468fc78 100644
--- a/base_comment_template/readme/CONTRIBUTORS.rst
+++ b/base_comment_template/readme/CONTRIBUTORS.rst
@@ -11,3 +11,12 @@
* Iván Todorovich
* Pierre Verkest
+
+* `NextERP Romania `_:
+
+ * Fekete Mihai
+
+* `Tecnativa `_:
+
+ * Carlos Roca
+ * Víctor Martínez
diff --git a/base_comment_template/readme/DESCRIPTION.rst b/base_comment_template/readme/DESCRIPTION.rst
index 4b538a9f..6909ad5d 100644
--- a/base_comment_template/readme/DESCRIPTION.rst
+++ b/base_comment_template/readme/DESCRIPTION.rst
@@ -1,9 +1,19 @@
-Add a new model to define templates of comments to print on
-documents.
+Add a new mixin class to define templates of comments to print on documents.
+The comment templates can be defined like make templates, so you can use variables from linked models.
Two positions are available for the comments:
-* above document lines
-* below document lines
+
+* above document lines (before_lines)
+* below document lines (after_lines)
+
+The template are general, and can be attached to any Model and based on some domain defined in the template.
+You can define one default template per Model and domain, which can be overwritten for any company and partners.
+It has a priority field (smaller number = higher priority)
+
+In existing reports, if you add this line will get the comment template if you created one like
+
+* ( or without any parameter)
+
This module is the base module for following modules:
diff --git a/base_comment_template/readme/USAGE.rst b/base_comment_template/readme/USAGE.rst
new file mode 100644
index 00000000..2be8054a
--- /dev/null
+++ b/base_comment_template/readme/USAGE.rst
@@ -0,0 +1,31 @@
+#. Go to *Settings* and activate the developer mode.
+#. Go to *Settings > Technical > Reporting > Comment Templates*.
+#. Create a new record.
+#. Define the Company the template is linked or leave default for all companies.
+#. Define the Partner the template is linked or leave default for all partners.
+#. Define the Model, Domain the template is linked.
+#. Define the Position where the template will be printed:
+
+ * above document lines
+ * below document lines
+
+You should have at least one template with Default field set, if you choose a Partner the template is deselected as a Default one.
+If you create a new template with the same configuration (Model, Domain, Position) and set it as Default, the previous one will be deselected as a default one.
+
+The template is a html field which will be rendered just like a mail template, so you can use variables like ${object}, ${user}, ${ctx} to add dynamic content.
+
+Change the report related to the model from configuration and add a statement like:
+
+
+
+
+
+
+
+
+
+
+
+
+
+You should always use t-if since the method returns False if no template is found.
diff --git a/base_comment_template/security/ir.model.access.csv b/base_comment_template/security/ir.model.access.csv
index 7485600f..d2db39e3 100644
--- a/base_comment_template/security/ir.model.access.csv
+++ b/base_comment_template/security/ir.model.access.csv
@@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_base_comment_template_user,access_base_comment_template_user,model_base_comment_template,,1,0,0,0
access_base_comment_template,access_base_comment_template no one,model_base_comment_template,base.group_no_one,1,1,1,1
diff --git a/base_comment_template/security/security.xml b/base_comment_template/security/security.xml
index e8fa2692..44009142 100644
--- a/base_comment_template/security/security.xml
+++ b/base_comment_template/security/security.xml
@@ -5,9 +5,8 @@
Base comment multi-company
- ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
+
+ ['|',('company_id','=',False),('company_id','in',company_ids)]
diff --git a/base_comment_template/static/description/index.html b/base_comment_template/static/description/index.html
index 354d7e20..bc9c427a 100644
--- a/base_comment_template/static/description/index.html
+++ b/base_comment_template/static/description/index.html
@@ -3,7 +3,7 @@
-
+
Base Comments Templates