Browse Source

[REM] easy_my_coop_online_payment : not in v12

pull/84/head
robin.keunen 4 years ago
parent
commit
9ae59380f6
  1. 2
      easy_my_coop_online_payment/__init__.py
  2. 40
      easy_my_coop_online_payment/__openerp__.py
  3. 1
      easy_my_coop_online_payment/controllers/__init__.py
  4. 112
      easy_my_coop_online_payment/controllers/main.py
  5. 65
      easy_my_coop_online_payment/i18n/fr.po
  6. 2
      easy_my_coop_online_payment/models/__init__.py
  7. 26
      easy_my_coop_online_payment/models/coop.py
  8. 47
      easy_my_coop_online_payment/models/payment_transaction.py
  9. 25
      easy_my_coop_online_payment/views/online_payment_template.xml
  10. 28
      easy_my_coop_online_payment/views/subscription_request_view.xml

2
easy_my_coop_online_payment/__init__.py

@ -1,2 +0,0 @@
from . import models
from . import controllers

40
easy_my_coop_online_payment/__openerp__.py

@ -1,40 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013-2017 Open Architects Consulting SPRL.
# Copyright (C) 2018- Coop IT Easy SCRLfs.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Easy My Coop Online Payment",
"version": "1.0",
"depends": ["easy_my_coop",
"website_payment",
"payment_paypal"],
"author": "Houssine BAKKALI <houssine@coopiteasy.be>",
"category": "Cooperative management",
'website': "www.coopiteasy.be",
"description": """
This module allows the cooperator to pay the subscribed shares online
during the subscription process
""",
'data': [
"views/online_payment_template.xml",
"views/subscription_request_view.xml",
],
'installable': False,
'application': False,
}

1
easy_my_coop_online_payment/controllers/__init__.py

@ -1 +0,0 @@
from . import main

112
easy_my_coop_online_payment/controllers/main.py

@ -1,112 +0,0 @@
# -*- coding: utf-8 -*-
from openerp import http
from openerp.http import request
from openerp.tools.translate import _
from openerp.addons.easy_my_coop.controllers.main import WebsiteSubscription
from openerp.addons.website_payment.controllers.main import website_payment
class SubscriptionOnlinePayment(WebsiteSubscription):
def fill_values(self, values, is_company, load_from_user=False):
values = super(SubscriptionOnlinePayment, self).fill_values(values, is_company, load_from_user)
fields_desc = request.env['subscription.request'].sudo().fields_get(['payment_type'])
values['payment_types'] = fields_desc['payment_type']['selection']
return values
def get_subscription_response(self, values, kwargs):
subscription = values.get('subscription_id', False)
if kwargs.get('payment_type') == 'online':
invoice = subscription.validate_subscription_request()[0]
acquirer = request.env['payment.acquirer'].search([('website_published', '=', True)])[0]
return website_payment().pay(reference=invoice.number, amount=invoice.residual, currency_id=invoice.currency_id.id, acquirer_id=acquirer.id)
else:
values = self.preRenderThanks(values, kwargs)
return request.website.render(kwargs.get("view_callback", "easy_my_coop.cooperator_thanks"), values)
return True
class SubscriptionWebsitePayment(website_payment):
@http.route(['/website_payment/transaction'],
type='json',
auth="public", website=True)
def transaction(self, reference, amount, currency_id, acquirer_id):
inv_obj = request.env['account.invoice']
partner_id = request.env.user.partner_id.id if request.env.user.partner_id != request.website.partner_id else False
capital_release_request = inv_obj.sudo().search([('release_capital_request', '=', True),
('number', '=', reference)])
values = {
'acquirer_id': int(acquirer_id),
'reference': reference,
'amount': float(amount),
'currency_id': int(currency_id),
'partner_id': partner_id,
'release_capital_request': capital_release_request.id,
}
if len(capital_release_request) > 0:
values['partner_id'] = capital_release_request.partner_id.id
values['release_capital_request'] = capital_release_request.id
tx = request.env['payment.transaction'].sudo().create(values)
request.session['website_payment_tx_id'] = tx.id
return tx.id
@http.route(['/website_payment/confirm'],
type='http',
auth='public', website=True)
def confirm(self, **kw):
tx_id = request.session.pop('website_payment_tx_id', False)
if tx_id:
tx = request.env['payment.transaction'].sudo().browse(tx_id)
status = (tx.state == 'done' and 'success') or 'danger'
message = (tx.state == 'done' and 'Your payment was successful! It may take some time to be validated on our end.') or 'OOps! There was a problem with your payment.'
return request.website.render('website_payment.confirm', {'tx': tx, 'status': status, 'message': message})
else:
return request.redirect('/my/home')
@http.route(['/website_payment/pay'],
type='http',
auth='public', website=True)
def pay(self, reference='', amount=False, currency_id=None,
acquirer_id=None, **kw):
env = request.env
user = env.user.sudo()
currency_id = currency_id and int(currency_id) or user.company_id.currency_id.id
currency = env['res.currency'].browse(currency_id)
# Try default one then fallback on first
acquirer_id = acquirer_id and int(acquirer_id) or \
env['ir.values'].get_default('payment.transaction', 'acquirer_id', company_id=user.company_id.id) or \
env['payment.acquirer'].search([('website_published', '=', True), ('company_id', '=', user.company_id.id)])[0].id
acquirer = env['payment.acquirer'].with_context(submit_class='btn btn-primary pull-right',
submit_txt=_('Pay Now')).browse(acquirer_id)
# auto-increment reference with a number suffix if the reference already exists
reference = request.env['payment.transaction'].get_next_reference(reference)
partner_id = user.partner_id.id if user.partner_id.id != request.website.partner_id.id else False
capital_release_request = request.env['account.invoice'].sudo().search(
[('release_capital_request', '=', True),
('number', '=', reference)]
)
if len(capital_release_request) > 0:
partner_id = capital_release_request.partner_id.id
payment_form = acquirer.sudo().render(reference, float(amount), currency.id, values={'return_url': '/website_payment/confirm', 'partner_id': partner_id})[0]
values = {
'reference': reference,
'acquirer': acquirer,
'currency': currency,
'amount': float(amount),
'payment_form': payment_form,
}
return request.website.render('website_payment.pay', values)

