summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJitendra Prajapati <jpr@openerp.com>2017-05-17 11:15:11 +0200
committerThibault Delavallée <tde@odoo.com>2017-05-17 14:41:00 +0200
commitb6d636617c290457538ea8ea589698d7dde70575 (patch)
tree218b85d99efdc8b3aa5da94c55034c3410dd65af
parentde5433f4154f7fbd9b496432637c7fd27eb7ced7 (diff)
[FIX] payment: perform small code improvements
* add a constraints about authorized state for tx and authorize feature available on acquirer; * order acquirers first by publish, then sequence then name; * add a sequence on some provider data and use a default to have some popular acquirers first; * use update instead of write in an onchange;
-rw-r--r--addons/payment/data/payment_acquirer_data.xml4
-rw-r--r--addons/payment/models/payment_acquirer.py12
-rw-r--r--addons/website_sale/data/demo.xml2
3 files changed, 14 insertions, 4 deletions
diff --git a/addons/payment/data/payment_acquirer_data.xml b/addons/payment/data/payment_acquirer_data.xml
index fb1ddf4ee16..0271aebdd52 100644
--- a/addons/payment/data/payment_acquirer_data.xml
+++ b/addons/payment/data/payment_acquirer_data.xml
@@ -36,6 +36,7 @@
<record id="payment_acquirer_ogone" model="payment.acquirer">
<field name="name">Ingenico</field>
+ <field name="sequence">2</field>
<field name="view_template_id" ref="default_acquirer_button"/>
<field name="image" type="base64" file="payment_ogone/static/src/img/ogone_icon.png"/>
<field name="module_id" ref="base.module_payment_ogone"/>
@@ -70,6 +71,7 @@
<record id="payment_acquirer_authorize" model="payment.acquirer">
<field name="name">Authorize.net</field>
+ <field name="sequence">3</field>
<field name="view_template_id" ref="default_acquirer_button"/>
<field name="image" type="base64" file="payment_authorize/static/src/img/authorize_icon.png"/>
<field name="module_id" ref="base.module_payment_authorize"/>
@@ -89,6 +91,7 @@
<record id="payment_acquirer_transfer" model="payment.acquirer">
<field name="name">Wire Transfer</field>
+ <field name="sequence">2</field>
<field name="view_template_id" ref="default_acquirer_button"/>
<field name="image" type="base64" file="payment_transfer/static/src/img/transfer_icon.png"/>
<field name="module_id" ref="base.module_payment_transfer"/>
@@ -118,6 +121,7 @@
<record id="payment_acquirer_paypal" model="payment.acquirer">
<field name="name">Paypal</field>
+ <field name="sequence">1</field>
<field name="view_template_id" ref="default_acquirer_button"/>
<field name="image" type="base64" file="payment_paypal/static/src/img/paypal_icon.png"/>
<field name="module_id" ref="base.module_payment_paypal"/>
diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py
index 9c8402d3d48..a8e3f895c9f 100644
--- a/addons/payment/models/payment_acquirer.py
+++ b/addons/payment/models/payment_acquirer.py
@@ -48,11 +48,11 @@ class PaymentAcquirer(models.Model):
"""
_name = 'payment.acquirer'
_description = 'Payment Acquirer'
- _order = 'sequence'
+ _order = 'website_published desc, sequence, name'
name = fields.Char('Name', required=True, translate=True)
description = fields.Html('Description')
- sequence = fields.Integer('Sequence', help="Determine the display order")
+ sequence = fields.Integer('Sequence', default=10, help="Determine the display order")
provider = fields.Selection(
selection=[('manual', 'Manual Configuration')], string='Provider',
default='manual', required=True)
@@ -459,7 +459,7 @@ class PaymentTransaction(models.Model):
@api.onchange('partner_id')
def _onchange_partner_id(self):
onchange_vals = self.on_change_partner_id(self.partner_id.id).get('value', {})
- self.write(onchange_vals)
+ self.update(onchange_vals)
@api.multi
def on_change_partner_id(self, partner_id):
@@ -485,6 +485,12 @@ class PaymentTransaction(models.Model):
raise exceptions.ValidationError(_('The payment transaction reference must be unique!'))
return True
+ @api.constrains('state', 'acquirer_id')
+ def _check_authorize_state(self):
+ failed_tx = self.filtered(lambda tx: tx.state == 'authorized' and tx.acquirer_id.provider not in self.env['payment.acquirer']._get_feature_support()['authorize'])
+ if failed_tx:
+ raise exceptions.ValidationError(_('The %s payment acquirers are not allowed to manual capture mode!' % failed_tx.mapped('acquirer_id.name')))
+
@api.model
def create(self, values):
if values.get('partner_id'): # @TDENOTE: not sure
diff --git a/addons/website_sale/data/demo.xml b/addons/website_sale/data/demo.xml
index d583adbd514..25a7a954669 100644
--- a/addons/website_sale/data/demo.xml
+++ b/addons/website_sale/data/demo.xml
@@ -1041,7 +1041,7 @@ Weight: 31 grams</field>
<field name="sale_order_id" ref="website_sale_order_13"/>
<field name="reference" ref="website_sale_order_13"/>
<field name="type">form</field>
- <field name="state">authorized</field>
+ <field name="state">pending</field>
<field name="amount">1799.0</field>
<field name="currency_id" ref="base.USD"/>
<field name="partner_id" ref="base.res_partner_3"/>