[RFR] Sort out move line code between payment and debit module

This commit is contained in:
Stefan Rijnhart
2013-05-28 13:49:08 +02:00
parent 345381a8a7
commit b05036098f
2 changed files with 9 additions and 69 deletions

View File

@@ -2,9 +2,8 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# This module additional (C) 2011 Therp BV (<http://therp.nl>).
# (C) 2011 Smile Benelux (<http://smile.fr>).
# This module (C) 2011 - 2013 Therp BV (<http://therp.nl>).
# (C) 2011 Smile Benelux (<http://smile.fr>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -22,10 +21,9 @@
##############################################################################
from operator import itemgetter
from osv import fields, osv
from tools.translate import _
from openerp.osv import fields, orm
class account_move_line(osv.osv):
class account_move_line(orm.Model):
_inherit = "account.move.line"
def amount_to_receive(self, cr, uid, ids, name, arg={}, context=None):
@@ -55,6 +53,9 @@ class account_move_line(osv.osv):
return r
def _to_receive_search(self, cr, uid, obj, name, args, context=None):
"""
Reverse of account_payment/account_move_line.py:_to_pay_search()
"""
if not args:
return []
line_obj = self.pool.get('account.move.line')
@@ -86,70 +87,9 @@ class account_move_line(osv.osv):
return [('id', '=', '0')]
return [('id', 'in', map(lambda x:x[0], res))]
def _dummy(self, cr, user, ids, name, arg, context=None):
res = {}
if ids:
res = dict([(x, False) for x in ids])
return res
def _invoice_payment_term_id_search(
self, cr, uid, obj, name, args, context=None):
"""
Allow to search move lines associated with an invoice with
a particular payment term
"""
if not args:
return []
invoice_obj = self.pool.get('account.invoice')
invoice_ids = invoice_obj.search(
cr, uid, [('payment_term', args[0][1], args[0][2])],
context=context)
operator = 'in' # (args[0][1] not in ['in', '=', '==', 'like', 'ilike']
# and 'not in' or 'in')
if not invoice_ids:
return [('id', operator, [])]
cr.execute('SELECT l.id ' \
'FROM account_move_line l, account_invoice i ' \
'WHERE l.move_id = i.move_id AND i.id in %s', (tuple(invoice_ids),))
res = cr.fetchall()
if not res:
return [('id', '=', False)]
return [('id', operator, [x[0] for x in res])]
def _invoice_state_search(self, cr, uid, obj, name, args, context=None):
if not args:
return []
invoice_obj = self.pool.get('account.invoice')
invoice_ids = invoice_obj.search(
cr, uid, [('state', args[0][1], args[0][2])],
context=context)
operator = 'in' # (args[0][1] not in ['in', '=', '==', 'like', 'ilike']
# and 'not in' or 'in')
if not invoice_ids:
return [('id', operator, [])]
cr.execute('SELECT l.id ' \
'FROM account_move_line l, account_invoice i ' \
'WHERE l.move_id = i.move_id AND i.id in %s', (tuple(invoice_ids),))
res = cr.fetchall()
if not res:
return [('id', '=', False)]
return [('id', operator, [x[0] for x in res])]
_columns = {
'amount_to_receive': fields.function(
amount_to_receive, method=True,
type='float', string='Amount to receive',
fnct_search=_to_receive_search),
'payment_term_id': fields.function(
_dummy, method=True,
string='Select by invoice payment term',
type='many2one', relation='account.payment.term',
fnct_search=_invoice_payment_term_id_search),
'invoice_state': fields.function(
_dummy, method=True,
string='Select by invoice state',
type='char', size=24,
fnct_search=_invoice_state_search),
}
account_move_line()

View File

@@ -443,7 +443,7 @@ class payment_order_create(osv.osv_memory):
domain = [
('reconcile_id', '=', False),
('account_id.type', '=', 'receivable'),
('invoice_state', '!=', 'debit_denied'),
('invoice.state', '!=', 'debit_denied'),
('amount_to_receive', '>', 0),
]
else:
@@ -456,7 +456,7 @@ class payment_order_create(osv.osv_memory):
# apply payment term filter
if payment.mode.payment_term_ids:
domain = domain + [
('payment_term_id', 'in',
('invoice.payment_term', 'in',
[term.id for term in payment.mode.payment_term_ids]
)
]