diff --git a/sale_payment_method_auto_pay_selection/README.rst b/sale_payment_method_auto_pay_selection/README.rst new file mode 100644 index 00000000000..7273db6516c --- /dev/null +++ b/sale_payment_method_auto_pay_selection/README.rst @@ -0,0 +1,53 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +===================================================== +Sale Payment Method - Selection for Automatic Payment +===================================================== + +* Adds an selection to payment methods to configure when an automatic payment is allowed to be created. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/167/8.0 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Katja Matthes +* Rami Alwafaie + +Sponsors +-------- + +* Sponsored by Nitrokey: www.nitrokey.com + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/sale_payment_method_auto_pay_selection/__init__.py b/sale_payment_method_auto_pay_selection/__init__.py new file mode 100644 index 00000000000..d04096e37e2 --- /dev/null +++ b/sale_payment_method_auto_pay_selection/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import payment_method +from . import sale diff --git a/sale_payment_method_auto_pay_selection/__openerp__.py b/sale_payment_method_auto_pay_selection/__openerp__.py new file mode 100644 index 00000000000..49220851d5c --- /dev/null +++ b/sale_payment_method_auto_pay_selection/__openerp__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{'name': 'Sale Payment Method - Selection for Automatic Payment', + 'version': '8.0.1.0.0', + 'category': '', + 'depends': ['sale_payment_method', + ], + 'author': "initOS GmbH, Odoo Community Association (OCA) ", + 'license': 'AGPL-3', + 'data': ['payment_method_view.xml', + ], + 'installable': True, + 'application': False, + } diff --git a/sale_payment_method_auto_pay_selection/payment_method.py b/sale_payment_method_auto_pay_selection/payment_method.py new file mode 100644 index 00000000000..26b9a86ba42 --- /dev/null +++ b/sale_payment_method_auto_pay_selection/payment_method.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, api, fields, _ + + +class PaymentMethod(models.Model): + _inherit = 'payment.method' + + @api.model + def _get_allow_automatic_payment_selection(self): + return [('never', _('never')), + ('none', _('no limitation')), + ] + + allow_automatic_payment = fields.Selection( + '_get_allow_automatic_payment_selection', + string='Allow Automatic Payment', + default='none', + required=True, + ) diff --git a/sale_payment_method_auto_pay_selection/payment_method_view.xml b/sale_payment_method_auto_pay_selection/payment_method_view.xml new file mode 100644 index 00000000000..cd657deb8c9 --- /dev/null +++ b/sale_payment_method_auto_pay_selection/payment_method_view.xml @@ -0,0 +1,15 @@ + + + + + sale_payment_method.payment_method.view_form + payment.method + + + + + + + + + diff --git a/sale_payment_method_auto_pay_selection/sale.py b/sale_payment_method_auto_pay_selection/sale.py new file mode 100644 index 00000000000..f67aa349b29 --- /dev/null +++ b/sale_payment_method_auto_pay_selection/sale.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, api + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + @api.multi + def automatic_payment(self, amount=None): + """ Add some limitations to the creation of automatic_payments. + """ + self.ensure_one() + # do nothing when it isn't allow + if self.payment_method_id\ + and self.payment_method_id.allow_automatic_payment == 'never': + return True + return super(SaleOrder, self).automatic_payment(amount=amount)