From f2e5e578474c274d3e884e3f097f6d85ba6cecce Mon Sep 17 00:00:00 2001 From: KolushovAlexandr Date: Mon, 26 Nov 2018 15:20:43 +0500 Subject: [PATCH] :arrow_up::one::two: mail_multi_website --- mail_multi_website/README.rst | 10 ++++----- mail_multi_website/__manifest__.py | 6 ++++-- mail_multi_website/doc/index.rst | 4 ++-- mail_multi_website/models/ir_property.py | 9 ++++---- mail_multi_website/models/mail_template.py | 2 +- mail_multi_website/models/res_users.py | 2 +- mail_multi_website/tests/test_fetch.py | 8 +++---- mail_multi_website/tests/test_mail_model.py | 2 +- mail_multi_website/tests/test_render.py | 23 +++++++++++++++++---- 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/mail_multi_website/README.rst b/mail_multi_website/README.rst index a7c4dd1..3c8133e 100644 --- a/mail_multi_website/README.rst +++ b/mail_multi_website/README.rst @@ -40,7 +40,7 @@ Maintainers To get a guaranteed support you are kindly requested to purchase the module - at `odoo apps store `__. + at `odoo apps store `__. Thank you for understanding! @@ -49,14 +49,14 @@ Maintainers Further information =================== -Demo: http://runbot.it-projects.info/demo/mail-addons/11.0 +Demo: http://runbot.it-projects.info/demo/mail-addons/12.0 -HTML Description: https://apps.odoo.com/apps/modules/11.0/mail_multi_website/ +HTML Description: https://apps.odoo.com/apps/modules/12.0/mail_multi_website/ Usage instructions: ``_ Changelog: ``_ -Notifications on updates: `via Atom `_, `by Email `_ +Notifications on updates: `via Atom `_, `by Email `_ -Tested on Odoo 11.0 4d0a1330e05bd688265bea14df4ad12838f9f2d7 +Tested on Odoo 12.0 80cef9e8c52ff7dc0715a7478a2288d3de7065df diff --git a/mail_multi_website/__manifest__.py b/mail_multi_website/__manifest__.py index b447932..86658db 100644 --- a/mail_multi_website/__manifest__.py +++ b/mail_multi_website/__manifest__.py @@ -1,4 +1,5 @@ # Copyright 2018 Ivan Yelizariev +# Copyright 2018 Kolushov Alexandr # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": """Email Addresses and Templates per Website""", @@ -6,7 +7,7 @@ "category": "Discuss", "live_test_url": "http://apps.it-projects.info/shop/product/website-multi-company?version=11.0", "images": ["images/main.jpg"], - "version": "11.0.1.0.0", + "version": "12.0.1.0.0", "application": False, "author": "IT-Projects LLC, Ivan Yelizariev", @@ -20,6 +21,7 @@ "ir_config_parameter_multi_company", "web_website", "mail", + "test_mail", ], "external_dependencies": {"python": [], "bin": []}, "data": [ @@ -36,7 +38,7 @@ "uninstall_hook": "uninstall_hook", "auto_install": False, - "installable": False, + "installable": True, # "demo_title": "Email Addresses per Website", # "demo_addons": [ diff --git a/mail_multi_website/doc/index.rst b/mail_multi_website/doc/index.rst index bdfaf0b..74b2a46 100644 --- a/mail_multi_website/doc/index.rst +++ b/mail_multi_website/doc/index.rst @@ -48,7 +48,7 @@ Note. If related record (e.g. ``sale.order``) has field ``company_id`` or ``webs Alias domain per website ------------------------ -Configure ``mail.catchall.domain`` per website. See Documentation of the module `Context-dependent values in System Parameters`__. +Configure ``mail.catchall.domain`` per website. See Documentation of the module `Context-dependent values in System Parameters`__. Outgoing mails servers per -------------------------- @@ -61,7 +61,7 @@ If each domain has different Outgoing Mail Server you need following adjustments Properties ---------- -To review properties by website use menu ``[[ Settings ]] >> Technical >> Parameters >> Company Properties``. See **How it works** in Documentation of module `Website Switcher in Backend`__. +To review properties by website use menu ``[[ Settings ]] >> Technical >> Parameters >> Company Properties``. See **How it works** in Documentation of module `Website Switcher in Backend`__. Usage ===== diff --git a/mail_multi_website/models/ir_property.py b/mail_multi_website/models/ir_property.py index bbf1cb4..64c601d 100644 --- a/mail_multi_website/models/ir_property.py +++ b/mail_multi_website/models/ir_property.py @@ -1,4 +1,5 @@ # Copyright 2018 Ivan Yelizariev +# Copyright 2018 Kolushov Alexandr # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). from odoo import models, api @@ -10,10 +11,10 @@ class IrProperty(models.Model): def write(self, vals): res = super(IrProperty, self).write(vals) field_object_list = [ - self.env.ref('base.field_res_users_email'), - self.env.ref('mail.field_mail_template_body_html'), - self.env.ref('mail.field_mail_template_mail_server_id'), - self.env.ref('mail.field_mail_template_report_template'), + self.env.ref('base.field_res_users__email'), + self.env.ref('mail.field_mail_template__body_html'), + self.env.ref('mail.field_mail_template__mail_server_id'), + self.env.ref('mail.field_mail_template__report_template'), ] for fobj in field_object_list: self._update_db_value_website_dependent(fobj) diff --git a/mail_multi_website/models/mail_template.py b/mail_multi_website/models/mail_template.py index 7342663..ebd96c3 100644 --- a/mail_multi_website/models/mail_template.py +++ b/mail_multi_website/models/mail_template.py @@ -43,7 +43,7 @@ class MailTemplate(models.Model): return res @api.model - def render_template(self, template_txt, model, res_ids, post_process=False): + def _render_template(self, template_txt, model, res_ids, post_process=False): """Override to add website to context""" multi_mode = True if isinstance(res_ids, pycompat.integer_types): diff --git a/mail_multi_website/models/res_users.py b/mail_multi_website/models/res_users.py index 07a77a0..8d8762d 100644 --- a/mail_multi_website/models/res_users.py +++ b/mail_multi_website/models/res_users.py @@ -18,7 +18,7 @@ class User(models.Model): signature = fields.Html(company_dependent=True, website_dependent=True) # extra field to detach email field from res.partner - email = fields.Char(related='email_multi_website', inherited=False) + email = fields.Char(string='Multi Website Email', related='email_multi_website', inherited=False) email_multi_website = fields.Char(company_dependent=True, website_dependent=True) @api.model diff --git a/mail_multi_website/tests/test_fetch.py b/mail_multi_website/tests/test_fetch.py index 7c34a07..c821501 100644 --- a/mail_multi_website/tests/test_fetch.py +++ b/mail_multi_website/tests/test_fetch.py @@ -1,8 +1,9 @@ # Copyright 2018 Ivan Yelizariev +# Copyright 2018 Kolushov Alexandr # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). -from odoo.addons.mail.tests.common import TestMail +from odoo.addons.test_mail.tests.test_mail_mail import TestMail from odoo.tools import mute_logger -from odoo.addons.mail.tests.test_mail_gateway import MAIL_TEMPLATE +from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE class TestFetch(TestMail): @@ -21,7 +22,7 @@ class TestFetch(TestMail): self.website.company_id = self.company # copy-paste from mail.tests.test_mail_gateway - mail_test_model = self.env['ir.model']._get('mail.test') + mail_test_model = self.env['ir.model']._get('mail.test.simple') # groups@.. will cause the creation of new mail.test self.alias = self.env['mail.alias'].create({ 'alias_name': 'groups', @@ -36,6 +37,5 @@ class TestFetch(TestMail): # Test: one group created by mailgateway administrator self.assertEqual(len(new_groups), 1, 'message_process: a new mail.test should have been created') - self.assertEqual(new_groups.website_id, self.website, 'New record is created with wrong website') self.assertEqual(new_groups.company_id, self.company, 'New record is created with wrong company') diff --git a/mail_multi_website/tests/test_mail_model.py b/mail_multi_website/tests/test_mail_model.py index 040225d..7b16dc0 100644 --- a/mail_multi_website/tests/test_mail_model.py +++ b/mail_multi_website/tests/test_mail_model.py @@ -4,7 +4,7 @@ from odoo import models, fields class MailTest(models.Model): - _inherit = 'mail.test' + _inherit = 'mail.test.simple' company_id = fields.Many2one('res.company', default=lambda self: self.env['res.company']._company_default_get()) website_id = fields.Many2one('website', default=lambda self: self.env['website'].browse(self.env.context.get('website_id'))) diff --git a/mail_multi_website/tests/test_render.py b/mail_multi_website/tests/test_render.py index b3d0c22..9b99b7b 100644 --- a/mail_multi_website/tests/test_render.py +++ b/mail_multi_website/tests/test_render.py @@ -1,8 +1,9 @@ # Copyright 2018 Ivan Yelizariev +# Copyright 2018 Kolushov Alexandr # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). import base64 -from odoo.addons.mail.tests.common import TestMail +from odoo.addons.test_mail.tests.test_mail_mail import TestMail class TestRender(TestMail): @@ -28,6 +29,7 @@ class TestRender(TestMail): }) self.website.mail_server_id = self.mail_server_id + user_admin = self.env.ref('base.user_admin') # copy-paste from mail.tests.test_mail_template self._attachments = [{ 'name': '_Test_First', @@ -35,15 +37,17 @@ class TestRender(TestMail): 'first.txt', 'datas': base64.b64encode(b'My first attachment'), 'res_model': 'res.partner', - 'res_id': self.user_admin.partner_id.id + 'res_id': user_admin.partner_id.id }, { 'name': '_Test_Second', 'datas_fname': 'second.txt', 'datas': base64.b64encode(b'My second attachment'), 'res_model': 'res.partner', - 'res_id': self.user_admin.partner_id.id + 'res_id': user_admin.partner_id.id }] + self.partner_1 = self.env['res.partner'].create({'name': 'partner_1'}) + self.partner_2 = self.env['res.partner'].create({'name': 'partner_2'}) self.email_1 = 'test1@example.com' self.email_2 = 'test2@example.com' self.email_3 = self.partner_1.email @@ -71,6 +75,16 @@ class TestRender(TestMail): """Mail values are per website""" self.env.user.backend_website_id = None + TestModel = self.env['mail.test'].with_context({ + 'mail_create_nolog': True, + 'mail_create_nosubscribe': True, + }) + self.test_pigs = TestModel.create({ + 'name': 'Pigs', + 'description': 'Fans of Pigs, unite !', + 'alias_name': 'pigs', + 'alias_contact': 'followers', + }) # sending without website mail_id = self.email_template.send_mail(self.test_pigs.id) @@ -87,7 +101,8 @@ class TestRender(TestMail): # copy-pasted tests self.assertEqual(mail.email_to, self.email_template.email_to) - self.assertEqual(mail.email_cc, self.email_template.email_cc) + # for some reason self.email_template.email_cc might return u'False' + self.assertEqual(mail.email_cc or 'False', self.email_template.email_cc or 'False') self.assertEqual(mail.recipient_ids, self.partner_2 | self.user_employee.partner_id) # sending from frontend