[MERGE] Merge with main branch
bzr revid: mra@tinyerp.com-20100429083619-8r0pkxtjsnqcrb1f
This commit is contained in:
commit
a3e5ebbbb5
|
@ -29,69 +29,15 @@ import tools
|
|||
from tools import config
|
||||
|
||||
class account_analytic_line(osv.osv):
|
||||
_name = 'account.analytic.line'
|
||||
_inherit = 'account.analytic.line'
|
||||
_description = 'Analytic lines'
|
||||
|
||||
def _amount_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
cmp_cur_id=rec.company_id.currency_id.id
|
||||
aa_cur_id=rec.account_id.currency_id.id
|
||||
# Always provide the amount in currency
|
||||
if cmp_cur_id != aa_cur_id:
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
ctx = {}
|
||||
if rec.date and rec.amount:
|
||||
ctx['date'] = rec.date
|
||||
result[rec.id] = cur_obj.compute(cr, uid, rec.company_id.currency_id.id,
|
||||
rec.account_id.currency_id.id, rec.amount,
|
||||
context=ctx)
|
||||
else:
|
||||
result[rec.id]=rec.amount
|
||||
return result
|
||||
|
||||
def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
# Always provide second currency
|
||||
result[rec.id] = (rec.account_id.currency_id.id,rec.account_id.currency_id.code)
|
||||
return result
|
||||
|
||||
def _get_account_line(self, cr, uid, ids, context={}):
|
||||
aac_ids = {}
|
||||
for acc in self.pool.get('account.analytic.account').browse(cr, uid, ids):
|
||||
aac_ids[acc.id] = True
|
||||
aal_ids = []
|
||||
if aac_ids:
|
||||
aal_ids = self.pool.get('account.analytic.line').search(cr, uid, [('account_id','in',aac_ids.keys())], context=context)
|
||||
return aal_ids
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Description', size=256, required=True),
|
||||
'date' : fields.date('Date', required=True),
|
||||
'amount' : fields.float('Amount', required=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price.'),
|
||||
'unit_amount' : fields.float('Quantity', help='Specifies the amount of quantity to count.'),
|
||||
'product_uom_id' : fields.many2one('product.uom', 'UoM'),
|
||||
'product_id' : fields.many2one('product.product', 'Product'),
|
||||
'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
|
||||
'general_account_id' : fields.many2one('account.account', 'General Account', required=True, ondelete='cascade'),
|
||||
'move_id' : fields.many2one('account.move.line', 'Move Line', ondelete='cascade', select=True),
|
||||
'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='cascade', select=True),
|
||||
'code' : fields.char('Code', size=8),
|
||||
'user_id' : fields.many2one('res.users', 'User',),
|
||||
'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency',
|
||||
store={
|
||||
'account.analytic.account': (_get_account_line, ['company_id'], 50),
|
||||
'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
|
||||
},
|
||||
help="The related account currency if not equal to the company one."),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
'amount_currency': fields.function(_amount_currency, method=True, digits_compute= dp.get_precision('Account'), string='Amount currency',
|
||||
store={
|
||||
'account.analytic.account': (_get_account_line, ['company_id'], 50),
|
||||
'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
|
||||
},
|
||||
help="The amount expressed in the related account currency if not equal to the company one."),
|
||||
'ref': fields.char('Ref.', size=64),
|
||||
}
|
||||
_defaults = {
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
import time
|
||||
import operator
|
||||
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from osv import fields, osv
|
||||
import decimal_precision as dp
|
||||
|
||||
#
|
||||
# Object definition
|
||||
|
@ -282,3 +282,70 @@ class account_analytic_account(osv.osv):
|
|||
|
||||
account_analytic_account()
|
||||
|
||||
|
||||
class account_analytic_line(osv.osv):
|
||||
_name = 'account.analytic.line'
|
||||
_description = 'Analytic lines'
|
||||
def _amount_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
cmp_cur_id=rec.company_id.currency_id.id
|
||||
aa_cur_id=rec.account_id.currency_id.id
|
||||
# Always provide the amount in currency
|
||||
if cmp_cur_id != aa_cur_id:
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
ctx = {}
|
||||
if rec.date and rec.amount:
|
||||
ctx['date'] = rec.date
|
||||
result[rec.id] = cur_obj.compute(cr, uid, rec.company_id.currency_id.id,
|
||||
rec.account_id.currency_id.id, rec.amount,
|
||||
context=ctx)
|
||||
else:
|
||||
result[rec.id]=rec.amount
|
||||
return result
|
||||
|
||||
def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
# Always provide second currency
|
||||
result[rec.id] = (rec.account_id.currency_id.id,rec.account_id.currency_id.code)
|
||||
return result
|
||||
def _get_account_line(self, cr, uid, ids, context={}):
|
||||
aac_ids = {}
|
||||
for acc in self.pool.get('account.analytic.account').browse(cr, uid, ids):
|
||||
aac_ids[acc.id] = True
|
||||
aal_ids = []
|
||||
if aac_ids:
|
||||
aal_ids = self.pool.get('account.analytic.line').search(cr, uid, [('account_id','in',aac_ids.keys())], context=context)
|
||||
return aal_ids
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Description', size=256, required=True),
|
||||
'date' : fields.date('Date', required=True),
|
||||
'amount' : fields.float('Amount', required=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price.'),
|
||||
'unit_amount' : fields.float('Quantity', help='Specifies the amount of quantity to count.'),
|
||||
'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
|
||||
'user_id' : fields.many2one('res.users', 'User',),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency',
|
||||
store={
|
||||
'account.analytic.account': (_get_account_line, ['company_id'], 50),
|
||||
'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
|
||||
},
|
||||
help="The related account currency if not equal to the company one."),
|
||||
'amount_currency': fields.function(_amount_currency, method=True, digits_compute= dp.get_precision('Account'), string='Amount currency',
|
||||
store={
|
||||
'account.analytic.account': (_get_account_line, ['company_id'], 50),
|
||||
'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
|
||||
},
|
||||
help="The amount expressed in the related account currency if not equal to the company one."),
|
||||
|
||||
}
|
||||
_defaults = {
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', c),
|
||||
}
|
||||
_order = 'date'
|
||||
account_analytic_line()
|
||||
|
||||
|
||||
|
|
|
@ -190,10 +190,13 @@
|
|||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
<button colspan="2" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.opportunity'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
<button colspan="2" string="Forward to Partner"
|
||||
name="%(crm_opportunity_forward_to_partner_act)d"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
|
@ -157,4 +157,129 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
|||
return res
|
||||
|
||||
crm_lead_forward_to_partner()
|
||||
|
||||
class crm_opportunity_forward_to_partner(osv.osv_memory):
|
||||
_name = 'crm.opportunity.forward.to.partner'
|
||||
|
||||
_columns = {
|
||||
'partner_id' : fields.many2one('res.partner', 'Partner'),
|
||||
'address_id' : fields.many2one('res.partner.address', 'Address'),
|
||||
'email_from' : fields.char('From', required=True, size=128),
|
||||
'email_to' : fields.char('To', required=True, size=128),
|
||||
'subject' : fields.char('Subject', required=True, size=128),
|
||||
'message' : fields.text('Message', required=True),
|
||||
}
|
||||
|
||||
def on_change_partner(self, cr, uid, ids, partner_id):
|
||||
return {
|
||||
'domain' : {
|
||||
'address_id' : partner_id and "[('partner_id', '=', partner_id)]" or "[]",
|
||||
}
|
||||
}
|
||||
|
||||
def on_change_address(self, cr, uid, ids, address_id):
|
||||
email = ''
|
||||
if address_id:
|
||||
email = self.pool.get('res.partner.address').browse(cr, uid, address_id).email
|
||||
|
||||
return {
|
||||
'value' : {
|
||||
'email_to' : email,
|
||||
}
|
||||
}
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
return {'type' : 'ir.actions.act_window_close'}
|
||||
|
||||
def action_forward(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Forward the opportunity to a partner
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
res_id = context.get('active_id', False)
|
||||
|
||||
if not res_id:
|
||||
return {}
|
||||
|
||||
this = self.browse(cr, uid, ids[0], context=context)
|
||||
|
||||
hist_obj = self.pool.get('crm.case.history')
|
||||
smtp_pool = self.pool.get('email.smtpclient')
|
||||
case_pool = self.pool.get('crm.opportunity')
|
||||
case = case_pool.browse(cr, uid, res_id, context=context)
|
||||
|
||||
emails = [this.email_to]
|
||||
body = case_pool.format_body(this.message)
|
||||
email_from = this.email_from or False
|
||||
case_pool._history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, details=body, email_from=email_from)
|
||||
|
||||
flag = False
|
||||
if case.section_id and case.section_id.server_id:
|
||||
flag = smtp_pool.send_email(
|
||||
cr=cr,
|
||||
uid=uid,
|
||||
server_id=case.section_id.server_id.id,
|
||||
emailto=emails,
|
||||
subject=this.subject,
|
||||
body="<pre>%s</pre>" % body,
|
||||
)
|
||||
else:
|
||||
flag = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
this.subject,
|
||||
body,
|
||||
)
|
||||
|
||||
return {}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
active_ids = context.get('active_ids')
|
||||
if not active_ids:
|
||||
return {}
|
||||
|
||||
opportunity_proxy = self.pool.get('crm.opportunity')
|
||||
|
||||
opportunity = opportunity_proxy.browse(cr, uid, active_ids[0], context=context)
|
||||
|
||||
pa = opportunity.partner_address_id
|
||||
message = [
|
||||
"Partner: %s" % (opportunity.partner_id.name_get()[0][1]),
|
||||
"Contact: %s" % (pa.name),
|
||||
"Title: %s" % (pa.title),
|
||||
"Function: %s" % (pa.function and pa.function.name_get()[0][1] or ''),
|
||||
"Street: %s" % (pa.street),
|
||||
"Street2: %s" % (pa.street2),
|
||||
"Zip: %s" % (pa.zip),
|
||||
"City: %s" % (pa.city),
|
||||
"Country: %s" % (pa.country_id and pa.country_id.name_get()[0][1] or ''),
|
||||
"State: %s" % (pa.state_id and pa.state_id.name_get()[0][1] or ''),
|
||||
"Email: %s" % (pa.email),
|
||||
"Phone: %s" % (pa.phone),
|
||||
"Fax: %s" % (pa.fax),
|
||||
"Mobile: %s" % (pa.mobile),
|
||||
]
|
||||
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
email_from = ''
|
||||
if user.address_id and user.address_id.email:
|
||||
email_from = "%s <%s>" % (user.name, user.address_id.email)
|
||||
|
||||
res = {
|
||||
'email_from' : email_from,
|
||||
'subject' : '[Opportunity-Forward:%06d] %s' % (opportunity.id, opportunity.name),
|
||||
'message' : "\n".join(message + ['---']),
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
crm_opportunity_forward_to_partner()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -34,5 +34,39 @@
|
|||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="crm_opportunity_forward_to_partner_form">
|
||||
<field name="name">crm_opportunity_forward_to_partner</field>
|
||||
<field name="model">crm.opportunity.forward.to.partner</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Forward to Partner">
|
||||
<separator string="User" colspan="4" />
|
||||
<field name="email_from" colspan="4" />
|
||||
|
||||
<separator string="Destination" colspan="4" />
|
||||
<field name="partner_id" on_change="on_change_partner(partner_id)" colspan="4" />
|
||||
<field name="address_id" string="Contact" on_change="on_change_address(address_id)" colspan="4" />
|
||||
<field name="email_to" colspan="4" />
|
||||
|
||||
<separator string="Email" colspan="4" />
|
||||
<field name="subject" colspan="4" />
|
||||
<field name="message" colspan="4" />
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="2">
|
||||
<button name="action_cancel" special="cancel" string="Cancel" icon="gtk-cancel" type="object" />
|
||||
<button name="action_forward" string="Forward" icon="gtk-go-forward" type="object" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="crm_opportunity_forward_to_partner_act">
|
||||
<field name="name">Forward to Partner</field>
|
||||
<field name="res_model">crm.opportunity.forward.to.partner</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue