[IMP] payment_acquirer_paypal: paypal account integration in payment_paypal
- added a call to _migrate_paypal_account in the payment_paypal data that does the migration from company.paypal_account (char field) to a payment.acquirer and company.paypal_account becoming a function field, with a getter / setter. This function field is company aware. - added an update of the res_config view of invoicing to link to the list of acquirers - added possibilty to install acquirers from invoicing (paypal / ogone / adyen are installable through config) bzr revid: tde@openerp.com-20140123150135-07b4pkbjade6vimq
This commit is contained in:
parent
4f1423588c
commit
3a679c2b7f
|
@ -7,9 +7,10 @@
|
|||
'version': '1.0',
|
||||
'description': """Payment Acquirer Base Module""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': ['mail'],
|
||||
'depends': ['mail', 'account'],
|
||||
'data': [
|
||||
'views/payment_acquirer.xml',
|
||||
'views/res_config_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'installable': True,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import payment_acquirer
|
||||
import res_config
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
|
||||
class AccountPaymentConfig(osv.TransientModel):
|
||||
_inherit = 'account.config.settings'
|
||||
|
||||
_columns = {
|
||||
'module_payment_paypal': fields.boolean(
|
||||
'Manage Payments Using Paypal',
|
||||
help='Blahblahblah\n'
|
||||
'-It installs the module payment_paypal.'),
|
||||
'module_payment_ogone': fields.boolean(
|
||||
'Manage Payments Using Ogone',
|
||||
help='Blahblahblah\n'
|
||||
'-It installs the module payment_ogone.'),
|
||||
'module_payment_adyen': fields.boolean(
|
||||
'Manage Payments Using Adyen',
|
||||
help='Blahblahblah\n'
|
||||
'-It installs the module payment_adyen.'),
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Add payment options to sale.order and invoice forms -->
|
||||
<record model="ir.ui.view" id="payment_acquirer_installation">
|
||||
<field name="model">account.config.settings</field>
|
||||
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='payment_acquirer']" version="7.0" position="inside">
|
||||
<div>
|
||||
<field name="module_payment_paypal" class="oe_inline"/>
|
||||
<label for="module_payment_paypal"/>
|
||||
</div>
|
||||
<div>
|
||||
<field name="module_payment_ogone" class="oe_inline"/>
|
||||
<label for="module_payment_ogone"/>
|
||||
</div>
|
||||
<div>
|
||||
<field name="module_payment_adyen" class="oe_inline"/>
|
||||
<label for="module_payment_adyen"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -11,6 +11,7 @@
|
|||
'data': [
|
||||
'views/paypal.xml',
|
||||
'views/payment_acquirer.xml',
|
||||
'views/res_config_view.xml',
|
||||
'data/paypal.xml',
|
||||
],
|
||||
'installable': True,
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
<record id="payment_acquirer_paypal" model="payment.acquirer">
|
||||
<field name="name">paypal</field>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="view_template_id" ref="paypal_acquirer_button"/>
|
||||
<field name="env">test</field>
|
||||
<field name="message"><![CDATA[
|
||||
|
@ -14,5 +15,6 @@
|
|||
<field name="paypal_api_password">dummy</field>
|
||||
</record>
|
||||
|
||||
<function model="payment.acquirer" name="_migrate_paypal_account"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import paypal
|
||||
import res_company
|
||||
|
|
|
@ -36,8 +36,10 @@ class AcquirerPaypal(osv.Model):
|
|||
|
||||
_columns = {
|
||||
'paypal_email_account': fields.char('Paypal Email ID', required_if_provider='paypal'),
|
||||
'paypal_seller_account': fields.char('Paypal Seller ID', required_if_provider='paypal'),
|
||||
'paypal_use_ipn': fields.boolean('Use IPN'),
|
||||
'paypal_seller_account': fields.char(
|
||||
'Paypal Seller ID',
|
||||
help='The Seller ID is used to ensure communications coming from Paypal are valid and secured.'),
|
||||
'paypal_use_ipn': fields.boolean('Use IPN', help='Paypal Instant Payment Notification'),
|
||||
# Server 2 server
|
||||
'paypal_api_enabled': fields.boolean('Use Rest API'),
|
||||
'paypal_api_username': fields.char('Rest API Username'),
|
||||
|
@ -56,6 +58,23 @@ class AcquirerPaypal(osv.Model):
|
|||
'paypal_api_enabled': False,
|
||||
}
|
||||
|
||||
def _migrate_paypal_account(self, cr, uid, context=None):
|
||||
""" COMPLETE ME """
|
||||
cr.execute('SELECT id, paypal_account FROM res_company')
|
||||
res = cr.fetchall()
|
||||
for (company_id, company_paypal_account) in res:
|
||||
if company_paypal_account:
|
||||
company_paypal_ids = self.search(cr, uid, [('company_id', '=', company_id), ('name', '=', 'paypal')], limit=1, context=context)
|
||||
if company_paypal_ids:
|
||||
self.write(cr, uid, company_paypal_ids, {'paypal_email_account': company_paypal_account}, context=context)
|
||||
else:
|
||||
paypal_view = self.pool['ir.model.data'].get_object(cr, uid, 'payment_paypal', 'paypal_acquirer_button')
|
||||
self.create(cr, uid, {
|
||||
'paypal_email_account': company_paypal_account,
|
||||
'view_template_id': paypal_view.id,
|
||||
}, context=context)
|
||||
return True
|
||||
|
||||
def paypal_compute_fees(self, cr, uid, id, amount, currency_id, country_id, context=None):
|
||||
""" Compute paypal fees.
|
||||
|
||||
|
@ -195,7 +214,7 @@ class TxPaypal(osv.Model):
|
|||
# check seller
|
||||
if data.get('receiver_email') != tx.acquirer_id.paypal_email_account:
|
||||
invalid_parameters.append(('receiver_email', data.get('receiver_email'), tx.acquirer_id.paypal_email_account))
|
||||
if data.get('receiver_id') != tx.acquirer_id.paypal_seller_account:
|
||||
if tx.acquirer_id.paypal_seller_account and data.get('receiver_id') != tx.acquirer_id.paypal_seller_account:
|
||||
invalid_parameters.append(('receiver_id', data.get('receiver_id'), tx.acquirer_id.paypal_seller_account))
|
||||
|
||||
return invalid_parameters
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
|
||||
class ResCompany(osv.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
def _get_paypal_account(self, cr, uid, ids, name, arg, context=None):
|
||||
Acquirer = self.pool['payment.acquirer']
|
||||
company_id = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.id
|
||||
paypal_ids = Acquirer.search(cr, uid, [
|
||||
('portal_published', '=', True),
|
||||
('name', 'ilike', 'paypal'),
|
||||
('company_id', '=', company_id),
|
||||
], limit=1, context=context)
|
||||
if paypal_ids:
|
||||
paypal = Acquirer.browse(cr, uid, paypal_ids[0], context=context)
|
||||
return dict.fromkeys(ids, paypal.paypal_email_account)
|
||||
return dict.fromkeys(ids, False)
|
||||
|
||||
def _set_paypal_account(self, cr, uid, id, name, value, arg, context=None):
|
||||
Acquirer = self.pool['payment.acquirer']
|
||||
company_id = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.id
|
||||
paypal_account = self.browse(cr, uid, id, context=context).paypal_account
|
||||
paypal_ids = Acquirer.search(cr, uid, [
|
||||
('portal_published', '=', True),
|
||||
('paypal_email_account', '=', paypal_account),
|
||||
('company_id', '=', company_id),
|
||||
], context=context)
|
||||
if paypal_ids:
|
||||
Acquirer.write(cr, uid, paypal_ids, {'paypal_email_account': value}, context=context)
|
||||
return True
|
||||
|
||||
_columns = {
|
||||
'paypal_account': fields.function(
|
||||
_get_paypal_account,
|
||||
fnct_inv=_set_paypal_account,
|
||||
nodrop=True,
|
||||
type='char', string='Paypal Account',
|
||||
help="Paypal username (usually email) for receiving online payments."
|
||||
),
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Add payment options to sale.order and invoice forms -->
|
||||
<record model="ir.ui.view" id="payment_paypal_option_config">
|
||||
<field name="model">account.config.settings</field>
|
||||
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='payment_acquirer']" version="7.0" position="inside">
|
||||
<button name='%(payment.acquirer_list)d' type="action"
|
||||
string="Configure payment acquiring methods" class="oe_link"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -11,6 +11,8 @@
|
|||
<div>
|
||||
<field name="group_payment_options" class="oe_inline"/>
|
||||
<label for="group_payment_options"/>
|
||||
<button name='%(payment.acquirer_list)d' type="action"
|
||||
string="Configure payment acquiring methods" class="oe_link"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
|
|
Loading…
Reference in New Issue