[IMP] insted of replacing int field with function and add new int fied add new function field only, use fnct_inv insted of overwriting write method.
bzr revid: tpa@tinyerp.com-20130821111113-5n022roofguvea0f
This commit is contained in:
parent
f21aa3c371
commit
ee9b75603f
|
@ -75,17 +75,27 @@ class crm_case_section(osv.osv):
|
|||
for item in self.browse(cr, uid, ids, context=context):
|
||||
base_currency_id = item.user_id.company_id.currency_id.id if item.user_id else item.create_uid.company_id.currency_id.id
|
||||
res[item.id] = {
|
||||
'invoiced_forecast': currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.base_invoiced_forecast, context=context),
|
||||
'invoiced_target': currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.base_invoiced_target, context=context),
|
||||
'user_currency_invoiced_forecast': currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.invoiced_forecast, context=context),
|
||||
'user_currency_invoiced_target': currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.invoiced_target, context=context),
|
||||
}
|
||||
return res
|
||||
|
||||
def _set_forecast_target(self, cr, uid, team_id, name, value, arg, context=None):
|
||||
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
|
||||
team = self.browse(cr, uid, team_id, context=context)
|
||||
base_currency_id = team.user_id.company_id.currency_id.id if team.user_id else team.create_uid.company_id.currency_id.id
|
||||
amount = self.pool.get('res.currency').compute(cr, uid, user_currency_id, base_currency_id, value, context=context)
|
||||
self.write(cr, uid, [team_id], {name.strip("user_currency"): amount}, context=context)
|
||||
return True
|
||||
|
||||
_columns = {
|
||||
'invoiced_forecast': fields.function(_compute_amounts_in_user_currency, string='Invoice Forecast',type='integer', multi="_compute_amounts",
|
||||
'invoiced_forecast': fields.integer("Invoice Forecast"),
|
||||
'user_currency_invoiced_forecast': fields.function(_compute_amounts_in_user_currency, fnct_inv=_set_forecast_target, string='Invoice Forecast',type='integer', multi="_compute_amounts",
|
||||
help="Forecast of the invoice revenue for the current month. This is the amount the sales \n"
|
||||
"team should invoice this month. It is used to compute the progression ratio \n"
|
||||
" of the current and forecast revenue on the kanban view."),
|
||||
'invoiced_target': fields.function(_compute_amounts_in_user_currency,string='Invoice Target',type='integer', multi="_compute_amounts",
|
||||
'invoiced_target': fields.integer("Invoice Target"),
|
||||
'user_currency_invoiced_target': fields.function(_compute_amounts_in_user_currency, fnct_inv=_set_forecast_target, string='Invoice Target',type='integer', multi="_compute_amounts",
|
||||
help="Target of invoice revenue for the current month. This is the amount the sales \n"
|
||||
"team estimates to be able to invoice this month."),
|
||||
'monthly_quoted': fields.function(_get_sale_orders_data,
|
||||
|
@ -97,24 +107,11 @@ class crm_case_section(osv.osv):
|
|||
'monthly_invoiced': fields.function(_get_invoices_data,
|
||||
type='string', readonly=True,
|
||||
string='Rate of sent invoices per duration'),
|
||||
'base_invoiced_forecast': fields.integer(string="Invoice Forecast"),
|
||||
'base_invoiced_target': fields.integer(string="Invoice Target"),
|
||||
'create_uid': fields.many2one('res.users', 'Create User'),
|
||||
}
|
||||
|
||||
def action_forecast(self, cr, uid, id, value, context=None):
|
||||
return self.write(cr, uid, [id], {'invoiced_forecast': int(float(value))}, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
currency_obj = self.pool.get('res.currency')
|
||||
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
|
||||
for item in self.browse(cr, uid, ids, context=context):
|
||||
base_currency_id = item.user_id.company_id.currency_id.id if item.user_id else item.create_uid.company_id.currency_id.id
|
||||
if vals.get('invoiced_forecast'):
|
||||
vals['base_invoiced_forecast'] = currency_obj.compute(cr, uid, user_currency_id, base_currency_id, vals['invoiced_forecast'], context=context)
|
||||
if vals.get('invoiced_target'):
|
||||
vals['base_invoiced_target'] = currency_obj.compute(cr, uid, user_currency_id, base_currency_id, vals['invoiced_target'], context=context)
|
||||
return super(crm_case_section, self).write(cr, uid, ids, vals, context=context)
|
||||
return self.write(cr, uid, [id], {'user_currency_invoiced_forecast': int(float(value))}, context=context)
|
||||
|
||||
class res_users(osv.Model):
|
||||
_inherit = 'res.users'
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
<data>
|
||||
|
||||
<record model="crm.case.section" id="crm.section_sales_department">
|
||||
<field name="base_invoiced_forecast">52700</field>
|
||||
<field name="base_invoiced_target">60000</field>
|
||||
<field name="invoiced_forecast">52700</field>
|
||||
<field name="invoiced_target">60000</field>
|
||||
</record>
|
||||
|
||||
<record model="crm.case.section" id="crm.crm_case_section_1">
|
||||
<field name="name">Indirect Sales</field>
|
||||
<field name="code">IM</field>
|
||||
<field name="base_invoiced_forecast">36000</field>
|
||||
<field name="base_invoiced_target">40000</field>
|
||||
<field name="invoiced_forecast">36000</field>
|
||||
<field name="invoiced_target">40000</field>
|
||||
</record>
|
||||
|
||||
<!-- Invoice for Direct Marketing -->
|
||||
|
|
|
@ -248,8 +248,8 @@
|
|||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='code']" position="after">
|
||||
<field name="invoiced_target" readonly="0"/>
|
||||
<field name="invoiced_forecast" readonly="0"/>
|
||||
<field name="user_currency_invoiced_target" readonly="0"/>
|
||||
<field name="user_currency_invoiced_forecast" readonly="0"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
|
@ -265,8 +265,8 @@
|
|||
<field name="monthly_quoted"/>
|
||||
<field name="monthly_confirmed"/>
|
||||
<field name="monthly_invoiced"/>
|
||||
<field name="invoiced_forecast"/>
|
||||
<field name="invoiced_target"/>
|
||||
<field name="user_currency_invoiced_forecast"/>
|
||||
<field name="user_currency_invoiced_target"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@class='oe_salesteams_leads']" position="after">
|
||||
<div class="oe_salesteams_orders">
|
||||
|
@ -297,11 +297,11 @@
|
|||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//div[@class='oe_items_list']" position="after">
|
||||
<div class="oe_center oe_salesteams_justgage" t-if="record.invoiced_target.raw_value">
|
||||
<field name="monthly_invoiced" widget="gage" style="width:160px; height: 120px;" options="{'max_field': 'invoiced_target'}">Invoiced</field>
|
||||
<field name="invoiced_forecast" widget="gage" style="width:160px; height: 120px; cursor: pointer;" options="{'max_field': 'invoiced_target', 'action_change': 'action_forecast'}">Forecast</field>
|
||||
<div class="oe_center oe_salesteams_justgage" t-if="record.user_currency_invoiced_target.raw_value">
|
||||
<field name="monthly_invoiced" widget="gage" style="width:160px; height: 120px;" options="{'max_field': 'user_currency_invoiced_target'}">Invoiced</field>
|
||||
<field name="user_currency_invoiced_forecast" widget="gage" style="width:160px; height: 120px; cursor: pointer;" options="{'max_field': 'user_currency_invoiced_target', 'action_change': 'action_forecast'}">Forecast</field>
|
||||
</div>
|
||||
<div class="oe_center oe_salesteams_help" style="color:#bbbbbb;" t-if="!record.invoiced_target.raw_value">
|
||||
<div class="oe_center oe_salesteams_help" style="color:#bbbbbb;" t-if="!record.user_currency_invoiced_target.raw_value">
|
||||
<br/>Define an invoicing target in the sales team settings to see the period's achievement and forecast at a glance.
|
||||
</div>
|
||||
</xpath>
|
||||
|
|
Loading…
Reference in New Issue