diff --git a/sale_payment_method_payment_acquirer/README.rst b/sale_payment_method_payment_acquirer/README.rst new file mode 100644 index 00000000000..61c97bcb8b5 --- /dev/null +++ b/sale_payment_method_payment_acquirer/README.rst @@ -0,0 +1,36 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +====================================== +Sale Payment Method - Payment Acquirer +====================================== + +* this module adds acquirer_id to sale payment method and links between them + +Installation +============ + +* No thing is required to install this module + +Contributors +------------ + +* Katja Matthes +* Rami Alwafaie +* 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. \ No newline at end of file diff --git a/sale_payment_method_payment_acquirer/__init__.py b/sale_payment_method_payment_acquirer/__init__.py new file mode 100644 index 00000000000..c0441e965c6 --- /dev/null +++ b/sale_payment_method_payment_acquirer/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import payment_method +from . import payment_acquirer +from . import payment_transaction +from . import sale +from . import controller diff --git a/sale_payment_method_payment_acquirer/__openerp__.py b/sale_payment_method_payment_acquirer/__openerp__.py new file mode 100644 index 00000000000..fae6478b31e --- /dev/null +++ b/sale_payment_method_payment_acquirer/__openerp__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Payment Method - Payment Acquirer", + "version": "8.0.1.0.0", + "depends": ["payment", + "sale_payment_method", + "sale", + "website_sale", + ], + 'author': 'initOS GmbH, Odoo Community Association (OCA)', + "category": "", + "summary": "", + 'license': 'AGPL-3', + "description": """ + Sale Payment Method - Payment Acquirer + ======================================= + * this module adds acquirer_id to sale payment method + """, + 'data': ['payment_method_view.xml', + 'payment_acquirer_view.xml', + ], + 'images': [], + 'demo': [ + ], + 'test': [ + ], + 'installable': True, + 'auto_install': False, + } diff --git a/sale_payment_method_payment_acquirer/controller.py b/sale_payment_method_payment_acquirer/controller.py new file mode 100644 index 00000000000..31fca8ee054 --- /dev/null +++ b/sale_payment_method_payment_acquirer/controller.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.addons.website_sale.controllers.main import website_sale +from openerp import http +from openerp.http import request, route + + +class website_sale_customization(website_sale): + + # change the payment method if we choose the acquirer id from the website + @http.route(['/shop/payment/transaction/'], + type='json', auth="public", website=True) + def payment_transaction(self, acquirer_id): + + res = super(website_sale_customization, self).\ + payment_transaction(acquirer_id) + if acquirer_id: + cr, uid, context, registry = \ + request.cr, request.uid, request.context, request.registry + order = request.website.sale_get_order(context=context) + order.onchange_payment_acquirer_id() + order.onchange_payment_method_set_workflow() + return res diff --git a/sale_payment_method_payment_acquirer/payment_acquirer.py b/sale_payment_method_payment_acquirer/payment_acquirer.py new file mode 100644 index 00000000000..9562678236e --- /dev/null +++ b/sale_payment_method_payment_acquirer/payment_acquirer.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields + + +class PaymentAcquirer(models.Model): + _inherit = 'payment.acquirer' + + payment_method_id = fields.Many2one('payment.method', + 'Payment Method', + ) diff --git a/sale_payment_method_payment_acquirer/payment_acquirer_view.xml b/sale_payment_method_payment_acquirer/payment_acquirer_view.xml new file mode 100644 index 00000000000..ce00834cd65 --- /dev/null +++ b/sale_payment_method_payment_acquirer/payment_acquirer_view.xml @@ -0,0 +1,15 @@ + + + + + paymennt.acquirer.extension_method.view_form + payment.acquirer + + + + + + + + + diff --git a/sale_payment_method_payment_acquirer/payment_method.py b/sale_payment_method_payment_acquirer/payment_method.py new file mode 100644 index 00000000000..8eee9dea16b --- /dev/null +++ b/sale_payment_method_payment_acquirer/payment_method.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields + + +class PaymentMethod(models.Model): + _inherit = 'payment.method' + + acquirer_id = fields.One2many('payment.acquirer', + 'payment_method_id', + 'Acquirer', + required=False,) diff --git a/sale_payment_method_payment_acquirer/payment_method_view.xml b/sale_payment_method_payment_acquirer/payment_method_view.xml new file mode 100644 index 00000000000..b43b0fda50f --- /dev/null +++ b/sale_payment_method_payment_acquirer/payment_method_view.xml @@ -0,0 +1,26 @@ + + + + + sale.acquirer.extension_method.view_form + payment.method + + + + + + + + + + sale_acquirer_extension.payment_method.view_tree + payment.method + + + + + + + + + diff --git a/sale_payment_method_payment_acquirer/payment_transaction.py b/sale_payment_method_payment_acquirer/payment_transaction.py new file mode 100644 index 00000000000..18e680d2a05 --- /dev/null +++ b/sale_payment_method_payment_acquirer/payment_transaction.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2016 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models +from openerp import SUPERUSER_ID + + +class PaymentTransaction(models.Model): + _inherit = 'payment.transaction' + + def form_feedback(self, cr, uid, data, acquirer_name, context=None): + """ Override to create automatic payments for order, + if transaction is done. """ + + res = super(PaymentTransaction, self).\ + form_feedback(cr, uid, data, acquirer_name, context=context) + # Order already confirmed. (cmp. module website_sale) + + tx = None + # fetch the tx, check its state, confirm the potential SO + tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name + if hasattr(self, tx_find_method_name): + tx = getattr(self, + tx_find_method_name)(cr, uid, data, context=context) + if tx and tx.state == 'done' and tx.sale_order_id\ + and tx.sale_order_id.payment_method_id\ + and not tx.sale_order_id.payment_ids: + self.pool['sale.order'].automatic_payment(cr, + SUPERUSER_ID, + [tx.sale_order_id.id], + context=context, + amount=tx.amount) + + return res diff --git a/sale_payment_method_payment_acquirer/sale.py b/sale_payment_method_payment_acquirer/sale.py new file mode 100644 index 00000000000..4a962afbd71 --- /dev/null +++ b/sale_payment_method_payment_acquirer/sale.py @@ -0,0 +1,18 @@ +# -*- 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.onchange('payment_acquirer_id') + def onchange_payment_acquirer_id(self): + # change payment method according to payment_acquirer_id + if not self.payment_acquirer_id: + return + method = self.payment_acquirer_id.payment_method_id + if method: + self.payment_method_id = method