bzr revid: mra@tinyerp.com-20100512034842-x9dq66upzod1dh9x
This commit is contained in:
mra (Open ERP) 2010-05-12 09:18:42 +05:30
commit 809ca99874
7 changed files with 76 additions and 42 deletions

View File

@ -315,8 +315,7 @@ class crm_case(osv.osv):
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Description', size=1024, required=True),
'active': fields.boolean('Active', help="If the active field is set to\
true, it will allow you to hide the case without removing it."),
'active': fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the case without removing it."),
'description': fields.text('Description'),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help='Sales team to which Case belongs to.\

View File

@ -113,7 +113,7 @@ class crm_lead(osv.osv):
'type_id': fields.many2one('crm.case.resource.type', 'Lead Type', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.lead')]"),
'partner_name': fields.char("Contact Name", size=64),
'partner_name': fields.char("Company Name", size=64),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'date_closed': fields.datetime('Closed', readonly=True),

View File

@ -69,7 +69,7 @@
<page string="Lead">
<group colspan="2" col="4">
<separator string="Contact" colspan="4" col="4"/>
<field name="partner_name" string="Contact Name" colspan="4"/>
<field name="partner_name" colspan="4"/>
<newline/>
<field domain="[('domain', '=', 'contact')]" name="title"/>
<field name="function_name" />

View File

@ -168,13 +168,14 @@ class email_parser(object):
def _decode_header(self, s):
from email.Header import decode_header
s = decode_header(s)
s = decode_header(s.replace('\r', ''))
return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), s or []))
def msg_new(self, msg):
message = self.msg_body_get(msg)
msg_subject = self._decode_header(msg['Subject'])
msg_from = self._decode_header(msg['From'])
msg_to = self._decode_header(msg['To'])
msg_cc = self._decode_header(msg['Cc'] or '')
data = {
@ -189,7 +190,7 @@ class email_parser(object):
try:
id = self.rpc(self.model, 'create', data)
self.rpc(self.model, 'history', [id], 'Receive', True, msg['From'], message['body'], False, False, {'model' : self.model})
self.rpc(self.model, 'history', [id], 'Receive', True, msg_to, message['body'], msg_from, False, {'model' : self.model})
#self.rpc(self.model, 'case_open', [id])
except Exception, e:
if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode:
@ -314,7 +315,7 @@ class email_parser(object):
'res_id': id
}
self.rpc('ir.attachment', 'create', data_attach)
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], body['body'])
self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['From']), body['body'])
return id
def msg_send(self, msg, emails, priority=None):
@ -357,7 +358,7 @@ class email_parser(object):
'res_id': id
}
self.rpc('ir.attachment', 'create', data_attach)
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['From']), message['body'])
return id
def msg_test(self, msg, case_str):

View File

