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:
@@ -26,6 +26,7 @@
|
|||||||
'security/payment_security.xml',
|
'security/payment_security.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'wizard/account_payment_line_create_view.xml',
|
'wizard/account_payment_line_create_view.xml',
|
||||||
|
'wizard/account_invoice_payment_line_multi_view.xml',
|
||||||
'views/account_payment_mode.xml',
|
'views/account_payment_mode.xml',
|
||||||
'views/account_payment_order.xml',
|
'views/account_payment_order.xml',
|
||||||
'views/account_payment_line.xml',
|
'views/account_payment_line.xml',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2013-2014 ACSONE SA (<http://acsone.eu>).
|
# © 2013-2014 ACSONE SA (<http://acsone.eu>).
|
||||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
# © 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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from openerp import models, fields, api, _
|
from openerp import models, fields, api, _
|
||||||
@@ -39,14 +40,22 @@ class AccountInvoice(models.Model):
|
|||||||
def create_account_payment_line(self):
|
def create_account_payment_line(self):
|
||||||
apoo = self.env['account.payment.order']
|
apoo = self.env['account.payment.order']
|
||||||
aplo = self.env['account.payment.line']
|
aplo = self.env['account.payment.line']
|
||||||
action = {}
|
result_payorder_ids = []
|
||||||
|
action_payment_type = 'debit'
|
||||||
for inv in self:
|
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:
|
if not inv.payment_mode_id:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"No Payment Mode on invoice %s") % inv.number)
|
"No Payment Mode on invoice %s") % inv.number)
|
||||||
if not inv.move_id:
|
if not inv.move_id:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"No Journal Entry on invoice %s") % inv.number)
|
"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([
|
payorders = apoo.search([
|
||||||
('payment_mode_id', '=', inv.payment_mode_id.id),
|
('payment_mode_id', '=', inv.payment_mode_id.id),
|
||||||
('state', '=', 'draft')])
|
('state', '=', 'draft')])
|
||||||
@@ -56,16 +65,17 @@ class AccountInvoice(models.Model):
|
|||||||
else:
|
else:
|
||||||
payorder = apoo.create(inv._prepare_new_payment_order())
|
payorder = apoo.create(inv._prepare_new_payment_order())
|
||||||
new_payorder = True
|
new_payorder = True
|
||||||
|
result_payorder_ids.append(payorder.id)
|
||||||
|
action_payment_type = payorder.payment_type
|
||||||
count = 0
|
count = 0
|
||||||
for line in inv.move_id.line_ids:
|
for line in inv.move_id.line_ids:
|
||||||
if line.account_id == inv.account_id and not line.reconciled:
|
if line.account_id == inv.account_id and not line.reconciled:
|
||||||
paylines = aplo.search([
|
paylines = aplo.search([
|
||||||
('move_line_id', '=', line.id),
|
('move_line_id', '=', line.id),
|
||||||
('state', '!=', 'cancel')])
|
('state', '!=', 'cancel')])
|
||||||
if paylines:
|
if not paylines:
|
||||||
continue
|
line.create_payment_line_from_move_line(payorder)
|
||||||
line.create_payment_line_from_move_line(payorder)
|
count += 1
|
||||||
count += 1
|
|
||||||
if count:
|
if count:
|
||||||
if new_payorder:
|
if new_payorder:
|
||||||
inv.message_post(_(
|
inv.message_post(_(
|
||||||
@@ -82,12 +92,19 @@ class AccountInvoice(models.Model):
|
|||||||
'No Payment Line created for invoice %s because '
|
'No Payment Line created for invoice %s because '
|
||||||
'it already exists or because this invoice is '
|
'it already exists or because this invoice is '
|
||||||
'already paid.') % inv.number)
|
'already paid.') % inv.number)
|
||||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||||
'account_payment_order',
|
'account_payment_order',
|
||||||
'account_payment_order_%s_action' % payorder.payment_type)
|
'account_payment_order_%s_action' % action_payment_type)
|
||||||
|
if len(result_payorder_ids) == 1:
|
||||||
action.update({
|
action.update({
|
||||||
'view_mode': 'form,tree,pivot,graph',
|
'view_mode': 'form,tree,pivot,graph',
|
||||||
'res_id': payorder.id,
|
'res_id': payorder.id,
|
||||||
'views': False,
|
'views': False,
|
||||||
})
|
})
|
||||||
|
else:
|
||||||
|
action.update({
|
||||||
|
'view_mode': 'tree,form,pivot,graph',
|
||||||
|
'domain': "[('id', 'in', %s)]" % result_payorder_ids,
|
||||||
|
'views': False,
|
||||||
|
})
|
||||||
return action
|
return action
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class BankPaymentLine(models.Model):
|
|||||||
readonly=True)
|
readonly=True)
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
'res.partner', related='payment_line_ids.partner_id',
|
'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,
|
# Function Float fields are sometimes badly displayed in tree view,
|
||||||
# see bug report https://github.com/odoo/odoo/issues/8632
|
# see bug report https://github.com/odoo/odoo/issues/8632
|
||||||
# But is it still true in v9 ?
|
# But is it still true in v9 ?
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Copyright (C) 2016 Akretion (http://www.akretion.com/)
|
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
The licence is in the file __openerp__.py
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
<record id="invoice_form" model="ir.ui.view">
|
<record id="invoice_form" model="ir.ui.view">
|
||||||
@@ -51,5 +49,14 @@
|
|||||||
</record>
|
</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>
|
</data>
|
||||||
</openerp>
|
</odoo>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<form string="Payment Order">
|
<form string="Payment Order">
|
||||||
<header>
|
<header>
|
||||||
<button name="%(account_payment_line_create_action)d" type="action"
|
<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" />
|
states="draft" class="oe_highlight" />
|
||||||
<button name="draft2open" type="object" states="draft"
|
<button name="draft2open" type="object" states="draft"
|
||||||
string="Confirm Payments" class="oe_highlight"/>
|
string="Confirm Payments" class="oe_highlight"/>
|
||||||
|
|||||||
@@ -62,7 +62,6 @@
|
|||||||
<filter name="inbound" string="Inbound" domain="[('payment_type', '=', 'inbound')]" />
|
<filter name="inbound" string="Inbound" domain="[('payment_type', '=', 'inbound')]" />
|
||||||
<filter name="outbound" string="Outbound" domain="[('payment_type', '=', 'outbound')]" />
|
<filter name="outbound" string="Outbound" domain="[('payment_type', '=', 'outbound')]" />
|
||||||
<group string="Group By" name="groupby">
|
<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="state_groupby" string="State" context="{'group_by': 'state'}"/>
|
||||||
<filter name="partner_groupby" string="Partner" context="{'group_by': 'partner_id'}"/>
|
<filter name="partner_groupby" string="Partner" context="{'group_by': 'partner_id'}"/>
|
||||||
</group>
|
</group>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import account_payment_line_create
|
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>
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Copyright (C) 2014-2016 Akretion (http://www.akretion.com/)
|
© 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
The licence is in the file __openerp__.py
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
<record id="view_account_invoice_filter" model="ir.ui.view">
|
<record id="view_account_invoice_filter" model="ir.ui.view">
|
||||||
@@ -33,7 +31,6 @@
|
|||||||
widget="selection"/>
|
widget="selection"/>
|
||||||
<field name="commercial_partner_id" invisible="1"/>
|
<field name="commercial_partner_id" invisible="1"/>
|
||||||
</field>
|
</field>
|
||||||
<!-- TODO : check if we have to add/fix domain -->
|
|
||||||
<field name="partner_bank_id" position="attributes">
|
<field name="partner_bank_id" position="attributes">
|
||||||
<attribute name="invisible">0</attribute>
|
<attribute name="invisible">0</attribute>
|
||||||
</field>
|
</field>
|
||||||
@@ -53,14 +50,34 @@
|
|||||||
<field name="commercial_partner_id" invisible="1"/>
|
<field name="commercial_partner_id" invisible="1"/>
|
||||||
</field>
|
</field>
|
||||||
<field name="partner_bank_id" position="attributes">
|
<field name="partner_bank_id" position="attributes">
|
||||||
|
<attribute name="domain">[('partner_id', '=', commercial_partner_id)]</attribute>
|
||||||
<attribute name="invisible">0</attribute>
|
<attribute name="invisible">0</attribute>
|
||||||
</field>
|
</field>
|
||||||
<field name="partner_bank_id" position="attributes">
|
</field>
|
||||||
<attribute name="domain">[('partner_id', '=', commercial_partner_id)]</attribute>
|
</record>
|
||||||
|
|
||||||
|
<record id="invoice_tree" model="ir.ui.view">
|
||||||
|
<field name="name">account_payment_partner.customer_invoice_tree</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="inherit_id" ref="account.invoice_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="residual_signed" position="after">
|
||||||
|
<field name="payment_mode_id"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="invoice_supplier_tree" model="ir.ui.view">
|
||||||
|
<field name="name">account_payment_partner.supplier_invoice_tree</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="inherit_id" ref="account.invoice_supplier_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="residual_signed" position="after">
|
||||||
|
<field name="payment_mode_id"/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user