From 3c46c813dd30c5ad95850ce7a6f05fc163ed30a7 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Mon, 30 Mar 2015 14:51:58 +0200 Subject: [PATCH] [IMP][account_banking_payment_export] Add a custom view to select journal items that will added on payment order * Add a custom journal items view based on an analysis of several production system * Display credit only if account_banking_sepa_credit_transfer is installed * Display debit only if account_banking_sepa_direct_debit is installed * Create a new journal entry ref field which will contain the number of the related invoice if it exist and if the state of the releted move is draft. otherwise, it will contain the name of the related journal entry. --- .../models/account_move_line.py | 21 ++++++++++++++- .../wizard/payment_order_create.py | 18 +++++++++++++ .../wizard/payment_order_create_view.xml | 26 ++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/account_banking_payment_export/models/account_move_line.py b/account_banking_payment_export/models/account_move_line.py index 54adf2ca8..75c201836 100644 --- a/account_banking_payment_export/models/account_move_line.py +++ b/account_banking_payment_export/models/account_move_line.py @@ -19,12 +19,31 @@ # ############################################################################## -from openerp.osv import orm +from openerp.osv import orm, fields class AccountMoveLine(orm.Model): _inherit = 'account.move.line' + def _get_journal_entry_ref(self, cr, uid, ids, name, args, context=None): + res = {} + for record in self.browse(cr, uid, ids, context=context): + res[record.id] = record.move_id.name + if record.move_id.state == 'draft': + if record.invoice.id: + res[record.id] = record.invoice.number + else: + res[record.id] = '*' + str(record.move_id.id) + else: + res[record.id] = record.move_id.name + return res + + _columns = { + 'journal_entry_ref': fields.function(_get_journal_entry_ref, + string='Journal Entry Ref', + type="char") + } + def get_balance(self, cr, uid, ids, context=None): """ Return the balance of any set of move lines. diff --git a/account_banking_payment_export/wizard/payment_order_create.py b/account_banking_payment_export/wizard/payment_order_create.py index 40a98457d..b991a04d9 100644 --- a/account_banking_payment_export/wizard/payment_order_create.py +++ b/account_banking_payment_export/wizard/payment_order_create.py @@ -86,6 +86,22 @@ class PaymentOrderCreate(models.TransientModel): to_exclude = set([l.move_line_id.id for l in payment_lines]) return [l.id for l in lines if l.id not in to_exclude] + @api.model + def display_credit(self): + ir_module = self.env['ir.module.module'] + res = ir_module\ + .search([('name', '=', 'account_banking_sepa_credit_transfer'), + ('state', '=', 'installed')]) + return len(res) > 0 + + @api.model + def display_debit(self): + ir_module = self.env['ir.module.module'] + res = ir_module\ + .search([('name', '=', 'account_banking_sepa_direct_debit'), + ('state', '=', 'installed')]) + return len(res) > 0 + @api.multi def search_entries(self): """This method taken from account_payment module. @@ -109,6 +125,8 @@ class PaymentOrderCreate(models.TransientModel): context = self.env.context.copy() context['line_ids'] = self.filter_lines(lines) context['populate_results'] = self.populate_results + context['display_credit'] = self.display_credit() + context['display_debit'] = self.display_debit() model_datas = model_data_obj.search( [('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')]) diff --git a/account_banking_payment_export/wizard/payment_order_create_view.xml b/account_banking_payment_export/wizard/payment_order_create_view.xml index d70135343..d4d4b44dc 100644 --- a/account_banking_payment_export/wizard/payment_order_create_view.xml +++ b/account_banking_payment_export/wizard/payment_order_create_view.xml @@ -24,11 +24,35 @@ - {'journal_type': 'sale'} + {'display_credit': context.get('display_credit', False),'display_debit': context.get('display_debit', False),'journal_type': 'sale', 'tree_view_ref' : 'account_banking_payment_export.payment_order_populate_view_move_line_tree'} 1 + + payment.order.populate.account.move.line.tree + account.move.line + + + + + + + + + + + + + + + + + + + + +