diff --git a/addons/account/invoice.py b/addons/account/invoice.py index b810ef02a74..87874c0a1b2 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -415,7 +415,7 @@ class account_invoice(osv.osv): def onchange_currency_id(self, cr, uid, ids, curr_id, company_id): if curr_id: currency = self.pool.get('res.currency').browse(cr, uid, curr_id) - if currency.company_id != company_id: + if currency.company_id.id != company_id: raise osv.except_osv(_('Configration Error !'), _('Can not select currency that is not related to current company.\nPlease select accordingly !.')) return {} diff --git a/addons/caldav/calendar.py b/addons/caldav/calendar.py index 2d8edb1b204..9ec36538b0b 100644 --- a/addons/caldav/calendar.py +++ b/addons/caldav/calendar.py @@ -161,12 +161,12 @@ class CalDAV(object): if cal_data.name.lower() == 'attendee': attendee = self.pool.get('basic.calendar.attendee') att_data.append(attendee.import_ical(cr, uid, cal_data)) - self.ical_set(cal_data.name.lower(), cal_data.value, 'value') + self.ical_set(cal_data.name.lower(), att_data, 'value') continue if cal_data.name.lower() == 'valarm': alarm = self.pool.get('basic.calendar.alarm') vals = alarm.import_ical(cr, uid, cal_data) - self.ical_set(cal_data.name.lower(), cal_data.value, 'value') + self.ical_set(cal_data.name.lower(), vals, 'value') continue if cal_data.name.lower() in self.__attribute__: self.ical_set(cal_data.name.lower(), cal_data.value, 'value') diff --git a/addons/caldav/common.py b/addons/caldav/common.py index a96d40e2a9c..208b88dd6e3 100644 --- a/addons/caldav/common.py +++ b/addons/caldav/common.py @@ -20,7 +20,7 @@ ############################################################################## -from datetime import datetime +from datetime import datetime, timedelta from osv import fields, osv from service import web_services from tools.translate import _ @@ -32,7 +32,7 @@ months = { 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", \ 10:"October", 11:"November", 12:"December"} -def caldav_id2real_id(caldav_id = None, with_date=False): +def caldav_id2real_id(caldav_id=None, with_date=False): if caldav_id and isinstance(caldav_id, (str, unicode)): res = caldav_id.split('-') if len(res) >= 2: @@ -135,24 +135,30 @@ class calendar_attendee(osv.osv): fromdata = map(get_delegate_data, attdata.del_from_user_ids) result[id][name] = ', '.join(fromdata) if name == 'event_date': + # TO fix date for project task if attdata.ref: model, res_id = tuple(attdata.ref.split(',')) model_obj = self.pool.get(model) obj = model_obj.read(cr, uid, res_id, ['date'])[0] - result[id][name] = obj['date'] + result[id][name] = None#obj['date'] + else: + result[id][name] = None if name == 'event_end_date': if attdata.ref: model, res_id = tuple(attdata.ref.split(',')) model_obj = self.pool.get(model) obj = model_obj.read(cr, uid, res_id, ['date_deadline'])[0] result[id][name] = obj['date_deadline'] - + else: + result[id][name] = None if name == 'sent_by_uid': if attdata.ref: model, res_id = tuple(attdata.ref.split(',')) model_obj = self.pool.get(model) obj = model_obj.read(cr, uid, res_id, ['user_id'])[0] result[id][name] = obj['user_id'] + else: + result[id][name] = uid return result def _links_get(self, cr, uid, context={}): @@ -319,11 +325,11 @@ or contains the text to be used for display"""), if event_date: dtstart = datetime.strptime(vals['event_date'], "%Y-%m-%d %H:%M:%S") if vals['trigger_interval'] == 'days': - delta = datetime.timedelta(days=vals['trigger_duration']) + delta = timedelta(days=vals['trigger_duration']) if vals['trigger_interval'] == 'hours': - delta = datetime.timedelta(hours=vals['trigger_duration']) + delta = timedelta(hours=vals['trigger_duration']) if vals['trigger_interval'] == 'minutes': - delta = datetime.timedelta(minutes=vals['trigger_duration']) + delta = timedelta(minutes=vals['trigger_duration']) trigger_date = dtstart + (vals['trigger_occurs'] == 'after' and delta or -delta) vals['trigger_date'] = trigger_date res = super(calendar_alarm, self).create(cr, uid, vals, context) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index a0c45978b71..53173754b8e 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -223,11 +223,33 @@ class crm_case(osv.osv): else: res[case.id] = False return res + def copy(self, cr, uid, id, default=None, context={}): if not default: default = {} - default.update( {'state':'draft', 'id':False, 'history_line':[],'log_ids':[]}) + default.update( {'state':'draft', 'id':False}) return super(crm_case, self).copy(cr, uid, id, default, context) + def _get_log_ids(self, cr, uid, ids, field_names, arg, context={}): + result = {} + history_obj = False + model_obj = self.pool.get('ir.model') + if 'history_line' in field_names: + history_obj = self.pool.get('crm.case.history') + name = 'history_line' + if 'log_ids' in field_names: + history_obj = self.pool.get('crm.case.log') + name = 'log_ids' + if not history_obj: + return result + for case in self.browse(cr, uid, ids, context): + model_ids = model_obj.search(cr, uid, [('model','=',case._name)]) + history_ids = history_obj.search(cr, uid, [('model_id','=',model_ids[0]),('res_id','=',case.id)]) + if history_ids: + result[case.id] = {name:history_ids} + else: + result[case.id] = {name:[]} + return result + _columns = { 'id': fields.integer('ID', readonly=True), 'name': fields.char('Description',size=64,required=True), @@ -245,8 +267,8 @@ class crm_case(osv.osv): 'create_date': fields.datetime('Created' ,readonly=True), 'date_deadline': fields.datetime('Deadline'), 'user_id': fields.many2one('res.users', 'Responsible'), - 'history_line': fields.one2many('crm.case.history', 'case_id', 'Communication', readonly=1), - 'log_ids': fields.one2many('crm.case.log', 'case_id', 'Logs History', readonly=1), + 'history_line': fields.function(_get_log_ids, method=True, type='one2many', multi="history_line", relation="crm.case.history", string="Communication"), + 'log_ids': fields.function(_get_log_ids, method=True, type='one2many', multi="log_ids", relation="crm.case.log", string="Logs History"), 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True, help='The state is set to \'Draft\', when a case is created.\ \nIf the case is in progress the state is set to \'Open\'.\ @@ -495,32 +517,17 @@ class crm_case(osv.osv): } return self.format_body(body % data) - def email_send(self, cr, uid, case, emails, body, context={}): - body = self.format_mail(case, body) - if case.user_id and case.user_id.address_id and case.user_id.address_id.email: - emailfrom = case.user_id.address_id.email - else: - emailfrom = case.section_id.reply_to - name = '[%d] %s' % (case.id, case.name.encode('utf8')) - reply_to = case.section_id.reply_to or False - if reply_to: reply_to = reply_to.encode('utf8') - if not emailfrom: - raise osv.except_osv(_('Error!'), - _("No E-Mail ID Found for your Company address or missing reply address in section!")) - tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, tinycrm=str(case.id)) - return True - def __history(self, cr, uid, cases, keyword, history=False, email=False, details=None, context={}): - + model_obj = self.pool.get('ir.model') for case in cases: + model_ids = model_obj.search(cr, uid, [('model','=',case._name)]) data = { - 'name': keyword, - 'som': case.som.id, - 'canal_id': case.canal_id.id, + 'name': keyword, 'user_id': uid, 'date': time.strftime('%Y-%m-%d %H:%M:%S'), - 'case_id': case.id, + 'model_id' : model_ids and model_ids[0] or False, + 'res_id': case.id, 'section_id': case.section_id.id } obj = self.pool.get('crm.case.log') @@ -530,7 +537,7 @@ class crm_case(osv.osv): data['email'] = email or \ (case.user_id and case.user_id.address_id and \ case.user_id.address_id.email) or False - obj.create(cr, uid, data, context) + res = obj.create(cr, uid, data, context) return True _history = __history @@ -590,8 +597,8 @@ class crm_case(osv.osv): def add_reply(self, cursor, user, ids, context=None): for case in self.browse(cursor, user, ids, context=context): - if case.history_line: - description = case.history_line[0].description + if case.email_last: + description = email_last self.write(cursor, user, case.id, { 'description': '> ' + description.replace('\n','\n> '), }, context=context) @@ -740,7 +747,8 @@ class crm_case_log(osv.osv): 'canal_id': fields.many2one('res.partner.canal', 'Channel'), 'section_id': fields.many2one('crm.case.section', 'Section'), 'user_id': fields.many2one('res.users', 'User Responsible', readonly=True), - 'case_id': fields.many2one('crm.case', 'Case', required=True, ondelete='cascade') + 'model_id': fields.many2one('ir.model', "Model"), + 'res_id': fields.integer('Resource ID'), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), @@ -754,9 +762,9 @@ class crm_case_history(osv.osv): _inherits = {'crm.case.log':"log_id"} def create(self, cr, user, vals, context=None): - if vals.has_key('case_id') and vals['case_id']: - case_obj = self.pool.get('crm.case') - cases = case_obj.browse(cr, user, [vals['case_id']]) + if vals.has_key('res_id') and vals['res_id']: + case_obj = self.pool.get(vals['model_id']) + cases = case_obj.browse(cr, user, [vals['res_id']]) case_obj._action(cr, user, cases, '') return super(crm_case_history, self).create(cr, user, vals, context) @@ -845,4 +853,3 @@ users() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm/crm_mailgate.py b/addons/crm/crm_mailgate.py index e64bb34e12f..6189bb7088a 100644 --- a/addons/crm/crm_mailgate.py +++ b/addons/crm/crm_mailgate.py @@ -44,13 +44,15 @@ class crm_cases(osv.osv): 'email_from': msg['From'], 'email_cc': msg['Cc'], 'user_id': False, - 'description': msg_body['body'], - 'history_line': [(0, 0, {'description': msg_body['body'], 'email': msg['From'] })], + 'description': msg_body['body'], } res = mailgate_obj.partner_get(cr, uid, msg['From']) if res: data.update(res) - return self.create(cr, uid, data) + res = self.create(cr, uid, data) + cases = self.browse(cr, uid, [res]) + self.__history(cr, uid, cases, _('Receive'), history=True, email=msg['From']) + return res def msg_update(self, cr, uid, ids, msg, data={}, default_act='pending'): mailgate_obj = self.pool.get('mail.gateway') diff --git a/addons/crm/crm_meeting.py b/addons/crm/crm_meeting.py index cbdb7998a38..8eabe65d9bd 100644 --- a/addons/crm/crm_meeting.py +++ b/addons/crm/crm_meeting.py @@ -113,9 +113,16 @@ class crm_meeting(osv.osv): return {'value': {'rrule': rrulestr}} _columns = { + 'id': fields.integer('ID', readonly=True), 'name': fields.char('Description', size=64, required=True), 'section_id': fields.many2one('crm.case.section', 'Section', select=True, help='Section to which Case belongs to. Define Responsible user and Email \ account for mail gateway.'), + 'priority': fields.selection([('5','Lowest'), + ('4','Low'), + ('3','Normal'), + ('2','High'), + ('1','Highest') + ], 'Priority'), 'date': fields.datetime('Date'), 'date_deadline': fields.datetime('Deadline'), 'duration': fields.function(_get_duration, method=True, \ @@ -125,6 +132,7 @@ account for mail gateway.'), help='Category related to the section.Subdivide the CRM cases \ independently or section-wise.'), 'description': fields.text('Your action'), + 'user_id': fields.many2one('res.users', 'Responsible'), 'class': fields.selection([('public', 'Public'), ('private', 'Private'), \ ('confidential', 'Confidential')], 'Mark as'), 'location': fields.char('Location', size=264, help="Location of Meeting"), @@ -140,7 +148,7 @@ rule or repeating pattern for anexception to a recurrence set"), 'rrule_type': fields.selection([('none', 'None'), ('daily', 'Daily'), \ ('weekly', 'Weekly'), ('monthly', 'Monthly'), \ ('yearly', 'Yearly'), ('custom', 'Custom')], 'Recurrency'), - 'attendee_ids': fields.many2many('calendar.attendee', 'crm_attendee_rel', 'case_id', 'attendee_id', 'Attendees'), + 'attendee_ids': fields.many2many('calendar.attendee', 'crm_attendee_rel', 'case_id', 'attendee_id', 'Attendees'), 'alarm_id': fields.many2one('res.alarm', 'Alarm'), 'caldav_alarm_id': fields.many2one('calendar.alarm', 'Alarm'), } @@ -156,8 +164,8 @@ rule or repeating pattern for anexception to a recurrence set"), model_id = model_obj.search(cr, uid, [('model', '=', self._name)])[0] for meeting in self.browse(cr, uid, ids): - self.do_alarm_unlink(cr, uid, [meeting.id]) basic_alarm = meeting.alarm_id + self.do_alarm_unlink(cr, uid, [meeting.id]) if basic_alarm: vals = { 'action': 'display', @@ -177,8 +185,8 @@ rule or repeating pattern for anexception to a recurrence set"), 'user_id': uid } alarm_id = alarm_obj.create(cr, uid, vals) - cr.execute('Update crm_meeting set caldav_alarm_id=%s \ - where id=%s' % (alarm_id, meeting.id)) + cr.execute('Update crm_meeting set caldav_alarm_id=%s, \ + alarm_id=%s where id=%s' % (alarm_id, basic_alarm.id, meeting.id)) cr.commit() return True @@ -221,6 +229,14 @@ rule or repeating pattern for anexception to a recurrence set"), file_content = base64.decodestring(data) event_obj = self.pool.get('basic.calendar.event') event_obj.__attribute__.update(self.__attribute__) + + attendee_obj = self.pool.get('basic.calendar.attendee') + attendee = self.pool.get('calendar.attendee') + attendee_obj.__attribute__.update(attendee.__attribute__) + + alarm_obj = self.pool.get('basic.calendar.alarm') + alarm = self.pool.get('calendar.alarm') + alarm_obj.__attribute__.update(alarm.__attribute__) vals = event_obj.import_ical(cr, uid, file_content) ids = [] @@ -337,10 +353,9 @@ rule or repeating pattern for anexception to a recurrence set"), id = common.caldav_id2real_id(id) if not id in new_ids: new_ids.append(id) - if 'case_id' in vals: - vals['case_id'] = common.caldav_id2real_id(vals['case_id']) res = super(crm_meeting, self).write(cr, uid, new_ids, vals, context=context) - self.do_alarm_create(cr, uid, new_ids) + if vals.get('alarm_id'): + self.do_alarm_create(cr, uid, new_ids) return res def browse(self, cr, uid, ids, context=None, list_class=None, fields_process={}): @@ -399,13 +414,12 @@ rule or repeating pattern for anexception to a recurrence set"), res = super(crm_meeting, self).unlink(cr, uid, common.caldav_id2real_id(ids)) self.do_alarm_unlink(cr, uid, ids) else: + ids = map(lambda x: common.caldav_id2real_id(x), ids) res = super(crm_meeting, self).unlink(cr, uid, ids) self.do_alarm_unlink(cr, uid, ids) return res def create(self, cr, uid, vals, context={}): - if 'case_id' in vals: - vals['case_id'] = common.caldav_id2real_id(vals['case_id']) res = super(crm_meeting, self).create(cr, uid, vals, context) self.do_alarm_create(cr, uid, [res]) return res @@ -430,59 +444,6 @@ rule or repeating pattern for anexception to a recurrence set"), crm_meeting() - -class crm_meeting_generic_wizard(osv.osv_memory): - _name = 'crm.meeting.generic_wizard' - - _columns = { - 'section_id': fields.many2one('crm.case.section', 'Section', required=False), - 'user_id': fields.many2one('res.users', 'Responsible'), - } - - def _get_default_section(self, cr, uid, context): - case_id = context.get('active_id', False) - if not case_id: - return False - case_obj = self.pool.get('crm.meeting') - case = case_obj.read(cr, uid, case_id, ['state', 'section_id']) - if case['state'] in ('done'): - raise osv.except_osv(_('Error !'), _('You can not assign Closed Case.')) - return case['section_id'] - - - _defaults = { - 'section_id': _get_default_section - } - - def action_create(self, cr, uid, ids, context=None): - case_obj = self.pool.get('crm.meeting') - case_id = context.get('active_id', []) - res = self.read(cr, uid, ids)[0] - case = case_obj.browse(cr, uid, case_id) - if case.state in ('done'): - raise osv.except_osv(_('Error !'), _('You can not assign Closed Case.')) - new_case_id = case_obj.copy(cr, uid, case_id, default= { - 'section_id': res.get('section_id', False), - 'user_id': res.get('user_id', False), - 'case_id': case.inherit_case_id.id - }, context=context) - case_obj.case_close(cr, uid, [case_id]) - data_obj = self.pool.get('ir.model.data') - result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter') - search_view = data_obj.read(cr, uid, result, ['res_id']) - new_case = case_obj.read(cr, uid, new_case_id, ['id']) - value = { - 'name': _('Meetings'), - 'view_type': 'form', - 'view_mode': 'calendar, tree, form', - 'res_model': 'crm.meeting', - 'type': 'ir.actions.act_window', - 'search_view_id': search_view['res_id'] - } - return value - -crm_meeting_generic_wizard() - class res_users(osv.osv): _inherit = 'res.users' def _get_user_avail(self, cr, uid, ids, context=None): diff --git a/addons/crm/crm_meeting_data.xml b/addons/crm/crm_meeting_data.xml index c3244e88f3f..540133d6753 100644 --- a/addons/crm/crm_meeting_data.xml +++ b/addons/crm/crm_meeting_data.xml @@ -4,7 +4,7 @@ Meetings - Mtngs + Mtngs diff --git a/addons/crm/crm_meeting_view.xml b/addons/crm/crm_meeting_view.xml index 7a4ab7e8878..ae25a907176 100644 --- a/addons/crm/crm_meeting_view.xml +++ b/addons/crm/crm_meeting_view.xml @@ -5,34 +5,6 @@ # Meetings # ------------------------------------------------------ - - crm.meeting.generic_wizard.form - crm.meeting.generic_wizard - form - -
- - - - - - - -