[RFR] Sort out 'add invoices' wizard code between payment and debit module

This commit is contained in:
Stefan Rijnhart
2013-05-28 15:37:47 +02:00
parent 7fc4e0f975
commit fd6cac4854
4 changed files with 117 additions and 65 deletions

View File

@@ -25,12 +25,78 @@
from datetime import datetime from datetime import datetime
from openerp.osv import orm, fields from openerp.osv import orm, fields
from openerp.misc import DEFAULT_SERVER_DATE_FORMAT from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.tools.translate import _
class payment_order_create(orm.TransientModel): class payment_order_create(orm.TransientModel):
_inherit = 'payment.order.create' _inherit = 'payment.order.create'
def extend_payment_order_domain(
self, cr, uid, payment_order, domain, context=None):
if payment_order.payment_order_type == 'payment':
domain += [
('reconcile_id', '=', False),
('account_id.type', '=', 'payable'),
('amount_to_pay', '>', 0)
]
return True
def search_entries(self, cr, uid, ids, context=None):
"""
This method taken from account_payment module.
We adapt the domain based on the payment_order_type
"""
line_obj = self.pool.get('account.move.line')
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}
data = self.read(cr, uid, ids, ['duedate'], context=context)[0]
search_due_date = data['duedate']
### start account_banking_payment ###
payment = self.pool.get('payment.order').browse(
cr, uid, context['active_id'], context=context)
# Search for move line to pay:
domain = [
('reconcile_id', '=', False),
('company_id', '=', payment.mode.company_id.id),
]
# apply payment term filter
if payment.mode.payment_term_ids:
domain += [
('invoice.payment_term', 'in',
[term.id for term in payment.mode.payment_term_ids]
)
]
self.extend_payment_order_domain(
cr, uid, payment, domain, context=context)
### end account_direct_debit ###
domain = domain + [
'|', ('date_maturity', '<=', search_due_date),
('date_maturity', '=', False)
]
line_ids = line_obj.search(cr, uid, domain, context=context)
context.update({'line_ids': line_ids})
model_data_ids = mod_obj.search(
cr, uid,[
('model', '=', 'ir.ui.view'),
('name', '=', 'view_create_payment_order_lines')],
context=context)
resource_id = mod_obj.read(
cr, uid, model_data_ids, fields=['res_id'],
context=context)[0]['res_id']
return {'name': _('Entry Lines'),
'context': context,
'view_type': 'form',
'view_mode': 'form',
'res_model': 'payment.order.create',
'views': [(resource_id, 'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
def create_payment(self, cr, uid, ids, context=None): def create_payment(self, cr, uid, ids, context=None):
''' '''
This method is a slightly modified version of the existing method on this This method is a slightly modified version of the existing method on this
@@ -51,7 +117,8 @@ class payment_order_create(orm.TransientModel):
if not line_ids: if not line_ids:
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
payment = order_obj.browse(cr, uid, context['active_id'], context=context) payment = order_obj.browse(
cr, uid, context['active_id'], context=context)
### account banking ### account banking
# t = None # t = None
# line2bank = line_obj.line2bank(cr, uid, line_ids, t, context) # line2bank = line_obj.line2bank(cr, uid, line_ids, t, context)
@@ -75,10 +142,10 @@ class payment_order_create(orm.TransientModel):
### end account banking ### end account banking
elif payment.date_prefered == 'fixed': elif payment.date_prefered == 'fixed':
### account_banking ### account_banking
# date_to_pay = payment.date_planned # date_to_pay = payment.date_scheduled
date_to_pay = ( date_to_pay = (
payment.date_planned payment.date_scheduled
if payment.date_planned and payment.date_planned > _today if payment.date_scheduled and payment.date_scheduled > _today
else False) else False)
### end account banking ### end account banking
@@ -121,6 +188,8 @@ class payment_order_create(orm.TransientModel):
'state': state, 'state': state,
### end account banking ### end account banking
'date': date_to_pay, 'date': date_to_pay,
'currency': line.invoice and line.invoice.currency_id.id or line.journal_id.currency.id or line.journal_id.company_id.currency_id.id, 'currency': (line.invoice and line.invoice.currency_id.id
or line.journal_id.currency.id
or line.journal_id.company_id.currency_id.id),
}, context=context) }, context=context)
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}

View File

@@ -2,3 +2,4 @@ import account_payment
import payment_line import payment_line
import account_move_line import account_move_line
import account_invoice import account_invoice
import payment_order_create

View File

@@ -150,62 +150,3 @@ class payment_line(orm.Model):
help=("If this is true, the debit order has been canceled " help=("If this is true, the debit order has been canceled "
"by the bank or by the customer")), "by the bank or by the customer")),
} }
class payment_order_create(orm.Model_memory):
_inherit = 'payment.order.create'
def search_entries(self, cr, uid, ids, context=None):
"""
This method taken from account_payment module.
We adapt the domain based on the payment_order_type
"""
line_obj = self.pool.get('account.move.line')
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}
data = self.read(cr, uid, ids, [], context=context)[0]
search_due_date = data['duedate']
### start account_direct_debit ###
payment = self.pool.get('payment.order').browse(
cr, uid, context['active_id'], context=context)
# Search for move line to pay:
if payment.payment_order_type == 'debit':
domain = [
('reconcile_id', '=', False),
('account_id.type', '=', 'receivable'),
('invoice.state', '!=', 'debit_denied'),
('amount_to_receive', '>', 0),
]
else:
domain = [
('reconcile_id', '=', False),
('account_id.type', '=', 'payable'),
('amount_to_pay', '>', 0)
]
domain.append(('company_id', '=', payment.mode.company_id.id))
# apply payment term filter
if payment.mode.payment_term_ids:
domain = domain + [
('invoice.payment_term', 'in',
[term.id for term in payment.mode.payment_term_ids]
)
]
# domain = [('reconcile_id', '=', False), ('account_id.type', '=', 'payable'), ('amount_to_pay', '>', 0)]
### end account_direct_debit ###
domain = domain + ['|', ('date_maturity', '<=', search_due_date), ('date_maturity', '=', False)]
line_ids = line_obj.search(cr, uid, domain, context=context)
context.update({'line_ids': line_ids})
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {'name': ('Entry Lines'),
'context': context,
'view_type': 'form',
'view_mode': 'form',
'res_model': 'payment.order.create',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}

View File

@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Therp BV (<http://therp.nl>).
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
class payment_order_create(orm.TransientModel):
_inherit = 'payment.order.create'
def extend_payment_order_domain(
self, cr, uid, payment_order, domain, context=None):
super(payment_order_create, self).extend_payment_order_domain(
cr, uid, payment_order, domain, context=context)
if payment_order.payment_order_type == 'debit':
domain += [
('account_id.type', '=', 'receivable'),
('invoice.state', '!=', 'debit_denied'),
('amount_to_receive', '>', 0),
]
return True