Browse Source

[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
myc-14.0-py3o
Ivan Todorovich 5 years ago
committed by Pierre Verkest
parent
commit
e7d0910671
  1. 5
      base_comment_template/README.rst
  2. 4
      base_comment_template/__manifest__.py
  3. 2
      base_comment_template/models/__init__.py
  4. 20
      base_comment_template/models/comment.py
  5. 19
      base_comment_template/models/res_partner.py
  6. 5
      base_comment_template/readme/CONTRIBUTORS.rst
  7. 11
      base_comment_template/security/security.xml
  8. 2
      base_comment_template/tests/__init__.py
  9. 21
      base_comment_template/tests/test_base_comment_template.py
  10. 32
      base_comment_template/views/comment_view.xml
  11. 14
      base_comment_template/views/res_partner.xml

5
base_comment_template/README.rst

@ -75,6 +75,11 @@ Contributors
* Raf Ven <raf.ven@dynapps.be>
* `Druidoo <https://www.druidoo.io>`_:
* Iván Todorovich <ivan.todorovich@druidoo.io>
Maintainers
~~~~~~~~~~~

4
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",
],
}

2
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

20
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

19
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

5
base_comment_template/readme/CONTRIBUTORS.rst

@ -7,3 +7,8 @@
* `DynApps <https://www.dynapps.be>`_:
* Raf Ven <raf.ven@dynapps.be>
* `Druidoo <https://www.druidoo.io>`_:
* Iván Todorovich <ivan.todorovich@druidoo.io>

11
base_comment_template/security/security.xml

@ -0,0 +1,11 @@
<?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>
</record>
</odoo>

2
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

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

32
base_comment_template/views/comment_view.xml

@ -8,6 +8,7 @@
<search string="Comment Templates">
<field name="name"/>
<field name="position"/>
<field name="company_id" groups="base.group_multi_company"/>
</search>
</field>
</record>
@ -17,11 +18,31 @@
<field name="model">base.comment.template</field>
<field name="arch" type="xml">
<form string="Comment Templates">
<group>
<field name="name"/>
<field name="position"/>
<field name="text" colspan="4"/>
</group>
<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>
<group>
<field name="position" widget="radio" invisible="context.get('default_position')"/>
</group>
<group>
<field name="company_id" groups="base.group_multi_company"/>
</group>
</group>
<notebook>
<page name="text" string="Comment">
<field name="text"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
@ -34,6 +55,7 @@
<tree>
<field name="name"/>
<field name="position"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree>
</field>
</record>

14
base_comment_template/views/res_partner.xml

@ -0,0 +1,14 @@
<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="arch" type="xml">
<group name="sale" position="inside">
<field name="property_comment_template_id" attrs="{'invisible': ['|',('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
</group>
</field>
</record>
</odoo>
Loading…
Cancel
Save