From 3c46c813dd30c5ad95850ce7a6f05fc163ed30a7 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Mon, 30 Mar 2015 14:51:58 +0200 Subject: [PATCH 1/3] [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 + + + + + + + + + + + + + + + + + + + + + From cfb27532b63727a18ae5ddc0676a38bfc3808531 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Tue, 31 Mar 2015 15:55:02 +0200 Subject: [PATCH 2/3] [IMP][account_banking_payment_export] Use payment mode type instead of check if modules are installed --- .../wizard/payment_order_create.py | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/account_banking_payment_export/wizard/payment_order_create.py b/account_banking_payment_export/wizard/payment_order_create.py index b991a04d9..33eaaebc3 100644 --- a/account_banking_payment_export/wizard/payment_order_create.py +++ b/account_banking_payment_export/wizard/payment_order_create.py @@ -86,22 +86,6 @@ 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. @@ -125,8 +109,12 @@ 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() + if payment.payment_order_type == 'payment': + context['display_credit'] = True + context['display_debit'] = False + else: + context['display_credit'] = False + context['display_debit'] = True model_datas = model_data_obj.search( [('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')]) From 8a56787cbc6a94f462e7bf7da5de925d08b0c588 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Wed, 22 Apr 2015 13:02:24 +0200 Subject: [PATCH 3/3] [IMP] Port account_move_line.py on new API --- .../models/account_move_line.py | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/account_banking_payment_export/models/account_move_line.py b/account_banking_payment_export/models/account_move_line.py index 75c201836..e7c2bdc3d 100644 --- a/account_banking_payment_export/models/account_move_line.py +++ b/account_banking_payment_export/models/account_move_line.py @@ -19,32 +19,27 @@ # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields, api -class AccountMoveLine(orm.Model): +class AccountMoveLine(models.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) + @api.one + def _get_journal_entry_ref(self): + if self.move_id.state == 'draft': + if self.invoice.id: + self.journal_entry_ref = self.invoice.number else: - res[record.id] = record.move_id.name - return res + self.journal_entry_ref = '*' + str(self.move_id.id) + else: + self.journal_entry_ref = self.move_id.name - _columns = { - 'journal_entry_ref': fields.function(_get_journal_entry_ref, - string='Journal Entry Ref', - type="char") - } + journal_entry_ref = fields.Char(compute=_get_journal_entry_ref, + string='Journal Entry Ref') - def get_balance(self, cr, uid, ids, context=None): + @api.multi + def get_balance(self): """ Return the balance of any set of move lines. @@ -52,9 +47,6 @@ class AccountMoveLine(orm.Model): returns the account balance that the move line applies to. """ total = 0.0 - if not ids: - return total - for line in self.read( - cr, uid, ids, ['debit', 'credit'], context=context): - total += (line['debit'] or 0.0) - (line['credit'] or 0.0) + for line in self: + total += (line.debit or 0.0) - (line.credit or 0.0) return total