Skip to content

Commit

Permalink
[FIX] point_of_sale: fix session report payment difference
Browse files Browse the repository at this point in the history
Current behavior:
If you use a non cash payment method, with "identify customer" option
and register a payment difference at the closing of the session. The
difference is not taken into account in the session report.

Steps to reproduce:
- Activate "identify customer" option on the bank payment method
- Open a session
- Add a product to the order
- Pay the order with the bank payment method
- Close the session with a payment difference
- Print the session report
- Open the report, at the bottom you should see the payment difference
  but it is not the case

opw-3597291

closes odoo#148753

X-original-commit: 30ba7fd
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Robin Engels (roen) <roen@odoo.com>
  • Loading branch information
robinengels committed Jan 11, 2024
1 parent ec9610d commit 9564374
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
32 changes: 17 additions & 15 deletions addons/point_of_sale/models/report_sale_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,25 @@ def get_sale_details(self, date_start=False, date_stop=False, config_ids=False,
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']:
for account_payment in account_payments:
if payment['id'] == account_payment.pos_payment_method_id.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
break
ref_value = "Closing difference in %s (%s)" % (payment['name'], session.name)
account_move = self.env['account.move'].search([("ref", "=", ref_value)], limit=1)
if account_move:
payment_method = self.env['pos.payment.method'].browse(payment['id'])
is_loss = any(l.account_id == payment_method.journal_id.loss_account_id for l in account_move.line_ids)
is_profit = any(l.account_id == payment_method.journal_id.profit_account_id for l in account_move.line_ids)
payment['final_count'] = payment['total']
payment['money_difference'] = -account_move.amount_total if is_loss else account_move.amount_total
payment['money_counted'] = payment['final_count'] + payment['money_difference']
payment['cash_moves'] = []
if is_profit:
move_name = 'Difference observed during the counting (Profit)'
payment['cash_moves'] = [{'name': move_name, 'amount': payment['money_difference']}]
elif is_loss:
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)
Expand Down
1 change: 1 addition & 0 deletions addons/point_of_sale/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
from . import test_pos_stock_account
from . import test_js
from . import test_report_pos_order
from . import test_report_session
from . import test_res_config_settings
49 changes: 49 additions & 0 deletions addons/point_of_sale/tests/test_report_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo

from odoo.addons.point_of_sale.tests.common import TestPoSCommon

@odoo.tests.tagged('post_install', '-at_install')
class TestReportSession(TestPoSCommon):

def setUp(self):
super(TestReportSession, self).setUp()
self.config = self.basic_config

def test_report_session(self):

product1 = self.create_product('Product 1', self.categ_basic, 150)
self.open_new_session()
session = self.pos_session

order = self.env['pos.order'].create({
'session_id': session.id,
'partner_id': self.partner_a.id,
'lines': [(0, 0, {
'name': "OL/0001",
'product_id': product1.id,
'price_unit': 150,
'discount': 0,
'qty': 1.0,
'price_subtotal': 150,
'price_subtotal_incl': 150,
}),],
'amount_total': 150.0,
'amount_tax': 0.0,
'amount_paid': 0.0,
'amount_return': 0.0,
'last_order_preparation_change': '{}'
})

payment_context = {"active_ids": order.ids, "active_id": order.id}
order_payment = self.env['pos.make.payment'].with_context(**payment_context).create({
'amount': 150,
'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})

# 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)

0 comments on commit 9564374

Please sign in to comment.