mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Better filters on payment.order.create wizard
Add default values for those filters on payment.mode
This commit is contained in:
committed by
Pedro M. Baeza
parent
f9bde4af35
commit
32470c3705
@@ -108,3 +108,14 @@ class PaymentMode(models.Model):
|
||||
purchase_ok = fields.Boolean(string='Selectable on purchase operations',
|
||||
default=True)
|
||||
note = fields.Text(string="Note", translate=True)
|
||||
# Default options for the "payment.order.create" wizard
|
||||
default_journal_ids = fields.Many2many(
|
||||
'account.journal', string="Journals Filter")
|
||||
default_invoice = fields.Boolean(
|
||||
string='Linked to an Invoice or Refund', default=True)
|
||||
default_date_type = fields.Selection([
|
||||
('due', 'Due'),
|
||||
('move', 'Move'),
|
||||
], default='due', string="Type of Date Filter")
|
||||
default_populate_results = fields.Boolean(
|
||||
string='Populate Results Directly')
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
<field name="sale_ok"/>
|
||||
</field>
|
||||
<form position="inside">
|
||||
<group name="payment_order_create_defaults" string="Select Move Lines to Pay - Default Values">
|
||||
<field name="default_populate_results"/>
|
||||
<field name="default_journal_ids" widget="many2many_tags"/>
|
||||
<field name="default_invoice"/>
|
||||
<field name="default_date_type"/>
|
||||
</group>
|
||||
<group string="Note" col="4">
|
||||
<field name="note" nolabel="1"/>
|
||||
</group>
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
|
||||
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
|
||||
# (C) 2014 - 2015 ACSONE SA/NV (<http://acsone.eu>).
|
||||
# (C) 2015 Akretion (<http://www.akretion.com>).
|
||||
#
|
||||
# All other contributions are (C) by their respective contributors
|
||||
#
|
||||
# All Rights Reserved
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
@@ -30,8 +29,18 @@ from openerp import models, fields, api, _
|
||||
class PaymentOrderCreate(models.TransientModel):
|
||||
_inherit = 'payment.order.create'
|
||||
|
||||
populate_results = fields.Boolean(string="Populate results directly",
|
||||
default=True)
|
||||
journal_ids = fields.Many2many(
|
||||
'account.journal', string='Journals Filter', required=True)
|
||||
invoice = fields.Boolean(
|
||||
string='Linked to an Invoice or Refund')
|
||||
date_type = fields.Selection([
|
||||
('due', 'Due'),
|
||||
('move', 'Move'),
|
||||
], string="Type of Date Filter", required=True)
|
||||
duedate = fields.Date(required=False)
|
||||
move_date = fields.Date(
|
||||
string='Move Date', default=fields.Date.context_today)
|
||||
populate_results = fields.Boolean(string="Populate Results Directly")
|
||||
|
||||
@api.model
|
||||
def default_get(self, field_list):
|
||||
@@ -40,6 +49,16 @@ class PaymentOrderCreate(models.TransientModel):
|
||||
if ('entries' in field_list and context.get('line_ids') and
|
||||
context.get('populate_results')):
|
||||
res.update({'entries': context['line_ids']})
|
||||
assert context.get('active_model') == 'payment.order',\
|
||||
'active_model should be payment.order'
|
||||
assert context.get('active_id'), 'Missing active_id in context !'
|
||||
pay_order = self.env['payment.order'].browse(context['active_id'])
|
||||
res.update({
|
||||
'journal_ids': pay_order.mode.default_journal_ids.ids or False,
|
||||
'invoice': pay_order.mode.default_invoice,
|
||||
'date_type': pay_order.mode.default_date_type,
|
||||
'populate_results': pay_order.mode.default_populate_results,
|
||||
})
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
@@ -101,9 +120,16 @@ class PaymentOrderCreate(models.TransientModel):
|
||||
domain = [('move_id.state', '=', 'posted'),
|
||||
('reconcile_id', '=', False),
|
||||
('company_id', '=', payment.mode.company_id.id),
|
||||
'|',
|
||||
('date_maturity', '<=', self.duedate),
|
||||
('date_maturity', '=', False)]
|
||||
('journal_id', 'in', self.journal_ids.ids)]
|
||||
if self.date_type == 'due':
|
||||
domain += [
|
||||
'|',
|
||||
('date_maturity', '<=', self.duedate),
|
||||
('date_maturity', '=', False)]
|
||||
elif self.date_type == 'move':
|
||||
domain.append(('date', '<=', self.move_date))
|
||||
if self.invoice:
|
||||
domain.append(('invoice', '!=', False))
|
||||
self.extend_payment_order_domain(payment, domain)
|
||||
# -- end account_direct_debit --
|
||||
lines = line_obj.search(domain)
|
||||
|
||||
@@ -13,8 +13,17 @@
|
||||
<field name="inherit_id" ref="account_payment.view_create_payment_order"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="duedate" position="after">
|
||||
<field name="journal_ids" widget="many2many_tags"/>
|
||||
<field name="invoice"/>
|
||||
<field name="populate_results"/>
|
||||
</field>
|
||||
<field name="duedate" position="before">
|
||||
<field name="date_type"/>
|
||||
<field name="move_date" attrs="{'required': [('date_type', '=', 'move')], 'invisible': [('date_type', '!=', 'move')]}"/>
|
||||
</field>
|
||||
<field name="duedate" position="attributes">
|
||||
<attribute name="attrs">{'required': [('date_type', '=', 'due')], 'invisible': [('date_type', '!=', 'due')]}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
'views/res_partner_view.xml',
|
||||
'views/account_invoice_view.xml',
|
||||
'views/report_invoice.xml',
|
||||
'views/payment_mode.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'wizard/payment_order_create_view.xml',
|
||||
],
|
||||
'demo': ['demo/partner_demo.xml'],
|
||||
'installable': True,
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Account Payment Partner module for OpenERP
|
||||
# Copyright (C) 2014 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import res_partner
|
||||
from . import account_invoice
|
||||
from . import payment_mode
|
||||
|
||||
32
account_payment_partner/models/payment_mode.py
Normal file
32
account_payment_partner/models/payment_mode.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import models, fields
|
||||
|
||||
|
||||
class PaymentMode(models.Model):
|
||||
_inherit = "payment.mode"
|
||||
|
||||
default_payment_mode = fields.Selection([
|
||||
('same', 'Same'),
|
||||
('same_or_null', 'Same or empty'),
|
||||
('any', 'Any'),
|
||||
], string='Payment Mode on Invoice', default='same')
|
||||
20
account_payment_partner/views/payment_mode.xml
Normal file
20
account_payment_partner/views/payment_mode.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="view_payment_mode_form" model="ir.ui.view">
|
||||
<field name="name">account_payment_partner.payment.mode.form</field>
|
||||
<field name="model">payment.mode</field>
|
||||
<field name="inherit_id" ref="account_banking_payment_export.view_payment_mode_form_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<group name="payment_order_create_defaults" position="inside">
|
||||
<field name="default_payment_mode"
|
||||
attrs="{'invisible': [('default_invoice', '=', False)]}"/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,8 +1,8 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Account Payment Partner module for OpenERP
|
||||
# Copyright (C) 2014 Akretion (http://www.akretion.com)
|
||||
# Account Payment Partner module for Odoo
|
||||
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@@ -20,39 +20,41 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import models, api
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class PaymentOrderCreate(models.TransientModel):
|
||||
_inherit = 'payment.order.create'
|
||||
|
||||
payment_mode = fields.Selection([
|
||||
('same', 'Same'),
|
||||
('same_or_null', 'Same or empty'),
|
||||
('any', 'Any'),
|
||||
], string='Payment Mode on Invoice', default='same')
|
||||
|
||||
@api.model
|
||||
def default_get(self, field_list):
|
||||
res = super(PaymentOrderCreate, self).default_get(field_list)
|
||||
context = self.env.context
|
||||
assert context.get('active_model') == 'payment.order',\
|
||||
'active_model should be payment.order'
|
||||
assert context.get('active_id'), 'Missing active_id in context !'
|
||||
pay_order = self.env['payment.order'].browse(context['active_id'])
|
||||
res['payment_mode'] = pay_order.mode.default_payment_mode,
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def extend_payment_order_domain(self, payment_order, domain):
|
||||
res = super(PaymentOrderCreate, self).extend_payment_order_domain(
|
||||
payment_order, domain)
|
||||
# Monkey patch for fixing problem with the core search function
|
||||
# when args has ('invoice', '=', False), referred in the issue #4857
|
||||
# (https://github.com/odoo/odoo/issues/4857)
|
||||
#
|
||||
# Original domain:
|
||||
# domain += ['|', '|',
|
||||
# ('invoice', '=', False),
|
||||
# ('invoice.payment_mode_id', '=', False),
|
||||
# ('invoice.payment_mode_id', '=', payment_order.mode.id)]
|
||||
self.env.cr.execute(
|
||||
"SELECT l.id "
|
||||
"FROM account_move_line l "
|
||||
"LEFT OUTER JOIN account_invoice i "
|
||||
"ON l.move_id = i.move_id "
|
||||
"INNER JOIN account_account a "
|
||||
"ON a.id = l.account_id "
|
||||
"WHERE i.id IS NULL"
|
||||
" AND l.reconcile_id IS NULL"
|
||||
" AND a.type in ('receivable', 'payable')")
|
||||
ids = [x[0] for x in self.env.cr.fetchall()]
|
||||
domain += ['|',
|
||||
('id', 'in', ids),
|
||||
'|',
|
||||
('invoice.payment_mode_id', '=', False),
|
||||
('invoice.payment_mode_id', '=', payment_order.mode.id)]
|
||||
if self.invoice and self.payment_mode:
|
||||
if self.payment_mode == 'same':
|
||||
domain.append(
|
||||
('invoice.payment_mode_id', '=', payment_order.mode.id))
|
||||
elif self.payment_mode == 'same_or_null':
|
||||
domain += [
|
||||
'|',
|
||||
('invoice.payment_mode_id', '=', False),
|
||||
('invoice.payment_mode_id', '=', payment_order.mode.id)]
|
||||
# if payment_mode == 'any', don't modify domain
|
||||
return res
|
||||
|
||||
25
account_payment_partner/wizard/payment_order_create_view.xml
Normal file
25
account_payment_partner/wizard/payment_order_create_view.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="view_create_payment_order" model="ir.ui.view">
|
||||
<field name="name">account_payment_partner.payment.order.create.form</field>
|
||||
<field name="model">payment.order.create</field>
|
||||
<field name="inherit_id" ref="account_banking_payment_export.view_create_payment_order"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="invoice" position="after">
|
||||
<field name="payment_mode"
|
||||
attrs="{'invisible': [('invoice', '=', False)], 'required': [('invoice', '=', True)]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user