From e7d0910671042fa12f12e820c38a98d0de0c99e8 Mon Sep 17 00:00:00 2001 From: Ivan Todorovich Date: Fri, 19 Apr 2019 13:47:37 +0000 Subject: [PATCH] [IMP] base_comment_template multi company rules [IMP] Move comment_template_id from account_invoice_comment_template and make it company_dependant [IMP] base_comment_template: Add test --- base_comment_template/README.rst | 5 +++ base_comment_template/__manifest__.py | 4 ++- base_comment_template/models/__init__.py | 2 +- base_comment_template/models/comment.py | 20 +++++++++--- base_comment_template/models/res_partner.py | 19 +++++++++++ base_comment_template/readme/CONTRIBUTORS.rst | 5 +++ base_comment_template/security/security.xml | 11 +++++++ base_comment_template/tests/__init__.py | 2 ++ .../tests/test_base_comment_template.py | 21 ++++++++++++ base_comment_template/views/comment_view.xml | 32 ++++++++++++++++--- base_comment_template/views/res_partner.xml | 14 ++++++++ 11 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 base_comment_template/models/res_partner.py create mode 100644 base_comment_template/security/security.xml create mode 100644 base_comment_template/tests/__init__.py create mode 100644 base_comment_template/tests/test_base_comment_template.py create mode 100644 base_comment_template/views/res_partner.xml diff --git a/base_comment_template/README.rst b/base_comment_template/README.rst index fbe08e30..5ee2ff53 100644 --- a/base_comment_template/README.rst +++ b/base_comment_template/README.rst @@ -75,6 +75,11 @@ Contributors * Raf Ven +* `Druidoo `_: + + * Iván Todorovich + + Maintainers ~~~~~~~~~~~ diff --git a/base_comment_template/__manifest__.py b/base_comment_template/__manifest__.py index eaa2d8a9..11c926f8 100644 --- a/base_comment_template/__manifest__.py +++ b/base_comment_template/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Base Comments Templates", "summary": "Comments templates on documents", - "version": "12.0.1.0.0", + "version": "12.0.2.0.0", "category": "Sale", "website": "https://github.com/OCA/account-invoice-reporting", "author": "Camptocamp, Odoo Community Association (OCA)", @@ -15,6 +15,8 @@ ], "data": [ "security/ir.model.access.csv", + "security/security.xml", "views/comment_view.xml", + "views/res_partner.xml", ], } diff --git a/base_comment_template/models/__init__.py b/base_comment_template/models/__init__.py index 4ad9af3c..b62fbec1 100644 --- a/base_comment_template/models/__init__.py +++ b/base_comment_template/models/__init__.py @@ -1,3 +1,3 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import comment +from . import res_partner diff --git a/base_comment_template/models/comment.py b/base_comment_template/models/comment.py index 0cd33e26..6dec9062 100644 --- a/base_comment_template/models/comment.py +++ b/base_comment_template/models/comment.py @@ -9,23 +9,35 @@ 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 + required=True, ) + position = fields.Selection( selection=[ ('before_lines', 'Before lines'), - ('after_lines', 'After lines') + ('after_lines', 'After lines'), ], required=True, default='before_lines', - help="Position on document" + help="Position on document", ) + text = fields.Html( string='Comment', translate=True, - required=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, ) @api.multi diff --git a/base_comment_template/models/res_partner.py b/base_comment_template/models/res_partner.py new file mode 100644 index 00000000..b7171210 --- /dev/null +++ b/base_comment_template/models/res_partner.py @@ -0,0 +1,19 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + property_comment_template_id = fields.Many2one( + comodel_name='base.comment.template', + string='Conditions template', + company_dependant=True, + ) + + @api.model + def _commercial_fields(self): + res = super(ResPartner, self)._commercial_fields() + res += ['property_comment_template_id'] + return res diff --git a/base_comment_template/readme/CONTRIBUTORS.rst b/base_comment_template/readme/CONTRIBUTORS.rst index ba762f7e..e81ad442 100755 --- a/base_comment_template/readme/CONTRIBUTORS.rst +++ b/base_comment_template/readme/CONTRIBUTORS.rst @@ -7,3 +7,8 @@ * `DynApps `_: * Raf Ven + +* `Druidoo `_: + + * Iván Todorovich + diff --git a/base_comment_template/security/security.xml b/base_comment_template/security/security.xml new file mode 100644 index 00000000..3fab3262 --- /dev/null +++ b/base_comment_template/security/security.xml @@ -0,0 +1,11 @@ + + + + + Base comment multi-company + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + diff --git a/base_comment_template/tests/__init__.py b/base_comment_template/tests/__init__.py new file mode 100644 index 00000000..e198115e --- /dev/null +++ b/base_comment_template/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_base_comment_template diff --git a/base_comment_template/tests/test_base_comment_template.py b/base_comment_template/tests/test_base_comment_template.py new file mode 100644 index 00000000..d8bba34a --- /dev/null +++ b/base_comment_template/tests/test_base_comment_template.py @@ -0,0 +1,21 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests.common import TransactionCase + + +class TestResPartner(TransactionCase): + + def setUp(self): + self.template_id = self.env['base.comment.template'].create({ + 'name': 'Comment before lines', + 'position': 'before_lines', + 'text': 'Text before lines', + }) + + def test_commercial_partner_fields(self): + # Azure Interior + partner_id = self.env.ref('base.res_partner_12') + partner_id.property_comment_template_id = self.template_id.id + # 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) diff --git a/base_comment_template/views/comment_view.xml b/base_comment_template/views/comment_view.xml index c0cf9174..d33c4377 100644 --- a/base_comment_template/views/comment_view.xml +++ b/base_comment_template/views/comment_view.xml @@ -8,6 +8,7 @@ + @@ -17,11 +18,31 @@ base.comment.template
- - - - - + +
+ +
+
+

+ +

+
+ + + + + + + + + + + + + +
@@ -34,6 +55,7 @@ + diff --git a/base_comment_template/views/res_partner.xml b/base_comment_template/views/res_partner.xml new file mode 100644 index 00000000..d12cc53a --- /dev/null +++ b/base_comment_template/views/res_partner.xml @@ -0,0 +1,14 @@ + + + + res.partner + + + + + + + + + +