diff --git a/account_banking/banking_import_transaction.py b/account_banking/banking_import_transaction.py index ba15bcef1..60601a000 100644 --- a/account_banking/banking_import_transaction.py +++ b/account_banking/banking_import_transaction.py @@ -805,7 +805,7 @@ class banking_import_transaction(osv.osv): retval['type'] = type_map[move_lines[0].invoice.type] return retval - def move_info2values(move_info): + def move_info2values(self, move_info): vals = {} vals['match_type'] = move_info['match_type'] vals['move_line_ids'] = [(6, 0, move_info.get('move_line_ids') or [])] diff --git a/account_banking_payment/model/account_bank_statement_line.py b/account_banking_payment/model/account_bank_statement_line.py index 3f6b3c782..4cf2ead46 100644 --- a/account_banking_payment/model/account_bank_statement_line.py +++ b/account_banking_payment/model/account_bank_statement_line.py @@ -1,7 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2009 EduSense BV (). +# (C) 2011 - 2013 Therp BV (). +# +# 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 . +# +############################################################################## + from openerp.osv import orm, fields -class account_bank_statement_line(osv.osv): +class account_bank_statement_line(orm.Model): _inherit = 'account.bank.statement.line' _columns = { 'match_type': fields.related( diff --git a/account_banking_payment/model/account_payment.py b/account_banking_payment/model/account_payment.py index f915b7661..62be337c6 100644 --- a/account_banking_payment/model/account_payment.py +++ b/account_banking_payment/model/account_payment.py @@ -110,7 +110,7 @@ class payment_order(orm.Model): } _defaults = { - 'payment_order_type': lambda *a: 'payment', + 'payment_order_type': 'payment', } def launch_wizard(self, cr, uid, ids, context=None): diff --git a/account_banking_payment/model/bank_payment_manual.py b/account_banking_payment/model/bank_payment_manual.py index c29c74695..0c1f951f7 100644 --- a/account_banking_payment/model/bank_payment_manual.py +++ b/account_banking_payment/model/bank_payment_manual.py @@ -1,20 +1,24 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (C) 2009 EduSense BV (). +# (C) 2011 - 2013 Therp BV (). +# +# 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 General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# 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 General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## @@ -24,11 +28,10 @@ This module contains a single "wizard" for including a 'sent' state for manual bank transfers. ''' -import wizard -import pooler +from openerp.osv import orm -class payment_manual(osv.Model): +class payment_manual(orm.Model): _name = 'payment.manual' _description = 'Set payment orders to \'sent\' manually' diff --git a/account_banking_payment/model/banking_import_transaction.py b/account_banking_payment/model/banking_import_transaction.py index 5f6a1645d..2d9a890c2 100644 --- a/account_banking_payment/model/banking_import_transaction.py +++ b/account_banking_payment/model/banking_import_transaction.py @@ -24,31 +24,14 @@ ############################################################################## from openerp.osv import orm, fields +from openerp import netsvc +from openerp.tools.translate import _ from openerp.addons.account_banking.parsers.convert import str2date class banking_import_transaction(orm.Model): _inherit = 'banking.import.transaction' - confirm_map = { - # Add storno and payment types - 'storno': _confirm_storno, - 'invoice': _confirm_move, - 'manual': _confirm_move, - 'payment_order': _confirm_payment_order, - 'payment': _confirm_payment, - 'move': _confirm_move, - } - - cancel_map = { - 'storno': _cancel_storno, - 'invoice': _cancel_voucher, - 'manual': _cancel_voucher, - 'move': _cancel_voucher, - 'payment_order': _cancel_payment_order, - 'payment': _cancel_payment, - } - def _match_debit_order( self, cr, uid, trans, log, context=None): @@ -127,18 +110,21 @@ class banking_import_transaction(orm.Model): # TODO: Not sure what side effects are created when payments are done # for credited customer invoices, which will be matched later on too. digits = dp.get_precision('Account')(cr)[1] - candidates = [x for x in payment_lines - if x.communication == trans.reference - and round(x.amount, digits) == -round(trans.transferred_amount, digits) - and trans.remote_account in (x.bank_id.acc_number, - x.bank_id.acc_number_domestic) - ] + candidates = [ + x for x in payment_lines + if x.communication == trans.reference + and round(x.amount, digits) == -round( + trans.transferred_amount, digits) + and trans.remote_account in (x.bank_id.acc_number, + x.bank_id.acc_number_domestic) + ] if len(candidates) == 1: candidate = candidates[0] # Check cache to prevent multiple matching of a single payment if candidate.id not in linked_payments: linked_payments[candidate.id] = True - move_info = self._get_move_info(cr, uid, [candidate.move_line_id.id]) + move_info = self._get_move_info( + cr, uid, [candidate.move_line_id.id]) move_info.update({ 'match_type': 'payment', 'payment_line_id': candidate.id, @@ -157,7 +143,7 @@ class banking_import_transaction(orm.Model): statement_line_pool = self.pool.get('account.bank.statement.line') transaction = self.browse(cr, uid, transaction_id, context=context) if not transaction.payment_line_id: - raise osv.except_osv( + raise orm.except_orm( _("Cannot link with storno"), _("No direct debit order item")) reconcile_id = payment_line_pool.debit_storno( @@ -182,11 +168,11 @@ class banking_import_transaction(orm.Model): statement_line_pool = self.pool.get('account.bank.statement.line') transaction = self.browse(cr, uid, transaction_id, context=context) if not transaction.payment_order_id: - raise osv.except_osv( + raise orm.except_orm( _("Cannot reconcile"), _("Cannot reconcile: no direct debit order")) if transaction.payment_order_id.payment_order_type != 'debit': - raise osv.except_osv( + raise orm.except_orm( _("Cannot reconcile"), _("Reconcile payment order not implemented")) reconcile_id = payment_order_obj.debit_reconcile_transfer( @@ -217,7 +203,7 @@ class banking_import_transaction(orm.Model): def _cancel_payment( self, cr, uid, transaction_id, context=None): - raise osv.except_osv( + raise orm.except_orm( _("Cannot unreconcile"), _("Cannot unreconcile: this operation is not yet supported for " "match type 'payment'")) @@ -229,11 +215,11 @@ class banking_import_transaction(orm.Model): payment_order_obj = self.pool.get('payment.order') transaction = self.browse(cr, uid, transaction_id, context=context) if not transaction.payment_order_id: - raise osv.except_osv( + raise orm.except_orm( _("Cannot unreconcile"), _("Cannot unreconcile: no direct debit order")) if transaction.payment_order_id.payment_order_type != 'debit': - raise osv.except_osv( + raise orm.except_orm( _("Cannot unreconcile"), _("Unreconcile payment order not implemented")) return payment_order_obj.debit_unreconcile_transfer( @@ -253,11 +239,11 @@ class banking_import_transaction(orm.Model): transaction = self.browse(cr, uid, transaction_id, context=context) if not transaction.payment_line_id: - raise osv.except_osv( + raise orm.except_orm( _("Cannot cancel link with storno"), _("No direct debit order item")) if not transaction.payment_line_id.storno: - raise osv.except_osv( + raise orm.except_orm( _("Cannot cancel link with storno"), _("The direct debit order item is not marked for storno")) @@ -276,7 +262,7 @@ class banking_import_transaction(orm.Model): cancel_line = line break if not cancel_line: - raise osv.except_osv( + raise orm.except_orm( _("Cannot cancel link with storno"), _("Line id not found")) reconcile = cancel_line.reconcile_id or cancel_line.reconcile_partial_id @@ -289,7 +275,8 @@ class banking_import_transaction(orm.Model): reconcile_obj.write( cr, uid, reconcile.id, {'line_partial_ids': - [(6, 0, [x.id for x in lines_reconcile if x.id != cancel_line.id])], + [(6, 0, [x.id for x in lines_reconcile + if x.id != cancel_line.id])], 'line_id': [(6, 0, [])], }, context) # redo the original payment line reconciliation with the invoice @@ -341,7 +328,7 @@ class banking_import_transaction(orm.Model): }, context=context) - def move_info2values(move_info): + def move_info2values(self, move_info): vals = super(banking_import_transaction, self).move_info2values vals['payment_line_id'] = move_info.get('payment_line_id', False) vals['payment_order_ids'] = [ @@ -383,3 +370,16 @@ class banking_import_transaction(orm.Model): wf_service.trg_validate( uid, 'payment.order', id, 'done', cr) return res + + def __init__(self, pool, cr): + super(banking_import_transaction, self).__init__(pool, cr) + self.confirm_map.update({ + 'storno': self._confirm_storno, + 'payment_order': self._confirm_payment_order, + 'payment': self._confirm_payment, + }) + self.cancel_map.update({ + 'storno': self._cancel_storno, + 'payment_order': self._cancel_payment_order, + 'payment': self._cancel_payment, + }) diff --git a/account_banking_payment/model/banking_transaction_wizard.py b/account_banking_payment/model/banking_transaction_wizard.py index 8b55a8b02..470a81c81 100644 --- a/account_banking_payment/model/banking_transaction_wizard.py +++ b/account_banking_payment/model/banking_transaction_wizard.py @@ -30,12 +30,16 @@ class banking_transaction_wizard(orm.TransientModel): _inherit = 'banking.transaction.wizard' _columns = { 'payment_line_id': fields.related( - 'import_transaction_id', 'payment_line_id', string="Matching payment or storno", - type='many2one', relation='payment.line', readonly=True), + 'import_transaction_id', 'payment_line_id', + string="Matching payment or storno", + type='many2one', relation='payment.line', + readonly=True), 'payment_order_ids': fields.related( - 'import_transaction_id', 'payment_order_ids', string="Matching payment orders", + 'import_transaction_id', 'payment_order_ids', + string="Matching payment orders", type='many2many', relation='payment.order'), 'payment_order_id': fields.related( - 'import_transaction_id', 'payment_order_id', string="Payment order to reconcile", + 'import_transaction_id', 'payment_order_id', + string="Payment order to reconcile", type='many2one', relation='payment.order'), } diff --git a/account_banking_payment/model/payment_line.py b/account_banking_payment/model/payment_line.py index abe196f5d..30bef3564 100644 --- a/account_banking_payment/model/payment_line.py +++ b/account_banking_payment/model/payment_line.py @@ -26,7 +26,7 @@ from openerp.osv import orm, fields -class payment_line(osv.osv): +class payment_line(orm.Model): ''' Add extra export_state and date_done fields; make destination bank account mandatory, as it makes no sense to send payments into thin air. @@ -160,9 +160,9 @@ class payment_line(osv.osv): ), } _defaults = { - 'export_state': lambda *a: 'draft', - 'date_done': lambda *a: False, - 'msg': lambda *a: '', + 'export_state': 'draft', + 'date_done': False, + 'msg': '', } def fields_get(self, cr, uid, fields=None, context=None): @@ -216,6 +216,3 @@ class payment_line(osv.osv): """ return False - -payment_line() - diff --git a/account_banking_payment/model/payment_mode.py b/account_banking_payment/model/payment_mode.py index a60f57149..a250afa40 100644 --- a/account_banking_payment/model/payment_mode.py +++ b/account_banking_payment/model/payment_mode.py @@ -49,4 +49,3 @@ class payment_mode(orm.Model): help='Select the Payment Type for the Payment Mode.' ), } -payment_mode() diff --git a/account_banking_payment/model/payment_mode_type.py b/account_banking_payment/model/payment_mode_type.py index 0713aca45..51de7ca66 100644 --- a/account_banking_payment/model/payment_mode_type.py +++ b/account_banking_payment/model/payment_mode_type.py @@ -27,9 +27,9 @@ from openerp.osv import orm, fields class payment_mode_type(orm.Model): - _name= 'payment.mode.type' - _description= 'Payment Mode Type' - _columns= { + _name = 'payment.mode.type' + _description = 'Payment Mode Type' + _columns = { 'name': fields.char( 'Name', size=64, required=True, help='Payment Type' @@ -58,5 +58,5 @@ class payment_mode_type(orm.Model): } _defaults = { - 'payment_order_type': lambda *a: 'payment', + 'payment_order_type': 'payment', } diff --git a/account_banking_payment/model/payment_order_create.py b/account_banking_payment/model/payment_order_create.py index c09e65c25..8ee6a3649 100644 --- a/account_banking_payment/model/payment_order_create.py +++ b/account_banking_payment/model/payment_order_create.py @@ -23,16 +23,8 @@ # ############################################################################## -import datetime -from openerp.osv import orm -from account_banking.struct import struct -from account_banking.parsers import convert +from openerp.osv import orm, fields -today = datetime.date.today - -def str2date(str): - dt = convert.str2date(str, '%Y-%m-%d') - return datetime.date(dt.year, dt.month, dt.day) class payment_order_create(orm.TransientModel): _inherit = 'payment.order.create' @@ -62,7 +54,7 @@ class payment_order_create(orm.TransientModel): # t = None # line2bank = line_obj.line2bank(cr, uid, line_ids, t, context) line2bank = line_obj.line2bank(cr, uid, line_ids, payment.mode.id, context) - _today = today() + _today = fields.date.context_today(self, cr, uid, context=context) ### end account banking ## Finally populate the current payment with new lines: @@ -73,16 +65,16 @@ class payment_order_create(orm.TransientModel): elif payment.date_prefered == 'due': ### account_banking # date_to_pay = line.date_maturity - date_to_pay = line.date_maturity and \ - str2date(line.date_maturity) > _today\ - and line.date_maturity or False + date_to_pay = ( + line.date_maturity if line.date_maturity + and line.date_maturity > _today else False) ### end account banking elif payment.date_prefered == 'fixed': ### account_banking # date_to_pay = payment.date_planned - date_to_pay = payment.date_planned and \ - str2date(payment.date_planned) > _today\ - and payment.date_planned or False + date_to_pay = ( + payment.date_planned if payment.date_planned + and payment.date_planned > _today else False) ### end account banking ### account_banking @@ -111,7 +103,7 @@ class payment_order_create(orm.TransientModel): amount_currency = line.amount_to_pay ### end account_banking - payment_obj.create(cr, uid,{ + payment_obj.create(cr, uid, { 'move_line_id': line.id, 'amount_currency': amount_currency, 'bank_id': line2bank.get(line.id),