From ec308a08e73dc07a71216a7127ffd74160e80c55 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Fri, 4 May 2012 14:51:58 +0200 Subject: [PATCH] [IMP] account: Add new wizard for the cash register "Take Money Out", "Put Money In" [FIX] point_of_sale: Fix some bugs bzr revid: stw@openerp.com-20120504125158-p45qfzo8mif6x9xe --- addons/account/__openerp__.py | 1 + addons/account/account.py | 4 + addons/account/account_cash_statement.py | 41 +++++++++- addons/account/account_view.xml | 18 +++-- addons/account/wizard/__init__.py | 2 + addons/account/wizard/pos_box.py | 80 +++++++++++++++++++ addons/account/wizard/pos_box.xml | 62 ++++++++++++++ addons/point_of_sale/__openerp__.py | 3 +- .../point_of_sale/account_bank_statement.py | 5 +- .../point_of_sale/account_statement_view.xml | 1 - addons/point_of_sale/point_of_sale.py | 20 ++--- addons/point_of_sale/point_of_sale_view.xml | 35 ++++---- addons/point_of_sale/wizard/__init__.py | 4 +- addons/point_of_sale/wizard/pos_box.py | 26 ++++++ addons/point_of_sale/wizard/pos_box.xml | 22 +++++ .../point_of_sale/wizard/pos_box_entries.py | 22 ++++- addons/point_of_sale/wizard/pos_payment.py | 22 ++++- addons/point_of_sale/wizard/pos_payment.xml | 3 +- 18 files changed, 327 insertions(+), 44 deletions(-) create mode 100644 addons/account/wizard/pos_box.py create mode 100644 addons/account/wizard/pos_box.xml create mode 100644 addons/point_of_sale/wizard/pos_box.py create mode 100644 addons/point_of_sale/wizard/pos_box.xml diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 221a58e35d1..e6f356e0a44 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -100,6 +100,7 @@ module named account_voucher. 'wizard/account_reconcile_partner_process_view.xml', 'wizard/account_automatic_reconcile_view.xml', 'wizard/account_financial_report_view.xml', + 'wizard/pos_box.xml', 'project/wizard/project_account_analytic_line_view.xml', 'account_end_fy.xml', 'account_invoice_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index 75bfc891980..df446abc3bc 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -739,6 +739,10 @@ class account_journal(osv.osv): 'entry_posted': fields.boolean('Skip \'Draft\' State for Manual Entries', help='Check this box if you don\'t want new journal entries to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation. \nNote that journal entries that are automatically created by the system are always skipping that state.'), 'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"), 'allow_date':fields.boolean('Check Date in Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'), + + 'profit_account_id' : fields.many2one('account.account', 'Profit Account'), + 'loss_account_id' : fields.many2one('account.account', 'Loss Account'), + 'internal_account_id' : fields.many2one('account.account', 'Internal Transfers Account', select=1), } _defaults = { diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index f21bd7e9a36..9cec8dfc723 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -188,6 +188,14 @@ class account_cash_statement(osv.osv): result[line.statement_id.id] = True return result.keys() + def _compute_difference(self, cr, uid, ids, fieldnames, args, context=None): + result = dict.fromkeys(ids, 0.0) + + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = obj.balance_end - obj.balance_end_cash + + return result + _columns = { 'total_entry_encoding': fields.function(_get_sum_entry_encoding, string="Cash Transaction", help="Total cash transactions", store = { @@ -198,6 +206,7 @@ class account_cash_statement(osv.osv): 'balance_end_cash': fields.function(_balance_end_cash, store=False, string='Closing Balance', help="Closing balance based on cashBox"), 'details_ids' : fields.one2many('account.cashbox.line', 'bank_statement_id', string='CashBox Lines'), 'user_id': fields.many2one('res.users', 'Responsible', required=False), + 'difference' : fields.function(_compute_difference, method=True, string="Difference", type="float"), } _defaults = { @@ -234,7 +243,8 @@ class account_cash_statement(osv.osv): for line in vals.get('details_ids',[]): print "line: %r" % (line,) if line and len(line)==3 and line[2]: - amount_total+= line[2]['pieces'] * line[2]['number_opening'] + # FIXME: If there is no piece # does not work with GTK + amount_total+= line[2].get('pieces', 0) * line[2]['number_opening'] vals.update(balance_start= amount_total) vals.update(balance_end_real=self._compute_balance_end_real(cr, uid, vals['journal_id'], context=context)) @@ -287,7 +297,7 @@ class account_cash_statement(osv.osv): balance_start = 0.0 if journal_id: count = self.search_count(cr, uid, [('journal_id', '=', journal_id),('state', '=', 'open')], context=None) - if count: + if 0: # count: journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context) raise osv.except_osv(_('Error !'), (_('The Account Journal %s is opened by an other Cash Register !') % (journal.name,))) else: @@ -380,6 +390,33 @@ class account_cash_statement(osv.osv): def button_confirm_cash(self, cr, uid, ids, context=None): super(account_cash_statement, self).button_confirm_bank(cr, uid, ids, context=context) + absl_proxy = self.pool.get('account.bank.statement.line') + + TABLES = (('Profit', 'profit_account_id'), ('Loss', 'loss_account_id'),) + + for obj in self.browse(cr, uid, ids, context=context): + if obj.difference == 0.0: + continue + + for item_label, item_account in TALBES: + if getattr(obj.journal_id, item_account): + raise osv.except_osv(_('Error !'), + _('There is no %s Account on the Journal %s') % (item_label, obj.journal_id.name,)) + + is_profit = obj.difference < 0.0 + + account = getattr(obj.journal_id, TABLES[is_profit][1]) + + values = { + 'statement_id' : obj.id, + 'journal_id' : obj.journal_id.id, + 'account_id' : account.id, + 'amount' : obj.difference, + 'name' : 'Exceptional %s' % TABLES[is_profit][0], + } + + absl_proxy.create(cr, uid, values, context=context) + return self.write(cr, uid, ids, {'closing_date': time.strftime("%Y-%m-%d %H:%M:%S")}, context=context) def button_cancel(self, cr, uid, ids, context=None): diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 5258b876ad2..273035fbc2a 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -505,11 +505,17 @@ - + + + + + + + @@ -2659,12 +2665,13 @@ action = pool.get('res.config').next(cr, uid, [], context) - + + - + - + @@ -2677,7 +2684,7 @@ action = pool.get('res.config').next(cr, uid, [], context) - + @@ -2690,6 +2697,7 @@ action = pool.get('res.config').next(cr, uid, [], context) + diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index a78cf12050b..87a053d558c 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -64,6 +64,8 @@ import account_report_account_balance import account_change_currency +import pos_box; + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/wizard/pos_box.py b/addons/account/wizard/pos_box.py new file mode 100644 index 00000000000..a9e752397e0 --- /dev/null +++ b/addons/account/wizard/pos_box.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +from osv import osv, fields +import decimal_precision as dp + +class CashBox(osv.osv_memory): + _register = False + _columns = { + 'name' : fields.char('Reason', size=64, required=True), + # Attention, we don't set a domain, because there is a journal_type key + # in the context of the action + 'amount' : fields.float('Amount', + digits_compute = dp.get_precision('Account'), + required=True), + } + + def run(self, cr, uid, ids, context=None): + if not context: + context = dict() + + active_model = context.get('active_model', False) or False + active_ids = context.get('active_ids', []) or [] + + records = self.pool.get(active_model).browse(cr, uid, active_ids, context=context) + + return self._run(cr, uid, ids, records, context=None) + + def _run(self, cr, uid, ids, records, context=None): + for box in self.browse(cr, uid, ids, context=context): + for record in records: + if not record.journal_id.internal_account_id: + raise osv.except_osv(_('Error !'), + _('Please check that internal account is set to %s') % (record.journal_id.name,)) + + self._create_bank_statement_line(cr, uid, box, record, context=context) + + return {} + + +class CashBoxIn(CashBox): + _name = 'cash.box.in' + + _columns = CashBox._columns.copy() + _columns.update({ + 'ref' : fields.char('Reference', size=32), + }) + + def _create_bank_statement_line(self, cr, uid, box, record, context=None): + absl_proxy = self.pool.get('account.bank.statement.line') + + values = { + 'statement_id' : record.id, + 'journal_id' : record.journal_id.id, + 'account_id' : record.journal_id.internal_account_id.id, + 'amount' : box.amount or 0.0, + 'ref' : "%s" % (box.ref or ''), + 'name' : box.name, + } + + return absl_proxy.create(cr, uid, values, context=context) + +CashBoxIn() + +class CashBoxOut(CashBox): + _name = 'cash.box.out' + + def _create_bank_statement_line(self, cr, uid, box, record, context=None): + absl_proxy = self.pool.get('account.bank.statement.line') + + amount = box.amount or 0.0 + values = { + 'statement_id' : record.id, + 'journal_id' : record.journal_id.id, + 'account_id' : record.journal_id.internal_account_id.id, + 'amount' : -amount if amount > 0.0 else amount, + 'name' : box.name, + } + + return absl_proxy.create(cr, uid, values, context=context) + +CashBoxOut() diff --git a/addons/account/wizard/pos_box.xml b/addons/account/wizard/pos_box.xml new file mode 100644 index 00000000000..6136cca06ad --- /dev/null +++ b/addons/account/wizard/pos_box.xml @@ -0,0 +1,62 @@ + + + + + cash_box_in + cash.box.in + form + +
+ + + + + + + +