def get_full_name(self, cr, uid, ids, field_name, arg, context=None):
return dict(self.name_get(cr, uid, ids, context=context))
- def _currency_conversation(self, cr, uid, id, amount, relation_id, relation_field, context=None):
- team = self.browse(cr, uid, id, context=context)
- base_currency_id = team.currency_id.id
- if relation_field == 'company_id':
- base_currency_id = self.pool.get('res.company').browse(cr, uid, relation_id, context=context).currency_id.id
- return self.pool.get('res.currency').compute(cr, uid, base_currency_id, team.currency_id.id, amount, context=context)
-
- def __get_bar_values(self, cr, uid, id, obj, domain, read_fields, value_field, groupby_field, context=None):
+ def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None):
""" Generic method to generate data for bar chart values using SparklineBarWidget.
This method performs obj.read_group(cr, uid, domain, read_fields, groupby_field).
group_obj = obj.read_group(cr, uid, domain, read_fields, groupby_field, context=context)
for group in group_obj:
group_begin_date = datetime.strptime(group['__domain'][0][2], tools.DEFAULT_SERVER_DATE_FORMAT)
- month = self._period_number - (relativedelta.relativedelta(month_begin, group_begin_date).months + 1)
- section_result[month] = {'value': 0, 'tooltip': group_begin_date.strftime('%B')}
- inner_groupby = (group.get('__context', {})).get('group_by',[])
- if value_field == 'create_date_count' or not inner_groupby:
- section_result[month]['value'] = group.get(value_field, 0)
- continue
- if inner_groupby:
- inner_group_obj = obj.read_group(cr, uid, group.get('__domain'), read_fields, inner_groupby, context=context)
- for groupby in inner_group_obj:
- section_result[month]['value'] += self._currency_conversation(cr, uid, id, groupby.get(value_field, 0), groupby['__domain'][0][2], inner_groupby[0], context=context)
+ month_delta = relativedelta.relativedelta(month_begin, group_begin_date)
+ section_result[self._period_number - (month_delta.months + 1)] = {'value': group.get(value_field, 0), 'tooltip': group_begin_date.strftime('%B')}
return section_result
def _get_opportunities_data(self, cr, uid, ids, field_name, arg, context=None):
for id in ids:
res[id] = dict()
lead_domain = date_domain + [('type', '=', 'lead'), ('section_id', '=', id)]
- res[id]['monthly_open_leads'] = self.__get_bar_values(cr, uid, id, obj, lead_domain, ['create_date','company_id'], 'create_date_count', ['create_date', 'company_id'], context=context)
+ res[id]['monthly_open_leads'] = self.__get_bar_values(cr, uid, obj, lead_domain, ['create_date'], 'create_date_count', 'create_date', context=context)
opp_domain = date_domain + [('type', '=', 'opportunity'), ('section_id', '=', id)]
- res[id]['monthly_planned_revenue'] = self.__get_bar_values(cr, uid, id, obj, opp_domain, ['planned_revenue', 'create_date', 'company_id'], 'planned_revenue', ['create_date', 'company_id'], context=context)
+ res[id]['monthly_planned_revenue'] = self.__get_bar_values(cr, uid, obj, opp_domain, ['planned_revenue', 'create_date'], 'planned_revenue', 'create_date', context=context)
return res
_columns = {
string='Open Leads per Month'),
'monthly_planned_revenue': fields.function(_get_opportunities_data,
type="string", readonly=True, multi='_get_opportunities_data',
- string='Planned Revenue per Month'),
- 'create_uid': fields.many2one('res.users', 'Create User'),
- 'currency_id': fields.many2one('res.currency', 'Currency', required=True),
- 'currency_symbol': fields.related('currency_id', 'symbol', type='char', string='Currency Symbol'),
+ string='Planned Revenue per Month')
}
def _get_stage_common(self, cr, uid, context):
'active': 1,
'stage_ids': _get_stage_common,
'use_leads': True,
- 'currency_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
}
_sql_constraints = [
mail_alias.unlink(cr, uid, alias_ids, context=context)
return res
- def onchange_user(self, cr, uid, ids, user_id, context=None):
- if user_id:
- currency_id = self.pool.get('res.users').browse(cr, uid, user_id, context=context).company_id.currency_id.id
- else:
- currency_id = self.browse(cr, uid, ids[0], context=context).create_uid.company_id.currency_id.id
- return {'value': {'currency_id': currency_id}}
-
class crm_case_categ(osv.osv):
""" Category of Case """
_name = "crm.case.categ"
<field name="color"/>
<field name="monthly_open_leads"/>
<field name="monthly_planned_revenue"/>
- <field name="currency_symbol"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_kanban_crm_salesteams">
</div>
<div class="oe_salesteams_opportunities">
<a name="%(crm_case_form_view_salesteams_opportunity)d" type="action">Opportunities</a>
- <a name="%(action_report_crm_opportunity_salesteam)d" type="action"><field name="monthly_planned_revenue" widget="sparkline_bar" options="{'height': '20px', 'barWidth': '4', 'barSpacing': '1', 'delayIn': '3000', 'tooltip_suffix_field': 'currency_symbol'}">Planned Revenue per Month<br/>Click to see a detailed analysis of opportunities.</field></a>
+ <a name="%(action_report_crm_opportunity_salesteam)d" type="action"><field name="monthly_planned_revenue" widget="sparkline_bar" options="{'height': '20px', 'barWidth': '4', 'barSpacing': '1', 'delayIn': '3000'}">Planned Revenue per Month<br/>Click to see a detailed analysis of opportunities.</field></a>
</div>
</div>
<div class="oe_kanban_salesteams_avatars">
</div>
<group>
<group>
- <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}" on_change="onchange_user(user_id)"/>
+ <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>
<field name="code"/>
<field name="parent_id"/>
<field name="change_responsible"/>
font-size: 10px;
}
-.openerp .oe_kanban_view .oe_salesteams_justgage {
- color: black;
- display: inline-block;
- bottom: 0;
-}
-
-.openerp .oe_kanban_view .oe_sparkline_bar {
- height: 20px;
- width: 36px !important;
-}
-
.openerp .oe_kanban_view .oe_salesteams_help {
display: inline-block;
}
class crm_case_section(osv.osv):
_inherit = 'crm.case.section'
- def _currency_conversation(self, cr, uid, id, amount, relation_id, relation_field, context=None):
- team = self.browse(cr, uid, id, context=context)
- base_currency_id = team.currency_id.id
- if relation_field not in ['pricelist_id', 'currency_id']:
- return super(crm_case_section, self)._currency_conversation(cr, uid, id, amount, relation_id, relation_field, context=context)
- if relation_field == 'pricelist_id':
- base_currency_id = self.pool.get('product.pricelist').browse(cr, uid, relation_id, context=context).currency_id.id
- elif relation_field == 'currency_id':
- currency_rates = self.pool.get('res.currency.rate').search_read(cr, uid, [('rate', '=', 1)], ['currency_id'], limit=1, context=context)
- if currency_rates:
- base_currency_id = currency_rates[0]['currency_id'][0]
- return self.pool.get('res.currency').compute(cr, uid, base_currency_id, team.currency_id.id, amount, context=context)
-
def _get_sale_orders_data(self, cr, uid, ids, field_name, arg, context=None):
obj = self.pool.get('sale.order')
res = dict.fromkeys(ids, False)
for id in ids:
res[id] = dict()
created_domain = [('section_id', '=', id), ('state', 'in', ['draft', 'sent']), ('date_order', '>=', date_begin), ('date_order', '<=', date_end)]
- res[id]['monthly_quoted'] = self.__get_bar_values(cr, uid, id, obj, created_domain, ['amount_total', 'date_order', 'pricelist_id'], 'amount_total', ['date_order', 'pricelist_id'], context=context)
+ res[id]['monthly_quoted'] = self.__get_bar_values(cr, uid, obj, created_domain, ['amount_total', 'date_order'], 'amount_total', 'date_order', context=context)
validated_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'sent']), ('date_confirm', '>=', date_begin), ('date_order', '<=', date_end)]
- res[id]['monthly_confirmed'] = self.__get_bar_values(cr, uid, id, obj, validated_domain, ['amount_total', 'date_confirm', 'pricelist_id'], 'amount_total', ['date_confirm', 'pricelist_id'], context=context)
+ res[id]['monthly_confirmed'] = self.__get_bar_values(cr, uid, obj, validated_domain, ['amount_total', 'date_confirm'], 'amount_total', 'date_confirm', context=context)
return res
def _get_invoices_data(self, cr, uid, ids, field_name, arg, context=None):
date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
for id in ids:
created_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'cancel']), ('date', '>=', date_begin), ('date', '<=', date_end)]
- res[id] = self.__get_bar_values(cr, uid, id, obj, created_domain, ['price_total', 'date', 'currency_id'], 'price_total', ['date', 'currency_id'], context=context)
+ res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['price_total', 'date'], 'price_total', 'date', context=context)
return res
_columns = {
- 'invoiced_forecast': fields.float("Invoice Forecast",
+ 'invoiced_forecast': fields.integer(string='Invoice Forecast',
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.float("Invoice Target",
+ 'invoiced_target': fields.integer(string='Invoice Target',
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,
}
def action_forecast(self, cr, uid, id, value, context=None):
- return self.write(cr, uid, [id], {'invoiced_forecast': value}, context=context)
+ return self.write(cr, uid, [id], {'invoiced_forecast': round(float(value))}, context=context)
+
class res_users(osv.Model):
_inherit = 'res.users'
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='code']" position="after">
- <field name="currency_id" invisible="1"/>
- <field name="invoiced_target" readonly="0" widget="monetary" options="{'currency_field': 'currency_id'}"/>
- <field name="invoiced_forecast" readonly="0" widget="monetary" options="{'currency_field': 'currency_id'}"/>
+ <field name="invoiced_target"/>
+ <field name="invoiced_forecast"/>
</xpath>
</data>
</field>
<div class="oe_salesteams_orders">
<a name="%(action_orders_salesteams)d" type="action">Sales Orders</a>
<a name="%(action_order_report_so_salesteam)d" type="action" class="oe_sparkline_bar_link">
- <field name="monthly_confirmed" widget="sparkline_bar" options="{'delayIn': '3000', 'tooltip_suffix_field': 'currency_symbol'}">
+ <field name="monthly_confirmed" widget="sparkline_bar" options="{'delayIn': '3000'}">
Revenue of confirmed sales orders per month.<br/>Click to acces the Sales Analysis.
</field>
</a>
<div class="oe_salesteams_invoices" groups="account.group_account_invoice">
<a name="%(action_invoice_salesteams)d" type="action">Invoices</a>
<a name="%(action_account_invoice_report_salesteam)d" type="action" class="oe_sparkline_bar_link">
- <field name="monthly_invoiced" widget="sparkline_bar" options="{'delayIn': '3000', 'tooltip_suffix_field': 'currency_symbol'}">
+ <field name="monthly_invoiced" widget="sparkline_bar" options="{'delayIn': '3000'}">
Revenue of sent invoices per month.<br/>Click to see a detailed analysis of invoices.
</field>
</a>
<div class="oe_salesteams_quotations">
<a name="%(action_quotations_salesteams)d" type="action" class="oe_sparkline_bar_link">Quotations</a>
<a name="%(action_order_report_quotation_salesteam)d" type="action" class="oe_sparkline_bar_link">
- <field name="monthly_quoted" widget="sparkline_bar" options="{'delayIn': '3000', 'tooltip_suffix_field': 'currency_symbol'}">
+ <field name="monthly_quoted" widget="sparkline_bar" options="{'delayIn': '3000'}">
Revenue of created quotations per month.<br/>Click to see a detailed analysis.
</field>
</a>
+++ /dev/null
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Business Applications
-# Copyright (c) 2013-TODAY OpenERP S.A. <http://www.openerp.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-
-from . import test_sale_crm_case
-
-checks = [
- test_sale_crm_case,
-]
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+++ /dev/null
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Business Applications
-# Copyright (c) 2013-TODAY OpenERP S.A. <http://www.openerp.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-
-from openerp.addons.mail.tests.common import TestMail
-
-class TestSaleCrm(TestMail):
-
- def test_sale_crm_case(self):
- """Testing __get_bar_values method"""
- cr, uid, = self.cr, self.uid
-
- # Usefull models
- ir_model_obj = self.registry('ir.model.data')
- res_company_obj = self.registry('res.company')
- res_users_obj = self.registry('res.users')
- crm_case_section_obj = self.registry('crm.case.section')
- crm_lead_obj = self.registry('crm.lead')
-
- # Get required ids
- direct_sales_id = ir_model_obj.get_object_reference(cr, uid, 'crm', 'section_sales_department')[1]
- usd_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'USD')[1]
- your_company_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'main_company')[1]
-
- # Call relevant methods before changing manager of sales team.
- opportunities_before = crm_case_section_obj._get_opportunities_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
- sale_order_before = crm_case_section_obj._get_sale_orders_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
- invoice_before = crm_case_section_obj._get_invoices_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
-
- # Create new company with USD currency.
- res_company_id = res_company_obj.create(cr, uid,{
- 'name': 'New Company',
- 'currency_id': usd_id,
- 'parent_id': your_company_id
- })
-
- # Create new user with sales manager access rights for new company.
- group_sale_manager_id = ir_model_obj.get_object_reference(cr, uid, 'base', 'group_sale_manager')[1]
- res_users_id = res_users_obj.create(cr, uid,{
- 'name': 'User',
- 'login': 'admin@example.com',
- 'company_id': res_company_id,
- 'company_ids': [(6, 0, [res_company_id])],
- 'email': 'admin@gmail.com',
- 'groups_id': [(6, 0, [group_sale_manager_id])]
- })
-
- # Change manager of sales team with USD currency.
- crm_case_section_obj.write(cr, uid, [direct_sales_id], {
- 'user_id' : res_users_id,
- 'currency_id': usd_id,
- })
-
- # Call relevant methods and get converted data in another currency.
- opportunities_after = crm_case_section_obj._get_opportunities_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
- sale_order_after = crm_case_section_obj._get_sale_orders_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
- invoice_after = crm_case_section_obj._get_invoices_data(cr, uid, [direct_sales_id], field_name=False, arg=False, context=False)
-
- team_currency_rate = crm_case_section_obj.browse(cr, uid, direct_sales_id).currency_id.rate_silent
-
- # Check currency conversion for Quotations,Sale orders and Invoices in to the current users currency
- for month in range(0,5):
- self.assertTrue(round(opportunities_before[1]['monthly_planned_revenue'][month]['value']) == round(opportunities_after[1]['monthly_planned_revenue'][month]['value'] / team_currency_rate), "Not Proper Currency Conversion for Opportunities")
- self.assertTrue(round(sale_order_before[1]['monthly_quoted'][month]['value']) == round(sale_order_after[1]['monthly_quoted'][month]['value'] / team_currency_rate), "Currency conversion for quotations is wrong")
- self.assertTrue(round(sale_order_before[1]['monthly_confirmed'][month]['value']) == round(sale_order_after[1]['monthly_confirmed'][month]['value'] / team_currency_rate), "Currency conversion for sale orders is wrong")
- self.assertTrue(round(invoice_before[1][month]['value']) == round(invoice_after[1][month]['value'] / team_currency_rate), "Currency conversion for invoices is wrong")