From 32470c37056aa8dd402a3175df4483df9a4aa494 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 1 Dec 2015 16:39:58 +0100 Subject: [PATCH] Better filters on payment.order.create wizard Add default values for those filters on payment.mode --- .../models/payment_mode.py | 11 ++++ .../views/payment_mode.xml | 6 ++ .../wizard/payment_order_create.py | 40 ++++++++++--- .../wizard/payment_order_create_view.xml | 9 +++ account_payment_partner/__openerp__.py | 2 + account_payment_partner/models/__init__.py | 23 +------ .../models/payment_mode.py | 32 ++++++++++ .../views/payment_mode.xml | 20 +++++++ .../wizard/payment_order_create.py | 60 ++++++++++--------- .../wizard/payment_order_create_view.xml | 25 ++++++++ 10 files changed, 171 insertions(+), 57 deletions(-) create mode 100644 account_payment_partner/models/payment_mode.py create mode 100644 account_payment_partner/views/payment_mode.xml create mode 100644 account_payment_partner/wizard/payment_order_create_view.xml diff --git a/account_banking_payment_export/models/payment_mode.py b/account_banking_payment_export/models/payment_mode.py index a0084f114..dff0071e1 100644 --- a/account_banking_payment_export/models/payment_mode.py +++ b/account_banking_payment_export/models/payment_mode.py @@ -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') diff --git a/account_banking_payment_export/views/payment_mode.xml b/account_banking_payment_export/views/payment_mode.xml index 5441bb428..cdc5a33c1 100644 --- a/account_banking_payment_export/views/payment_mode.xml +++ b/account_banking_payment_export/views/payment_mode.xml @@ -17,6 +17,12 @@
+ + + + + + diff --git a/account_banking_payment_export/wizard/payment_order_create.py b/account_banking_payment_export/wizard/payment_order_create.py index 726f26e86..6de8dd869 100644 --- a/account_banking_payment_export/wizard/payment_order_create.py +++ b/account_banking_payment_export/wizard/payment_order_create.py @@ -4,11 +4,10 @@ # Copyright (C) 2009 EduSense BV (). # (C) 2011 - 2013 Therp BV (). # (C) 2014 - 2015 ACSONE SA/NV (). +# (C) 2015 Akretion (). # # 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) 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 d4d4b44dc..5e1d9a69d 100644 --- a/account_banking_payment_export/wizard/payment_order_create_view.xml +++ b/account_banking_payment_export/wizard/payment_order_create_view.xml @@ -13,8 +13,17 @@ + + + + + + + + {'required': [('date_type', '=', 'due')], 'invisible': [('date_type', '!=', 'due')]} + diff --git a/account_payment_partner/__openerp__.py b/account_payment_partner/__openerp__.py index ef8b028ce..2bbc92f96 100644 --- a/account_payment_partner/__openerp__.py +++ b/account_payment_partner/__openerp__.py @@ -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, diff --git a/account_payment_partner/models/__init__.py b/account_payment_partner/models/__init__.py index c2c7b405d..be3f531bb 100644 --- a/account_payment_partner/models/__init__.py +++ b/account_payment_partner/models/__init__.py @@ -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 -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- from . import res_partner from . import account_invoice +from . import payment_mode diff --git a/account_payment_partner/models/payment_mode.py b/account_payment_partner/models/payment_mode.py new file mode 100644 index 000000000..a4cd31616 --- /dev/null +++ b/account_payment_partner/models/payment_mode.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +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') diff --git a/account_payment_partner/views/payment_mode.xml b/account_payment_partner/views/payment_mode.xml new file mode 100644 index 000000000..120ca6970 --- /dev/null +++ b/account_payment_partner/views/payment_mode.xml @@ -0,0 +1,20 @@ + + + + + + + account_payment_partner.payment.mode.form + payment.mode + + + + + + + + + + + diff --git a/account_payment_partner/wizard/payment_order_create.py b/account_payment_partner/wizard/payment_order_create.py index 442047610..656ef9878 100644 --- a/account_payment_partner/wizard/payment_order_create.py +++ b/account_payment_partner/wizard/payment_order_create.py @@ -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 # # 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 diff --git a/account_payment_partner/wizard/payment_order_create_view.xml b/account_payment_partner/wizard/payment_order_create_view.xml new file mode 100644 index 000000000..f163b8cd6 --- /dev/null +++ b/account_payment_partner/wizard/payment_order_create_view.xml @@ -0,0 +1,25 @@ + + + + + + + + account_payment_partner.payment.order.create.form + payment.order.create + + + + + + + + + + +