From 468fed66be75eec5bc8b2af7a52373c38d09120b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 24 Jan 2013 10:42:41 +0100 Subject: [PATCH 01/51] [IMP] mail: add a method get_signature_footer to add a good signature on bottom of messages sent with the chatter and invite followers bzr revid: chm@openerp.com-20130124094241-k9ophrwqhne611il --- addons/mail/mail_followers.py | 60 +++++++++++++++++++++++++++++++---- addons/mail/mail_mail.py | 2 +- addons/mail/wizard/invite.py | 7 ++-- addons/portal/mail_mail.py | 6 ++-- 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index ec9bc86d6c5..85adfae5d09 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -20,6 +20,8 @@ ############################################################################## from openerp.osv import osv, fields from openerp import tools, SUPERUSER_ID +from openerp.tools.translate import _ +from openerp.tools.mail import plaintext2html class mail_followers(osv.Model): """ mail_followers holds the data related to the follow mechanism inside @@ -103,6 +105,54 @@ class mail_notification(osv.Model): notify_pids.append(partner.id) return notify_pids + def get_signature_footer(self, cr, uid, user_id, res_model=None, res_id=None, context=None): + footer = "" + user = self.pool.get("res.users").browse(cr, uid, [user_id], context=context)[0] + if user and user.signature: + signature = plaintext2html(user.signature) + else: + signature = "--
%s" % user.name + footer = tools.append_content_to_html(footer, signature, plaintext=False, container_tag='p') + + company = None + if user.company_id: + company = user.company_id.website and "%s" % (user.company_id.website, user.company_id.name) or user.company_id.name + else: + company = user.name + + model_name = None + record_name = None + if res_model: + res_model_obj = self.pool.get('ir.model') + res_model_ids = res_model_obj.search(cr, uid, [('model', '=', res_model)], context=context) + model_name = res_model_obj.browse(cr, uid, res_model_ids, context=context)[0].name + if res_id: + record_obj = self.pool.get(res_model) + record = record_obj.browse(cr, uid, [res_id], context=context)[0] + record_name = record.name + + if company: + if model_name: + if record_name: + signature_company = _("This message is written on the document '%(record_name)s' of '%(model_name)s' from '%(company)s'." % { + 'record_name': record_name, + 'model_name': model_name, + 'company': company + }) + else: + signature_company = _("This message is written on '%(model_name)s' from '%(company)s'." % { + 'model_name': model_name, + 'company': company + }) + else: + signature_company = _("This message is written from '%(company)s'." % { + 'company': company + }) + + footer = tools.append_content_to_html(footer, "%s" % signature_company, plaintext=False, container_tag='div') + + return footer + def _notify(self, cr, uid, msg_id, context=None): """ Send by email the notification depending on the user preferences """ if context is None: @@ -120,14 +170,11 @@ class mail_notification(osv.Model): # TDE FIXME: commented, to be improved in a future branch # quote_context = self.pool.get('mail.message').message_quote_context(cr, uid, msg_id, context=context) - mail_mail = self.pool.get('mail.mail') # add signature body_html = msg.body - # if quote_context: - # body_html = tools.append_content_to_html(body_html, quote_context, plaintext=False) - signature = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].signature or '' - if signature: - body_html = tools.append_content_to_html(body_html, signature, plaintext=True, container_tag='div') + user = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0] or None + signature_company = self.get_signature_footer(cr, uid, user_id=user.id, res_model=msg.model, res_id=msg.res_id, context=context) + body_html = tools.append_content_to_html(body_html, signature_company, plaintext=False, container_tag='div') mail_values = { 'mail_message_id': msg.id, @@ -137,6 +184,7 @@ class mail_notification(osv.Model): 'state': 'outgoing', } mail_values['email_to'] = ', '.join(mail_values['email_to']) + mail_mail = self.pool.get('mail.mail') email_notif_id = mail_mail.create(cr, uid, mail_values, context=context) try: return mail_mail.send(cr, uid, [email_notif_id], recipient_ids=notify_partner_ids, context=context) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 7b8ec0b3579..d91c3f7a8cf 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -177,7 +177,7 @@ class mail_mail(osv.Model): 'id': mail.res_id, } url = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment))) - text = _("""

