mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Add wizard to select several invoices at once and add them to payment order
Fix bug in groupby on bank payment lines
This commit is contained in:
committed by
Enric Tobella
parent
dd18c5f421
commit
efdb8cba03
@@ -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',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2013-2014 ACSONE SA (<http://acsone.eu>).
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# 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
|
||||
|
||||
@@ -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 ?
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
@@ -51,5 +49,14 @@
|
||||
</record>
|
||||
|
||||
|
||||
<act_window id="account_invoice_create_account_payment_line_action"
|
||||
multi="True"
|
||||
key2="client_action_multi"
|
||||
name="Add to Payment/Debit Order"
|
||||
res_model="account.invoice.payment.line.multi"
|
||||
src_model="account.invoice"
|
||||
view_mode="form"
|
||||
target="new"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<form string="Payment Order">
|
||||
<header>
|
||||
<button name="%(account_payment_line_create_action)d" type="action"
|
||||
string="Create Payment Lines from Move Lines"
|
||||
string="Create Payment Lines from Journal Items"
|
||||
states="draft" class="oe_highlight" />
|
||||
<button name="draft2open" type="object" states="draft"
|
||||
string="Confirm Payments" class="oe_highlight"/>
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
<filter name="inbound" string="Inbound" domain="[('payment_type', '=', 'inbound')]" />
|
||||
<filter name="outbound" string="Outbound" domain="[('payment_type', '=', 'outbound')]" />
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="currency_groupby" string="Currency" context="{'group_by': 'currency_id'}"/>
|
||||
<filter name="state_groupby" string="State" context="{'group_by': 'state'}"/>
|
||||
<filter name="partner_groupby" string="Partner" context="{'group_by': 'partner_id'}"/>
|
||||
</group>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import account_payment_line_create
|
||||
from . import account_invoice_payment_line_multi
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Akretion (<http://www.akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, api
|
||||
|
||||
|
||||
class AccountInvoicePaymentLineMulti(models.TransientModel):
|
||||
_name = 'account.invoice.payment.line.multi'
|
||||
_description = 'Create payment lines from invoice tree view'
|
||||
|
||||
@api.multi
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
assert self._context['active_model'] == 'account.invoice',\
|
||||
'Active model should be account.invoice'
|
||||
invoices = self.env['account.invoice'].browse(
|
||||
self._context['active_ids'])
|
||||
action = invoices.create_account_payment_line()
|
||||
return action
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="account_invoice_payment_line_multi_form" model="ir.ui.view">
|
||||
<field name="name">account_invoice_payment_line_multi.form</field>
|
||||
<field name="model">account.invoice.payment.line.multi</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create Payment Lines">
|
||||
<p>This wizard will create payment lines for the selected invoices:</p>
|
||||
<ul>
|
||||
<li>if there are existing draft payment orders for the payment modes of the invoices, the payment lines will be added to those payment orders</li>
|
||||
<li>otherwise, new payment orders will be created (one per payment mode).</li>
|
||||
</ul>
|
||||
<footer>
|
||||
<button type="object" name="run" string="Create" class="oe_highlight"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user