[FIX] point_of_sale: fix daily sales report for normal bank payment
Current behavior: When entering a difference at the closing of the session for a bank payment method, the daily sales report was not taking into account the difference for the bank payment method. Steps to reproduce: - Start PoS and make a sales with bank and a sales with cash - Close the session with a difference for both payment methods - Go to the daily sales report and check the difference for the bank payment method. The one for the cash is there but not the one for the bank. Note: This bring back the original behavior of the report that was removed here (https://github.com/odoo/odoo/pull/146341) and makes it coexist with the current one so that all cases are covered. opw-3737223 closes odoo/odoo#156376 X-original-commit: d9190e34543c4a1151656859acb41556bcb3a364 Signed-off-by: David Monnom (moda) <moda@odoo.com> Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
@@ -126,6 +126,7 @@ class ReportSaleDetails(models.AbstractModel):
|
||||
cash_counted = session.cash_register_balance_end_real
|
||||
is_cash_method = False
|
||||
for payment in payments:
|
||||
account_payments = self.env['account.payment'].search([('pos_session_id', '=', session.id)])
|
||||
if payment['session'] == session.id:
|
||||
if not payment['cash']:
|
||||
ref_value = "Closing difference in %s (%s)" % (payment['name'], session.name)
|
||||
@@ -145,6 +146,19 @@ class ReportSaleDetails(models.AbstractModel):
|
||||
move_name = 'Difference observed during the counting (Loss)'
|
||||
payment['cash_moves'] = [{'name': move_name, 'amount': payment['money_difference']}]
|
||||
payment['count'] = True
|
||||
elif payment['id'] in account_payments.mapped('pos_payment_method_id.id'):
|
||||
account_payment = account_payments.filtered(lambda p: p.pos_payment_method_id.id == payment['id'])
|
||||
payment['final_count'] = payment['total']
|
||||
payment['money_counted'] = account_payment.amount
|
||||
payment['money_difference'] = payment['money_counted'] - payment['final_count']
|
||||
payment['cash_moves'] = []
|
||||
if payment['money_difference'] > 0:
|
||||
move_name = 'Difference observed during the counting (Profit)'
|
||||
payment['cash_moves'] = [{'name': move_name, 'amount': payment['money_difference']}]
|
||||
elif payment['money_difference'] < 0:
|
||||
move_name = 'Difference observed during the counting (Loss)'
|
||||
payment['cash_moves'] = [{'name': move_name, 'amount': payment['money_difference']}]
|
||||
payment['count'] = True
|
||||
else:
|
||||
is_cash_method = True
|
||||
previous_session = self.env['pos.session'].search([('id', '<', session.id), ('state', '=', 'closed'), ('config_id', '=', session.config_id.id)], limit=1)
|
||||
|
||||
@@ -37,13 +37,22 @@ class TestReportSession(TestPoSCommon):
|
||||
|
||||
payment_context = {"active_ids": order.ids, "active_id": order.id}
|
||||
order_payment = self.env['pos.make.payment'].with_context(**payment_context).create({
|
||||
'amount': 150,
|
||||
'amount': 60,
|
||||
'payment_method_id': self.bank_split_pm1.id
|
||||
})
|
||||
order_payment.with_context(**payment_context).check()
|
||||
session.action_pos_session_closing_control(bank_payment_method_diffs={self.bank_split_pm1.id: 50})
|
||||
|
||||
order_payment = self.env['pos.make.payment'].with_context(**payment_context).create({
|
||||
'amount': 90,
|
||||
'payment_method_id': self.bank_pm1.id
|
||||
})
|
||||
order_payment.with_context(**payment_context).check()
|
||||
|
||||
session.action_pos_session_closing_control(bank_payment_method_diffs={self.bank_split_pm1.id: 50, self.bank_pm1.id: 40})
|
||||
|
||||
# PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order
|
||||
report = self.env['report.point_of_sale.report_saledetails'].get_sale_details(session_ids=[session.id])
|
||||
split_payment_bank = [p for p in report['payments'] if p.get('id', 0) == self.bank_split_pm1.id]
|
||||
self.assertEqual(split_payment_bank[0]['cash_moves'][0]['amount'], 50)
|
||||
bank_payment = [p for p in report['payments'] if p.get('id', 0) == self.bank_pm1.id]
|
||||
self.assertEqual(bank_payment[0]['cash_moves'][0]['amount'], 40)
|
||||
|
||||
Reference in New Issue
Block a user