From 58ffd9fc029aece5658f766a26e25995aef6adac Mon Sep 17 00:00:00 2001 From: Srushti Patel Date: Fri, 8 Apr 2016 13:58:15 +0530 Subject: [PATCH] [IMP] point_of_sale: Cash Control Default Opening/Closing Balance ======== Purpose ======== POS : It is annoying process to put coin/bill value repeatedly in the cash register. If user select cash control check box it should add default values. In pos configuration the option cash control checkbox move to a new category called Cash Control. -When opening a POS session, when doing the cash control, it should already prefill the modal with the defaults cash control values (Coin/Bill Value, Number of Coins/Bills, Subtotal). -When closing the POS session, the closing balance should just take the Coin/Bill Value defaults values. The user has to type in the number of Coins/Bills manually). --- addons/point_of_sale/models/pos_config.py | 22 +++++++++++++++++++ .../point_of_sale/views/pos_config_view.xml | 11 +++++++++- .../point_of_sale/views/pos_session_view.xml | 4 ++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 1f73121ffed..5f6a06308f3 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -5,6 +5,27 @@ import uuid from odoo import api, fields, models, _ from odoo.exceptions import UserError + +class AccountCashboxLine(models.Model): + _inherit = 'account.cashbox.line' + + default_pos_id = fields.Many2one('pos.config', string='This cashbox line is used by default when opening or closing a balance for this point of sale') + +class AccountBankStmtCashWizard(models.Model): + _inherit = 'account.bank.statement.cashbox' + + @api.model + def default_get(self, fields): + vals = super(AccountBankStmtCashWizard, self).default_get(fields) + config_id = self.env.context.get('default_pos_id') + if config_id: + lines = self.env['account.cashbox.line'].search([('default_pos_id', '=', config_id)]) + if self.env.context.get('balance', False) == 'start': + vals['cashbox_lines_ids'] = [[0, 0, {'coin_value': line.coin_value, 'number': line.number, 'subtotal': line.subtotal}] for line in lines] + else: + vals['cashbox_lines_ids'] = [[0, 0, {'coin_value': line.coin_value, 'number': 0, 'subtotal': 0.0}] for line in lines] + return vals + class PosConfig(models.Model): _name = 'pos.config' @@ -92,6 +113,7 @@ class PosConfig(models.Model): help="The product used to encode the customer tip. Leave empty if you do not accept tips.") fiscal_position_ids = fields.Many2many('account.fiscal.position', string='Fiscal Positions') default_fiscal_position_id = fields.Many2one('account.fiscal.position', string='Default Fiscal Position') + default_cashbox_lines_ids = fields.One2many('account.cashbox.line', 'default_pos_id', string='Default Balance') @api.depends('journal_id.currency_id', 'journal_id.company_id.currency_id') def _compute_currency(self): diff --git a/addons/point_of_sale/views/pos_config_view.xml b/addons/point_of_sale/views/pos_config_view.xml index 77f30c9830f..22c7f04f93e 100644 --- a/addons/point_of_sale/views/pos_config_view.xml +++ b/addons/point_of_sale/views/pos_config_view.xml @@ -44,7 +44,6 @@ - @@ -54,6 +53,16 @@ + + + + + + + + + + diff --git a/addons/point_of_sale/views/pos_session_view.xml b/addons/point_of_sale/views/pos_session_view.xml index 4cf44bbf1f3..c5e070251f8 100644 --- a/addons/point_of_sale/views/pos_session_view.xml +++ b/addons/point_of_sale/views/pos_session_view.xml @@ -52,14 +52,14 @@ class="oe_stat_button" attrs="{'invisible':['|', ('cash_control', '=', False), ('state', '!=', 'opening_control')]}" icon="fa-money" - type="action" context="{'balance': 'start', 'bank_statement_id': cash_register_id}"> + type="action" context="{'balance': 'start', 'bank_statement_id': cash_register_id, 'default_pos_id': config_id}"> Set Opening Balance