summaryrefslogtreecommitdiff
path: root/addons/project_issue
diff options
context:
space:
mode:
authorMustufa Rangwala <mra@mra-laptop>2010-06-25 08:32:07 +0530
committerMustufa Rangwala <mra@mra-laptop>2010-06-25 08:32:07 +0530
commitf32f30aefb7db4b9f3ebfb23b1c15ee2ca9e99c2 (patch)
tree45c13556a17b6ecf4b574af1f37a4262dbf69d1f /addons/project_issue
parent1aa2d4c59cd3d59778b4c87c611478537217e998 (diff)
parent59f9be67f791f40d698b7183b81f7a7abc34a654 (diff)
[MERGE] Merge with trunk addons
bzr revid: mra@mra-laptop-20100625030207-r995xyuf3zjt7eho
Diffstat (limited to 'addons/project_issue')
-rw-r--r--addons/project_issue/project_issue.py131
1 files changed, 129 insertions, 2 deletions
diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py
index 675818214a5..3523485f542 100644
--- a/addons/project_issue/project_issue.py
+++ b/addons/project_issue/project_issue.py
@@ -31,6 +31,9 @@ from crm import crm
from osv import fields,osv,orm
from osv.orm import except_orm
from tools.translate import _
+import collections
+import binascii
+import tools
class project_issue(osv.osv, crm.crm_case):
_name = "project.issue"
@@ -178,8 +181,8 @@ class project_issue(osv.osv, crm.crm_case):
method=True, multi='working_days_open', type="float", store=True),
'working_hours_close': fields.function(_compute_day, string='Working Hours to Close the Issue', \
method=True, multi='working_days_close', type="float", store=True),
- 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
- 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]),
}
def _get_project(self, cr, uid, context):
@@ -299,5 +302,129 @@ class project_issue(osv.osv, crm.crm_case):
self.write(cr, uid, [case.id], data)
return True
+ def message_new(self, cr, uid, msg, context):
+ """
+ Automatically calls when new email message arrives
+
+ @param self: The object pointer
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks
+ """
+
+ mailgate_pool = self.pool.get('email.server.tools')
+
+ subject = msg.get('subject')
+ body = msg.get('body')
+ msg_from = msg.get('from')
+ priority = msg.get('priority')
+
+ vals = {
+ 'name': subject,
+ 'email_from': msg_from,
+ 'email_cc': msg.get('cc'),
+ 'description': body,
+ 'user_id': False,
+ }
+ if msg.get('priority', False):
+ vals['priority'] = priority
+
+ res = mailgate_pool.get_partner(cr, uid, msg.get('from'))
+ if res:
+ vals.update(res)
+ res = self.create(cr, uid, vals, context)
+
+
+ attachents = msg.get('attachments', [])
+ for attactment in attachents or []:
+ data_attach = {
+ 'name': attactment,
+ 'datas':binascii.b2a_base64(str(attachents.get(attactment))),
+ 'datas_fname': attactment,
+ 'description': 'Mail attachment',
+ 'res_model': self._name,
+ 'res_id': res,
+ }
+ self.pool.get('ir.attachment').create(cr, uid, data_attach)
+
+ return res
+
+ def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context={}):
+ """
+ @param self: The object pointer
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param ids: List of update mail’s IDs
+ """
+
+ if isinstance(ids, (str, int, long)):
+ ids = [ids]
+
+ msg_from = msg['from']
+ vals.update({
+ 'description': msg['body']
+ })
+ if msg.get('priority', False):
+ vals['priority'] = msg.get('priority')
+
+ maps = {
+ 'cost':'planned_cost',
+ 'revenue': 'planned_revenue',
+ 'probability':'probability'
+ }
+ vls = { }
+ for line in msg['body'].split('\n'):
+ line = line.strip()
+ res = tools.misc.command_re.match(line)
+ if res and maps.get(res.group(1).lower(), False):
+ key = maps.get(res.group(1).lower())
+ vls[key] = res.group(2).lower()
+
+ vals.update(vls)
+ res = self.write(cr, uid, ids, vals)
+ return res
+
+ def emails_get(self, cr, uid, ids, context=None):
+
+ """
+ Get Emails
+ @param self: The object pointer
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param ids: List of email’s IDs
+ @param context: A standard dictionary for contextual values
+ """
+ res = {}
+
+ if isinstance(ids, (str, int, long)):
+ select = [long(ids)]
+ else:
+ select = ids
+
+ for thread in self.browse(cr, uid, select, context=context):
+ values = collections.defaultdict(set)
+
+ for message in thread.message_ids:
+ user_email = (message.user_id and message.user_id.address_id and message.user_id.address_id.email) or False
+ values['user_email'].add(user_email)
+ values['email_from'].add(message.email_from)
+ values['email_cc'].add(message.email_cc or False)
+ values['priority'] = thread.priority
+
+ res[thread.id] = dict((key,list(values[key])) for key, value in values.iteritems())
+
+ return res
+
+ def msg_send(self, cr, uid, id, *args, **argv):
+
+ """ Send The Message
+ @param self: The object pointer
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param ids: List of email’s IDs
+ @param *args: Return Tuple Value
+ @param **args: Return Dictionary of Keyword Value
+ """
+ return True
+
project_issue()