diff --git a/addons/crm/crm.py b/addons/crm/crm.py index cddd2a166de..a98fcadb959 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -101,14 +101,7 @@ class crm_case_section(osv.osv): 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). @@ -132,16 +125,8 @@ class crm_case_section(osv.osv): 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): @@ -158,9 +143,9 @@ class crm_case_section(osv.osv): 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 = { @@ -191,10 +176,7 @@ class crm_case_section(osv.osv): 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): @@ -205,7 +187,6 @@ class crm_case_section(osv.osv): '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 = [ @@ -249,13 +230,6 @@ class crm_case_section(osv.osv): 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" diff --git a/addons/crm/crm_case_section_view.xml b/addons/crm/crm_case_section_view.xml index e032376cb05..b674bf95061 100644 --- a/addons/crm/crm_case_section_view.xml +++ b/addons/crm/crm_case_section_view.xml @@ -124,7 +124,6 @@ -
@@ -148,7 +147,7 @@
@@ -224,7 +223,7 @@
- + diff --git a/addons/crm/static/src/css/crm.css b/addons/crm/static/src/css/crm.css index 311727fe51d..f11e932504e 100644 --- a/addons/crm/static/src/css/crm.css +++ b/addons/crm/static/src/css/crm.css @@ -55,17 +55,6 @@ 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; } diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 1fedc6a9945..a2c2b7e2af3 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -45,19 +45,6 @@ class sale_order(osv.osv): 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) @@ -67,9 +54,9 @@ class crm_case_section(osv.osv): 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): @@ -80,15 +67,15 @@ class crm_case_section(osv.osv): 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, @@ -103,7 +90,8 @@ class crm_case_section(osv.osv): } 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' diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index ce8c5a26efb..4669f669276 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -248,9 +248,8 @@ - - - + + @@ -273,7 +272,7 @@
Sales Orders - + Revenue of confirmed sales orders per month.
Click to acces the Sales Analysis.
@@ -283,7 +282,7 @@
Invoices - + Revenue of sent invoices per month.
Click to see a detailed analysis of invoices.
@@ -291,7 +290,7 @@
Quotations - + Revenue of created quotations per month.
Click to see a detailed analysis.
diff --git a/addons/sale_crm/tests/__init__.py b/addons/sale_crm/tests/__init__.py deleted file mode 100644 index fc04080875f..00000000000 --- a/addons/sale_crm/tests/__init__.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Business Applications -# Copyright (c) 2013-TODAY OpenERP S.A. -# -# 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 . -# -############################################################################## - -from . import test_sale_crm_case - -checks = [ - test_sale_crm_case, -] - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale_crm/tests/test_sale_crm_case.py b/addons/sale_crm/tests/test_sale_crm_case.py deleted file mode 100644 index 6fb7d4c555a..00000000000 --- a/addons/sale_crm/tests/test_sale_crm_case.py +++ /dev/null @@ -1,83 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Business Applications -# Copyright (c) 2013-TODAY OpenERP S.A. -# -# 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 . -# -############################################################################## - -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")