diff --git a/account_payment_order/__openerp__.py b/account_payment_order/__openerp__.py index ae6271bdd..60f7dda5a 100644 --- a/account_payment_order/__openerp__.py +++ b/account_payment_order/__openerp__.py @@ -26,6 +26,7 @@ 'security/payment_security.xml', 'security/ir.model.access.csv', 'wizard/account_payment_line_create_view.xml', + 'wizard/account_invoice_payment_line_multi_view.xml', 'views/account_payment_mode.xml', 'views/account_payment_order.xml', 'views/account_payment_line.xml', diff --git a/account_payment_order/models/account_invoice.py b/account_payment_order/models/account_invoice.py index 39a57d370..e9cd0fe85 100644 --- a/account_payment_order/models/account_invoice.py +++ b/account_payment_order/models/account_invoice.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # © 2013-2014 ACSONE SA (). # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza +# © 2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api, _ @@ -39,14 +40,22 @@ class AccountInvoice(models.Model): def create_account_payment_line(self): apoo = self.env['account.payment.order'] aplo = self.env['account.payment.line'] - action = {} + result_payorder_ids = [] + action_payment_type = 'debit' for inv in self: + if inv.state != 'open': + raise UserError(_( + "The invoice %s is not in Open state") % inv.number) if not inv.payment_mode_id: raise UserError(_( "No Payment Mode on invoice %s") % inv.number) if not inv.move_id: raise UserError(_( "No Journal Entry on invoice %s") % inv.number) + if not inv.payment_order_ok: + raise UserError(_( + "The invoice %s has a payment mode '%s' " + "which is not selectable in payment orders.")) payorders = apoo.search([ ('payment_mode_id', '=', inv.payment_mode_id.id), ('state', '=', 'draft')]) @@ -56,16 +65,17 @@ class AccountInvoice(models.Model): else: payorder = apoo.create(inv._prepare_new_payment_order()) new_payorder = True + result_payorder_ids.append(payorder.id) + action_payment_type = payorder.payment_type count = 0 for line in inv.move_id.line_ids: if line.account_id == inv.account_id and not line.reconciled: paylines = aplo.search([ ('move_line_id', '=', line.id), ('state', '!=', 'cancel')]) - if paylines: - continue - line.create_payment_line_from_move_line(payorder) - count += 1 + if not paylines: + line.create_payment_line_from_move_line(payorder) + count += 1 if count: if new_payorder: inv.message_post(_( @@ -82,12 +92,19 @@ class AccountInvoice(models.Model): 'No Payment Line created for invoice %s because ' 'it already exists or because this invoice is ' 'already paid.') % inv.number) - action = self.env['ir.actions.act_window'].for_xml_id( - 'account_payment_order', - 'account_payment_order_%s_action' % payorder.payment_type) + action = self.env['ir.actions.act_window'].for_xml_id( + 'account_payment_order', + 'account_payment_order_%s_action' % action_payment_type) + if len(result_payorder_ids) == 1: action.update({ 'view_mode': 'form,tree,pivot,graph', 'res_id': payorder.id, 'views': False, }) + else: + action.update({ + 'view_mode': 'tree,form,pivot,graph', + 'domain': "[('id', 'in', %s)]" % result_payorder_ids, + 'views': False, + }) return action diff --git a/account_payment_order/models/bank_payment_line.py b/account_payment_order/models/bank_payment_line.py index 8bd0fc431..a1533f6ad 100644 --- a/account_payment_order/models/bank_payment_line.py +++ b/account_payment_order/models/bank_payment_line.py @@ -27,7 +27,7 @@ class BankPaymentLine(models.Model): readonly=True) partner_id = fields.Many2one( 'res.partner', related='payment_line_ids.partner_id', - readonly=True) + readonly=True, store=True) # store=True for groupby # Function Float fields are sometimes badly displayed in tree view, # see bug report https://github.com/odoo/odoo/issues/8632 # But is it still true in v9 ? diff --git a/account_payment_order/views/account_invoice_view.xml b/account_payment_order/views/account_invoice_view.xml index 02a7afcc2..2ca7919ff 100644 --- a/account_payment_order/views/account_invoice_view.xml +++ b/account_payment_order/views/account_invoice_view.xml @@ -1,12 +1,10 @@ - - + @@ -51,5 +49,14 @@ + + - + diff --git a/account_payment_order/views/account_payment_order.xml b/account_payment_order/views/account_payment_order.xml index c9ef0ec5a..eec3c0e83 100644 --- a/account_payment_order/views/account_payment_order.xml +++ b/account_payment_order/views/account_payment_order.xml @@ -10,7 +10,7 @@