[IMP] base_comment_template: black, isort, prettier

This commit is contained in:
Mihai Fekete
2020-07-08 10:36:28 +03:00
committed by Carlos Roca
parent 3a99194ede
commit 01354d0498
14 changed files with 98 additions and 87 deletions

View File

@@ -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",

View File

@@ -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",
)
)

View File

@@ -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"
)

View File

@@ -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)]})

View File

@@ -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

View File

@@ -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

1
base_comment_template/readme/CONTRIBUTORS.rst Executable file → Normal file
View File

@@ -11,4 +11,3 @@
* `Druidoo <https://www.druidoo.io>`_:
* Iván Todorovich <ivan.todorovich@druidoo.io>

1
base_comment_template/readme/DESCRIPTION.rst Executable file → Normal file
View File

@@ -10,4 +10,3 @@ This module is the base module for following modules:
* sale_comment_template
* purchase_comment_template
* invoice_comment_template

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="ir.rule" id="rule_multicompany">
<field name="name">Base comment multi-company</field>
<field name="model_id" ref="model_base_comment_template"/>
<field name="global" eval="True"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
<field name="model_id" ref="model_base_comment_template" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>
</odoo>

View File

@@ -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)

View File

@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record model="ir.ui.view" id="view_base_comment_template_search">
<field name="name">base.comment.template.search</field>
<field name="model">base.comment.template</field>
<field name="arch" type="xml">
<search string="Comment Templates">
<field name="name"/>
<field name="position"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="name" />
<field name="position" />
<field name="company_id" groups="base.group_multi_company" />
</search>
</field>
</record>
<record model="ir.ui.view" id="view_base_comment_template_form">
<field name="name">base.comment.template.form</field>
<field name="model">base.comment.template</field>
@@ -20,53 +18,66 @@
<form string="Comment 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
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"/>
<field name="name" placeholder="Name" />
</h1>
</div>
<group>
<group>
<field name="position" widget="radio" invisible="context.get('default_position')"/>
<field
name="position"
widget="radio"
invisible="context.get('default_position')"
/>
</group>
<group>
<field name="company_id" groups="base.group_multi_company"/>
<field
name="company_id"
groups="base.group_multi_company"
/>
</group>
</group>
<notebook>
<page name="text" string="Comment">
<field name="text"/>
<field name="text" />
</page>
</notebook>
</sheet>
</form>
</field>
</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="priority" eval="6" />
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="position"/>
<field name="company_id" groups="base.group_multi_company"/>
<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">
<field name="name">Comment Templates</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">base.comment.template</field>
<field name="view_type">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>
</odoo>

View File

@@ -1,14 +1,15 @@
<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="priority" eval="2"/>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="2" />
<field name="arch" type="xml">
<group name="sale" position="inside">
<field name="property_comment_template_id" attrs="{'invisible': ['|',('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
<field
name="property_comment_template_id"
attrs="{'invisible': ['|',('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"
/>
</group>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
../../../../base_comment_template

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)