[FIX] point_of_sale: display bank statement lines

Since the bank statements have been removed, we don't have anymore a
stat button to show the bank statement.

So we re)introduce a button that display the statement lines.

caused by: https://github.com/odoo/odoo/pull/99092

closes odoo/odoo#101929

X-original-commit: dd21c708cc08d484530bc7c8433ebbb79f59323a
Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
Pierre Masereel
2022-10-03 19:22:45 +02:00
parent c57f839721
commit 0535e86216
3 changed files with 38 additions and 11 deletions
+27 -10
View File
@@ -108,13 +108,14 @@ class PosSession(models.Model):
cash_payment_method = session.payment_method_ids.filtered('is_cash_count')[:1]
if cash_payment_method:
total_cash_payment = 0.0
last_session = session.search([('config_id', '=', session.config_id.id), ('id', '!=', session.id)], limit=1)
result = self.env['pos.payment']._read_group([('session_id', '=', session.id), ('payment_method_id', '=', cash_payment_method.id)], ['amount'], ['session_id'])
if result:
total_cash_payment = result[0]['amount']
session.cash_register_total_entry_encoding = sum(session.statement_line_ids.mapped('amount')) + (
0.0 if session.state == 'closed' else total_cash_payment
)
session.cash_register_balance_end = session.cash_register_balance_start + session.cash_register_total_entry_encoding
session.cash_register_balance_end = last_session.cash_register_balance_end_real + session.cash_register_total_entry_encoding
session.cash_register_difference = session.cash_register_balance_end_real - session.cash_register_balance_end
else:
session.cash_register_total_entry_encoding = 0.0
@@ -287,6 +288,7 @@ class PosSession(models.Model):
raise UserError(_('This session is already closed.'))
self._check_if_no_draft_orders()
self._check_invoices_are_posted()
cash_difference_before_statements = self.cash_register_difference
if self.update_stock_at_closing:
self._create_picking_at_end_of_session()
self.order_ids.filtered(lambda o: not o.is_total_cost_computed)._compute_total_cost_at_session_closing(self.picking_ids.move_ids)
@@ -313,6 +315,7 @@ class PosSession(models.Model):
self.env.cr.rollback()
return self._close_session_action(balance)
self._post_statement_difference(cash_difference_before_statements)
if self.move_id.line_ids:
self.move_id.sudo().with_company(self.company_id)._post()
# Set the uninvoiced orders' state to 'done'
@@ -321,11 +324,19 @@ class PosSession(models.Model):
self.move_id.sudo().unlink()
self.sudo().with_company(self.company_id)._reconcile_account_move_lines(data)
else:
self._post_statement_difference(self.cash_register_difference)
self.write({'state': 'closed'})
return True
def _post_statement_difference(self, amount):
if amount:
if self.config_id.cash_control:
st_line_vals = {
'journal_id': self.cash_journal_id.id,
'amount': self.cash_register_difference,
'amount': amount,
'date': self.statement_line_ids.sorted()[-1:].date or fields.Date.context_today(self),
'pos_session_id': self.id,
}
if self.cash_register_difference < 0.0:
@@ -348,9 +359,6 @@ class PosSession(models.Model):
self.env['account.bank.statement.line'].create(st_line_vals)
self.write({'state': 'closed'})
return True
def _close_session_action(self, amount_to_balance):
# NOTE This can't handle `bank_payment_method_diffs` because there is no field in the wizard that can carry it.
default_account = self._get_balancing_account()
@@ -513,6 +521,7 @@ class PosSession(models.Model):
cash_in_count = 0
cash_out_count = 0
cash_in_out_list = []
last_session = self.search([('config_id', '=', self.config_id.id), ('id', '!=', self.id)], limit=1)
for cash_move in self.statement_line_ids.sorted('create_date'):
if cash_move.amount > 0:
cash_in_count += 1
@@ -535,10 +544,10 @@ class PosSession(models.Model):
'opening_notes': self.opening_notes,
'default_cash_details': {
'name': default_cash_payment_method_id.name,
'amount': self.cash_register_balance_start
'amount': last_session.cash_register_balance_end_real
+ total_default_cash_payment_amount
+ sum(self.statement_line_ids.mapped('amount')),
'opening': self.cash_register_balance_start,
'opening': last_session.cash_register_balance_end_real,
'payment_amount': total_default_cash_payment_amount,
'moves': cash_in_out_list,
'id': default_cash_payment_method_id.id
@@ -1063,8 +1072,6 @@ class PosSession(models.Model):
payment_method_to_receivable_lines = data.get('payment_method_to_receivable_lines')
payment_to_receivable_lines = data.get('payment_to_receivable_lines')
if not self.config_id.cash_control:
self.cash_register_balance_end_real = self.cash_register_balance_end
all_lines = (
split_cash_statement_lines
@@ -1381,6 +1388,15 @@ class PosSession(models.Model):
# self should be single record as this method is only called in the subfunctions of self._validate_session
return self.currency_id._convert(amount, self.company_id.currency_id, self.company_id, date, round=round)
def show_cash_register(self):
return {
'name': _('Cash register'),
'type': 'ir.actions.act_window',
'res_model': 'account.bank.statement.line',
'view_mode': 'tree',
'domain': [('id', 'in', self.statement_line_ids.ids)],
}
def show_journal_items(self):
self.ensure_one()
all_related_moves = self._get_related_account_moves()
@@ -1450,6 +1466,7 @@ class PosSession(models.Model):
self.opening_notes = notes
difference = cashbox_value - self.cash_register_balance_start
self.cash_register_balance_start = cashbox_value
self._post_statement_difference(difference)
self._post_cash_details_message('Opening', difference, notes)
def _post_cash_details_message(self, state, difference, notes):
@@ -1705,7 +1722,7 @@ class PosSession(models.Model):
'domain': [('id', '=', self.id)],
'fields': [
'id', 'name', 'user_id', 'config_id', 'start_at', 'stop_at', 'sequence_number',
'payment_method_ids', 'state', 'update_stock_at_closing'
'payment_method_ids', 'state', 'update_stock_at_closing', 'cash_register_balance_start'
],
},
}
+2 -1
View File
@@ -621,7 +621,8 @@ class TestPoSCommon(ValuationReconciliationTestCommon):
_logger.info('DONE: Call of before_closing_cb.')
self._check_invoice_journal_entries(pos_session, orders_map, expected_values=args['journal_entries_before_closing'])
_logger.info('DONE: Checks for journal entries before closing the session.')
total_cash_payment = sum(pos_session.mapped('order_ids.payment_ids').filtered(lambda payment: payment.payment_method_id.type == 'cash').mapped('amount'))
cash_payment_method = pos_session.payment_method_ids.filtered('is_cash_count')[:1]
total_cash_payment = sum(pos_session.mapped('order_ids.payment_ids').filtered(lambda payment: payment.payment_method_id.id == cash_payment_method.id).mapped('amount'))
pos_session.post_closing_cash_details(total_cash_payment)
pos_session.close_session_from_ui()
after_closing_cb = args.get('after_closing_cb')
@@ -45,6 +45,15 @@
groups="account.group_account_readonly"
>
</button>
<button
name="show_cash_register"
type="object"
class="oe_stat_button"
icon="fa-bars"
string="Cash Register"
attrs="{'invisible':[('cash_control', '=', False)]}"
groups="account.group_account_readonly"
/>
</div>
<h1 class="oe_title">
<field name="name" attrs="{'invisible': [('name','=','/')]}" class="oe_inline"/>