Skip to content

[ADD] hr_expense: add similar expense detection - #5226

Open
Tom-Hermann wants to merge 1 commit into
19.0-onboarding-august-malbfrom
19.0-hr_expense-onboarding-duplicate-detection-toher
Open

[ADD] hr_expense: add similar expense detection#5226
Tom-Hermann wants to merge 1 commit into
19.0-onboarding-august-malbfrom
19.0-hr_expense-onboarding-duplicate-detection-toher

Conversation

@Tom-Hermann

Copy link
Copy Markdown

Add a new warning message in the expense form view to alert the user when a similar expense already exists. The similarity is determined by matching the product, date, total amount, and employee.

Task id: 6438999

@robodoo

robodoo commented Aug 7, 2026

Copy link
Copy Markdown

This PR targets the un-managed branch odoo-dev/odoo:19.0-onboarding-august-malb, it needs to be retargeted before it can be merged.

@SaddemAmine SaddemAmine left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about the commit tag here btw!
Nice work

Comment thread addons/hr_expense/models/hr_expense.py Outdated
Comment on lines +734 to +735


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line break here

Suggested change

Comment thread addons/hr_expense/models/hr_expense.py Outdated
def action_show_similar_expense_ids(self):
self.ensure_one()
return self.similar_expense_ids._get_records_action(
name=_("Similar Expenses to %(other_expense_name)s", other_expense_name=self.name),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting version 18.0, the translation method is loaded in env

Suggested change
name=_("Similar Expenses to %(other_expense_name)s", other_expense_name=self.name),
name=self.env._("Similar Expenses to %(other_expense_name)s", other_expense_name=self.name),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the code base, I found a few places where this is still used. Does it no longer work, or is it just depreciate?
I'm just curious.

Comment thread addons/hr_expense/models/hr_expense.py Outdated
Comment on lines +147 to +149
duplicate_expense_ids = fields.Many2many(comodel_name='hr.expense', compute='_compute_duplicate_expense_ids') # Used to trigger warnings
same_receipt_expense_ids = fields.Many2many(comodel_name='hr.expense', compute='_compute_same_receipt_expense_ids') # Used to trigger warnings
similar_expense_ids = fields.Many2many(comodel_name='hr.expense', compute='_compute_similar_expense_ids') # Used to trigger warnings

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have the field setup for you!
duplicate_expense_ids

Comment thread addons/hr_expense/models/hr_expense.py Outdated
expense.same_receipt_expense_ids = [Command.set(list(same_receipt_ids))]

@api.depends('product_id', 'date', 'total_amount_currency', 'employee_id')
def _compute_similar_expense_ids(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this

@Tom-Hermann
Tom-Hermann force-pushed the 19.0-hr_expense-onboarding-duplicate-detection-toher branch from 0cccb39 to 7fe53c0 Compare August 13, 2026 12:10
Add a new warning message in the expense form view to alert the user when a similar expense already exists.
The similarity is determined by matching the product, date, total amount, and employee.
@Tom-Hermann
Tom-Hermann force-pushed the 19.0-hr_expense-onboarding-duplicate-detection-toher branch from 7fe53c0 to 4d996ce Compare August 13, 2026 12:11
Comment on lines +1281 to +1285
def action_show_duplicate_expense_ids(self):
self.ensure_one()
return self.duplicate_expense_ids._get_records_action(
name=self.env._("Duplicate Expenses to %(other_expense_name)s", other_expense_name=self.name),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should subtract self from the recordset you render so you don't show the current record to the user
Rest looks good, good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants