[ADD] hr_expense: add similar expense detection - #5226
Conversation
|
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
left a comment
There was a problem hiding this comment.
Same comment about the commit tag here btw!
Nice work
|
|
||
|
|
There was a problem hiding this comment.
Extra line break here
| 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), |
There was a problem hiding this comment.
Starting version 18.0, the translation method is loaded in env
| 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), |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
You already have the field setup for you!
duplicate_expense_ids
| 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): |
0cccb39 to
7fe53c0
Compare
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.
7fe53c0 to
4d996ce
Compare
| 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), | ||
| ) |
There was a problem hiding this comment.
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!
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