Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] new module sale_order_note_template (Sale Orders Terms and conditions Templates) #1431

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions sale_order_note_template/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
==========================================
Sale Orders Terms and conditions Templates
==========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https:/OCA/sale-workflow/tree/14.0/sale_order_note_template
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_order_note_template
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module add sale order terms and conditions templates and change existing
terms and conditions (`sale_order.note`) field type from `Text` to `Html`.

Users will be able to select *terms and conditions template* to fulfill *terms and
conditions* likes in mail composer users can configure their template using
`jinja2`.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https:/OCA/sale-workflow/issues>`_.
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
`feedback <https:/OCA/sale-workflow/issues/new?body=module:%20sale_order_note_template%0Aversion:%2014.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.

Credits
=======

Authors
~~~~~~~

* Pierre Verkest

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/sale-workflow <https:/OCA/sale-workflow/tree/14.0/sale_order_note_template>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_order_note_template/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions sale_order_note_template/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# © 2020 Pierre Verkest <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Orders Terms and conditions Templates",
"summary": "Add sale orders terms and conditions template that can be "
"used to quickly fullfill sale order terms and conditions",
"category": "Sales/Sales",
"version": "14.0.1.0.0",
"author": "Pierre Verkest,Odoo Community Association (OCA)",
"website": "https:/OCA/sale-workflow",
"license": "AGPL-3",
"depends": [
"sale_management",
],
"data": [
"views/sale_terms_template.xml",
"views/sale_views.xml",
"security/ir.model.access.csv",
],
"installable": True,
}
1 change: 1 addition & 0 deletions sale_order_note_template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_terms_template, sale_order
22 changes: 22 additions & 0 deletions sale_order_note_template/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2021 Pierre Verkest <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class SaleOrder(models.Model):

_inherit = "sale.order"

terms_template_id = fields.Many2one(
"sale.terms_template",
string="Terms and conditions template",
readonly=True,
states={"draft": [("readonly", False)]},
)
note = fields.Html(readonly=True, states={"draft": [("readonly", False)]})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly. you change the type of the field note.
you should maybe add a post_init_hook and / or a uninstall_hook to handle correctly the conversion (Text <--> Html). Otherwise, I guess if you uninstall the module, you'll have a lot of html anchors in all the note column. Don't you think ? (or maybe there is a core feature in Odoo to handle such conversion, I must confess that I have not tested to install your module, add some text in the note field, and then, uninstall the module.)

If it's not in the scope of your PR, you can make a mention in a ROADMAP.rst section.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move that in roadmap at the moment !

thanks for review


@api.onchange("terms_template_id")
def _onchange_terms_template_id(self):
if self.terms_template_id:
self.note = self.terms_template_id.get_value(self)
50 changes: 50 additions & 0 deletions sale_order_note_template/models/sale_terms_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 SaleTermsTemplate(models.Model):
_name = "sale.terms_template"
_description = "Sale terms template"

active = fields.Boolean(default=True)

name = fields.Char(
string="Name",
required=True,
)

text = fields.Html(
string="Terms template",
translate=True,
)

def get_value(self, sale_order, add_context=None, post_process=True):
"""Get sales terms from template.

Like in mail composer `text` template can use jinja or qweb syntax.

if `partner_id` is provide, it will retreive it's lang to use the
right translation.

Then template is populated with model/res_id attributes according
jinja/qweb instructions.

:param sale_order: recordset (browsed) sale order
:param add_context: context forwarded to the templating engine
:param post_process: what ever to use `post_process` from the templating
engine. If `True` urls are transform to absolute urls
"""
self.ensure_one()
sale_order.ensure_one()
lang = sale_order.partner_id.lang if sale_order.partner_id else None
return self.env["mail.render.mixin"]._render_template(
self.with_context(lang=lang).text,
"sale.order",
[sale_order.id],
engine="jinja",
add_context=add_context,
post_process=post_process,
)[sale_order.id]
1 change: 1 addition & 0 deletions sale_order_note_template/readme/CONTRIBUTOR.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Pierre Verkest <[email protected]>
24 changes: 24 additions & 0 deletions sale_order_note_template/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This module add sale terms and conditions templates and change existing terms
and conditions (`sale_order.note`) field type from `Text` to `Html`.

Users will be able to select *terms and conditions template* to fulfill *terms and
conditions* likes in mail composer users can configure their template using
`jinja2`.


How this module differ from `sale_comment_template`_?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* `base_comment_template`_ is for managing comments not terms, it would probably
see as mess for users to mixed terms and comments.

* `sale_comment_template`_ depends on `account_comment_template`_ comments are
forwards to generated invoices, here we don't really display sales terms on
final invoices

* `base_comment_template`_ at the time writing do not support template engine


.. _base_comment_template: https:/OCA/reporting-engine/tree/14.0/base_comment_template
.. _sale_comment_template: https:/OCA/sale-reporting/tree/14.0/sale_comment_template
.. _account_comment_template: https:/OCA/account-invoice-reporting/tree/14.0/account_comment_template
2 changes: 2 additions & 0 deletions sale_order_note_template/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* add a post_init_hook and / or a uninstall_hook to handle correctly the conversion (Text <--> Html).
* support qweb report templating engine
3 changes: 3 additions & 0 deletions sale_order_note_template/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sale_terms_template_sale_manager,Access sale_terms_template sale manager,model_sale_terms_template,sales_team.group_sale_manager,1,1,1,1
access_sale_terms_template_users,Access sale_terms_template users,model_sale_terms_template,base.group_user,1,0,0,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_order_note_template/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_sale_terms_template, test_sale_order
20 changes: 20 additions & 0 deletions sale_order_note_template/tests/test_sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase


class TestSaleOrder(TransactionCase):
def setUp(self):
super().setUp()
self.term_template = self.env["sale.terms_template"].create(
{
"name": "My terms and conditions template",
"text": "<p>Terms template ${object.partner_id.name}</p>",
}
)
self.sale_order = self.env.ref("sale.sale_order_2")

def test_on_change_term_template(self):
self.assertEqual(self.sale_order.note, "")
self.sale_order.terms_template_id = self.term_template
self.sale_order._onchange_terms_template_id()
self.assertEqual(self.sale_order.note, "<p>Terms template Ready Mat</p>")
31 changes: 31 additions & 0 deletions sale_order_note_template/tests/test_sale_terms_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase


class TestSaleTermsTemplate(TransactionCase):
def setUp(self):
super().setUp()
self.term_template = self.env["sale.terms_template"].create(
{
"name": "My terms and conditions template",
"text": "<p>Terms template ${object.partner_id.name}</p>",
}
)
self.sale_order = self.env.ref("sale.sale_order_2")

def test_get_value(self):
self.assertEqual(
self.term_template.get_value(self.sale_order),
"<p>Terms template Ready Mat</p>",
)

def test_get_value_with_translation(self):
self.env["res.lang"]._activate_lang("fr_BE")
self.sale_order.partner_id.lang = "fr_BE"
self.term_template.with_context(lang="fr_BE").write(
{"text": "<p>Testing translated fr_BE `${object.partner_id.name}`</p>"}
)
self.assertEqual(
self.term_template.get_value(self.sale_order),
"<p>Testing translated fr_BE `Ready Mat`</p>",
)
66 changes: 66 additions & 0 deletions sale_order_note_template/views/sale_terms_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record model="ir.ui.view" id="view_sale_terms_template_search">
<field name="name">sale.terms_template.search</field>
<field name="model">sale.terms_template</field>
<field name="arch" type="xml">
<search string="Terms and conditions Templates">
<field name="name" />
</search>
</field>
</record>

<record model="ir.ui.view" id="view_sale_terms_template_form">
<field name="name">sale.terms_template.form</field>
<field name="model">sale.terms_template</field>
<field name="arch" type="xml">
<form string="Terms and conditions Templates">
<sheet>
<div class="oe_button_box" name="button_box">
<button
name="toggle_active"
type="object"
class="oe_stat_button"
icon="fa-archive"
>
<field
name="active"
widget="boolean_button"
options="{&quot;terminology&quot;: &quot;archive&quot;}"
/>
</button>
</div>
<div class="oe_title">
<h1>
<field name="name" placeholder="Name" />
</h1>
</div>
<group>
<field name="text" nolabel="1" />
</group>
</sheet>
</form>
</field>
</record>

<record model="ir.ui.view" id="view_sale_terms_template_tree">
<field name="name">sale.terms_template.list</field>
<field name="model">sale.terms_template</field>
<field name="priority" eval="6" />
<field name="arch" type="xml">
<tree>
<field name="name" />
</tree>
</field>
</record>

<record model="ir.actions.act_window" id="action_sale_terms_template">
<field name="name">Terms and conditions template</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.terms_template</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_sale_terms_template_tree" />
</record>

</odoo>
20 changes: 20 additions & 0 deletions sale_order_note_template/views/sale_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<odoo>
<record model="ir.ui.view" id="view_order_form_terms_template">
<field name="name">sale_order_note_templatesale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath
expr="//group[@name='note_group']/group/field[@name='note']"
position="before"
>
<field
name="terms_template_id"
placeholder="Terms and conditions template"
nolabel="1"
colspan="4"
/>
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/sale_order_note_template/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)