Skip to content

Commit

Permalink
Merge 0efede3 into 8e9d44d
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-wafaie committed Aug 5, 2016
2 parents 8e9d44d + 0efede3 commit 3e98791
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 0 deletions.
47 changes: 47 additions & 0 deletions sale_payment_method_payment_acquirer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. 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

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

Contributors
------------

* Katja Matthes <katja.matthes@initos.com>
* Rami Alwafaie <rami.alwafaie@initos.com>

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.
9 changes: 9 additions & 0 deletions sale_payment_method_payment_acquirer/__init__.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions sale_payment_method_payment_acquirer/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- 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',
'data': ['payment_method_view.xml',
'payment_acquirer_view.xml',
'sale_view.xml',
],
'images': [],
'demo': [
],
'test': [
],
'installable': True,
'auto_install': False,
}
24 changes: 24 additions & 0 deletions sale_payment_method_payment_acquirer/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- 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


class website_sale_customization(website_sale):

# change the payment method if we choose the acquirer id from the website
@http.route(['/shop/payment/transaction/<int:acquirer_id>'],
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:
context, registry = request.context
order = request.website.sale_get_order(context=context)
order.onchange_payment_acquirer_id()
order.onchange_payment_method_set_workflow()
return res
13 changes: 13 additions & 0 deletions sale_payment_method_payment_acquirer/payment_acquirer.py
Original file line number Diff line number Diff line change
@@ -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',
)
15 changes: 15 additions & 0 deletions sale_payment_method_payment_acquirer/payment_acquirer_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="payment_acquirer_view_form" model="ir.ui.view">
<field name="name">paymennt.acquirer.extension_method.view_form</field>
<field name="model">payment.acquirer</field>
<field name="inherit_id" ref="payment.acquirer_form" />
<field name="arch" type="xml">
<field name="validation" position="after">
<field name="payment_method_id" />
</field>
</field>
</record>
</data>
</openerp>
14 changes: 14 additions & 0 deletions sale_payment_method_payment_acquirer/payment_method.py
Original file line number Diff line number Diff line change
@@ -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,)
26 changes: 26 additions & 0 deletions sale_payment_method_payment_acquirer/payment_method_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="payment_method_acquirer_view_form" model="ir.ui.view">
<field name="name">sale.acquirer.extension_method.view_form</field>
<field name="model">payment.method</field>
<field name="inherit_id" ref="sale_payment_method.payment_method_view_form" />
<field name="arch" type="xml">
<field name="journal_id" position="after">
<field name="acquirer_id" readonly="1" />
</field>
</field>
</record>

<record id="payment_method_acquirer_view_tree" model="ir.ui.view">
<field name="name">sale_acquirer_extension.payment_method.view_tree</field>
<field name="model">payment.method</field>
<field name="inherit_id" ref="sale_payment_method.payment_method_view_tree" />
<field name="arch" type="xml">
<field name="payment_term_id" position="after">
<field name="acquirer_id" readonly="1" />
</field>
</field>
</record>
</data>
</openerp>
35 changes: 35 additions & 0 deletions sale_payment_method_payment_acquirer/payment_transaction.py
Original file line number Diff line number Diff line change
@@ -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:
self.pool['sale.order'].automatic_payment(cr,
SUPERUSER_ID,
[tx.sale_order_id.id],
context=context,
amount=tx.amount)

return res
18 changes: 18 additions & 0 deletions sale_payment_method_payment_acquirer/sale.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions sale_payment_method_payment_acquirer/sale_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="sale_order_view_form2" model="ir.ui.view">
<field name="name">sale.order.view_form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_payment_method.sale_order_view_form" />
<field name="arch" type="xml">
<field name="payment_method_id" position="after">
<field name="payment_acquirer_id" />
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 3e98791

Please sign in to comment.