diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 932fa998d0a..dc7ebf3ca95 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -19,6 +19,7 @@ # ############################################################################## +import calendar from datetime import date, datetime from dateutil import relativedelta @@ -117,9 +118,9 @@ class crm_case_section(osv.osv): """ month_begin = date.today().replace(day=1) section_result = [{ - 'value': 0, - 'tooltip': (month_begin + relativedelta.relativedelta(months=-i)).strftime('%B'), - } for i in range(self._period_number - 1, -1, -1)] + 'value': 0, + 'tooltip': (month_begin + relativedelta.relativedelta(months=-i)).strftime('%B'), + } for i in range(self._period_number - 1, -1, -1)] 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) @@ -135,12 +136,14 @@ class crm_case_section(osv.osv): obj = self.pool.get('crm.lead') res = dict.fromkeys(ids, False) month_begin = date.today().replace(day=1) - groupby_begin = (month_begin + relativedelta.relativedelta(months=-4)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + date_begin = month_begin - relativedelta.relativedelta(months=self._period_number - 1) + date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]) + date_domain = [('create_date', '>=', date_begin.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)), ('create_date', '<=', date_end.strftime(tools.DEFAULT_SERVER_DATE_FORMAT))] for id in ids: res[id] = dict() - lead_domain = [('type', '=', 'lead'), ('section_id', '=', id), ('create_date', '>=', groupby_begin)] + lead_domain = date_domain + [('type', '=', 'lead'), ('section_id', '=', id)] 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 = [('type', '=', 'opportunity'), ('section_id', '=', id), ('create_date', '>=', groupby_begin)] + opp_domain = date_domain + [('type', '=', 'opportunity'), ('section_id', '=', id)] 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 diff --git a/addons/mass_mailing/mass_mailing.py b/addons/mass_mailing/mass_mailing.py index 49ee106bc69..4f59994d4a6 100644 --- a/addons/mass_mailing/mass_mailing.py +++ b/addons/mass_mailing/mass_mailing.py @@ -194,10 +194,13 @@ class MassMailing(osv.Model): } for id in ids: res[id] = {} - date_begin = self.browse(cr, uid, id, context=context).date - domain = [('mass_mailing_id', '=', id), ('opened', '>=', date_begin)] + date_begin = datetime.strptime(self.browse(cr, uid, id, context=context).date, tools.DEFAULT_SERVER_DATETIME_FORMAT) + date_end = date_begin + relativedelta.relativedelta(days=self._period_number - 1) + date_begin_str = date_begin.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) + date_end_str = date_end.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) + domain = [('mass_mailing_id', '=', id), ('opened', '>=', date_begin_str), ('opened', '<=', date_end_str)] res[id]['opened_monthly'] = self.__get_bar_values(cr, uid, id, obj, domain, ['opened'], 'opened_count', 'opened', context=context) - domain = [('mass_mailing_id', '=', id), ('replied', '>=', date_begin)] + domain = [('mass_mailing_id', '=', id), ('replied', '>=', date_begin_str), ('replied', '<=', date_end_str)] res[id]['replied_monthly'] = self.__get_bar_values(cr, uid, id, obj, domain, ['replied'], 'replied_count', 'replied', context=context) return res @@ -274,7 +277,7 @@ class MassMailing(osv.Model): } _defaults = { - 'date': fields.datetime.now(), + 'date': fields.datetime.now, } diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index d6413c994e7..47caad79c26 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -19,6 +19,7 @@ # ############################################################################## +import calendar from datetime import date from dateutil import relativedelta @@ -48,12 +49,13 @@ class crm_case_section(osv.osv): obj = self.pool.get('sale.order') res = dict.fromkeys(ids, False) month_begin = date.today().replace(day=1) - groupby_begin = (month_begin + relativedelta.relativedelta(months=-4)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + date_begin = month_begin - relativedelta.relativedelta(months=self._period_number - 1).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + 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: res[id] = dict() - created_domain = [('section_id', '=', id), ('state', 'in', ['draft', 'sent']), ('date_order', '>=', groupby_begin)] + 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, 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', '>=', groupby_begin)] + 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, obj, validated_domain, ['amount_total', 'date_confirm'], 'amount_total', 'date_confirm', context=context) return res