Access this document directly in OpenERP

""") % url + text = _("""Access this document directly in OpenERP""") % url body = tools.append_content_to_html(body, ("

%s

" % text), plaintext=False) except except_orm, e: pass diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index 5fddd574182..4d3d34d8116 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -62,10 +62,9 @@ class invite_wizard(osv.osv_memory): # send an email if wizard.message: # add signature - user_id = self.pool.get("res.users").read(cr, uid, [uid], fields=["signature"], context=context)[0] - signature = user_id and user_id["signature"] or '' - if signature: - wizard.message = tools.append_content_to_html(wizard.message, signature, plaintext=True, container_tag='div') + signature_company = self.pool.get('mail.notification').get_signature_footer(cr, uid, user_id=uid, res_model=wizard.res_model, res_id=wizard.res_id, context=context) + wizard.message = tools.append_content_to_html(wizard.message, signature_company, plaintext=False, container_tag='div') + # send mail to new followers for follower_id in new_follower_ids: mail_mail = self.pool.get('mail.mail') diff --git a/addons/portal/mail_mail.py b/addons/portal/mail_mail.py index 5d2a91e691f..751b7d68033 100644 --- a/addons/portal/mail_mail.py +++ b/addons/portal/mail_mail.py @@ -41,7 +41,7 @@ class mail_mail(osv.Model): if partner: contex_signup = dict(context or {}, signup_valid=True) partner = partner_obj.browse(cr, SUPERUSER_ID, partner.id, context=contex_signup) - text = _("""

Access your messages and personal documents through our Customer Portal

""") % partner.signup_url + text = _("""Access your messages and personal documents through our Customer Portal""") % partner.signup_url # partner is an user: add a link to the document if read access if partner.user_ids and mail.model and mail.res_id \ and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False): @@ -49,8 +49,8 @@ class mail_mail(osv.Model): try: self.pool.get(mail.model).check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context) url = partner_obj._get_signup_url_for_action(cr, related_user.id, [partner.id], action='', res_id=mail.res_id, model=mail.model, context=context)[partner.id] - text = _("""

Access this document directly in OpenERP

""") % url + text = _("""Access this document directly in OpenERP""") % url except except_orm, e: pass - body = append_content_to_html(body, ("

%s

" % text), plaintext=False) + body = append_content_to_html(body, text, plaintext=False, container_tag='div') return body From ed7e0919f193f0b55e3bc10c009bc9745ccce951 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 25 Jan 2013 14:34:26 +0100 Subject: [PATCH 02/51] [IMP] res_user: change view form bzr revid: chm@openerp.com-20130125133426-o2yblxrrp7ambjzd --- addons/mail/res_users_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mail/res_users_view.xml b/addons/mail/res_users_view.xml index a119765e1ec..f49ff72194a 100644 --- a/addons/mail/res_users_view.xml +++ b/addons/mail/res_users_view.xml @@ -23,7 +23,7 @@ - + From 112426bb5b45aefc32120f6d29e25b33d6e9b9f3 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 25 Jan 2013 14:42:21 +0100 Subject: [PATCH 03/51] [IMP] res_user: change view form bzr revid: chm@openerp.com-20130125134221-cxysx6qoik3nz3p4 --- openerp/addons/base/res/res_users_view.xml | 69 ++++++++-------------- 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/openerp/addons/base/res/res_users_view.xml b/openerp/addons/base/res/res_users_view.xml index 7e83b43179f..33149f918a3 100644 --- a/openerp/addons/base/res/res_users_view.xml +++ b/openerp/addons/base/res/res_users_view.xml @@ -84,51 +84,7 @@ - - - res.users.simplified.form - res.users - 1 - -
- - -
-
-
-

- -

- -
- - - - - - - - - - -
-
-
-
res.users.form res.users @@ -155,8 +111,30 @@ - + + + + + + + + + + + + @@ -169,7 +147,6 @@ - From b7fe7956c503d76eb85323ea083359be37ce22d5 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 28 Jan 2013 11:23:08 +0100 Subject: [PATCH 04/51] [IMP] res_user: view and simple_mode view (hide notebook when simple_mode is in the context) bzr revid: chm@openerp.com-20130128102308-xwp0rl1jx93l1dwr --- openerp/addons/base/res/res_users_view.xml | 42 +++++++--------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/openerp/addons/base/res/res_users_view.xml b/openerp/addons/base/res/res_users_view.xml index 33149f918a3..1c858bbc994 100644 --- a/openerp/addons/base/res/res_users_view.xml +++ b/openerp/addons/base/res/res_users_view.xml @@ -92,7 +92,7 @@
-
+
@@ -102,37 +102,16 @@

- - - - - - - - - + - - - - - - - - - + + + + + @@ -151,6 +130,9 @@ + + + From 7d3bf223471c7c9e36376ba2f1c6095ab967446a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 28 Jan 2013 14:30:03 +0100 Subject: [PATCH 05/51] [IMP] res_user: we can add 'default_groups_ref' inside the context to set default value for group_id with xml values bzr revid: chm@openerp.com-20130128133003-rl1xem6hqhlkh621 --- openerp/addons/base/res/res_users.py | 13 +++++++++++++ openerp/addons/base/res/res_users_view.xml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index df83f0ac1e3..e3806643c28 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -778,6 +778,19 @@ class users_view(osv.osv): values['groups_id'] = [(3, id) for id in remove] + [(4, id) for id in add] def default_get(self, cr, uid, fields, context=None): + # add "default_groups_ref" inside the context to set default value for group_id with xml values + if context.get("default_groups_ref", None) and isinstance(context.get("default_groups_ref"), list): + context['default_groups_id'] = [] + ir_model_data = self.pool.get('ir.model.data') + for group in context.get("default_groups_ref"): + group_split = group.split('.') + if len(group_split) != 2 or \ + not group_split[0] or not isinstance(group_split[0], (str, unicode, basestring)) or \ + not group_split[1] or not isinstance(group_split[1], (str, unicode, basestring)): + raise osv.except_osv(_('Invalid context value'), _('Invalid context default_groups_ref value (model.name_id) : "%s"') % group) + model_data_ids = ir_model_data.search(cr, SUPERUSER_ID, [('model', '=', 'res.groups'), ('module', '=', group_split[0]), ('name', '=', group_split[1])]) + context['default_groups_id'] += [group_data['res_id'] for group_data in ir_model_data.read(cr, SUPERUSER_ID, model_data_ids, ['res_id'])] + group_fields, fields = partition(is_reified_group, fields) fields1 = (fields + ['groups_id']) if group_fields else fields values = super(users_view, self).default_get(cr, uid, fields1, context) diff --git a/openerp/addons/base/res/res_users_view.xml b/openerp/addons/base/res/res_users_view.xml index 1c858bbc994..9d6b334e180 100644 --- a/openerp/addons/base/res/res_users_view.xml +++ b/openerp/addons/base/res/res_users_view.xml @@ -125,7 +125,7 @@ - + From 098ce6d2584dddba948c5bcd05b7ea14b6ad7800 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 28 Jan 2013 15:01:20 +0100 Subject: [PATCH 06/51] [IMP] res_partner: context with simple_mode for the user_id field bzr revid: chm@openerp.com-20130128140120-3oxed3t9fj5r2agv --- openerp/addons/base/res/res_partner_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_partner_view.xml b/openerp/addons/base/res/res_partner_view.xml index d3f204e102a..c507509636d 100644 --- a/openerp/addons/base/res/res_partner_view.xml +++ b/openerp/addons/base/res/res_partner_view.xml @@ -269,7 +269,7 @@ - + From c2beeab40b5e187f59672c910753ffe8d0ae2c34 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 28 Jan 2013 15:02:01 +0100 Subject: [PATCH 07/51] [IMP] crm, project: context with simple_mode for the user_id field bzr revid: chm@openerp.com-20130128140201-pdy1xdkqxh0a3in4 --- addons/crm/crm_lead_view.xml | 4 ++-- addons/project/project_view.xml | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 3d7bd45a209..e0e8cdc5028 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -152,7 +152,7 @@ --> - +