From 01354d049850e0c02b0a1e9789b29027594a4f59 Mon Sep 17 00:00:00 2001 From: Mihai Fekete Date: Wed, 8 Jul 2020 10:36:28 +0300 Subject: [PATCH] [IMP] base_comment_template: black, isort, prettier --- base_comment_template/__manifest__.py | 6 +-- .../migrations/12.0.2.0.0/post-migrate.py | 31 ++++++----- .../migrations/12.0.3.0.0/post-migration.py | 7 +-- .../migrations/12.0.3.0.0/pre-migration.py | 4 +- base_comment_template/models/comment.py | 30 ++++------- base_comment_template/models/res_partner.py | 6 +-- base_comment_template/readme/CONTRIBUTORS.rst | 1 - base_comment_template/readme/DESCRIPTION.rst | 1 - base_comment_template/security/security.xml | 12 ++--- .../tests/test_base_comment_template.py | 18 +++---- base_comment_template/views/comment_view.xml | 51 +++++++++++-------- base_comment_template/views/res_partner.xml | 11 ++-- .../odoo/addons/base_comment_template | 1 + setup/base_comment_template/setup.py | 6 +++ 14 files changed, 98 insertions(+), 87 deletions(-) mode change 100755 => 100644 base_comment_template/readme/CONTRIBUTORS.rst mode change 100755 => 100644 base_comment_template/readme/DESCRIPTION.rst create mode 120000 setup/base_comment_template/odoo/addons/base_comment_template create mode 100644 setup/base_comment_template/setup.py diff --git a/base_comment_template/__manifest__.py b/base_comment_template/__manifest__.py index 9dd125d0c..8777bcbf2 100644 --- a/base_comment_template/__manifest__.py +++ b/base_comment_template/__manifest__.py @@ -4,15 +4,13 @@ { "name": "Base Comments Templates", "summary": "Comments templates on documents", - "version": "12.0.3.0.0", + "version": "13.0.1.0.0", "category": "Sale", "website": "https://github.com/OCA/account-invoice-reporting", "author": "Camptocamp, Odoo Community Association (OCA)", "license": "AGPL-3", "installable": True, - "depends": [ - "base" - ], + "depends": ["base"], "data": [ "security/ir.model.access.csv", "security/security.xml", diff --git a/base_comment_template/migrations/12.0.2.0.0/post-migrate.py b/base_comment_template/migrations/12.0.2.0.0/post-migrate.py index e08ccabb1..367c6dc1c 100644 --- a/base_comment_template/migrations/12.0.2.0.0/post-migrate.py +++ b/base_comment_template/migrations/12.0.2.0.0/post-migrate.py @@ -1,14 +1,15 @@ +import logging + from odoo import tools -import logging _logger = logging.getLogger(__name__) def migrate(cr, version): - _logger.debug('Migrating res.partner comment_template_id') + _logger.debug("Migrating res.partner comment_template_id") - if not tools.column_exists(cr, 'res_partner', 'comment_template_id'): + if not tools.column_exists(cr, "res_partner", "comment_template_id"): return cr.execute("SELECT id FROM res_company") @@ -16,11 +17,14 @@ def migrate(cr, version): cr.execute( "SELECT id FROM ir_model_fields WHERE model=%s AND name=%s", - ('res.partner', 'property_comment_template_id')) + ("res.partner", "property_comment_template_id"), + ) [field_id] = cr.fetchone() for company_id in company_ids: - cr.execute(""" + # pylint: disable=sql-injection + cr.execute( + """ INSERT INTO ir_property( name, type, @@ -47,11 +51,12 @@ def migrate(cr, version): AND res_id=CONCAT('{model},',t.id) ) """.format( - oldfield='comment_template_id', - field='property_comment_template_id', - field_id=field_id, - company_id=company_id, - model='res.partner', - target_model='base.comment.template', - table='res_partner', - )) + oldfield="comment_template_id", + field="property_comment_template_id", + field_id=field_id, + company_id=company_id, + model="res.partner", + target_model="base.comment.template", + table="res_partner", + ) + ) diff --git a/base_comment_template/migrations/12.0.3.0.0/post-migration.py b/base_comment_template/migrations/12.0.3.0.0/post-migration.py index 5294fca63..934b25f68 100644 --- a/base_comment_template/migrations/12.0.3.0.0/post-migration.py +++ b/base_comment_template/migrations/12.0.3.0.0/post-migration.py @@ -6,9 +6,10 @@ from openupgradelib import openupgrade @openupgrade.migrate() def migrate(env, version): cr = env.cr - table = 'res_partner' - new_column = 'property_comment_template_id' + table = "res_partner" + new_column = "property_comment_template_id" old_column = openupgrade.get_legacy_name(new_column) if openupgrade.column_exists(cr, table, old_column): openupgrade.convert_to_company_dependent( - env, 'res.partner', old_column, new_column, 'res_partner') + env, "res.partner", old_column, new_column, "res_partner" + ) diff --git a/base_comment_template/migrations/12.0.3.0.0/pre-migration.py b/base_comment_template/migrations/12.0.3.0.0/pre-migration.py index 12b04d8c3..0a90e6913 100644 --- a/base_comment_template/migrations/12.0.3.0.0/pre-migration.py +++ b/base_comment_template/migrations/12.0.3.0.0/pre-migration.py @@ -6,8 +6,8 @@ from openupgradelib import openupgrade @openupgrade.migrate() def migrate(env, version): cr = env.cr - table = 'res_partner' - old_column = 'property_comment_template_id' + table = "res_partner" + old_column = "property_comment_template_id" new_column = openupgrade.get_legacy_name(old_column) if openupgrade.column_exists(cr, table, old_column): openupgrade.rename_columns(cr, {table: [(old_column, new_column)]}) diff --git a/base_comment_template/models/comment.py b/base_comment_template/models/comment.py index 6dec9062f..d534d182c 100644 --- a/base_comment_template/models/comment.py +++ b/base_comment_template/models/comment.py @@ -2,7 +2,7 @@ # Copyright 2013-2014 Nicolas Bessi (Camptocamp SA) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import models, fields, api +from odoo import api, fields, models class BaseCommentTemplate(models.Model): @@ -11,32 +11,22 @@ class BaseCommentTemplate(models.Model): active = fields.Boolean(default=True) - name = fields.Char( - string='Comment summary', - required=True, - ) + name = fields.Char(string="Comment summary", required=True,) position = fields.Selection( - selection=[ - ('before_lines', 'Before lines'), - ('after_lines', 'After lines'), - ], + selection=[("before_lines", "Before lines"), ("after_lines", "After lines")], required=True, - default='before_lines', + default="before_lines", help="Position on document", ) - text = fields.Html( - string='Comment', - translate=True, - required=True, - ) + text = fields.Html(string="Comment", translate=True, required=True) company_id = fields.Many2one( - 'res.company', - string='Company', + "res.company", + string="Company", help="If set, it'll only be available for this company", - ondelete='cascade', + ondelete="cascade", index=True, ) @@ -45,5 +35,5 @@ class BaseCommentTemplate(models.Model): self.ensure_one() lang = None if partner_id: - lang = self.env['res.partner'].browse(partner_id).lang - return self.with_context({'lang': lang}).text + lang = self.env["res.partner"].browse(partner_id).lang + return self.with_context({"lang": lang}).text diff --git a/base_comment_template/models/res_partner.py b/base_comment_template/models/res_partner.py index c2d04609a..0a4cc9cc4 100644 --- a/base_comment_template/models/res_partner.py +++ b/base_comment_template/models/res_partner.py @@ -7,13 +7,13 @@ class ResPartner(models.Model): _inherit = "res.partner" property_comment_template_id = fields.Many2one( - comodel_name='base.comment.template', - string='Conditions template', + comodel_name="base.comment.template", + string="Conditions template", company_dependent=True, ) @api.model def _commercial_fields(self): res = super(ResPartner, self)._commercial_fields() - res += ['property_comment_template_id'] + res += ["property_comment_template_id"] return res diff --git a/base_comment_template/readme/CONTRIBUTORS.rst b/base_comment_template/readme/CONTRIBUTORS.rst old mode 100755 new mode 100644 index e81ad4425..435e9a188 --- a/base_comment_template/readme/CONTRIBUTORS.rst +++ b/base_comment_template/readme/CONTRIBUTORS.rst @@ -11,4 +11,3 @@ * `Druidoo `_: * Iván Todorovich - diff --git a/base_comment_template/readme/DESCRIPTION.rst b/base_comment_template/readme/DESCRIPTION.rst old mode 100755 new mode 100644 index 289173b4b..291a014cf --- a/base_comment_template/readme/DESCRIPTION.rst +++ b/base_comment_template/readme/DESCRIPTION.rst @@ -10,4 +10,3 @@ This module is the base module for following modules: * sale_comment_template * purchase_comment_template * invoice_comment_template - diff --git a/base_comment_template/security/security.xml b/base_comment_template/security/security.xml index 3fab3262d..2009b59de 100644 --- a/base_comment_template/security/security.xml +++ b/base_comment_template/security/security.xml @@ -1,11 +1,11 @@ - + - Base comment multi-company - - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - diff --git a/base_comment_template/tests/test_base_comment_template.py b/base_comment_template/tests/test_base_comment_template.py index c963c5894..319fab336 100644 --- a/base_comment_template/tests/test_base_comment_template.py +++ b/base_comment_template/tests/test_base_comment_template.py @@ -3,20 +3,20 @@ from odoo.tests.common import TransactionCase class TestResPartner(TransactionCase): - def setUp(self): super(TestResPartner, self).setUp() - self.template_id = self.env['base.comment.template'].create({ - 'name': 'Comment before lines', - 'position': 'before_lines', - 'text': 'Text before lines', - }) + 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 = 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) + 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 d33c43779..a11d0f3fa 100644 --- a/base_comment_template/views/comment_view.xml +++ b/base_comment_template/views/comment_view.xml @@ -1,18 +1,16 @@ - + - base.comment.template.search base.comment.template - - - + + + - base.comment.template.form base.comment.template @@ -20,53 +18,66 @@
-

- +

- + - + - +
- account.comment.template.list base.comment.template - + - - - + + + - Comment Templates ir.actions.act_window base.comment.template form tree,form - + -
diff --git a/base_comment_template/views/res_partner.xml b/base_comment_template/views/res_partner.xml index d12cc53ad..a04c88a63 100644 --- a/base_comment_template/views/res_partner.xml +++ b/base_comment_template/views/res_partner.xml @@ -1,14 +1,15 @@ - res.partner - - + + - + - diff --git a/setup/base_comment_template/odoo/addons/base_comment_template b/setup/base_comment_template/odoo/addons/base_comment_template new file mode 120000 index 000000000..e1637e738 --- /dev/null +++ b/setup/base_comment_template/odoo/addons/base_comment_template @@ -0,0 +1 @@ +../../../../base_comment_template \ No newline at end of file diff --git a/setup/base_comment_template/setup.py b/setup/base_comment_template/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/base_comment_template/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)