@ -26,6 +26,24 @@ import base64
import tools
from crm import crm
class crm_send_new_email(osv.osv_memory):
""" Sends new email for the case"""
_name = "crm.send.mail"
crm_send_new_email()
class crm_send_new_email_attachment(osv.osv_memory):
_name = 'crm.send.mail.attachment'
_columns = {
'binary' : fields.binary('Attachment', required=True),
'name' : fields.char('Name', size=128, required=True),
'wizard_id' : fields.many2one('crm.send.mail', 'Wizard', required=True),
}
crm_send_new_email_attachment()
class crm_send_new_email(osv.osv_memory):
""" Sends new email for the case"""
_name = "crm.send.mail"
@ -38,12 +56,8 @@ class crm_send_new_email(osv.osv_memory):
'subject': fields.char('Subject', size=128, required=True),
'text': fields.text('Message', required=True),
'state': fields.selection(crm.AVAILABLE_STATES, string='Set New State To', required=True),
'doc1': fields.binary("Attachment1"),
'doc1_fname': fields.char("File Name", size=64),
'doc2': fields.binary("Attachment2"),
'doc2_fname': fields.char("File Name", size=64),
'doc3': fields.binary("Attachment3"),
'doc3_fname': fields.char("File Name", size=64),
'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'),
}
def action_cancel(self, cr, uid, ids, context=None):
@ -68,12 +82,13 @@ class crm_send_new_email(osv.osv_memory):
case_pool = self.pool.get(model)
res_id = context and context.get('active_id', False) or False
for data in self.read(cr, uid, ids, context=context):
attach = filter(lambda x: x, [data['doc1'], data['doc2'], data['doc3']])
attach = map(lambda x: (data['doc' + str(attach.index(x) + 1) \
+ '_fname'], base64.decodestring(x)), attach)
message_id = None
for obj in self.browse(cr, uid, ids, context=context):
attach = [
(x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
]
message_id = None
case = case_pool.browse(cr, uid, res_id)
if context.get('mail', 'new') == 'new':
if len(case.history_line):
@ -84,13 +99,13 @@ class crm_send_new_email(osv.osv_memory):
model = hist.log_id.model_id.model
model_pool = self.pool.get(model)
case = model_pool.browse(cr, uid, hist.log_id.res_id)
emails = [data['email_to']] + (data['email_cc'] or '').split(',')
emails = [obj.email_to] + (obj.email_cc or '').split(',')
emails = filter(None, emails)
body = data['text']
body = obj.text
body = case_pool.format_body(body)
email_from = data.get('email_from', False)
case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['email_to'], details=body, email_from=email_from, message_id=message_id)
email_from = getattr(obj, 'email_from', False)
case_pool._history(cr, uid, [case], _('Send'), history=True, email=obj.email_to, details=body, email_from=email_from, message_id=message_id)
x_headers = dict()
#x_headers = {
@ -106,7 +121,7 @@ class crm_send_new_email(osv.osv_memory):
uid=uid,
server_id=case.section_id.server_id.id,
emailto=emails,
subject=data['subject'],
subject=obj.subject,
body="<pre>%s</pre>" % body,
attachments=attach,
headers=x_headers
@ -115,7 +130,7 @@ class crm_send_new_email(osv.osv_memory):
flag = tools.email_send(
email_from,
emails,
data['subject'],
obj.subject,
body,
attach=attach,
reply_to=case.section_id.reply_to,
@ -124,14 +139,14 @@ class crm_send_new_email(osv.osv_memory):
)
if flag:
if data['state'] == 'unchanged':
if obj.state == 'unchanged':
pass
elif data['state'] == 'done':
elif obj.state == 'done':
case_pool.case_close(cr, uid, [case.id])
elif data['state'] == 'draft':
elif obj.state == 'draft':
case_pool.case_reset(cr, uid, [case.id])
elif data['state'] in ['cancel', 'open', 'pending']:
act = 'case_' + data['state']
elif obj.state in ['cancel', 'open', 'pending']:
act = 'case_' + obj.state
getattr(case_pool, act)(cr, uid, [case.id])
cr.commit()
@ -187,6 +202,11 @@ class crm_send_new_email(osv.osv_memory):
res = {}
for hist in hist_obj.browse(cr, uid, res_ids):
model = hist.log_id.model_id.model
# In the case where the crm.case does not exist in the database
if not model:
return {}
model_pool = self.pool.get(model)
case = model_pool.browse(cr, uid, hist.log_id.res_id)
if 'email_to' in fields:
@ -202,7 +222,12 @@ class crm_send_new_email(osv.osv_memory):
to = 'To: %s' % (hist.email_to or '')
sentdate = 'Date: %s' % (hist.date)
desc = '\n%s'%(hist.description)
original = [header, sender, to, sentdate, desc]
signature = ''
if case.user_id.signature:
signature = '--\n' + case.user_id.signature
original = [header, sender, to, sentdate, desc, signature]
original = '\n'.join(original)
res['text']=original
if 'subject' in fields:

View File

@ -19,12 +19,15 @@
<field name="text" nolabel="1" colspan="4"/>
</page>
<page string="Attachments">
<field name="doc1" filename="doc1_fname"/>
<field name="doc1_fname" invisible="1" />
<field name="doc2" filename="doc2_fname" />
<field name="doc2_fname" invisible="1" />
<field name="doc3" filename="doc3_fname" />
<field name="doc3_fname" invisible="1" />
<field name="attachment_ids" colspan="4" nolabel="1">
<form string="Attachment">
<field name="binary" filename="name" />
<field name="name" />
</form>
<tree string="Attachments">
<field name="name" />
</tree>
</field>
</page>
</notebook>
<group colspan="2" col="4" >
@ -60,9 +63,15 @@
<field name="email_to" />
<field name="email_cc" />
<field name="subject" />
<field name="doc1" />
<field name="doc2" />
<field name="doc3" />
<field name="attachment_ids" colspan="4" nolabel="1">
<form string="Attachment">
<field name="binary" filename="name" />
<field name="name" />
</form>
<tree string="Attachments">
<field name="name" />
</tree>
</field>
<separator string="" colspan="4"/>
<field name="text" nolabel="1" colspan="4"/>
<separator string=" " colspan="4"/>

View File

@ -490,7 +490,7 @@ class stock_picking(osv.osv):
'min_date': fields.function(get_min_max_date, fnct_inv=_set_minimum_date, multi="min_max_date",
method=True, store=True, type='datetime', string='Expected Date', select=1, help="Expected date for Picking. Default it takes current date"),
'date': fields.datetime('Order Date', help="Date of Order"),
'date_done': fields.datetime('Date Done', help="Date of completion"),
'date_done': fields.datetime('Date Done', help="Date of Completion"),
'max_date': fields.function(get_min_max_date, fnct_inv=_set_maximum_date, multi="min_max_date",
method=True, store=True, type='datetime', string='Max. Expected Date', select=2),
'move_lines': fields.one2many('stock.move', 'picking_id', 'Entry lines', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),