From 1d480a1df3dd7ff32e10d1cb01e6bf6ff5ab7e6b Mon Sep 17 00:00:00 2001
From: ced <>
Date: Thu, 4 Oct 2007 05:59:39 +0000
Subject: [PATCH] Improve payment, invoice, statement
- Use the right reference from invoice on account move lines
- Add a reference type on invoice
- Payment are now multi-currency
- Add wizard to populate statement
- Make thread safe payment wizard
- Add mod10r in utils
- Add colors on statement lines
bzr revid: ced-35849fea0ca75fec483ba54836f4954c1b26d2c9
---
addons/account/account_bank_statement.py | 42 ++-
addons/account/account_invoice_view.xml | 6 +-
addons/account/account_view.xml | 6 +-
addons/account/invoice.py | 69 ++++-
addons/account_payment/__terp__.py | 24 +-
addons/account_payment/account_move_line.py | 50 ++--
addons/account_payment/payment.py | 280 +++++++++++++-----
addons/account_payment/payment_sequence.xml | 37 ++-
addons/account_payment/payment_view.xml | 97 +++---
addons/account_payment/payment_wizard.xml | 27 +-
addons/account_payment/wizard/__init__.py | 1 +
.../wizard/wizard_payment_order.py | 102 ++++---
.../wizard/wizard_populate_statement.py | 121 ++++++++
13 files changed, 635 insertions(+), 227 deletions(-)
create mode 100644 addons/account_payment/wizard/wizard_populate_statement.py
diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py
index 1ad7f588458..742e49f96cc 100644
--- a/addons/account/account_bank_statement.py
+++ b/addons/account/account_bank_statement.py
@@ -507,6 +507,25 @@ class account_bank_statement_line(osv.osv):
currency_id, balance, context=context)
return {'value': {'amount': balance, 'account_id': account_id}}
+ def _reconcile_amount(self, cursor, user, ids, name, args, context=None):
+ if not ids:
+ return {}
+ res_currency_obj = self.pool.get('res.currency')
+ res_users_obj = self.pool.get('res.users')
+
+ res = {}
+ company_currency_id = res_users_obj.browse(cursor, user, user,
+ context=context).company_id.currency_id.id
+
+ for line in self.browse(cursor, user, ids, context=context):
+ if line.reconcile_id:
+ res[line.id] = res_currency_obj.compute(cursor, user,
+ company_currency_id, line.statement_id.currency.id,
+ line.reconcile_id.total_entry, context=context)
+ else:
+ res[line.id] = 0.0
+ return res
+
_order = "date,name desc"
_name = "account.bank.statement.line"
_description = "Bank Statement Line"
@@ -514,14 +533,25 @@ class account_bank_statement_line(osv.osv):
'name': fields.char('Name', size=64, required=True),
'date': fields.date('Date', required=True),
'amount': fields.float('Amount'),
- 'type': fields.selection([('supplier','Supplier'),('customer','Customer'),('general','General')], 'Type', required=True),
+ 'type': fields.selection([
+ ('supplier','Supplier'),
+ ('customer','Customer'),
+ ('general','General')
+ ], 'Type', required=True),
'partner_id': fields.many2one('res.partner', 'Partner'),
- 'account_id': fields.many2one('account.account','Account', required=True),
- 'statement_id': fields.many2one('account.bank.statement', 'Statement', select=True, required=True),
- 'reconcile_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile', states={'confirm':[('readonly',True)]}),
- 'move_ids': fields.many2many('account.move', 'account_bank_statement_line_move_rel', 'move_id','statement_id', 'Moves'),
+ 'account_id': fields.many2one('account.account','Account',
+ required=True),
+ 'statement_id': fields.many2one('account.bank.statement', 'Statement',
+ select=True, required=True),
+ 'reconcile_id': fields.many2one('account.bank.statement.reconcile',
+ 'Reconcile', states={'confirm':[('readonly',True)]}),
+ 'move_ids': fields.many2many('account.move',
+ 'account_bank_statement_line_move_rel', 'move_id','statement_id',
+ 'Moves'),
'ref': fields.char('Ref.', size=32),
- 'note': fields.text('Notes')
+ 'note': fields.text('Notes'),
+ 'reconcile_amount': fields.function(_reconcile_amount,
+ string='Amount reconciled', method=True, type='float'),
}
_defaults = {
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'),
diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml
index 0a266e10fe0..d0607297d04 100644
--- a/addons/account/account_invoice_view.xml
+++ b/addons/account/account_invoice_view.xml
@@ -139,8 +139,10 @@
-
+
+
+
@@ -261,7 +263,9 @@
+
+
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 0b0e3adf058..62448d6c840 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -324,7 +324,8 @@
-
+
@@ -335,7 +336,8 @@
domain="[('journal_id','=',parent.journal_id)]"/>
+ context="{'partner_id': partner_id, 'amount': amount, 'account_id': account_id, 'currency_id': parent.currency}"/>
+
@@ -23,7 +23,8 @@
form
tree,form
-
+
payment.mode.tree
@@ -58,10 +59,11 @@
tree,form
-
-
+
+
+
payment.order.form
payment.order
form
@@ -88,7 +90,7 @@
-
+
@@ -115,12 +117,12 @@
Payment order
payment.order
form
- tree,form
+ form,tree
-
+
Draft payment order
@@ -129,10 +131,10 @@
tree,form
[('state','=','draft')]
-
+
Payment orders to validate
@@ -141,14 +143,10 @@
tree,form
[('state','=','open')]
-
-
-
-
-
+
Payment Line
@@ -156,15 +154,21 @@
form
@@ -175,16 +179,23 @@
tree
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
+
@@ -195,6 +206,18 @@
form,tree
+
+ account.bank.statement.form.inherit
+ account.bank.statement
+ form
+
+
+
+
+
+
+
diff --git a/addons/account_payment/payment_wizard.xml b/addons/account_payment/payment_wizard.xml
index 077f0750380..5d1b87ecad4 100644
--- a/addons/account_payment/payment_wizard.xml
+++ b/addons/account_payment/payment_wizard.xml
@@ -2,18 +2,25 @@
+ string="Populate payment"
+ model="payment.order"
+ name="populate_payment"
+ menu="False"
+ id="wizard_populate_payment"/>
+ string="Pay"
+ model="payment.order"
+ name="pay_payment"
+ menu="False"
+ id="wizard_pay_payment"/>
+
+
diff --git a/addons/account_payment/wizard/__init__.py b/addons/account_payment/wizard/__init__.py
index 36aaf78494a..9269a92a472 100644
--- a/addons/account_payment/wizard/__init__.py
+++ b/addons/account_payment/wizard/__init__.py
@@ -29,3 +29,4 @@
import wizard_payment_order
import wizard_pay
+import wizard_populate_statement
diff --git a/addons/account_payment/wizard/wizard_payment_order.py b/addons/account_payment/wizard/wizard_payment_order.py
index 72e85872c49..bf4388ec36b 100644
--- a/addons/account_payment/wizard/wizard_payment_order.py
+++ b/addons/account_payment/wizard/wizard_payment_order.py
@@ -25,88 +25,92 @@
#
##############################################################################
import wizard
-from osv import osv
import pooler
-from osv import fields
-import time
+from tools.misc import UpdateableStr
-ask_form="""
-
-"""
-ask_fields={
- 'entries': {'string':'Entries', 'type':'many2many',
- 'relation': 'account.move.line',},
- }
+FORM = UpdateableStr()
+
+FIELDS = {
+ 'entries': {'string':'Entries', 'type':'many2many',
+ 'relation': 'account.move.line',},
+}
def search_entries(self, cr, uid, data, context):
+ pool = pooler.get_pool(cr.dbname)
+ line_obj = pool.get('account.move.line')
- pool= pooler.get_pool(cr.dbname)
# Search for move line to pay:
- mline_ids = pool.get('account.move.line').search(cr, uid,
- [('reconcile_id', '=', False),
- ('amount_to_pay', '>', 0)],
- context=context)
+ line_ids = line_obj.search(cr, uid, [
+ ('reconcile_id', '=', False),
+ ('amount_to_pay', '>', 0)], context=context)
- if not mline_ids:
- ask_fields['entries']['domain']= [('id', 'in', [])]
- return {}
-
- ask_fields['entries']['domain']= [('id', 'in', mline_ids)]
- return {'entries': mline_ids}
+ FORM.string = '''
+''' % (','.join([str(x) for x in line_ids]))
+ return {'entries': line_ids}
def create_payment(self, cr, uid, data, context):
- mline_ids= data['form']['entries'][0][2]
- if not mline_ids: return {}
+ line_ids= data['form']['entries'][0][2]
+ if not line_ids: return {}
pool= pooler.get_pool(cr.dbname)
- payment = pool.get('payment.order').browse(cr, uid, data['id'],
+ order_obj = pool.get('payment.order')
+ line_obj = pool.get('account.move.line')
+
+ payment = order_obj.browse(cr, uid, data['id'],
context=context)
- t= payment.mode and payment.mode.type.code or 'manual'
- line2bank= pool.get('account.move.line').line2bank(cr,uid,
- mline_ids,t,context)
+ t = payment.mode and payment.mode.type.code or 'manual'
+ line2bank= pool.get('account.move.line').line2bank(cr, uid,
+ line_ids, t, context)
## Finally populate the current payment with new lines:
- for line in pool.get('account.move.line').browse(cr, uid, mline_ids,
- context=context):
+ for line in line_obj.browse(cr, uid, line_ids, context=context):
pool.get('payment.line').create(cr,uid,{
'move_line_id': line.id,
- 'amount': line.amount_to_pay,
+ 'amount_currency': line.amount_to_pay,
'bank_id': line2bank.get(line.id),
'order_id': payment.id,
- })
-
+ }, context=context)
return {}
+
class wizard_payment_order(wizard.interface):
"""
Create a payment object with lines corresponding to the account move line
to pay according to the date and the mode provided by the user.
Hypothesis:
- - Small number of non-reconcilied move line , payment mode and bank account type,
+ - Small number of non-reconcilied move line , payment mode and bank account type,
- Big number of partner and bank account.
If a type is given, unsuitable account move lines are ignored.
"""
- states = {'init' : {'actions':[search_entries],
- 'result': {'type':'form',
- 'arch':ask_form,
- 'fields':ask_fields,
- 'state':[('end','_Cancel'),('create','_Add to payment order')]}
-
- },
-
- 'create': {'actions': [],
- 'result': {'type':'action',
- 'action':create_payment,
- 'state':'end'}
- },
-
+ states = {
+ 'init': {
+ 'actions': [search_entries],
+ 'result': {
+ 'type': 'form',
+ 'arch': FORM,
+ 'fields': FIELDS,
+ 'state': [
+ ('end','_Cancel'),
+ ('create','_Add to payment order', '', True)
+ ]
+ },
+ },
+ 'create': {
+ 'actions': [],
+ 'result': {
+ 'type': 'action',
+ 'action': create_payment,
+ 'state': 'end'}
+ },
}
+
wizard_payment_order('populate_payment')
diff --git a/addons/account_payment/wizard/wizard_populate_statement.py b/addons/account_payment/wizard/wizard_populate_statement.py
new file mode 100644
index 00000000000..db8b5834767
--- /dev/null
+++ b/addons/account_payment/wizard/wizard_populate_statement.py
@@ -0,0 +1,121 @@
+##############################################################################
+#
+# Copyright (c) 2005-2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+import wizard
+import pooler
+from tools.misc import UpdateableStr
+
+FORM = UpdateableStr()
+
+FIELDS = {
+ 'lines': {'string': 'Payment Lines', 'type': 'many2many',
+ 'relation': 'payment.line'},
+}
+
+def _search_entries(obj, cursor, user, data, context):
+ pool = pooler.get_pool(cursor.dbname)
+ line_obj = pool.get('payment.line')
+ statement_obj = pool.get('account.bank.statement')
+
+ statement = statement_obj.browse(cursor, user, data['id'], context=context)
+
+ line_ids = line_obj.search(cursor, user, [
+ ('move_line_id.reconcile_id', '=', False),
+ ('order_id.mode.journal.id', '=', statement.journal_id.id)])
+ line_ids.extend(line_obj.search(cursor, user, [
+ ('move_line_id.reconcile_id', '=', False),
+ ('order_id.mode', '=', False)]))
+
+ FORM.string = '''
+''' % (','.join([str(x) for x in line_ids]))
+ return {'lines': line_ids}
+
+def _populate_statement(obj, cursor, user, data, context):
+ line_ids = data['form']['lines'][0][2]
+ if not line_ids:
+ return {}
+
+ pool = pooler.get_pool(cursor.dbname)
+ line_obj = pool.get('payment.line')
+ statement_obj = pool.get('account.bank.statement')
+ statement_line_obj = pool.get('account.bank.statement.line')
+ currency_obj = pool.get('res.currency')
+ statement_reconcile_obj = pool.get('account.bank.statement.reconcile')
+
+ statement = statement_obj.browse(cursor, user, data['id'], context=context)
+
+ for line in line_obj.browse(cursor, user, line_ids, context=context):
+ ctx = context.copy()
+ ctx['date'] = line.value_date
+ amount = currency_obj.compute(cursor, user, line.currency.id,
+ statement.currency.id, line.amount_currency, context=ctx)
+ reconcile_id = statement_reconcile_obj.create(cursor, user, {
+ 'line_ids': [(6, 0, [line.move_line_id.id])]
+ }, context=context)
+ statement_line_obj.create(cursor, user, {
+ 'name': line.order_id.reference or '?',
+ 'amount': - amount,
+ 'type': 'supplier',
+ 'partner_id': line.partner_id.id,
+ 'account_id': line.move_line_id.account_id.id,
+ 'statement_id': statement.id,
+ 'ref': line.reference,
+ 'reconcile_id': reconcile_id,
+ }, context=context)
+ return {}
+
+
+class PopulateStatement(wizard.interface):
+ """
+ Populate the current statement with selected payement lines
+ """
+ states = {
+ 'init': {
+ 'actions': [_search_entries],
+ 'result': {
+ 'type': 'form',
+ 'arch': FORM,
+ 'fields': FIELDS,
+ 'state': [
+ ('end', '_Cancel'),
+ ('add', '_Add', '', True)
+ ]
+ },
+ },
+ 'add': {
+ 'actions': [],
+ 'result': {
+ 'type': 'action',
+ 'action': _populate_statement,
+ 'state': 'end'
+ },
+ },
+ }
+
+PopulateStatement('populate_statement')