From b05036098f7d4ae3fa4e548b2f84eeb9dc840dd4 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 28 May 2013 13:49:08 +0200 Subject: [PATCH] [RFR] Sort out move line code between payment and debit module --- .../model/account_move_line.py | 74 ++----------------- account_direct_debit/model/account_payment.py | 4 +- 2 files changed, 9 insertions(+), 69 deletions(-) diff --git a/account_direct_debit/model/account_move_line.py b/account_direct_debit/model/account_move_line.py index 9a00955b1..943268912 100644 --- a/account_direct_debit/model/account_move_line.py +++ b/account_direct_debit/model/account_move_line.py @@ -2,9 +2,8 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# This module additional (C) 2011 Therp BV (). -# (C) 2011 Smile Benelux (). +# This module (C) 2011 - 2013 Therp BV (). +# (C) 2011 Smile Benelux (). # # 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() diff --git a/account_direct_debit/model/account_payment.py b/account_direct_debit/model/account_payment.py index 56c9fcbbf..abdce4977 100644 --- a/account_direct_debit/model/account_payment.py +++ b/account_direct_debit/model/account_payment.py @@ -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] ) ]