[FIX] point_of_sale: Traceback when opening sale details report with studio

Reproduction traceback:
1. Navigate to POS/Sessions
2. Open Studio
3. Navigate to Reports
4. Open Sale Details report

After this commit, if the report is open without any session or config
the currency used is the one from the company.

closes odoo/odoo#139254

X-original-commit: 79be7208116f6c2749871c0af1d548da58b1b7fa
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Bastien PIERRE
2023-10-20 16:20:45 +00:00
parent 2994c7589f
commit 39b9f72b46
@@ -62,7 +62,7 @@ class ReportSaleDetails(models.AbstractModel):
else:
config_currencies = self.env['pos.session'].search([('id', 'in', session_ids)]).mapped('config_id.currency_id')
# If all the pos.config have the same currency, we can use it, else we use the company currency
if all(i == config_currencies.ids[0] for i in config_currencies.ids):
if config_currencies and all(i == config_currencies.ids[0] for i in config_currencies.ids):
user_currency = config_currencies[0]
else:
user_currency = self.env.company.currency_id
@@ -92,7 +92,7 @@ class ReportSaleDetails(models.AbstractModel):
payment_ids = self.env["pos.payment"].search([('pos_order_id', 'in', orders.ids)]).ids
if payment_ids:
self.env.cr.execute("""
SELECT method.id as id, payment.session_id as session, COALESCE(method.name->>%s, method.name->>'en_US') as name, method.is_cash_count as cash,
SELECT method.id as id, payment.session_id as session, COALESCE(method.name->>%s, method.name->>'en_US') as name, method.is_cash_count as cash,
sum(amount) total, method.journal_id journal_id
FROM pos_payment AS payment,
pos_payment_method AS method