From 29bd7ba2db8c6763fa6f9a0190617c9d323b4c12 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 10 Aug 2012 14:26:21 +0200 Subject: [PATCH 1/4] [IMP] account: invoice form view usability improvement (display 'Refund' in place of 'Invoice' when needed) bzr revid: qdp-launchpad@openerp.com-20120810122621-dbhx84hse3fylajw --- addons/account/account_invoice_view.xml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 501a50b96c2..d8ba5f5159d 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -163,8 +163,10 @@

-

@@ -309,9 +311,11 @@

-

From 766ee9487268b18dc718c3b4239538c9f64b7d3b Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 10 Aug 2012 14:35:25 +0200 Subject: [PATCH 2/4] [REF] account_voucher: remove useless and unused code (classes account.statement.from.invoice and account.voucher.unreconcile) bzr revid: qdp-launchpad@openerp.com-20120810123525-lhijvv2khh0xqw38 --- addons/account_voucher/__openerp__.py | 1 - addons/account_voucher/wizard/__init__.py | 3 +- .../wizard/account_statement_from_invoice.py | 73 +------------------ .../account_statement_from_invoice_view.xml | 28 ------- .../wizard/account_voucher_unreconcile.py | 62 ---------------- .../account_voucher_unreconcile_view.xml | 31 -------- 6 files changed, 2 insertions(+), 196 deletions(-) delete mode 100644 addons/account_voucher/wizard/account_voucher_unreconcile.py delete mode 100644 addons/account_voucher/wizard/account_voucher_unreconcile_view.xml diff --git a/addons/account_voucher/__openerp__.py b/addons/account_voucher/__openerp__.py index a7be61db2c9..16ea771d123 100644 --- a/addons/account_voucher/__openerp__.py +++ b/addons/account_voucher/__openerp__.py @@ -49,7 +49,6 @@ eInvoicing & Payments module manage all Voucher Entries such as "Reconciliation "account_voucher_sequence.xml", "account_voucher_workflow.xml", "account_voucher_report.xml", - "wizard/account_voucher_unreconcile_view.xml", "wizard/account_statement_from_invoice_view.xml", "account_voucher_view.xml", "voucher_payment_receipt_view.xml", diff --git a/addons/account_voucher/wizard/__init__.py b/addons/account_voucher/wizard/__init__.py index bfe32ba4b83..47b87b27162 100644 --- a/addons/account_voucher/wizard/__init__.py +++ b/addons/account_voucher/wizard/__init__.py @@ -19,7 +19,6 @@ # ############################################################################## -import account_voucher_unreconcile import account_statement_from_invoice -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_voucher/wizard/account_statement_from_invoice.py b/addons/account_voucher/wizard/account_statement_from_invoice.py index 1b921e0ccf4..e72fee63af0 100644 --- a/addons/account_voucher/wizard/account_statement_from_invoice.py +++ b/addons/account_voucher/wizard/account_statement_from_invoice.py @@ -112,81 +112,10 @@ class account_statement_from_invoice_lines(osv.osv_memory): 'statement_id': statement_id, 'ref': line.ref, 'voucher_id': voucher_id, - 'date': time.strftime('%Y-%m-%d'), #time.strftime('%Y-%m-%d'), #line.date_maturity or, + 'date': time.strftime('%Y-%m-%d'), }, context=context) return {'type': 'ir.actions.act_window_close'} account_statement_from_invoice_lines() -class account_statement_from_invoice(osv.osv_memory): - """ - Generate Entries by Statement from Invoices - """ - _name = "account.statement.from.invoice" - _description = "Entries by Statement from Invoices" - _columns = { - 'date': fields.date('Date payment',required=True), - 'journal_ids': fields.many2many('account.journal', 'account_journal_relation', 'account_id', 'journal_id', 'Journal'), - 'line_ids': fields.many2many('account.move.line', 'account_move_line_relation', 'move_id', 'line_id', 'Invoices'), - } - _defaults = { - 'date': lambda *a: time.strftime('%Y-%m-%d'), - } - - def search_invoices(self, cr, uid, ids, context=None): - if context is None: - context = {} - line_obj = self.pool.get('account.move.line') - statement_obj = self.pool.get('account.bank.statement') - journal_obj = self.pool.get('account.journal') - mod_obj = self.pool.get('ir.model.data') - statement_id = 'statement_id' in context and context['statement_id'] - - data = self.read(cr, uid, ids, context=context)[0] - statement = statement_obj.browse(cr, uid, statement_id, context=context) - args_move_line = [] - repeated_move_line_ids = [] - # Creating a group that is unique for importing move lines(move lines, once imported into statement lines, should not appear again) - for st_line in statement.line_ids: - args_move_line = [] - args_move_line.append(('name', '=', st_line.name)) - args_move_line.append(('ref', '=', st_line.ref)) - if st_line.partner_id: - args_move_line.append(('partner_id', '=', st_line.partner_id.id)) - args_move_line.append(('account_id', '=', st_line.account_id.id)) - - move_line_id = line_obj.search(cr, uid, args_move_line, context=context) - if move_line_id: - repeated_move_line_ids += move_line_id - - journal_ids = data['journal_ids'] - if journal_ids == []: - journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale', 'cash', 'purchase'))], context=context) - - args = [ - ('reconcile_id', '=', False), - ('journal_id', 'in', journal_ids), - ('account_id.reconcile', '=', True)] - - if repeated_move_line_ids: - args.append(('id', 'not in', repeated_move_line_ids)) - - line_ids = line_obj.search(cr, uid, args, - context=context) - - model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_account_statement_from_invoice_lines')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - return { - 'domain': "[('id','in', ["+','.join([str(x) for x in line_ids])+"])]", - 'name': _('Import Entries'), - 'context': context, - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'account.statement.from.invoice.lines', - 'views': [(resource_id,'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - } - -account_statement_from_invoice() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_voucher/wizard/account_statement_from_invoice_view.xml b/addons/account_voucher/wizard/account_statement_from_invoice_view.xml index 33014f394a7..7af5155a6d3 100644 --- a/addons/account_voucher/wizard/account_statement_from_invoice_view.xml +++ b/addons/account_voucher/wizard/account_statement_from_invoice_view.xml @@ -1,34 +1,6 @@ - - account.statement.from.invoice.form - account.statement.from.invoice - form - -
- - - - -
-
-
-
-
- - - Import Invoices in Statement - account.statement.from.invoice - form - tree,form - - new - - account.statement.from.invoice.lines.form account.statement.from.invoice.lines diff --git a/addons/account_voucher/wizard/account_voucher_unreconcile.py b/addons/account_voucher/wizard/account_voucher_unreconcile.py deleted file mode 100644 index 42a9e1c5ec2..00000000000 --- a/addons/account_voucher/wizard/account_voucher_unreconcile.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from osv import osv -from osv import fields - -class account_voucher_unreconcile(osv.osv_memory): - _name = "account.voucher.unreconcile" - _description = "Account voucher unreconcile" - - _columns = { - 'remove':fields.boolean('Want to remove accounting entries too ?', required=False), - } - - _defaults = { - 'remove': True, - } - - def trans_unrec(self, cr, uid, ids, context=None): -# res = self.browse(cr, uid, ids[0]) - if context is None: - context = {} - voucher_pool = self.pool.get('account.voucher') - reconcile_pool = self.pool.get('account.move.reconcile') - if context.get('active_id'): - voucher = voucher_pool.browse(cr, uid, context.get('active_id'), context=context) - recs = [] - for line in voucher.move_ids: - if line.reconcile_id: - recs += [line.reconcile_id.id] - if line.reconcile_partial_id: - recs += [line.reconcile_partial_id.id] - #for rec in recs: - reconcile_pool.unlink(cr, uid, recs) -# if res.remove: - voucher_pool.cancel_voucher(cr, uid, [context.get('active_id')], context) -# wf_service = netsvc.LocalService("workflow") -# wf_service.trg_validate(uid, 'account.voucher', context.get('active_id'), 'cancel_voucher', cr) - - return {'type': 'ir.actions.act_window_close'} - -account_voucher_unreconcile() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account_voucher/wizard/account_voucher_unreconcile_view.xml b/addons/account_voucher/wizard/account_voucher_unreconcile_view.xml deleted file mode 100644 index 04131b643eb..00000000000 --- a/addons/account_voucher/wizard/account_voucher_unreconcile_view.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - Account voucher unreconcile - account.voucher.unreconcile - form - -
- -
-
- - Unreconcile entries - account.voucher.unreconcile - form - form - - new - - -
-
From 6391df3989e088380ae5f580af11f60c16bcf535 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 10 Aug 2012 14:40:56 +0200 Subject: [PATCH 3/4] [FIX/IMP] account_voucher: changed/fixed/improved the way to handle refunds payments through vouchers. Now, the refund have to be encoded as a negative of the right type (if the amount is -200 in a customer payment, it means your paying a customer refund of 200) bzr revid: qdp-launchpad@openerp.com-20120810124056-9rpa4ugnxhdtqhhb --- addons/account_voucher/account_voucher.py | 20 ++++++------- addons/account_voucher/invoice.py | 2 +- .../voucher_payment_receipt_view.xml | 8 ++--- .../wizard/account_statement_from_invoice.py | 30 +++++++++++-------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index ce0c64337b9..1287c7b3c18 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -46,11 +46,7 @@ class account_voucher(osv.osv): def _check_paid(self, cr, uid, ids, name, args, context=None): res = {} for voucher in self.browse(cr, uid, ids, context=context): - paid = False - for line in voucher.move_ids: - if (line.account_id.type, 'in', ('receivable', 'payable')) and line.reconcile_id: - paid = True - res[voucher.id] = paid + res[voucher.id] = any([((line.account_id.type, 'in', ('receivable', 'payable')) and line.reconcile_id) for line in voucher.move_ids]) return res def _get_type(self, cr, uid, context=None): @@ -186,15 +182,16 @@ class account_voucher(osv.osv): res['arch'] = etree.tostring(doc) return res - def _compute_writeoff_amount(self, cr, uid, line_dr_ids, line_cr_ids, amount): + def _compute_writeoff_amount(self, cr, uid, line_dr_ids, line_cr_ids, amount, type): debit = credit = 0.0 + sign = type == 'payment' and -1 or 1 for l in line_dr_ids: debit += l['amount'] for l in line_cr_ids: credit += l['amount'] - return abs(amount - abs(credit - debit)) + return amount - sign * (credit - debit) - def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount, voucher_currency, context=None): + def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount, voucher_currency, type, context=None): context = context or {} if not line_dr_ids and not line_cr_ids: return {'value':{}} @@ -215,7 +212,7 @@ class account_voucher(osv.osv): if voucher_line.get('currency_id', company_currency) != company_currency: is_multi_currency = True break - return {'value': {'writeoff_amount': self._compute_writeoff_amount(cr, uid, line_dr_ids, line_cr_ids, amount), 'is_multi_currency': is_multi_currency}} + return {'value': {'writeoff_amount': self._compute_writeoff_amount(cr, uid, line_dr_ids, line_cr_ids, amount, type), 'is_multi_currency': is_multi_currency}} def _get_writeoff_amount(self, cr, uid, ids, name, args, context=None): if not ids: return {} @@ -223,12 +220,13 @@ class account_voucher(osv.osv): res = {} debit = credit = 0.0 for voucher in self.browse(cr, uid, ids, context=context): + sign = voucher.type == 'payment' and -1 or 1 for l in voucher.line_dr_ids: debit += l.amount for l in voucher.line_cr_ids: credit += l.amount currency = voucher.currency_id or voucher.company_id.currency_id - res[voucher.id] = currency_obj.round(cr, uid, currency, abs(voucher.amount - abs(credit - debit))) + res[voucher.id] = currency_obj.round(cr, uid, currency, voucher.amount - sign * (credit - debit)) return res def _paid_amount_in_company_currency(self, cr, uid, ids, name, args, context=None): @@ -716,7 +714,7 @@ class account_voucher(osv.osv): default['value']['pre_line'] = 1 elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0: default['value']['pre_line'] = 1 - default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price) + default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price, ttype) return default def onchange_payment_rate_currency(self, cr, uid, ids, currency_id, payment_rate, payment_rate_currency_id, date, amount, company_id, context=None): diff --git a/addons/account_voucher/invoice.py b/addons/account_voucher/invoice.py index 006a622e25f..14b725cbeca 100644 --- a/addons/account_voucher/invoice.py +++ b/addons/account_voucher/invoice.py @@ -40,7 +40,7 @@ class invoice(osv.osv): 'domain': '[]', 'context': { 'default_partner_id': inv.partner_id.id, - 'default_amount': inv.residual, + 'default_amount': inv.type in ('out_refund', 'in_refund') and -inv.residual or inv.residual, 'default_name':inv.name, 'close_after_process': True, 'invoice_type':inv.type, diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 99ea3a2bbea..ef983145901 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -74,7 +74,7 @@ - + - + - + - + Date: Fri, 10 Aug 2012 16:37:07 +0200 Subject: [PATCH 4/4] [FIX] account_voucher: fixed yaml tests in order to reflect the new behavior of computed writeoff amount (does not use abs() anymore) bzr revid: qdp-launchpad@openerp.com-20120810143707-8vma2dld7mkolbh1 --- addons/account_voucher/test/case1_usd_usd.yml | 8 ++++---- addons/account_voucher/test/case_eur_usd.yml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index d8ac932a055..a30c85ffb71 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -173,12 +173,12 @@ self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount}) assert (voucher_id.state=='draft'), "Voucher is not in draft state" - - I check that writeoff amount computed is 10.0 + I check that writeoff amount computed is -10.0 - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_seagate'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == 10.0), "Writeoff amount is not 10.0" + assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0" - I confirm the voucher - @@ -266,12 +266,12 @@ self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount}) assert (voucher_id.state=='draft'), "Voucher is not in draft state" - - I check that writeoff amount computed is 5.0 + I check that writeoff amount computed is -5.0 - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_seagate'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0" + assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0" - I confirm the voucher - diff --git a/addons/account_voucher/test/case_eur_usd.yml b/addons/account_voucher/test/case_eur_usd.yml index 72f0d22aead..53db4ffaf80 100644 --- a/addons/account_voucher/test/case_eur_usd.yml +++ b/addons/account_voucher/test/case_eur_usd.yml @@ -107,11 +107,11 @@ self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount}) assert (voucher.state=='draft'), "Voucher is not in draft state" - - I check that writeoff amount computed is 50.0 + I check that writeoff amount computed is -50.0 - !python {model: account.voucher}: | voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case')) - assert (voucher.writeoff_amount == 50.0), "Writeoff amount is not 50.0" + assert (voucher.writeoff_amount == -50.0), "Writeoff amount is not -50.0" - I confirm the voucher - @@ -167,4 +167,4 @@ move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for Invoice" - \ No newline at end of file +