[IMP] view and fields in email_template

bzr revid: dhara@dhara-laptop-20100610124450-4j735ukcrxe1dh77
This commit is contained in:
Dhara 2010-06-10 18:14:50 +05:30
parent 7ec18af659
commit b6c32132b2
6 changed files with 21 additions and 120 deletions

View File

@ -102,9 +102,15 @@ class email_template(osv.osv):
}
_columns = {
'name' : fields.char('Name of Template', size=100, required=True),
'name' : fields.char('Name', size=100, required=True),
'object_name':fields.many2one('ir.model', 'Model'),
'model_int_name':fields.char('Model Internal Name', size=200,),
'enforce_from_account':fields.many2one(
'email_template.account',
string="Enforce From Account",
help="Emails will be sent only from this account."),
'from_email' : fields.related('enforce_from_account', 'email_id',
type='char', string='From',),
'def_to':fields.char(
'Recepient (To)',
size=250,
@ -141,7 +147,7 @@ class email_template(osv.osv):
help="The text version of the mail",
translate=True),
'use_sign':fields.boolean(
'Use Signature',
'Signature',
help="the signature from the User details"
"will be appened to the mail"),
'file_name':fields.char(
@ -168,11 +174,6 @@ class email_template(osv.osv):
string="Allowed User Groups",
help="Only users from these groups will be"
" allowed to send mails from this Template"),
'enforce_from_account':fields.many2one(
'email_template.account',
string="Enforce From Account",
help="Emails will be sent only from this account.",
domain="[('company','=','yes')]"),
'model_object_field':fields.many2one(
'ir.model.fields',
string="Field",
@ -218,6 +219,7 @@ class email_template(osv.osv):
}
_defaults = {
'template_language' : lambda *a:'mako',
}
_sql_constraints = [
@ -623,19 +625,6 @@ class email_template_preview(osv.osv_memory):
_name = "email_template.preview"
_description = "Email Template Preview"
def _get_model_recs(self, cr, uid, context=None):
if context is None:
context = {}
#Fills up the selection box which allows records from the selected object to be displayed
self.context = context
if 'active_id' in context.keys():
# context['active_id'] = 5
ref_obj_id = self.pool.get('email.template').read(cr, uid, context['active_id'], ['object_name'], context)
ref_obj_name = self.pool.get('ir.model').read(cr, uid, ref_obj_id[0], ['model'], context)['model']
ref_obj_ids = self.pool.get(ref_obj_name).search(cr, uid, [], context=context)
ref_obj_recs = self.pool.get(ref_obj_name).name_get(cr, uid, ref_obj_ids, context)
return ref_obj_recs
def _default_model(self, cursor, user, context=None):
"""
Returns the default value for model field
@ -655,7 +644,6 @@ class email_template_preview(osv.osv_memory):
'email.template',
'Template', readonly=True),
'rel_model':fields.many2one('ir.model', 'Model', readonly=True),
'rel_model_ref':fields.selection(_get_model_recs, 'Referred Document'),
'to':fields.char('To', size=250, readonly=True),
'cc':fields.char('CC', size=250, readonly=True),
'bcc':fields.char('BCC', size=250, readonly=True),
@ -668,7 +656,7 @@ class email_template_preview(osv.osv_memory):
'ref_template': lambda self, cr, uid, ctx:ctx['active_id'],
'rel_model': _default_model
}
# Need to check
def on_change_ref(self, cr, uid, ids, rel_model_ref, context=None):
if context is None:
context = {}

View File

@ -30,7 +30,7 @@ class email_template_account(osv.osv):
'text/html'
]
_columns = {
'name': fields.char('Email Account Desc',
'name': fields.char('Description',
size=64, required=True,
readonly=True, select=True,
states={'draft':[('readonly', False)]}),
@ -56,22 +56,16 @@ class email_template_account(osv.osv):
size=120, invisible=True,
required=False, readonly=True,
states={'draft':[('readonly', False)]}),
'smtptls':fields.boolean('Use TLS',
'smtptls':fields.boolean('TLS',
states={'draft':[('readonly', False)]}, readonly=True),
'smtpssl':fields.boolean('Use SSL/TLS (only in python 2.6)',
'smtpssl':fields.boolean('SSL/TLS (only in python 2.6)',
states={'draft':[('readonly', False)]}, readonly=True),
'send_pref':fields.selection([
('html', 'HTML otherwise Text'),
('text', 'Text otherwise HTML'),
('both', 'Both HTML & Text')
], 'Mail Format', required=True),
'allowed_groups':fields.many2many(
'res.groups',
'account_group_rel', 'templ_id', 'group_id',
string="Allowed User Groups",
help="Only users from these groups will be" \
"allowed to send mails from this ID"),
'company':fields.selection([
('yes', 'Yes'),
('no', 'No')
@ -89,7 +83,7 @@ class email_template_account(osv.osv):
('suspended', 'Suspended'),
('approved', 'Approved')
],
'Account Status', required=True, readonly=True),
'Status', required=True, readonly=True),
}
_defaults = {
@ -102,7 +96,6 @@ class email_template_account(osv.osv):
['name'],
context
)['name'],
'smtpssl':lambda * a:True,
'state':lambda * a:'draft',
'user':lambda self, cursor, user, context:user,
'send_pref':lambda * a: 'html',

View File

@ -36,9 +36,6 @@
<field name="send_pref" colspan="2" />
</group>
</page>
<page string="security" attrs="{'invisible':[('company','!=','yes')]}">
<field name="allowed_groups" attrs="{'required':[('company','=','yes')]}" nolabel="1"/>
</page>
</notebook>
<group colspan="4" col="10">
<field name="state" select="1"/>

View File

@ -52,7 +52,6 @@ class email_template_mailbox(osv.osv):
for attid in values['attachments_ids']:
attachment = self.pool.get('ir.attachment').browse(cr, uid, attid, context)#,['datas_fname','datas'])
payload[attachment.datas_fname] = attachment.datas
print "233333333333333"
result = account_obj.send_mail(cr, uid,
[values['account_id'][0]],
{'To':values.get('email_to', u'') or u'', 'CC':values.get('email_cc', u'') or u'', 'BCC':values.get('email_bcc', u'') or u''},
@ -153,30 +152,6 @@ class email_template_mailbox(osv.osv):
'folder': lambda * a: 'outbox',
}
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
context = {}
if context.get('company', False):
users_groups = self.pool.get('res.users').browse(cr, uid, uid, context).groups_id
group_acc_rel = {}
#get all accounts and get a table of {group1:[account1,account2],group2:[account1]}
for each_account_id in self.pool.get('email_template.account').search(cr, uid, [('state', '=', 'approved'), ('company', '=', 'yes')], context=context):
account = self.pool.get('email_template.account').browse(cr, uid, each_account_id, context)
for each_group in account.allowed_groups:
if not account.id in group_acc_rel.get(each_group, []):
groups = group_acc_rel.get(each_group, [])
groups.append(account.id)
group_acc_rel[each_group] = groups
users_company_accounts = []
for each_group in group_acc_rel.keys():
if each_group in users_groups:
for each_account in group_acc_rel[each_group]:
if not each_account in users_company_accounts:
users_company_accounts.append(each_account)
args.append(('account_id', 'in', users_company_accounts))
return super(osv.osv, self).search(cr, uid, args, offset, limit,
order, context=context, count=count)
email_template_mailbox()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -53,8 +53,8 @@
</notebook>
<separator colspan="4" string="" />
<group col="4" colspan="4">
<field name="state" colspan="2" readonly="1" />
<button name="complete_mail" type="object" string="Download Full Mail" colspan="2" states="read,unread" />
<field name="state" readonly="1" />
<button name="complete_mail" type="object" string="Download Full Mail" states="read,unread" />
<button name="send_this_mail" type="object" string="Send Mail" />
</group>
</form>
@ -62,9 +62,8 @@
</record>
<!--============================================= TREE VIEWS =============================================-->
<!--DRAFTS-->
<record model="ir.ui.view" id="email_template_drafts_tree">
<field name="name">email_template.mailbox.draftstree</field>
<record id="view_email_template_mailbox_tree" model="ir.ui.view">
<field name="name">email_template.mailbox.tree</field>
<field name="model">email_template.mailbox</field>
<field name="type">tree</field>
<field name="arch" type="xml">
@ -77,51 +76,6 @@
</tree>
</field>
</record>
<!--OUTBOX-->
<record model="ir.ui.view" id="email_template_outbox_tree">
<field name="name">email_template.mailbox.outboxtree</field>
<field name="model">email_template.mailbox</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Outbox">
<field name="user" />
<field name="email_from" select="1" />
<field name="subject" select="1" />
<field name="attachments_ids" select="2" />
<field name="date_mail" select="2" />
</tree>
</field>
</record>
<!--SENT-->
<record model="ir.ui.view" id="email_template_sentbox_tree">
<field name="name">email_template.mailbox.sentboxtree</field>
<field name="model">email_template.mailbox</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Sent">
<field name="user" />
<field name="email_from" select="1" />
<field name="subject" select="1" />
<field name="attachments_ids" select="2" />
<field name="date_mail" select="2" />
</tree>
</field>
</record>
<!--TRASH-->
<record model="ir.ui.view" id="email_template_trashbox_tree">
<field name="name">email_template.mailbox.trashboxtree</field>
<field name="model">email_template.mailbox</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Trash">
<field name="user" />
<field name="email_from" select="1" />
<field name="subject" select="1" />
<field name="attachments_ids" select="2" />
<field name="date_mail" select="2" />
</tree>
</field>
</record>
<record id="view_email_template_mailbox_search" model="ir.ui.view">
<field name="name">email_template.mailbox.search</field>
@ -150,7 +104,7 @@
<field name="res_model">email_template.mailbox</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="email_template_outbox_tree" />
<field name="view_id" ref="view_email_template_mailbox_tree" />
<field name="context">{'group_by': [], 'search_default_draft': 1, 'search_default_outbox': 1}</field>
<field name="search_view_id" ref="view_email_template_mailbox_search"/>
</record>

View File

@ -62,7 +62,9 @@
<field name="model_int_name" invisible="1" />
<notebook colspan="4">
<page string="Mail Details">
<field name="enforce_from_account" required= "1"/>
<group col="4" colspan="2">
<field name="from_email"/>
<field name="def_to" colspan="4" required="1" />
<field name="def_cc" colspan="4" />
<field name="def_bcc" colspan="4" />
@ -109,15 +111,7 @@
type="action" colspan="4" target="new" />
</group>
</page>
<page string="Security">
<separator colspan="4" string="Allowed User Groups" />
<field name="allowed_groups" string="Allowed User Groups"
nolabel="1" />
</page>
<page string="Advanced">
<separator string="Automatic Email" colspan="4" />
<field name="enforce_from_account" attrs="{'required':[('auto_email','=',True)]}" />
<newline/>
<field name="ref_ir_act_window" />
<field name="ref_ir_value" />
<separator string="Attachments (Report to attach)" colspan="4"/>