From 85e753eb4a0c606e386a58c4c928bd740d6bcfba Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 19 Oct 2015 17:50:53 +0200 Subject: [PATCH] [FIX+IMP] account_payment_partner: Several things: * Forgot to remove a usecase of debit_denied * Add ACL * Better filters on payment.order.create wizard * Add default values for those filters on payment.mode * FIX remove coma at end of line * Add translatable 'label' field on payment.mode, designed to be used in invoice report --- account_payment_partner/__openerp__.py | 2 + account_payment_partner/models/__init__.py | 23 +------ .../models/payment_mode.py | 35 +++++++++++ .../security/ir.model.access.csv | 1 + .../views/payment_mode.xml | 23 +++++++ .../wizard/payment_order_create.py | 60 ++++++++++--------- .../wizard/payment_order_create_view.xml | 25 ++++++++ 7 files changed, 119 insertions(+), 50 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_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..62b8767e6 --- /dev/null +++ b/account_payment_partner/models/payment_mode.py @@ -0,0 +1,35 @@ +# -*- 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" + + label = fields.Char( + string='Label', translate=True, + help="This field is designed to be used in the invoice report") + 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/security/ir.model.access.csv b/account_payment_partner/security/ir.model.access.csv index b277f0229..ac6d96dfd 100644 --- a/account_payment_partner/security/ir.model.access.csv +++ b/account_payment_partner/security/ir.model.access.csv @@ -1,2 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_payment_mode_read,Read access on payment.mode to Employees,account_payment.model_payment_mode,base.group_user,1,0,0,0 +access_payment_mode_type_read,Read access on payment.mode.type to Employees,account_banking_payment_export.model_payment_mode_type,base.group_user,1,0,0,0 diff --git a/account_payment_partner/views/payment_mode.xml b/account_payment_partner/views/payment_mode.xml new file mode 100644 index 000000000..b32d52b01 --- /dev/null +++ b/account_payment_partner/views/payment_mode.xml @@ -0,0 +1,23 @@ + + + + + + + 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..fbf4939fb 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') + + @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 + + + + + + + + + + +