diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 6af425a888787e8877dc21f62b9be0d65bef1268..fc0f1e14d9291c3e726c8c7d37e798a21048fc84 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -589,6 +589,9 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust ('user_id.email', 'ilike', email_address) ], limit=1) + if not employee: + return super().message_new(msg_dict, custom_values=custom_values) + expense_description = msg_dict.get('subject', '') if employee.user_id: @@ -651,15 +654,16 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust symbols_pattern = '|'.join(symbols) price_pattern = "((%s)?\s?%s\s?(%s)?)" % (symbols_pattern, float_pattern, symbols_pattern) matches = re.findall(price_pattern, expense_description) + currency = currencies and currencies[0] if matches: match = max(matches, key=lambda match: len([group for group in match if group])) # get the longuest match. e.g. "2 chairs 120$" -> the price is 120$, not 2 full_str = match[0] currency_str = match[1] or match[3] price = match[2].replace(',', '.') - if currency_str: - currency = currencies.filtered(lambda c: currency_str in [c.symbol, c.name])[0] - currency = currency or currencies[0] + if currency_str and currencies: + currencies = currencies.filtered(lambda c: currency_str in [c.symbol, c.name]) + currency = (currencies and currencies[0]) or currency expense_description = expense_description.replace(full_str, ' ') # remove price from description expense_description = re.sub(' +', ' ', expense_description.strip())