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

[IMP] point_of_sale: tests that generates sales report #163807

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

taal-odoo
Copy link

Ensure sales report generation stability

  • Added a tour to test sales report download flow
  • Implemented unit test for report generation and download controller method

task-3674920

@robodoo
Copy link
Contributor

robodoo commented Apr 29, 2024

@C3POdoo C3POdoo added the RD research & development, internal work label Apr 29, 2024
@taal-odoo taal-odoo force-pushed the master-pos-test-sales-report-taal branch from 9d79b2d to 8fafaf3 Compare May 9, 2024 11:11
@@ -0,0 +1,31 @@
/** @odoo-module */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** @odoo-module */

@@ -109,3 +112,69 @@ def test_report_session_2(self):
session_name = self.env['pos.session'].browse(payment['session']).name
payment_method_name = self.env['pos.payment.method'].browse(payment['id']).name
self.assertEqual(payment['name'], payment_method_name + " " + session_name)

def test_report_session_pdf(self):

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change


import { registry } from "@web/core/registry";

registry.category("web_tour.tours").add("SaleReportUITour", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
registry.category("web_tour.tours").add("SaleReportUITour", {
registry.category("web_tour.tours").add("PosSalesReportUITour", {

})

self.main_pos_config.with_user(self.pos_user).open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'SaleReportUITour', login="pos_user")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'SaleReportUITour', login="pos_user")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PosSalesReportUITour', login="pos_user")

Comment on lines 142 to 144
'discount': 0,
'qty': 1,
'tax_ids': [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'discount': 0,
'qty': 1,
'tax_ids': [],

Comment on lines 118 to 129
self.test_user = self.env['res.users'].create({
'name': 'A test user with account rights',
'login': 'test_user',
'password': 'test_user',
'groups_id': [(6, 0, [
self.env.ref('base.group_user').id,
self.env.ref('point_of_sale.group_pos_user').id,
self.env.ref('account.group_account_user').id,
])],
})

self.authenticate("test_user", "test_user")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.test_user = self.env['res.users'].create({
'name': 'A test user with account rights',
'login': 'test_user',
'password': 'test_user',
'groups_id': [(6, 0, [
self.env.ref('base.group_user').id,
self.env.ref('point_of_sale.group_pos_user').id,
self.env.ref('account.group_account_user').id,
])],
})
self.authenticate("test_user", "test_user")
self.authenticate("accountman", "accountman")

I would try something like this.

Comment on lines 158 to 180
# Generate report
report_url = f"/report/pdf/point_of_sale.report_saledetails/{session_id_2}"
data = json.dumps([report_url, 'qweb-pdf'])
context = json.dumps({
"lang": "en_US",
"tz": False,
"uid": self.env.uid,
"allowed_company_ids": [self.env.company.id]
})
token = 'dummy-token'
response = self.url_open(
'/report/download?data=%s&context=%s&token=%s' % (data, context, token),
headers={
'Content-Type': 'application/json',
'X-CSRF-Token': http.Request.csrf_token(self),
},
)

self.config.current_session_id.action_pos_session_closing_control()

self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers['Content-Type'], 'application/pdf')
self.assertIn('attachment; filename*=UTF-8\'\'Sales%20Details.pdf', response.headers['Content-Disposition'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Open UI and Order creation code are same in the above test.

Comment on lines 18 to 22
PaymentScreen.enterPaymentLineAmount("Cash", "5.1", true, {
amount: "5.10",
remaining: "0.00",
change: "0.00",
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
PaymentScreen.enterPaymentLineAmount("Cash", "5.1", true, {
amount: "5.10",
remaining: "0.00",
change: "0.00",
}),
PaymentScreen.enterPaymentLineAmount("Cash", "5.1"),

Comment on lines 168 to 174
response = self.url_open(
'/report/download?data=%s&context=%s&token=%s' % (data, context, token),
headers={
'Content-Type': 'application/json',
'X-CSRF-Token': http.Request.csrf_token(self),
},
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would test the report using _render_qweb_pdf method in test_report_session_2.

Comment on lines 1229 to 1237
def test_sales_report_generation(self):
self.pos_user.write({
'groups_id': [
(4, self.env.ref('account.group_account_user').id),
]
})

self.main_pos_config.with_user(self.pos_user).open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'SaleReportUITour', login="pos_user")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use report action and _render_qweb_pdf method for report test

@taal-odoo taal-odoo force-pushed the master-pos-test-sales-report-taal branch from 8fafaf3 to 50c8197 Compare May 17, 2024 10:06
Ensure sales report generation stability

- Added a tour to test sales report download flow
- Added checks for PDF generation and rendering after the report session test.

task-3674920
@taal-odoo taal-odoo force-pushed the master-pos-test-sales-report-taal branch from 50c8197 to c35f29f Compare May 20, 2024 05:47
@vlst-odoo vlst-odoo self-requested a review May 29, 2024 16:03
Comment on lines +40 to +50
export function secondary(text) {
let trigger = ".modal-footer .btn-secondary";
if (text) {
trigger += `:contains("${text}")`;
}
return {
content: "${text} dialog",
in_modal: true,
trigger,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you can simply use the confirm function with the proper arguments. There's no need for a new function

ReceiptScreen.isShown(),
ReceiptScreen.clickNextOrder(),
Chrome.clickMenuOption("Close Register"),
Dialog.secondary("Daily Sale"),
Copy link
Contributor

Choose a reason for hiding this comment

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

just add this one line, with Dialog.confirm instead of Dialog.secondary to an existing tour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants