[ADD]:Added Upstream patch for payment

This commit is contained in:
sheetalPatil 2018-07-09 16:50:36 +05:30
parent 21211564c3
commit 3ee4085418
7 changed files with 102 additions and 10 deletions

View File

@ -89,6 +89,7 @@ class WebsitePayment(http.Controller):
'amount': float(amount),
'currency_id': currency_id,
'partner_id': partner_id,
'type': 'form_save' if acquirer.save_token != 'none' and partner_id else 'form',
}
tx = request.env['payment.transaction'].sudo().create(values)
@ -117,7 +118,8 @@ class WebsitePayment(http.Controller):
'amount': float(amount),
'currency_id': int(currency_id),
'partner_id': partner_id,
'payment_token_id': pm_id
'payment_token_id': pm_id,
'type': 'form_save' if token.acquirer_id.save_token != 'none' and partner_id else 'form',
}
tx = request.env['payment.transaction'].sudo().create(values)

View File

@ -3,8 +3,7 @@
<template id="default_acquirer_button">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="csrf_token"
t-att-value="request.csrf_token()"/>
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<t t-if="return_url">
<input type="hidden" name="return_url" t-att-value="return_url"/>
</t>
@ -148,8 +147,7 @@
</field>
<field name="description" type="html">
<p>
Provide instructions to customers so that they can pay their
orders manually.
Provide instructions to customers so that they can pay their orders manually.
</p>
</field>
</record>

View File

@ -3,3 +3,4 @@
from . import payment_acquirer
from . import res_partner
from . import account_payment
from . import chart_template

View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from flectra import api, fields, models, _
class WizardMultiChartsAccounts(models.TransientModel):
_inherit = 'wizard.multi.charts.accounts'
@api.multi
def _create_bank_journals_from_o2m(self, company, acc_template_ref):
res = super(WizardMultiChartsAccounts, self)._create_bank_journals_from_o2m(company, acc_template_ref)
# Try to generate the missing journals
return res + self.env['payment.acquirer']._create_missing_journal_for_acquirers(company=company)

View File

