[MIG] [13.0] Migrate base_comment_template from account_invoic_reporting.
parent
6570eb6001
commit
a68181d03a
|
@ -13,24 +13,30 @@ Base Comments Templates
|
||||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting-engine-lightgray.png?logo=github
|
||||||
:target: https://github.com/OCA/reporting-engine/tree/14.0/base_comment_template
|
:target: https://github.com/OCA/reporting-engine/tree/13.0/base_comment_template
|
||||||
:alt: OCA/reporting-engine
|
:alt: OCA/reporting-engine
|
||||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||||
:target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-base_comment_template
|
:target: https://translation.odoo-community.org/projects/reporting-engine-13-0/reporting-engine-13-0-base_comment_template
|
||||||
:alt: Translate me on Weblate
|
:alt: Translate me on Weblate
|
||||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||||
:target: https://runbot.odoo-community.org/runbot/143/14.0
|
:target: https://runbot.odoo-community.org/runbot/143/13.0
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
|
|
||||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
Add a new model to define templates of comments to print on
|
**Table of contents**
|
||||||
documents.
|
|
||||||
|
|
||||||
Two positions are available for the comments:
|
.. contents::
|
||||||
* above document lines
|
:local:
|
||||||
* below document lines
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
Go to *Settings > Technical > Reporting > Comment Templates* and start designing you comment templates.
|
||||||
|
|
||||||
|
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 partner.
|
||||||
|
|
||||||
This module is the base module for following modules:
|
This module is the base module for following modules:
|
||||||
|
|
||||||
|
@ -39,10 +45,40 @@ This module is the base module for following modules:
|
||||||
* invoice_comment_template
|
* invoice_comment_template
|
||||||
* stock_picking_comment_template
|
* stock_picking_comment_template
|
||||||
|
|
||||||
**Table of contents**
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
#. 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 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:
|
||||||
|
|
||||||
|
<p t-if="o.get_comment_template('before_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)">
|
||||||
|
|
||||||
|
<span t-raw="o.get_comment_template('before_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)"/>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p t-if="o.get_comment_template('after_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)">
|
||||||
|
|
||||||
|
<span t-raw="o.get_comment_template('after_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)"/>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
You should always use t-if since the method returns False if no template is found.
|
||||||
|
|
||||||
.. contents::
|
|
||||||
:local:
|
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
@ -50,7 +86,7 @@ Bug Tracker
|
||||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
|
||||||
In case of trouble, please check there if your issue has already been reported.
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||||
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20base_comment_template%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20base_comment_template%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
Do not contact contributors directly about support or help with technical issues.
|
Do not contact contributors directly about support or help with technical issues.
|
||||||
|
|
||||||
|
@ -77,7 +113,11 @@ Contributors
|
||||||
* `Druidoo <https://www.druidoo.io>`_:
|
* `Druidoo <https://www.druidoo.io>`_:
|
||||||
|
|
||||||
* Iván Todorovich <ivan.todorovich@druidoo.io>
|
* Iván Todorovich <ivan.todorovich@druidoo.io>
|
||||||
* Pierre Verkest <pierreverkest84@gmail.com>
|
|
||||||
|
* `NextERP Romania <https://www.nexterp.ro>`_:
|
||||||
|
|
||||||
|
* Fekete Mihai <feketemihai@nexterp.ro>
|
||||||
|
|
||||||
|
|
||||||
Maintainers
|
Maintainers
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
@ -92,6 +132,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
mission is to support the collaborative development of Odoo features and
|
mission is to support the collaborative development of Odoo features and
|
||||||
promote its widespread use.
|
promote its widespread use.
|
||||||
|
|
||||||
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/base_comment_template>`_ project on GitHub.
|
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/13.0/base_comment_template>`_ project on GitHub.
|
||||||
|
|
||||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||||
|
|
|
@ -3,18 +3,19 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Base Comments Templates",
|
"name": "Base Comments Templates",
|
||||||
"summary": "Comments templates on documents",
|
"summary": "Add conditional mako template to any report "
|
||||||
|
"on models that inherits comment.template.",
|
||||||
"version": "14.0.1.0.0",
|
"version": "14.0.1.0.0",
|
||||||
"category": "Sale",
|
"category": "Reporting",
|
||||||
"website": "https://github.com/OCA/reporting-engine",
|
"website": "https://github.com/OCA/reporting-engine",
|
||||||
"author": "Camptocamp, Odoo Community Association (OCA)",
|
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"depends": ["base"],
|
"depends": ["base", "mail"],
|
||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"security/security.xml",
|
"security/security.xml",
|
||||||
"views/comment_view.xml",
|
"views/base_comment_template_view.xml",
|
||||||
"views/res_partner.xml",
|
"views/res_partner_view.xml",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Copyright 2020 NextERP Romania SRL
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
from openupgradelib import openupgrade
|
||||||
|
|
||||||
|
|
||||||
|
@openupgrade.migrate()
|
||||||
|
def migrate(env, version):
|
||||||
|
# Not tested
|
||||||
|
properties = env["ir.property"].search(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"fields_id",
|
||||||
|
"=",
|
||||||
|
env.ref("base.field_res_partner_property_comment_template_id").id,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if properties:
|
||||||
|
for template in properties.mapped("value_reference"):
|
||||||
|
template_id = template.value_reference.split(",")[-1]
|
||||||
|
if template_id:
|
||||||
|
template = env["base.comment.template"].browse(template_id)
|
||||||
|
part_prop = properties.filtered(lambda p: p.value_reference == template)
|
||||||
|
template.partner_ids = [
|
||||||
|
(prop["res_id"] or "").split(",")[-1] for prop in part_prop
|
||||||
|
]
|
|
@ -1,3 +1,3 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
from . import base_comment_template
|
||||||
from . import comment
|
|
||||||
from . import res_partner
|
from . import res_partner
|
||||||
|
from . import ir_model
|
||||||
|
|
|
@ -0,0 +1,207 @@
|
||||||
|
# Copyright 2014 Guewen Baconnier (Camptocamp SA)
|
||||||
|
# Copyright 2013-2014 Nicolas Bessi (Camptocamp SA)
|
||||||
|
# Copyright 2020 NextERP Romania SRL
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
base_comment_template_ids = fields.Many2many(
|
||||||
|
comodel_name="base.comment.template",
|
||||||
|
string="Comment templates",
|
||||||
|
compute="_compute_base_comment_template_ids",
|
||||||
|
search="_search_follower_partners",
|
||||||
|
help="Templates that can be included in your reports",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _compute_base_comment_template_ids(self):
|
||||||
|
company_id = self.env.company.id
|
||||||
|
present_model_id = self.env["ir.model"].search([("name", "=", self._name)])
|
||||||
|
templates = (
|
||||||
|
self.env["base.comment.template"]
|
||||||
|
.sudo()
|
||||||
|
.search(
|
||||||
|
[
|
||||||
|
("model_ids", "in", present_model_id.id),
|
||||||
|
"|",
|
||||||
|
("company_id", "=", company_id),
|
||||||
|
("company_id", "=", False),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# using read() below is much faster than followers.mapped('res_id')
|
||||||
|
model_mako_templates_ids = templates.mapped("id")
|
||||||
|
for record in self:
|
||||||
|
record.base_comment_template_ids = record.id in model_mako_templates_ids
|
||||||
|
|
||||||
|
def get_comment_template(
|
||||||
|
self, position="before_lines", company_id=False, partner_id=False
|
||||||
|
):
|
||||||
|
""" Method that is called from report xml and is returning the
|
||||||
|
position template as a html if exists
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
if not company_id:
|
||||||
|
company_id = self.env.company.id
|
||||||
|
present_model_id = self.env["ir.model"].search([("model", "=", self._name)])
|
||||||
|
default_dom = [
|
||||||
|
("model_ids", "in", present_model_id.id),
|
||||||
|
("position", "=", position),
|
||||||
|
]
|
||||||
|
lang = False
|
||||||
|
if partner_id and "partner_id" in self._fields:
|
||||||
|
default_dom += [
|
||||||
|
"|",
|
||||||
|
("partner_ids", "=", False),
|
||||||
|
("partner_ids", "in", partner_id),
|
||||||
|
]
|
||||||
|
lang = self.env["res.partner"].browse(partner_id).lang
|
||||||
|
if company_id and "company_id" in self._fields:
|
||||||
|
if partner_id and "partner_id" in self._fields:
|
||||||
|
default_dom.insert(-3, "&")
|
||||||
|
default_dom += [
|
||||||
|
"|",
|
||||||
|
("company_id", "=", company_id),
|
||||||
|
("company_id", "=", False),
|
||||||
|
]
|
||||||
|
templates = self.env["base.comment.template"].search(
|
||||||
|
default_dom, order="priority"
|
||||||
|
)
|
||||||
|
if lang:
|
||||||
|
templates = templates.with_context({"lang": lang})
|
||||||
|
template = False
|
||||||
|
if templates:
|
||||||
|
for templ in templates:
|
||||||
|
if self in self.search(safe_eval(templ.domain or "[]")):
|
||||||
|
template = templ
|
||||||
|
break
|
||||||
|
if not template:
|
||||||
|
return ""
|
||||||
|
return self.env["mail.template"]._render_template(
|
||||||
|
template.text, self._name, self.id, post_process=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseCommentTemplate(models.Model):
|
||||||
|
"""Comment templates printed on reports"""
|
||||||
|
|
||||||
|
_name = "base.comment.template"
|
||||||
|
_description = "Comments Template"
|
||||||
|
|
||||||
|
active = fields.Boolean(default=True)
|
||||||
|
position = fields.Selection(
|
||||||
|
selection=[("before_lines", "Before lines"), ("after_lines", "After lines")],
|
||||||
|
required=True,
|
||||||
|
default="before_lines",
|
||||||
|
help="Position on document",
|
||||||
|
)
|
||||||
|
name = fields.Char(
|
||||||
|
string="Name",
|
||||||
|
translate=True,
|
||||||
|
required=True,
|
||||||
|
help="Name/description of this mako comment template",
|
||||||
|
)
|
||||||
|
text = fields.Html(
|
||||||
|
string="Template",
|
||||||
|
translate=True,
|
||||||
|
required=True,
|
||||||
|
sanitize=False,
|
||||||
|
help="This is the mako template that will be inserted into reports.",
|
||||||
|
)
|
||||||
|
company_id = fields.Many2one(
|
||||||
|
"res.company",
|
||||||
|
string="Company",
|
||||||
|
ondelete="cascade",
|
||||||
|
index=True,
|
||||||
|
help="If set, it'll only be available for this company"
|
||||||
|
"(if the model_id has company_id)",
|
||||||
|
)
|
||||||
|
partner_ids = fields.Many2many(
|
||||||
|
comodel_name="res.partner",
|
||||||
|
string="Partner",
|
||||||
|
ondelete="cascade",
|
||||||
|
help="If set, the comment template will be available only for this "
|
||||||
|
"partner (if the model_id has a partner_id field).",
|
||||||
|
)
|
||||||
|
|
||||||
|
model_ids = fields.Many2many(
|
||||||
|
comodel_name="ir.model",
|
||||||
|
string="IR Model",
|
||||||
|
ondelete="cascade",
|
||||||
|
required=True,
|
||||||
|
help="This comment template will be available on this models."
|
||||||
|
"You can see here only models that have report on them "
|
||||||
|
"and have inherited comment.template",
|
||||||
|
)
|
||||||
|
|
||||||
|
domain = fields.Char(
|
||||||
|
"Filter Domain",
|
||||||
|
required=True,
|
||||||
|
default="[]",
|
||||||
|
help="This comment template will be available only for objects "
|
||||||
|
"that satisfy the condition",
|
||||||
|
)
|
||||||
|
|
||||||
|
priority = fields.Integer(
|
||||||
|
default=10, copy=False, help="the highest priority = the smallest number",
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.constrains("domain", "priority", "model_ids", "position")
|
||||||
|
def _check_partners_in_company_id(self):
|
||||||
|
templates = self.search([])
|
||||||
|
for record in self:
|
||||||
|
other_template_same_models_and_priority = templates.filtered(
|
||||||
|
lambda t: t.priority == record.priority
|
||||||
|
and set(record.model_ids).intersection(record.model_ids)
|
||||||
|
and t.domain == record.domain
|
||||||
|
and t.position == record.position
|
||||||
|
and t.id != record.id
|
||||||
|
)
|
||||||
|
if other_template_same_models_and_priority:
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
|
"The are other records with same models, priority, "
|
||||||
|
"domain and position."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def fields_view_get(
|
||||||
|
self, view_id=None, view_type="form", toolbar=False, submenu=False
|
||||||
|
):
|
||||||
|
# modify the form view of base_commnent_template
|
||||||
|
# Add domain on model_id to get only models that have a report set
|
||||||
|
# and those whom have inherited this model
|
||||||
|
res = super().fields_view_get(
|
||||||
|
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
|
||||||
|
)
|
||||||
|
if view_type == "form":
|
||||||
|
doc = etree.XML(res["arch"])
|
||||||
|
for node in doc.xpath("//field[@name='model_ids']"):
|
||||||
|
report_models = self.env["ir.actions.report"].search([]).mapped("model")
|
||||||
|
model_ids = (
|
||||||
|
self.env["ir.model"]
|
||||||
|
.search(
|
||||||
|
[
|
||||||
|
("model", "in", report_models),
|
||||||
|
("is_comment_template", "=", True),
|
||||||
|
"!",
|
||||||
|
("name", "=like", "ir.%"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.ids
|
||||||
|
)
|
||||||
|
model_filter = "[('id','in'," + str(model_ids) + ")]"
|
||||||
|
node.set("domain", model_filter)
|
||||||
|
res["arch"] = etree.tostring(doc, encoding="unicode")
|
||||||
|
return res
|
|
@ -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
|
|
|
@ -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
|
|
@ -1,19 +1,14 @@
|
||||||
|
# Copyright 2020 NextERP Romania SRL
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class ResPartner(models.Model):
|
class ResPartner(models.Model):
|
||||||
_inherit = "res.partner"
|
_inherit = "res.partner"
|
||||||
|
|
||||||
property_comment_template_id = fields.Many2one(
|
base_comment_template_ids = fields.Many2many(
|
||||||
comodel_name="base.comment.template",
|
comodel_name="base.comment.template",
|
||||||
string="Conditions template",
|
string="Comment Templates",
|
||||||
company_dependent=True,
|
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
|
|
||||||
|
|
|
@ -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
|
|
@ -11,3 +11,7 @@
|
||||||
|
|
||||||
* Iván Todorovich <ivan.todorovich@druidoo.io>
|
* Iván Todorovich <ivan.todorovich@druidoo.io>
|
||||||
* Pierre Verkest <pierreverkest84@gmail.com>
|
* Pierre Verkest <pierreverkest84@gmail.com>
|
||||||
|
|
||||||
|
* `NextERP Romania <https://www.nexterp.ro>`_:
|
||||||
|
|
||||||
|
* Fekete Mihai <feketemihai@nexterp.ro>
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
Add a new model to define templates of comments to print on
|
Add a new mixin class to define templates of comments to print on documents.
|
||||||
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:
|
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
|
||||||
|
|
||||||
|
* <span t-raw="o.get_comment_template('position',company_id=o.company_id, partner_id=o.parnter_id )"/> ( or without any parameter)
|
||||||
|
|
||||||
|
|
||||||
This module is the base module for following modules:
|
This module is the base module for following modules:
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
||||||
|
<p t-if="o.get_comment_template('before_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)">
|
||||||
|
|
||||||
|
<span t-raw="o.get_comment_template('before_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)"/>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p t-if="o.get_comment_template('after_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)">
|
||||||
|
|
||||||
|
<span t-raw="o.get_comment_template('after_lines', o.company_id.id, o.partner_id and o.partner_id.id or False)"/>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
You should always use t-if since the method returns False if no template is found.
|
|
@ -1,2 +1,3 @@
|
||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
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
|
access_base_comment_template,access_base_comment_template no one,model_base_comment_template,base.group_no_one,1,1,1,1
|
||||||
|
|
|
|
@ -5,9 +5,8 @@
|
||||||
<field name="name">Base comment multi-company</field>
|
<field name="name">Base comment multi-company</field>
|
||||||
<field name="model_id" ref="model_base_comment_template" />
|
<field name="model_id" ref="model_base_comment_template" />
|
||||||
<field name="global" eval="True" />
|
<field name="global" eval="True" />
|
||||||
<field
|
<field name="domain_force">
|
||||||
name="domain_force"
|
['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||||
>['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# Copyright 2017 LasLabs Inc.
|
||||||
|
# Copyright 2018 ACSONE
|
||||||
|
# Copyright 2018 Camptocamp
|
||||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
def setup_test_model(env, model_cls):
|
||||||
|
"""Pass a test model class and initialize it.
|
||||||
|
|
||||||
|
Courtesy of SBidoul from https://github.com/OCA/mis-builder :)
|
||||||
|
"""
|
||||||
|
model_cls._build_model(env.registry, env.cr)
|
||||||
|
env.registry.setup_models(env.cr)
|
||||||
|
env.registry.init_models(
|
||||||
|
env.cr, [model_cls._name], dict(env.context, update_custom_fields=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_test_model(env, model_cls):
|
||||||
|
"""Pass a test model class and deinitialize it.
|
||||||
|
|
||||||
|
Courtesy of SBidoul from https://github.com/OCA/mis-builder :)
|
||||||
|
"""
|
||||||
|
if not getattr(model_cls, "_teardown_no_delete", False):
|
||||||
|
del env.registry.models[model_cls._name]
|
||||||
|
env.registry.setup_models(env.cr)
|
||||||
|
|
||||||
|
|
||||||
|
class ResUsers(models.Model):
|
||||||
|
_name = "res.users"
|
||||||
|
_inherit = ["res.users", "comment.template"]
|
||||||
|
_teardown_no_delete = True
|
|
@ -1,37 +1,128 @@
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# Copyright 2020 NextERP Romania SRL
|
||||||
from odoo.tests.common import TransactionCase
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
from odoo.tests import common
|
||||||
|
|
||||||
|
from .fake_models import ResUsers, setup_test_model, teardown_test_model
|
||||||
|
|
||||||
|
|
||||||
class TestResPartner(TransactionCase):
|
class TestCommentTemplate(common.SavepointCase):
|
||||||
def setUp(self):
|
at_install = False
|
||||||
super(TestResPartner, self).setUp()
|
post_install = True
|
||||||
self.template_id = self.env["base.comment.template"].create(
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
setup_test_model(cls.env, ResUsers)
|
||||||
|
cls.user_obj = cls.env["ir.model"].search([("model", "=", "res.users")])
|
||||||
|
|
||||||
|
cls.user = cls.env.ref("base.user_demo")
|
||||||
|
cls.user2 = cls.env.ref("base.demo_user0")
|
||||||
|
cls.partner_id = cls.env.ref("base.res_partner_12")
|
||||||
|
cls.partner2_id = cls.env.ref("base.res_partner_10")
|
||||||
|
cls.company = cls.env["res.company"].create({"name": "Test Company 1"})
|
||||||
|
cls.before_template_id = cls.env["base.comment.template"].create(
|
||||||
{
|
{
|
||||||
"name": "Comment before lines",
|
"name": "before_lines",
|
||||||
"position": "before_lines",
|
"text": "Text before lines",
|
||||||
"text": "<p>Text before lines</p>",
|
"model_ids": [(6, 0, cls.user_obj.ids)],
|
||||||
|
"priority": 5,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
cls.after_template_id = cls.env["base.comment.template"].create(
|
||||||
|
{
|
||||||
|
"name": "after_lines",
|
||||||
|
"position": "after_lines",
|
||||||
|
"text": "Text after lines",
|
||||||
|
"model_ids": [(6, 0, cls.user_obj.ids)],
|
||||||
|
"priority": 6,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_commercial_partner_fields(self):
|
@classmethod
|
||||||
# Azure Interior
|
def tearDownClass(cls):
|
||||||
partner_id = self.env.ref("base.res_partner_12")
|
teardown_test_model(cls.env, ResUsers)
|
||||||
partner_id.property_comment_template_id = self.template_id.id
|
super(TestCommentTemplate, cls).tearDownClass()
|
||||||
# Test childs propagation of commercial partner field
|
|
||||||
for child_id in partner_id.child_ids:
|
|
||||||
self.assertEqual(child_id.property_comment_template_id, self.template_id)
|
|
||||||
|
|
||||||
def test_get_value_without_partner(self):
|
def test_general_template(self):
|
||||||
self.assertEqual(self.template_id.get_value(), "<p>Text before lines</p>")
|
# Check getting default comment template
|
||||||
|
templ = self.user.get_comment_template("before_lines")
|
||||||
|
self.assertEqual(templ, "Text before lines")
|
||||||
|
templ = self.user.get_comment_template("after_lines")
|
||||||
|
self.assertEqual(templ, "Text after lines")
|
||||||
|
|
||||||
def test_get_value_with_partner(self):
|
def test_company_general_template(self):
|
||||||
self.env["res.lang"]._activate_lang("fr_BE")
|
# Check getting default comment template company
|
||||||
partner = self.env.ref("base.res_partner_12")
|
self.before_template_id.company_id = self.company
|
||||||
partner.write({"lang": "fr_BE"})
|
templ = self.user.get_comment_template("before_lines")
|
||||||
self.template_id.with_context(lang="fr_BE").write(
|
self.assertEqual(templ, "")
|
||||||
{"text": "<p>Testing translated fr_BE</p>"}
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", company_id=self.company.id
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(templ, "Text before lines")
|
||||||
self.template_id.get_value(partner_id=partner.id),
|
templ = self.user.get_comment_template("after_lines")
|
||||||
"<p>Testing translated fr_BE</p>",
|
self.assertEqual(templ, "Text after lines")
|
||||||
|
|
||||||
|
def test_partner_template(self):
|
||||||
|
# Check getting the comment template if partner is set
|
||||||
|
self.before_template_id.partner_ids = self.partner2_id.ids
|
||||||
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner2_id.id
|
||||||
)
|
)
|
||||||
|
self.assertEqual(templ, "Text before lines")
|
||||||
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner_id.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "")
|
||||||
|
templ = self.user.get_comment_template("after_lines")
|
||||||
|
self.assertEqual(templ, "Text after lines")
|
||||||
|
|
||||||
|
def test_partner_template_domain(self):
|
||||||
|
# Check getting the comment template if domain is set
|
||||||
|
self.before_template_id.partner_ids = self.partner2_id.ids
|
||||||
|
self.before_template_id.domain = "[('id', 'in', %s)]" % self.user.ids
|
||||||
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner2_id.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "Text before lines")
|
||||||
|
templ = self.user2.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner_id.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "")
|
||||||
|
|
||||||
|
def test_company_partner_template_domain(self):
|
||||||
|
# Check getting the comment template with company and if domain is set
|
||||||
|
self.before_template_id.company_id = self.company
|
||||||
|
templ = self.user.get_comment_template("before_lines")
|
||||||
|
self.assertEqual(templ, "")
|
||||||
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", company_id=self.company.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "Text before lines")
|
||||||
|
self.before_template_id.partner_ids = self.partner2_id.ids
|
||||||
|
self.before_template_id.domain = "[('id', 'in', %s)]" % self.user.ids
|
||||||
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner2_id.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "")
|
||||||
|
self.before_template_id.company_id = self.env.user.company_id
|
||||||
|
templ = self.user.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner2_id.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "Text before lines")
|
||||||
|
templ = self.user2.get_comment_template(
|
||||||
|
"before_lines", partner_id=self.partner2_id.id
|
||||||
|
)
|
||||||
|
self.assertEqual(templ, "")
|
||||||
|
|
||||||
|
def test_priority(self):
|
||||||
|
# Check setting default template will change previous record default
|
||||||
|
new_template = self.env["base.comment.template"].create(
|
||||||
|
{
|
||||||
|
"name": "before_lines",
|
||||||
|
"text": "Text before lines 1",
|
||||||
|
"model_ids": [(6, 0, self.user_obj.ids)],
|
||||||
|
"priority": 2,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(new_template.text, "Text before lines 1")
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
<record model="ir.ui.view" id="view_base_comment_template_tree">
|
||||||
|
<field name="name">base.comment.template.search</field>
|
||||||
|
<field name="model">base.comment.template</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Comment Templates">
|
||||||
|
<field name="name" />
|
||||||
|
<field name="position" />
|
||||||
|
<field name="company_id" groups="base.group_multi_company" />
|
||||||
|
<field name="partner_ids" />
|
||||||
|
<field name="model_ids" />
|
||||||
|
<field name="domain" />
|
||||||
|
<field name="priority" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
<record model="ir.ui.view" id="view_base_comment_template_search">
|
<record model="ir.ui.view" id="view_base_comment_template_search">
|
||||||
<field name="name">base.comment.template.search</field>
|
<field name="name">base.comment.template.search</field>
|
||||||
<field name="model">base.comment.template</field>
|
<field name="model">base.comment.template</field>
|
||||||
|
@ -9,6 +23,10 @@
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="position" />
|
<field name="position" />
|
||||||
<field name="company_id" groups="base.group_multi_company" />
|
<field name="company_id" groups="base.group_multi_company" />
|
||||||
|
<field name="partner_ids" />
|
||||||
|
<field name="model_ids" />
|
||||||
|
<field name="domain" />
|
||||||
|
<field name="priority" />
|
||||||
</search>
|
</search>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -20,18 +38,12 @@
|
||||||
<form string="Comment Templates">
|
<form string="Comment Templates">
|
||||||
<sheet>
|
<sheet>
|
||||||
<div class="oe_button_box" name="button_box">
|
<div class="oe_button_box" name="button_box">
|
||||||
<button
|
<widget
|
||||||
name="toggle_active"
|
name="web_ribbon"
|
||||||
type="object"
|
title="Archived"
|
||||||
class="oe_stat_button"
|
bg_color="bg-danger"
|
||||||
icon="fa-archive"
|
attrs="{'invisible': [('active', '=', True)]}"
|
||||||
>
|
|
||||||
<field
|
|
||||||
name="active"
|
|
||||||
widget="boolean_button"
|
|
||||||
options="{"terminology": "archive"}"
|
|
||||||
/>
|
/>
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="oe_title">
|
<div class="oe_title">
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -40,17 +52,15 @@
|
||||||
</div>
|
</div>
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
<field
|
<field name="active" invisible="1" />
|
||||||
name="position"
|
<field name="position" />
|
||||||
widget="radio"
|
|
||||||
invisible="context.get('default_position')"
|
|
||||||
/>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<field
|
<field
|
||||||
name="company_id"
|
name="company_id"
|
||||||
groups="base.group_multi_company"
|
groups="base.group_multi_company"
|
||||||
/>
|
/>
|
||||||
|
<field name="model_ids" widget="many2many_tags" />
|
||||||
|
<field name="partner_ids" widget="many2many_tags" />
|
||||||
|
<field name="priority" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
|
@ -62,20 +72,6 @@
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="view_base_comment_template_tree">
|
|
||||||
<field name="name">account.comment.template.list</field>
|
|
||||||
<field name="model">base.comment.template</field>
|
|
||||||
<field name="priority" eval="6" />
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<tree>
|
|
||||||
<field name="name" />
|
|
||||||
<field name="position" />
|
|
||||||
<field name="company_id" groups="base.group_multi_company" />
|
|
||||||
</tree>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record model="ir.actions.act_window" id="action_base_comment_template">
|
<record model="ir.actions.act_window" id="action_base_comment_template">
|
||||||
<field name="name">Comment Templates</field>
|
<field name="name">Comment Templates</field>
|
||||||
<field name="type">ir.actions.act_window</field>
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
@ -83,5 +79,13 @@
|
||||||
<field name="view_mode">tree,form</field>
|
<field name="view_mode">tree,form</field>
|
||||||
<field name="view_id" ref="view_base_comment_template_tree" />
|
<field name="view_id" ref="view_base_comment_template_tree" />
|
||||||
</record>
|
</record>
|
||||||
|
<!-- menu in settings/technical/reporting -->
|
||||||
|
<menuitem
|
||||||
|
id="reports_base_comment_template_menuitem"
|
||||||
|
name="Comment Templates"
|
||||||
|
parent="base.reporting_menuitem"
|
||||||
|
action="action_base_comment_template"
|
||||||
|
sequence="4"
|
||||||
|
groups="base.group_no_one"
|
||||||
|
/>
|
||||||
</odoo>
|
</odoo>
|
|
@ -0,0 +1,21 @@
|
||||||
|
<odoo>
|
||||||
|
<record id="view_partner_form" model="ir.ui.view">
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="base.view_partner_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<page name='internal_notes' position="after">
|
||||||
|
<page name='base_comment_template_ids' string="Comment Templates">
|
||||||
|
<field
|
||||||
|
colspan="4"
|
||||||
|
mode="tree"
|
||||||
|
name="base_comment_template_ids"
|
||||||
|
nolabel="1"
|
||||||
|
widget="one2many"
|
||||||
|
height="300"
|
||||||
|
context="{'default_partner_id': active_id}"
|
||||||
|
/>
|
||||||
|
</page>
|
||||||
|
</page>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
Loading…
Reference in New Issue