-
Notifications
You must be signed in to change notification settings - Fork 23k
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
base: master
Are you sure you want to change the base?
Conversation
9d79b2d
to
8fafaf3
Compare
@@ -0,0 +1,31 @@ | |||
/** @odoo-module */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @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): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
import { registry } from "@web/core/registry"; | ||
|
||
registry.category("web_tour.tours").add("SaleReportUITour", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
'discount': 0, | ||
'qty': 1, | ||
'tax_ids': [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'discount': 0, | |
'qty': 1, | |
'tax_ids': [], |
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
# 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']) |
There was a problem hiding this comment.
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.
PaymentScreen.enterPaymentLineAmount("Cash", "5.1", true, { | ||
amount: "5.10", | ||
remaining: "0.00", | ||
change: "0.00", | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PaymentScreen.enterPaymentLineAmount("Cash", "5.1", true, { | |
amount: "5.10", | |
remaining: "0.00", | |
change: "0.00", | |
}), | |
PaymentScreen.enterPaymentLineAmount("Cash", "5.1"), |
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), | ||
}, | ||
) |
There was a problem hiding this comment.
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
.
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") |
There was a problem hiding this comment.
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
8fafaf3
to
50c8197
Compare
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
50c8197
to
c35f29f
Compare
export function secondary(text) { | ||
let trigger = ".modal-footer .btn-secondary"; | ||
if (text) { | ||
trigger += `:contains("${text}")`; | ||
} | ||
return { | ||
content: "${text} dialog", | ||
in_modal: true, | ||
trigger, | ||
}; | ||
} |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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.
Ensure sales report generation stability
task-3674920