Skip to content

Commit

Permalink
[FIX] hr_expense: view receipts of expense line when clicked on
Browse files Browse the repository at this point in the history
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in /pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

Part-of: #165117
  • Loading branch information
alialfie committed May 11, 2024
1 parent 14f8e20 commit 69d14a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _default_employee_id(self):
product_has_tax = fields.Boolean(string="Whether tax is defined on a selected product", compute='_compute_from_product')
quantity = fields.Float(required=True, digits='Product Unit of Measure', default=1)
description = fields.Text(string="Internal Notes")
message_main_attachment_checksum = fields.Char(related='message_main_attachment_id.checksum')
nb_attachment = fields.Integer(string="Number of Attachments", compute='_compute_nb_attachment')
attachment_ids = fields.One2many(
comodel_name='ir.attachment',
Expand Down
12 changes: 7 additions & 5 deletions addons/hr_expense/static/src/views/expense_line_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ export class ExpenseLinesListRenderer extends ListRenderer {
setup() {
super.setup();
this.store = useService("mail.store");

this.sheetId = this.env.model.root.resId;
this.sheetThread = this.store.Thread.insert({ model: "hr.expense.sheet", id: this.sheetId });
}

/** @override **/
async onCellClicked(record, column, ev) {
const sheetId = this.env.model.root.resId;
const sheetThread = this.store.Thread.insert({ model: "hr.expense.sheet", id: sheetId });
const attachmentId = record.data.message_main_attachment_id[0]
const attachmentChecksum = record.data.message_main_attachment_checksum;

if (attachmentId) {
sheetThread.update({ mainAttachment: sheetThread.attachments.find((attachment) => attachment.id === attachmentId) });
if (attachmentChecksum && this.sheetThread.mainAttachment.checksum !== attachmentChecksum) {
this.sheetThread.update({ mainAttachment: this.sheetThread.attachments.find((attachment) => attachment.checksum === attachmentChecksum) });
}
super.onCellClicked(record, column, ev);
}
Expand All @@ -45,6 +46,7 @@ export class ExpenseLinesWidget extends X2ManyField {
export const expenseLinesWidget = {
...x2ManyField,
component: ExpenseLinesWidget,
relatedFields: [{ name: "message_main_attachment_checksum", type: "char" }],
};

registry.category("fields").add("expense_lines_widget", expenseLinesWidget);

0 comments on commit 69d14a8

Please sign in to comment.