diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index b463eca6bb4..af5973b8e3e 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -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' diff --git a/addons/sale_crm/sale_crm_demo.xml b/addons/sale_crm/sale_crm_demo.xml index 3eff4061aa1..0c2822719dd 100644 --- a/addons/sale_crm/sale_crm_demo.xml +++ b/addons/sale_crm/sale_crm_demo.xml @@ -3,15 +3,15 @@ - 52700 - 60000 + 52700 + 60000 Indirect Sales IM - 36000 - 40000 + 36000 + 40000 diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index 7e4bca1d817..47d850c96fe 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -248,8 +248,8 @@ - - + + @@ -265,8 +265,8 @@ - - + +
@@ -297,11 +297,11 @@
-
- Invoiced - Forecast +
+ Invoiced + Forecast
-
+

Define an invoicing target in the sales team settings to see the period's achievement and forecast at a glance.