From 616e7a92ec39b9223f803f8f0635fdcb0286ad8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 9 Aug 2012 10:31:03 +0200 Subject: [PATCH 01/14] [IMP] orm: added a deprecated attribute on fields. If not False, is a string, and make the ORM print a warning telling the field is deprecated. Use: 'my_field': fields.char('Old field', size=64, deprecated="This field will be removed as of version 42 of OpenERP. Please update your module to use 'my_new_field' instead.") bzr revid: tde@openerp.com-20120809083103-pjc9ynvmtojnfnah --- openerp/osv/fields.py | 1 + openerp/osv/orm.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 4ff23956050..7717c1fbf51 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -109,6 +109,7 @@ class _column(object): self.selectable = True self.group_operator = args.get('group_operator', False) self.groups = False # CSV list of ext IDs of groups that can access this field + self.deprecated = False # Optional deprecation warning for a in args: if args[a]: setattr(self, a, args[a]) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index d8861a20c26..b47c419d0d4 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3598,6 +3598,13 @@ class BaseModel(object): record[f] = res2[record['id']] else: record[f] = [] + + # Warn about deprecated fields now that fields_pre and fields_post are computed + for f in fields_pre + fields_post: + field_column = (f != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(f).column) + if field_column and field_column.deprecated: + _logger.warning('Field %s.%s is deprecated: %s', self._name, f, field_column.deprecated) + readonly = None for vals in res: for field in vals.copy(): @@ -3975,6 +3982,9 @@ class BaseModel(object): direct = [] totranslate = context.get('lang', False) and (context['lang'] != 'en_US') for field in vals: + field_column = (f != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(field).column) + if field_column and field_column.deprecated: + _logger.warning('Field %s.%s is deprecated: %s', self._name, field, field_column.deprecated) if field in self._columns: if self._columns[field]._classic_write and not (hasattr(self._columns[field], '_fnct_inv')): if (not totranslate) or not self._columns[field].translate: From 90c695d14191bfa320a44b8dfa49a989a8e209c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 9 Aug 2012 10:41:48 +0200 Subject: [PATCH 02/14] [FIX] f -> field bzr revid: tde@openerp.com-20120809084148-a3wf9cihllhhmo82 --- openerp/osv/orm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index b47c419d0d4..9798b671e1d 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3982,7 +3982,7 @@ class BaseModel(object): direct = [] totranslate = context.get('lang', False) and (context['lang'] != 'en_US') for field in vals: - field_column = (f != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(field).column) + field_column = (field != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(field).column) if field_column and field_column.deprecated: _logger.warning('Field %s.%s is deprecated: %s', self._name, field, field_column.deprecated) if field in self._columns: From 79e035a3a223ebf3dcf801bd58fbb562878b247e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 9 Aug 2012 13:23:34 +0200 Subject: [PATCH 03/14] [REM] point of sale: removed references to check_dtls, unexistent field. bzr revid: tde@openerp.com-20120809112334-i35nbq54zhkqo1dc --- addons/point_of_sale/account_statement_demo.xml | 1 - addons/point_of_sale/wizard/pos_close_statement.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/addons/point_of_sale/account_statement_demo.xml b/addons/point_of_sale/account_statement_demo.xml index e8ee0a7c349..982e0480aeb 100644 --- a/addons/point_of_sale/account_statement_demo.xml +++ b/addons/point_of_sale/account_statement_demo.xml @@ -12,7 +12,6 @@ - diff --git a/addons/point_of_sale/wizard/pos_close_statement.py b/addons/point_of_sale/wizard/pos_close_statement.py index 336d9d51283..b5850e722d5 100644 --- a/addons/point_of_sale/wizard/pos_close_statement.py +++ b/addons/point_of_sale/wizard/pos_close_statement.py @@ -52,8 +52,6 @@ class pos_close_statement(osv.osv_memory): statement_obj.write(cr, uid, [statement.id], { 'balance_end_real': statement.balance_end }, context=context) - if not statement.journal_id.check_dtls: - statement_obj.button_confirm_cash(cr, uid, [statement.id], context=context) tree_res = mod_obj.get_object_reference(cr, uid, 'point_of_sale', 'view_cash_statement_pos_tree') tree_id = tree_res and tree_res[1] or False From 87625fd7421ead39cef9aa5f888721b11693696d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 9 Aug 2012 14:09:26 +0200 Subject: [PATCH 04/14] [IMP] deprecated feature: added protection against read/write on non-existing columns. The ORM already throws warnings, no need to crash in addition :) . bzr revid: tde@openerp.com-20120809120926-ngl31imcggzz9wzt --- openerp/osv/orm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 9798b671e1d..8c727424890 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3601,7 +3601,7 @@ class BaseModel(object): # Warn about deprecated fields now that fields_pre and fields_post are computed for f in fields_pre + fields_post: - field_column = (f != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(f).column) + field_column = (f != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(f) and self._all_columns.get(f).column) if field_column and field_column.deprecated: _logger.warning('Field %s.%s is deprecated: %s', self._name, f, field_column.deprecated) @@ -3982,7 +3982,7 @@ class BaseModel(object): direct = [] totranslate = context.get('lang', False) and (context['lang'] != 'en_US') for field in vals: - field_column = (field != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(field).column) + field_column = (field != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(field) and self._all_columns.get(field).column) if field_column and field_column.deprecated: _logger.warning('Field %s.%s is deprecated: %s', self._name, field, field_column.deprecated) if field in self._columns: From 8fef0b9a570cf0cfa5bb003e96e5d31519607deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 10 Aug 2012 09:32:42 +0200 Subject: [PATCH 05/14] [IMP] Removed unnecessary conditions. bzr revid: tde@openerp.com-20120810073242-5nc7h84x9r17kabl --- openerp/osv/orm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 8c727424890..345f26d7cb2 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3601,7 +3601,7 @@ class BaseModel(object): # Warn about deprecated fields now that fields_pre and fields_post are computed for f in fields_pre + fields_post: - field_column = (f != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(f) and self._all_columns.get(f).column) + field_column = self._all_columns.get(f) and self._all_columns.get(f).column if field_column and field_column.deprecated: _logger.warning('Field %s.%s is deprecated: %s', self._name, f, field_column.deprecated) @@ -3982,7 +3982,7 @@ class BaseModel(object): direct = [] totranslate = context.get('lang', False) and (context['lang'] != 'en_US') for field in vals: - field_column = (field != self.CONCURRENCY_CHECK_FIELD and self._all_columns.get(field) and self._all_columns.get(field).column) + field_column = self._all_columns.get(field) and self._all_columns.get(field).column if field_column and field_column.deprecated: _logger.warning('Field %s.%s is deprecated: %s', self._name, field, field_column.deprecated) if field in self._columns: From 29eb174ce5f065698f5837c35a1dd9a05b236fd4 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 14 Aug 2012 08:51:36 +0200 Subject: [PATCH 06/14] [ADD] mail: mail groups extract groups and add new features to them? bzr revid: fp@tinyerp.com-20120814065136-nlwh14rwbgj57tqx --- addons/mail/__init__.py | 1 + addons/mail/mail_group.py | 9 +- addons/mail/mail_group_menu.py | 240 +++++++++++++++++++++++++ addons/mail/mail_group_view.xml | 51 +++--- addons/mail/security/mail_security.xml | 13 +- 5 files changed, 273 insertions(+), 41 deletions(-) create mode 100644 addons/mail/mail_group_menu.py diff --git a/addons/mail/__init__.py b/addons/mail/__init__.py index cbd477f55e6..b19aad1afe3 100644 --- a/addons/mail/__init__.py +++ b/addons/mail/__init__.py @@ -30,6 +30,7 @@ import res_partner import report import wizard import res_config +import mail_group_menu # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index b850f1c29f7..31ac9636670 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -89,15 +89,16 @@ class mail_group(osv.osv): return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64')) _columns = { - 'name': fields.char('Name', size=64, required=True), + 'name': fields.char('Group Name', size=64, required=True), 'description': fields.text('Description'), 'responsible_id': fields.many2one('res.users', string='Responsible', ondelete='set null', required=True, select=1, help="Responsible of the group that has all rights on the record."), - 'public': fields.boolean('Visible by non members', help='This group is visible by non members. \ + 'public': fields.selection([('public','Public'),('private','Private'),('employee','Employees Only')], 'Privacy', required=True, + help='This group is visible by non members. \ Invisible groups can add members through the invite button.'), 'group_ids': fields.many2many('res.groups', rel='mail_group_res_group_rel', - id1='mail_group_id', id2='groups_id', string='Linked groups', + id1='mail_group_id', id2='groups_id', string='Auto Subscription', help="Members of those groups will automatically added as followers. "\ "Note that they will be able to manage their subscription manually "\ "if necessary."), @@ -135,7 +136,7 @@ class mail_group(osv.osv): } _defaults = { - 'public': True, + 'public': 'employee', 'responsible_id': (lambda s, cr, uid, ctx: uid), 'image': _get_default_image, } diff --git a/addons/mail/mail_group_menu.py b/addons/mail/mail_group_menu.py new file mode 100644 index 00000000000..af03f0956d2 --- /dev/null +++ b/addons/mail/mail_group_menu.py @@ -0,0 +1,240 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-today OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see +# +############################################################################## + +import datetime as DT +import openerp +import openerp.tools as tools +from operator import itemgetter +from osv import osv +from osv import fields +import tools +from tools.translate import _ +from lxml import etree + +class ir_ui_menu(osv.osv): + _inherit = 'ir.ui.menu' + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): + context = context or {} + ids = super(ir_ui_menu, self).search(cr, uid, args, offset=0, + limit=None, order=order, context=context, count=False) + if context.get('ir.ui.menu.full_list'): + return ids + + root_group = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'mail_group_root') + if not root_group: + return ids + root_group = root_group[1] + + print 'Root Group', root_group, ids, args + for a in args: + if a[0]=='id': + return ids + if a[0]=='parent_id': + if (a[1] == 'child_of'): + if root_group not in ids: + return ids + elif (a[1] == 'in'): + if root_group not in a[2]: + return ids + elif (a[1] <> '='): + if a[2] <> root_group: + return ids + + print 'Got IT' + subs = self.pool.get('mail.subscription') + sub_ids = subs.search(cr, uid, [('user_id','=',uid),('res_model','=','mail.group')], context=context) + result = ids + map(lambda x: 'group-'+str(x.res_id), subs.browse(cr, uid, sub_ids, context=context)) + print 'END SEARCH', result + return result + + def _read_flat(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): + group_ids = filter(lambda x: type(x)==str and x.startswith('group-'), ids) + nongroup_ids = filter(lambda x: x not in group_ids, ids) + print 'READ ***', ids, nongroup_ids, group_ids + result = super(ir_ui_menu, self)._read_flat(cr, uid, nongroup_ids, fields, context, load) + + group_ids = map(lambda x: int(x[6:]), group_ids) + root_group = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'mail_group_root') + if not root_group: + return result + root_group = root_group[1] + + for group in self.pool.get('mail.group').browse(cr, uid, group_ids, context=context): + data = { + 'id': 'group-'+str(group.id), + 'name': group.name, + 'child_id': [], + 'parent_id': root_group, + 'complete_name': group.name, + 'needaction_enabled': 1, + 'needaction_counter': 1, # to compute + 'action': 'ir.actions.client,1' + } + for key in fields or []: + data.setdefault(key, False) + for key in data.keys(): + if fields and key not in fields: + del data[key] + result.append(data) + + print result + return result + + + def _get_image(self, cr, uid, ids, name, args, context=None): + result = dict.fromkeys(ids, False) + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = tools.image_get_resized_images(obj.image) + return result + + def _set_image(self, cr, uid, id, name, value, args, context=None): + return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) + + def get_member_ids(self, cr, uid, ids, field_names, args, context=None): + if context is None: + context = {} + result = dict.fromkeys(ids) + for id in ids: + result[id] = {} + result[id]['member_ids'] = self.message_get_subscribers(cr, uid, [id], context=context) + result[id]['member_count'] = len(result[id]['member_ids']) + result[id]['is_subscriber'] = uid in result[id]['member_ids'] + return result + + def search_member_ids(self, cr, uid, obj, name, args, context=None): + if context is None: + context = {} + sub_obj = self.pool.get('mail.subscription') + sub_ids = sub_obj.search(cr, uid, ['&', ('res_model', '=', obj._name), ('user_id', '=', args[0][2])], context=context) + subs = sub_obj.read(cr, uid, sub_ids, context=context) + return [('id', 'in', map(itemgetter('res_id'), subs))] + + def get_last_month_msg_nbr(self, cr, uid, ids, name, args, context=None): + result = {} + message_obj = self.pool.get('mail.message') + for id in ids: + lower_date = (DT.datetime.now() - DT.timedelta(days=30)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + result[id] = self.message_search(cr, uid, [id], limit=None, domain=[('date', '>=', lower_date)], count=True, context=context) + return result + + def _get_default_image(self, cr, uid, context=None): + image_path = openerp.modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png') + return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64')) + + _columns = { + 'name': fields.char('Group Name', size=64, required=True), + 'description': fields.text('Description'), + 'responsible_id': fields.many2one('res.users', string='Responsible', + ondelete='set null', required=True, select=1, + help="Responsible of the group that has all rights on the record."), + 'public': fields.selection([('public','Public'),('private','Private'),('employee','Employees Only')], 'Privacy', required=True, + help='This group is visible by non members. \ + Invisible groups can add members through the invite button.'), + 'group_ids': fields.many2many('res.groups', rel='mail_group_res_group_rel', + id1='mail_group_id', id2='groups_id', string='Auto Subscription', + help="Members of those groups will automatically added as followers. "\ + "Note that they will be able to manage their subscription manually "\ + "if necessary."), + 'image': fields.binary("Photo", + help="This field holds the image used as photo for the "\ + "user. The image is base64 encoded, and PIL-supported. "\ + "It is limited to a 12024x1024 px image."), + 'image_medium': fields.function(_get_image, fnct_inv=_set_image, + string="Medium-sized photo", type="binary", multi="_get_image", + store = { + 'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized photo of the group. It is automatically "\ + "resized as a 180x180px image, with aspect ratio preserved. "\ + "Use this field in form views or some kanban views."), + 'image_small': fields.function(_get_image, fnct_inv=_set_image, + string="Small-sized photo", type="binary", multi="_get_image", + store = { + 'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized photo of the group. It is automatically "\ + "resized as a 50x50px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required."), + 'member_ids': fields.function(get_member_ids, fnct_search=search_member_ids, + type='many2many', relation='res.users', string='Group members', multi='get_member_ids'), + 'member_count': fields.function(get_member_ids, type='integer', + string='Member count', multi='get_member_ids'), + 'is_subscriber': fields.function(get_member_ids, type='boolean', + string='Joined', multi='get_member_ids'), + 'last_month_msg_nbr': fields.function(get_last_month_msg_nbr, type='integer', + string='Messages count for last month'), + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, + help="The email address associated with this group. New emails received will automatically " + "create new topics."), + } + + _defaults = { + 'public': 'employee', + 'responsible_id': (lambda s, cr, uid, ctx: uid), + 'image': _get_default_image, + } + + def _subscribe_user_with_group_m2m_command(self, cr, uid, ids, group_ids_command, context=None): + # form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]} + user_group_ids = [command[1] for command in group_ids_command if command[0] == 4] + user_group_ids += [id for command in group_ids_command if command[0] == 6 for id in command[2]] + # retrieve the user member of those groups + user_ids = [] + res_groups_obj = self.pool.get('res.groups') + for group in res_groups_obj.browse(cr, uid, user_group_ids, context=context): + user_ids += [user.id for user in group.users] + # subscribe the users + return self.message_subscribe(cr, uid, ids, user_ids, context=context) + + def create(self, cr, uid, vals, context=None): + alias_pool = self.pool.get('mail.alias') + if not vals.get('alias_id'): + name = vals.get('alias_name') or vals['name'] + alias_id = alias_pool.create_unique_alias(cr, uid, + {'alias_name': "group_"+name}, + model_name=self._name, context=context) + vals['alias_id'] = alias_id + mail_group_id = super(mail_group, self).create(cr, uid, vals, context) + alias_pool.write(cr, uid, [vals['alias_id']], {"alias_force_thread_id": mail_group_id}, context) + + if vals.get('group_ids'): + self._subscribe_user_with_group_m2m_command(cr, uid, [mail_group_id], vals.get('group_ids'), context=context) + + return mail_group_id + + def unlink(self, cr, uid, ids, context=None): + # Cascade-delete mail aliases as well, as they should not exist without the mail group. + mail_alias = self.pool.get('mail.alias') + alias_ids = [group.alias_id.id for group in self.browse(cr, uid, ids, context=context) if group.alias_id] + res = super(mail_group, self).unlink(cr, uid, ids, context=context) + mail_alias.unlink(cr, uid, alias_ids, context=context) + return res + + def write(self, cr, uid, ids, vals, context=None): + if vals.get('group_ids'): + self._subscribe_user_with_group_m2m_command(cr, uid, ids, vals.get('group_ids'), context=context) + return super(mail_group, self).write(cr, uid, ids, vals, context=context) + + def action_group_join(self, cr, uid, ids, context=None): + return self.message_subscribe(cr, uid, ids, context=context) + + def action_group_leave(self, cr, uid, ids, context=None): + return self.message_unsubscribe(cr, uid, ids, context=context) diff --git a/addons/mail/mail_group_view.xml b/addons/mail/mail_group_view.xml index 5c81d426d6a..126e8649a72 100644 --- a/addons/mail/mail_group_view.xml +++ b/addons/mail/mail_group_view.xml @@ -51,35 +51,31 @@
- - - - - -
-
-
-

-
- -
+ +
+
+
+

+ +
+
+ + + + + + + -