[MIG] [13.0] Migrate base_comment_template from account_invoic_reporting.

This commit is contained in:
Mihai Fekete
2020-07-08 10:37:24 +03:00
committed by Víctor Martínez
parent fe1da090d5
commit 2c3e562dde
18 changed files with 607 additions and 150 deletions

View File

@@ -1,37 +1,128 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
# Copyright 2020 NextERP Romania SRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import common
from .fake_models import ResUsers, setup_test_model, teardown_test_model
class TestResPartner(TransactionCase):
def setUp(self):
super(TestResPartner, self).setUp()
self.template_id = self.env["base.comment.template"].create(
class TestCommentTemplate(common.SavepointCase):
at_install = False
post_install = True
@classmethod
def setUpClass(cls):
super().setUpClass()
setup_test_model(cls.env, ResUsers)
cls.user_obj = cls.env["ir.model"].search([("model", "=", "res.users")])
cls.user = cls.env.ref("base.user_demo")
cls.user2 = cls.env.ref("base.demo_user0")
cls.partner_id = cls.env.ref("base.res_partner_12")
cls.partner2_id = cls.env.ref("base.res_partner_10")
cls.company = cls.env["res.company"].create({"name": "Test Company 1"})
cls.before_template_id = cls.env["base.comment.template"].create(
{
"name": "Comment before lines",
"position": "before_lines",
"text": "<p>Text before lines</p>",
"name": "before_lines",
"text": "Text before lines",
"model_ids": [(6, 0, cls.user_obj.ids)],
"priority": 5,
}
)
cls.after_template_id = cls.env["base.comment.template"].create(
{
"name": "after_lines",
"position": "after_lines",
"text": "Text after lines",
"model_ids": [(6, 0, cls.user_obj.ids)],
"priority": 6,
}
)
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)
@classmethod
def tearDownClass(cls):
teardown_test_model(cls.env, ResUsers)
super(TestCommentTemplate, cls).tearDownClass()
def test_get_value_without_partner(self):
self.assertEqual(self.template_id.get_value(), "<p>Text before lines</p>")
def test_general_template(self):
# Check getting default comment template
templ = self.user.get_comment_template("before_lines")
self.assertEqual(templ, "Text before lines")
templ = self.user.get_comment_template("after_lines")
self.assertEqual(templ, "Text after lines")
def test_get_value_with_partner(self):
self.env["res.lang"]._activate_lang("fr_BE")
partner = self.env.ref("base.res_partner_12")
partner.write({"lang": "fr_BE"})
self.template_id.with_context(lang="fr_BE").write(
{"text": "<p>Testing translated fr_BE</p>"}
def test_company_general_template(self):
# Check getting default comment template company
self.before_template_id.company_id = self.company
templ = self.user.get_comment_template("before_lines")
self.assertEqual(templ, "")
templ = self.user.get_comment_template(
"before_lines", company_id=self.company.id
)
self.assertEqual(
self.template_id.get_value(partner_id=partner.id),
"<p>Testing translated fr_BE</p>",
self.assertEqual(templ, "Text before lines")
templ = self.user.get_comment_template("after_lines")
self.assertEqual(templ, "Text after lines")
def test_partner_template(self):
# Check getting the comment template if partner is set
self.before_template_id.partner_ids = self.partner2_id.ids
templ = self.user.get_comment_template(
"before_lines", partner_id=self.partner2_id.id
)
self.assertEqual(templ, "Text before lines")
templ = self.user.get_comment_template(
"before_lines", partner_id=self.partner_id.id
)
self.assertEqual(templ, "")
templ = self.user.get_comment_template("after_lines")
self.assertEqual(templ, "Text after lines")
def test_partner_template_domain(self):
# Check getting the comment template if domain is set
self.before_template_id.partner_ids = self.partner2_id.ids
self.before_template_id.domain = "[('id', 'in', %s)]" % self.user.ids
templ = self.user.get_comment_template(
"before_lines", partner_id=self.partner2_id.id
)
self.assertEqual(templ, "Text before lines")
templ = self.user2.get_comment_template(
"before_lines", partner_id=self.partner_id.id
)
self.assertEqual(templ, "")
def test_company_partner_template_domain(self):
# Check getting the comment template with company and if domain is set
self.before_template_id.company_id = self.company
templ = self.user.get_comment_template("before_lines")
self.assertEqual(templ, "")
templ = self.user.get_comment_template(
"before_lines", company_id=self.company.id
)
self.assertEqual(templ, "Text before lines")
self.before_template_id.partner_ids = self.partner2_id.ids
self.before_template_id.domain = "[('id', 'in', %s)]" % self.user.ids
templ = self.user.get_comment_template(
"before_lines", partner_id=self.partner2_id.id
)
self.assertEqual(templ, "")
self.before_template_id.company_id = self.env.user.company_id
templ = self.user.get_comment_template(
"before_lines", partner_id=self.partner2_id.id
)
self.assertEqual(templ, "Text before lines")
templ = self.user2.get_comment_template(
"before_lines", partner_id=self.partner2_id.id
)
self.assertEqual(templ, "")
def test_priority(self):
# Check setting default template will change previous record default
new_template = self.env["base.comment.template"].create(
{
"name": "before_lines",
"text": "Text before lines 1",
"model_ids": [(6, 0, self.user_obj.ids)],
"priority": 2,
}
)
self.assertEqual(new_template.text, "Text before lines 1")