@ -8,6 +8,7 @@ from flectra import api, exceptions, fields, models, _
from flectra.tools import consteq, float_round, image_resize_images, image_resize_image, ustr
from flectra.addons.base.module import module
from flectra.exceptions import ValidationError
from flectra import api, SUPERUSER_ID
_logger = logging.getLogger(__name__)
@ -20,6 +21,11 @@ def _partner_split_name(partner_name):
return [' '.join(partner_name.split()[:-1]), ' '.join(partner_name.split()[-1:])]
def create_missing_journal_for_acquirers(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env['payment.acquirer']._create_missing_journal_for_acquirers()
class PaymentAcquirer(models.Model):
""" Acquirer Model. Each specific acquirer can extend the model by adding
its own fields, using the acquirer_name as a prefix for the new fields.
@ -51,6 +57,9 @@ class PaymentAcquirer(models.Model):
_description = 'Payment Acquirer'
_order = 'website_published desc, sequence, name'
def _get_default_view_template_id(self):
return self.env.ref('payment.default_acquirer_button', raise_if_not_found=False)
name = fields.Char('Name', required=True, translate=True)
description = fields.Html('Description')
sequence = fields.Integer('Sequence', default=10, help="Determine the display order")
@ -196,6 +205,58 @@ class PaymentAcquirer(models.Model):
"""
return dict(authorize=[], tokenize=[], fees=[])
@api.multi
def _prepare_account_journal_vals(self):
'''Prepare the values to create the acquirer's journal.
:return: a dictionary to create a account.journal record.
'''
self.ensure_one()
account_vals = self.env['account.journal']._prepare_liquidity_account(
self.name, self.company_id, None, 'bank')
account_vals['user_type_id'] = self.env.ref('account.data_account_type_current_assets').id
account_vals['reconcile'] = True
account = self.env['account.account'].create(account_vals)
return {
'name': self.name,
'code': self.name.upper(),
'sequence': 999,
'type': 'bank',
'company_id': self.company_id.id,
'default_debit_account_id': account.id,
'default_credit_account_id': account.id,
# Show the journal on dashboard if the acquirer is published on the website.
'show_on_dashboard': self.website_published,
# Don't show payment methods in the backend.
'inbound_payment_method_ids': [],
'outbound_payment_method_ids': [],
}
@api.model
def _create_missing_journal_for_acquirers(self, company=None):
'''Create the journal for active acquirers.
We want one journal per acquirer. However, we can't create them during the 'create' of the payment.acquirer
because every acquirers are defined on the 'payment' module but is active only when installing their own module
(e.g. payment_paypal for Paypal). We can't do that in such modules because we have no guarantee the chart template
is already installed.
'''
# Search for installed acquirers modules.
# If this method is triggered by a post_init_hook, the module is 'to install'.
# If the trigger comes from the chart template wizard, the modules are already installed.
acquirer_modules = self.env['ir.module.module'].search(
[('name', 'like', 'payment_%'), ('state', 'in', ('to install', 'installed'))])
acquirer_names = [a.name.split('_')[1] for a in acquirer_modules]
# Search for acquirers having no journal
company = company or self.env.user.company_id
acquirers = self.env['payment.acquirer'].search(
[('provider', 'in', acquirer_names), ('journal_id', '=', False), ('company_id', '=', company.id)])
journals = self.env['account.journal']
for acquirer in acquirers.filtered(lambda l: not l.journal_id and l.company_id.chart_template_id):
acquirer.journal_id = self.env['account.journal'].create(acquirer._prepare_account_journal_vals())
journals += acquirer.journal_id
return journals
@api.model
def create(self, vals):
image_resize_images(vals)
@ -208,7 +269,13 @@ class PaymentAcquirer(models.Model):
@api.multi
def toggle_website_published(self):
self.write({'website_published': not self.website_published})
''' When clicking on the website publish toggle button, the website_published is reversed and
the acquirer journal is set or not in favorite on the dashboard.
'''
self.ensure_one()
self.website_published = not self.website_published
if self.journal_id:
self.journal_id.show_on_dashboard = self.website_published
return True
@api.multi
@ -617,6 +684,10 @@ class PaymentTransaction(models.Model):
@api.model
def get_next_reference(self, reference):
return self._get_next_reference(reference)
@api.model
def _get_next_reference(self, reference, acquirer=None):
ref_suffix = 1
init_ref = reference
while self.env['payment.transaction'].sudo().search_count([('reference', '=', reference)]):

View File

@ -414,8 +414,14 @@ flectra.define('payment.payment_form', function (require) {
},
displayError: function (title, message) {
var $checkedRadio = this.$('input[type="radio"]:checked'),
acquirerID = this.getAcquirerIdFromRadio($checkedRadio[0]),
acquirerID = this.getAcquirerIdFromRadio($checkedRadio[0]);
var $acquirerForm;
if (this.isNewPaymentRadio($checkedRadio[0])) {
$acquirerForm = this.$('#o_payment_add_token_acq_' + acquirerID);
}
else if (this.isFormPaymentRadio($checkedRadio[0])) {
$acquirerForm = this.$('#o_payment_form_acq_' + acquirerID);
}
if ($checkedRadio.length === 0) {
return new Dialog(null, {

View File

@ -71,7 +71,7 @@
</page>
<page string="Messages">
<group>
<field name="pre_msg"/>
<field name="pre_msg" invisible="1"/>
<field name="post_msg"/>
<field name="pending_msg"/>
<field name="done_msg"/>
@ -81,7 +81,7 @@
</page>
<page string="Configuration">
<group name="acquirer_config">
<field name="journal_id" context="{'default_type': 'bank'}" required="1"/>
<field name="journal_id" context="{'default_type': 'bank'}"/>
<field name="capture_manually" attrs="{'invisible': [('authorize_implemented', '=', False)]}"/>
<field name="save_token" widget="radio" attrs="{'invisible': ['|', ('token_implemented', '=', False), ('payment_flow', '=', 's2s')]}"/>
<field name="fees_active" attrs="{'invisible': [('fees_implemented', '=', False)]}"/>
@ -113,7 +113,7 @@
</div>
<field name="registration_view_template_id" groups="base.group_no_one"/>
<field name="payment_icon_ids" widget="many2many_tags"/>
<field name="payment_flow" widget="radio"/>
<field name="payment_flow" widget="radio" attrs="{'invisible': [('token_implemented', '=', False)]}"/>
</group>
</page>
</notebook>