[IMP] make manual attach wizard usable again
parent
d6637a8e84
commit
d66327cfae
|
@ -19,22 +19,17 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
from openerp import fields, models
|
||||||
from openerp.osv import fields
|
|
||||||
from openerp.osv.orm import TransientModel
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class attach_mail_manually(TransientModel):
|
class attach_mail_manually(models.TransientModel):
|
||||||
_name = 'fetchmail.attach.mail.manually'
|
_name = 'fetchmail.attach.mail.manually'
|
||||||
|
|
||||||
_columns = {
|
folder_id = fields.Many2one(
|
||||||
'folder_id': fields.many2one('fetchmail.server.folder', 'Folder',
|
'fetchmail.server.folder', 'Folder', readonly=True)
|
||||||
readonly=True),
|
mail_ids = fields.One2many(
|
||||||
'mail_ids': fields.one2many(
|
'fetchmail.attach.mail.manually.mail', 'wizard_id', 'Emails')
|
||||||
'fetchmail.attach.mail.manually.mail', 'wizard_id', 'Emails'),
|
|
||||||
}
|
|
||||||
|
|
||||||
def default_get(self, cr, uid, fields_list, context=None):
|
def default_get(self, cr, uid, fields_list, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
|
@ -54,15 +49,13 @@ class attach_mail_manually(TransientModel):
|
||||||
None,
|
None,
|
||||||
'FLAGGED' if folder.flag_nonmatching else 'UNDELETED')
|
'FLAGGED' if folder.flag_nonmatching else 'UNDELETED')
|
||||||
if result != 'OK':
|
if result != 'OK':
|
||||||
logger.error('Could not search mailbox %s on %s' % (
|
logging.error('Could not search mailbox %s on %s' % (
|
||||||
folder.path, folder.server_id.name))
|
folder.path, folder.server_id.name))
|
||||||
continue
|
continue
|
||||||
attach_mail_manually_mail._columns['object_id'].selection = [
|
|
||||||
(folder.model_id.model, folder.model_id.name)]
|
|
||||||
for msgid in msgids[0].split():
|
for msgid in msgids[0].split():
|
||||||
result, msgdata = connection.fetch(msgid, '(RFC822)')
|
result, msgdata = connection.fetch(msgid, '(RFC822)')
|
||||||
if result != 'OK':
|
if result != 'OK':
|
||||||
logger.error('Could not fetch %s in %s on %s' % (
|
logging.error('Could not fetch %s in %s on %s' % (
|
||||||
msgid, folder.path, folder.server_id.name))
|
msgid, folder.path, folder.server_id.name))
|
||||||
continue
|
continue
|
||||||
mail_message = self.pool.get('mail.thread').message_parse(
|
mail_message = self.pool.get('mail.thread').message_parse(
|
||||||
|
@ -74,7 +67,7 @@ class attach_mail_manually(TransientModel):
|
||||||
'msgid': msgid,
|
'msgid': msgid,
|
||||||
'subject': mail_message.get('subject', ''),
|
'subject': mail_message.get('subject', ''),
|
||||||
'date': mail_message.get('date', ''),
|
'date': mail_message.get('date', ''),
|
||||||
'object_id': folder.model_id.model + ',False'
|
'object_id': '%s,-1' % folder.model_id.model,
|
||||||
}))
|
}))
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -87,7 +80,7 @@ class attach_mail_manually(TransientModel):
|
||||||
connection.select(this.folder_id.path)
|
connection.select(this.folder_id.path)
|
||||||
result, msgdata = connection.fetch(mail.msgid, '(RFC822)')
|
result, msgdata = connection.fetch(mail.msgid, '(RFC822)')
|
||||||
if result != 'OK':
|
if result != 'OK':
|
||||||
logger.error('Could not fetch %s in %s on %s' % (
|
logging.error('Could not fetch %s in %s on %s' % (
|
||||||
mail.msgid, this.folder_id.path, this.server))
|
mail.msgid, this.folder_id.path, this.server))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -104,26 +97,32 @@ class attach_mail_manually(TransientModel):
|
||||||
connection.close()
|
connection.close()
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
|
||||||
|
def fields_view_get(self, cr, user, view_id=None, view_type='form',
|
||||||
|
context=None, toolbar=False, submenu=False):
|
||||||
|
result = super(attach_mail_manually, self).fields_view_get(
|
||||||
|
cr, user, view_id, view_type, context, toolbar, submenu)
|
||||||
|
|
||||||
class attach_mail_manually_mail(TransientModel):
|
tree = result['fields']['mail_ids']['views']['tree']
|
||||||
|
for folder in self.pool['fetchmail.server.folder'].browse(
|
||||||
|
cr, user, [context.get('default_folder_id')], context):
|
||||||
|
tree['fields']['object_id']['selection'] = [
|
||||||
|
(folder.model_id.model, folder.model_id.name)
|
||||||
|
]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class attach_mail_manually_mail(models.TransientModel):
|
||||||
_name = 'fetchmail.attach.mail.manually.mail'
|
_name = 'fetchmail.attach.mail.manually.mail'
|
||||||
|
|
||||||
_columns = {
|
wizard_id = fields.Many2one(
|
||||||
'wizard_id': fields.many2one('fetchmail.attach.mail.manually',
|
'fetchmail.attach.mail.manually', readonly=True)
|
||||||
readonly=True),
|
msgid = fields.Char('Message id', readonly=True)
|
||||||
'msgid': fields.char('Message id', size=16, readonly=True),
|
subject = fields.Char('Subject', readonly=True)
|
||||||
'subject': fields.char('Subject', size=128, readonly=True),
|
date = fields.Datetime('Date', readonly=True)
|
||||||
'date': fields.datetime('Date', readonly=True),
|
object_id = fields.Reference(
|
||||||
'object_id': fields.reference(
|
lambda self: [
|
||||||
'Object',
|
|
||||||
selection=lambda self, cr, uid, context: [
|
|
||||||
(m.model, m.name)
|
(m.model, m.name)
|
||||||
for m in self.pool.get('ir.model').browse(
|
for m in self.env['ir.model'].search([])
|
||||||
cr, uid,
|
|
||||||
self.pool.get('ir.model').search(cr, uid, []),
|
|
||||||
context
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
size=128,
|
string='Object')
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
<field name="name">fetchmail.attach.mail.manually</field>
|
<field name="name">fetchmail.attach.mail.manually</field>
|
||||||
<field name="model">fetchmail.attach.mail.manually</field>
|
<field name="model">fetchmail.attach.mail.manually</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form col="4" version="7.0" string="Attach mail manually">
|
<form col="4" string="Attach mail manually">
|
||||||
<sheet>
|
|
||||||
<group>
|
<group>
|
||||||
<field name="folder_id" />
|
<field name="folder_id" />
|
||||||
<field name="mail_ids" nolabel="1" colspan="4">
|
<field name="mail_ids" nolabel="1" colspan="4">
|
||||||
|
@ -17,10 +16,10 @@
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
|
||||||
<footer>
|
<footer>
|
||||||
<button string="Save" type="object" name="attach_mails" icon="gtk-ok" />
|
<button string="Save" type="object" name="attach_mails" class="oe_highlight" />
|
||||||
<button special="cancel" string="Cancel" icon="gtk-cancel" />
|
or
|
||||||
|
<button special="cancel" string="Cancel" class="oe_link" />
|
||||||
</footer>
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
|
|
Loading…
Reference in New Issue