Skip to content

Commit

Permalink
Merge bddda75 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 + bddda75 commit b394563
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sale_payment_method_auto_pay_selection/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/OCA/sale-workflow/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 <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.
6 changes: 6 additions & 0 deletions sale_payment_method_auto_pay_selection/__init__.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions sale_payment_method_auto_pay_selection/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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,
}
22 changes: 22 additions & 0 deletions sale_payment_method_auto_pay_selection/payment_method.py
Original file line number Diff line number Diff line change
@@ -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,
)
15 changes: 15 additions & 0 deletions sale_payment_method_auto_pay_selection/payment_method_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>
<record id="payment_method_view_form" model="ir.ui.view">
<field name="name">sale_payment_method.payment_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="allow_automatic_payment"/>
</field>
</field>
</record>
</data>
</openerp>
20 changes: 20 additions & 0 deletions sale_payment_method_auto_pay_selection/sale.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b394563

Please sign in to comment.