65
easy_my_coop_online_payment/i18n/fr.po

@ -1,65 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * easy_my_coop_online_payment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-18 21:56+0000\n"
"PO-Revision-Date: 2017-01-18 23:19+0100\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 1.6.5\n"
"Language: fr\n"
#. module: easy_my_coop_online_payment
#: model:ir.ui.view,arch_db:easy_my_coop_online_payment.SubscriptionOnlinePayment
msgid "<i class=\"fa fa-arrow-circle-right\"/> Pay Now"
msgstr "<i class=\"fa fa-arrow-circle-right\"/> Pay Now"
#. module: easy_my_coop_online_payment
#: selection:subscription.request,payment_type:0
msgid "Deferred"
msgstr "Différé"
#. module: easy_my_coop_online_payment
#: selection:subscription.request,payment_type:0
msgid "Online"
msgstr "En ligne"
#. module: easy_my_coop_online_payment
#: code:addons/easy_my_coop_online_payment/controllers/main.py:86
#: model:ir.ui.view,arch_db:easy_my_coop_online_payment.SubscriptionOnlinePayment
#, python-format
msgid "Pay Now"
msgstr "Payer Maintenant"
#. module: easy_my_coop_online_payment
#: model:ir.model,name:easy_my_coop_online_payment.model_payment_transaction
msgid "Payment Transaction"
msgstr "Transaction"
#. module: easy_my_coop_online_payment
#: model:ir.model.fields,field_description:easy_my_coop_online_payment.field_subscription_request_payment_type
msgid "Payment Type"
msgstr "Type de paiement"
#. module: easy_my_coop_online_payment
#: model:ir.ui.view,arch_db:easy_my_coop_online_payment.subscription_payment_type
msgid "Payment type"
msgstr "Type de paiement"
#. module: easy_my_coop_online_payment
#: model:ir.model.fields,field_description:easy_my_coop_online_payment.field_payment_transaction_release_capital_request
msgid "Release Capital request"
msgstr "Demande de libération de capital"
#. module: easy_my_coop_online_payment
#: model:ir.model,name:easy_my_coop_online_payment.model_subscription_request
msgid "Subscription Request"
msgstr "Demande de souscription"

