Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] hr_expense: view receipts of expense line when clicked on #165117

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
45 changes: 45 additions & 0 deletions addons/hr_expense/static/src/js/tours/show_expense_receipt_tour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/** @odoo-module **/

import { registry } from "@web/core/registry";
import { stepUtils } from "@web_tour/tour_service/tour_utils";

registry.category("web_tour.tours").add('show_expense_receipt_tour', {
test: true,
url: '/web',
steps: () => [
...stepUtils.goToAppSteps('hr_expense.menu_hr_expense_root', "Go to the Expenses app"),
{
content: "Go to Expense Reports",
trigger: '.dropdown-item[data-menu-xmlid="hr_expense.menu_hr_expense_report"]',
position:'bottom',
},
{
content: "Go to a report",
trigger: '.o_data_row .o_data_cell[name="payment_state"]',
},
{
content: "Click on an expense line 2",
trigger: '.o_data_row .o_data_cell[data-tooltip="expense_2"]',
},
{
content: "Check attachment",
trigger: ".o_attachment_preview .o-mail-Attachment-imgContainer .img[src*='test_file_2.png']",
},
{
content: "Click on an expense line 3",
trigger: '.o_data_row .o_data_cell[data-tooltip="expense_3"]',
},
{
content: "Check attachment",
trigger: ".o_attachment_preview .o-mail-Attachment-imgContainer .img[src*='test_file_3.png']",
},
{
content: "Click on an expense line 1",
trigger: '.o_data_row .o_data_cell[data-tooltip="expense_1"]',
},
{
content: "Check attachment",
trigger: ".o_attachment_preview .o-mail-Attachment-imgContainer .img[src*='test_file_1.png']",
},
],
});
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);
109 changes: 0 additions & 109 deletions addons/hr_expense/static/tests/views/expense_line_widget.test.js

This file was deleted.

1 change: 1 addition & 0 deletions addons/hr_expense/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import test_expenses
from . import test_expenses_access_rights
from . import test_expenses_mail_import
from . import test_ui
62 changes: 62 additions & 0 deletions addons/hr_expense/tests/test_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from odoo import Command
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
from odoo.tests import tagged, HttpCase


@tagged('-at_install', 'post_install')
class TestUi(TestExpenseCommon, HttpCase):
browser_size = "1920,1080"

def test_show_expense_receipt_on_expense_line_click(self):
expense_1, expense_2, expense_3 = self.env['hr.expense'].create([
{
'name': 'expense_1',
'employee_id': self.expense_employee.id,
'product_id': self.product_c.id,
'total_amount': 1000,
},
{
'name': 'expense_2',
'employee_id': self.expense_employee.id,
'product_id': self.product_c.id,
'total_amount': 999,
},
{
'name': 'expense_3',
'employee_id': self.expense_employee.id,
'product_id': self.product_c.id,
'total_amount': 998,
},
])
attachment_1, attachment_2, attachment_3 = self.env['ir.attachment'].create([
{
'name': "test_file_1.png",
'raw': b"R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=1",
'res_id': expense_1.id,
'res_model': 'hr.expense',
},
{
'name': "test_file_2.png",
'raw': b"R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=2",
'res_id': expense_2.id,
'res_model': 'hr.expense',
},
{
'name': "test_file_3.png",
'raw': b"R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=3",
'res_id': expense_3.id,
'res_model': 'hr.expense',
},
])

expense_1.message_main_attachment_id = attachment_1
expense_2.message_main_attachment_id = attachment_2
expense_3.message_main_attachment_id = attachment_3

self.env['hr.expense.sheet'].create({
'employee_id': self.expense_employee.id,
'name': 'test sheet',
'expense_line_ids': [Command.set([expense_1.id, expense_2.id, expense_3.id])],
})

self.start_tour('/web', 'show_expense_receipt_tour', login=self.env.user.login)