diff --git a/addons/account/account.py b/addons/account/account.py index 1ab819c01c6..cd9527ff903 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1938,15 +1938,15 @@ class account_tax(osv.osv): # 'base_code_id': fields.many2one('account.tax.code', 'Account Base Code', help="Use this code for the tax declaration."), 'tax_code_id': fields.many2one('account.tax.code', 'Account Tax Code', help="Use this code for the tax declaration."), - 'base_sign': fields.float('Base Code Sign', help="Usually 1 or -1."), - 'tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1."), + 'base_sign': fields.float('Base Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()), + 'tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()), # Same fields for refund invoices 'ref_base_code_id': fields.many2one('account.tax.code', 'Refund Base Code', help="Use this code for the tax declaration."), 'ref_tax_code_id': fields.many2one('account.tax.code', 'Refund Tax Code', help="Use this code for the tax declaration."), - 'ref_base_sign': fields.float('Refund Base Code Sign', help="Usually 1 or -1."), - 'ref_tax_sign': fields.float('Refund Tax Code Sign', help="Usually 1 or -1."), + 'ref_base_sign': fields.float('Refund Base Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()), + 'ref_tax_sign': fields.float('Refund Tax Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()), 'include_base_amount': fields.boolean('Included in base amount', help="Indicates if the amount of tax must be included in the base amount for the computation of the next taxes"), 'company_id': fields.many2one('res.company', 'Company', required=True), 'description': fields.char('Tax Code'), diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index 784358dceed..adb0ef784d5 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -680,19 +680,23 @@ class calendar_event(osv.Model): return [d.astimezone(pytz.UTC) for d in rset1] def _get_recurrency_end_date(self, data, context=None): - if data.get('recurrency') and data.get('end_type') in ('count', unicode('count')): - data_date_deadline = datetime.strptime(data.get('date_deadline'), '%Y-%m-%d %H:%M:%S') - if data.get('rrule_type') in ('daily', unicode('count')): - rel_date = relativedelta(days=data.get('count') + 1) - elif data.get('rrule_type') in ('weekly', unicode('weekly')): - rel_date = relativedelta(days=(data.get('count') + 1) * 7) - elif data.get('rrule_type') in ('monthly', unicode('monthly')): - rel_date = relativedelta(months=data.get('count') + 1) - elif data.get('rrule_type') in ('yearly', unicode('yearly')): - rel_date = relativedelta(years=data.get('count') + 1) - end_date = data_date_deadline + rel_date - else: - end_date = data.get('end_date') + if not data.get('recurrency'): + return False + + end_type = data.get('end_type') + end_date = data.get('end_date') + + if end_type == 'count' and all(data.get(key) for key in ['count', 'rrule_type', 'date_deadline']): + count = data['count'] + 1 + delay, mult = { + 'daily': ('days', 1), + 'weekly': ('days', 7), + 'monthly': ('months', 1), + 'yearly': ('years', 1), + }[data['rrule_type']] + + deadline = datetime.strptime(data['date_deadline'], tools.DEFAULT_SERVER_DATETIME_FORMAT) + return deadline + relativedelta(**{delay: count * mult}) return end_date def _find_my_attendee(self, cr, uid, meeting_ids, context=None): @@ -774,7 +778,11 @@ class calendar_event(osv.Model): result[event] = "" return result + # retro compatibility function def _rrule_write(self, cr, uid, ids, field_name, field_value, args, context=None): + return self._set_rulestring(self, cr, uid, ids, field_name, field_value, args, context=context) + + def _set_rulestring(self, cr, uid, ids, field_name, field_value, args, context=None): if not isinstance(ids, list): ids = [ids] data = self._get_empty_rrule_data() @@ -812,7 +820,7 @@ class calendar_event(osv.Model): 'class': fields.selection([('public', 'Public'), ('private', 'Private'), ('confidential', 'Public for Employees')], 'Privacy', states={'done': [('readonly', True)]}), 'location': fields.char('Location', help="Location of Event", track_visibility='onchange', states={'done': [('readonly', True)]}), 'show_as': fields.selection([('free', 'Free'), ('busy', 'Busy')], 'Show Time as', states={'done': [('readonly', True)]}), - 'rrule': fields.function(_get_rulestring, type='char', fnct_inv=_rrule_write, store=True, string='Recurrent Rule'), + 'rrule': fields.function(_get_rulestring, type='char', fnct_inv=_set_rulestring, store=True, string='Recurrent Rule'), 'rrule_type': fields.selection([('daily', 'Day(s)'), ('weekly', 'Week(s)'), ('monthly', 'Month(s)'), ('yearly', 'Year(s)')], 'Recurrency', states={'done': [('readonly', True)]}, help="Let the event automatically repeat at that interval"), 'recurrency': fields.boolean('Recurrent', help="Recurrent Meeting"), 'recurrent_id': fields.integer('Recurrent ID'), @@ -1169,7 +1177,7 @@ class calendar_event(osv.Model): #repeat monthly by nweekday ((weekday, weeknumber), ) if r._bynweekday: data['week_list'] = day_list[r._bynweekday[0][0]].upper() - data['byday'] = r._bynweekday[0][1] + data['byday'] = str(r._bynweekday[0][1]) data['month_by'] = 'day' data['rrule_type'] = 'monthly' @@ -1423,7 +1431,7 @@ class calendar_event(osv.Model): # set end_date for calendar searching if values.get('recurrency', True) and values.get('end_type', 'count') in ('count', unicode('count')) and \ (values.get('rrule_type') or values.get('count') or values.get('date') or values.get('date_deadline')): - for data in self.read(cr, uid, ids, ['date', 'date_deadline', 'recurrency', 'rrule_type', 'count', 'end_type'], context=context): + for data in self.read(cr, uid, ids, ['end_date', 'date_deadline', 'recurrency', 'rrule_type', 'count', 'end_type'], context=context): end_date = self._get_recurrency_end_date(data, context=context) super(calendar_event, self).write(cr, uid, [data['id']], {'end_date': end_date}, context=context) @@ -1454,11 +1462,12 @@ class calendar_event(osv.Model): if not 'user_id' in vals: # Else bug with quick_create when we are filter on an other user vals['user_id'] = uid - if vals.get('recurrency', True) and vals.get('end_type', 'count') in ('count', unicode('count')) and \ - (vals.get('rrule_type') or vals.get('count') or vals.get('date') or vals.get('date_deadline')): - vals['end_date'] = self._get_recurrency_end_date(vals, context=context) - res = super(calendar_event, self).create(cr, uid, vals, context=context) + + data = self.read(cr, uid, [res], ['end_date', 'date_deadline', 'recurrency', 'rrule_type', 'count', 'end_type'], context=context)[0] + end_date = self._get_recurrency_end_date(data, context=context) + self.write(cr, uid, [res], {'end_date': end_date}, context=context) + self.create_attendees(cr, uid, [res], context=context) return res diff --git a/addons/calendar/test/calendar_test.yml b/addons/calendar/test/calendar_test.yml index 1454a635a4f..44290d8166f 100644 --- a/addons/calendar/test/calendar_test.yml +++ b/addons/calendar/test/calendar_test.yml @@ -65,3 +65,20 @@ - !python {model: calendar.event}: | self.write(cr, uid, [ref("calendar_event_alldaytestevent0")], {'alarm_ids': [(6,0,[ref("res_alarm_daybeforeeventstarts0")])]}) +- + I create a recuring rule for my event +- + !record {model: calendar.event, id: calendar.event_sprintreview1}: + name: Begin of month meeting + date: !eval time.strftime('%Y-%m-%d 12:00:00') + recurrency: true + rrule: FREQ=MONTHLY;INTERVAL=1;COUNT=12;BYDAY=1MO +- + I check that the attributes are set correctly +- + !assert {model: calendar.event, id: calendar.event_sprintreview1}: + - rrule_type == 'monthly' + - count == 12 + - month_by == 'day' + - byday == '1' + - week_list == 'MO' diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index c64406546c3..347475d100f 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -21,6 +21,7 @@ from openerp.osv import fields, osv from openerp.tools.translate import _ +from openerp.tools import email_split import re class crm_lead2opportunity_partner(osv.osv_memory): @@ -42,20 +43,21 @@ class crm_lead2opportunity_partner(osv.osv_memory): return {'value': {'partner_id': False if action != 'exist' else self._find_matching_partner(cr, uid, context=context)}} def _get_duplicated_leads(self, cr, uid, partner_id, email, context=None): + """ + Search for opportunities that have the same partner and that arent done or cancelled + """ lead_obj = self.pool.get('crm.lead') - results = [] + emails = set(email_split(email) + [email]) + final_stage_domain = [('stage_id.probability', '<', 100), '|', ('stage_id.probability', '>', 0), ('stage_id.sequence', '<=', 1)] + partner_match_domain = [] + for email in emails: + partner_match_domain.append(('email_from', '=ilike', email)) if partner_id: - # Search for opportunities that have the same partner and that arent done or cancelled - ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), '|', ('stage_id.probability', '=', False), ('stage_id.probability', '<', '100')]) - for id in ids: - results.append(id) - email = re.findall(r'([^ ,<@]+@[^> ,]+)', email or '') - if email: - ids = lead_obj.search(cr, uid, [('email_from', '=ilike', email[0]), '|', ('stage_id.probability', '=', False), ('stage_id.probability', '<', '100')]) - for id in ids: - results.append(id) - return list(set(results)) - + partner_match_domain.append(('partner_id', '=', partner_id)) + partner_match_domain = ['|'] * (len(partner_match_domain) - 1) + partner_match_domain + if not partner_match_domain: + return [] + return lead_obj.search(cr, uid, partner_match_domain + final_stage_domain) def default_get(self, cr, uid, fields, context=None): """ diff --git a/addons/crm_partner_assign/crm_lead_view.xml b/addons/crm_partner_assign/crm_lead_view.xml index aa9638fd579..d47e9ac5cbc 100644 --- a/addons/crm_partner_assign/crm_lead_view.xml +++ b/addons/crm_partner_assign/crm_lead_view.xml @@ -15,10 +15,10 @@