2
easy_my_coop_online_payment/models/__init__.py

@ -1,2 +0,0 @@
from . import payment_transaction
from . import coop

26
easy_my_coop_online_payment/models/coop.py

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
from openerp import fields, models
class SubscriptionRequest(models.Model):
_inherit = 'subscription.request'
payment_type = fields.Selection([('online', 'Online'),
('deferred', 'Deferred')],
string='Payment Type',
default="deferred")
def send_capital_release_request(self, inv):
if self.payment_type == 'deferred':
super(SubscriptionRequest, self).send_capital_release_request(inv)
return True
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
def post_process_confirm_paid(self, effective_date):
if self.subscription_request.payment_type == 'deferred':
self.set_cooperator_effective(effective_date)
return True

47
easy_my_coop_online_payment/models/payment_transaction.py

@ -1,47 +0,0 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import logging
from openerp import api, fields, models
_logger = logging.getLogger(__name__)
class PaymentTransaction(models.Model):
_inherit = 'payment.transaction'
release_capital_request = fields.Many2one('account.invoice',
string="Release Capital request")
@api.model
def process_online_payment_reception(self, tx):
release_capital_request = tx.release_capital_request
release_capital_request.subscription_request[0].state = 'paid'
effective_date = datetime.now().strftime("%d/%m/%Y")
release_capital_request.sudo().set_cooperator_effective(effective_date)
return True
@api.v7
def _paypal_form_validate(self, cr, uid, tx, data, context=None):
status = data.get('payment_status')
res = {
'acquirer_reference': data.get('txn_id'),
'paypal_txn_type': data.get('payment_type'),
}
if status in ['Completed', 'Processed']:
_logger.info('Validated Paypal payment for tx %s: set as done' % (tx.reference))
res.update(state='done', date_validate=fields.Datetime.now())
result = tx.write(res)
self.process_online_payment_reception(cr, uid, tx)
return result
elif status in ['Pending', 'Expired']:
_logger.info('Received notification for Paypal payment %s: set as pending' % (tx.reference))
res.update(state='pending', state_message=data.get('pending_reason', ''))
return tx.write(res)
else:
error = 'Received unrecognized status for Paypal payment %s: %s, set as error' % (tx.reference, status)
_logger.info(error)
res.update(state='error', state_message=error)
return tx.write(res)

25
easy_my_coop_online_payment/views/online_payment_template.xml

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="subscription_payment_type" inherit_id="easy_my_coop.becomecooperator" name="Removing fields">
<xpath expr="//div[@name='share_div']" position="after">
<div t-attf-class="form-group #{error and 'payment_type' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="company_type">Payment type</label>
<select name="payment_type" class="col-md-7 col-sm-8 form-control" required="True" style="width:54%;margin-left:15px">
<option value=""></option>
<t t-foreach="payment_types or []" t-as="pay_type">
<option t-att-value="pay_type[0]" t-att-selected="pay_type[0] == payment_type"><t t-esc="pay_type[1]"/></option>
</t>
</select>
</div>
</xpath>
</template>
<template id="easy_my_coop_online_payment.SubscriptionOnlinePayment" name="Subscription Online Payment" page="True">
<a t-if="invoice.state == 'open'" t-attf-href="/website_payment/pay?reference=#{invoice.number}&amp;amount=#{invoice.residual}&amp;currency_id=#{invoice.currency_id.id}&amp;acquirer_id=#{acquirer_id}&amp;country_id=#{invoice.partner_id.country_id.id}" alt="Pay Now" class="btn btn-xs btn-primary"><i class="fa fa-arrow-circle-right"/> Pay Now</a>
</template>
</data>
</odoo>

28
easy_my_coop_online_payment/views/subscription_request_view.xml

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="online_payment_subreq__tree" model="ir.ui.view">
<field name="name">subscription.request.tree</field>
<field name="model">subscription.request</field>
<field name="inherit_id" ref="easy_my_coop.subscription_request_tree"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="payment_type"/>
</field>
</field>
</record>
<record id="online_payment_subreq_form" model="ir.ui.view">
<field name="name">subscription.request.tree</field>
<field name="model">subscription.request</field>
<field name="inherit_id" ref="easy_my_coop.subscription_request_form"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="payment_type"/>
</field>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save