[IMP] payment: Supported payment options
- Added the ability to specify which payment option each payment acquirer supports and,
displays those payment option on e-commerce footer.
This commit is contained in:
@@ -150,6 +150,8 @@ class PaymentAcquirer(models.Model):
|
||||
"resized as a 64x64px image, with aspect ratio preserved. "
|
||||
"Use this field anywhere a small image is required.")
|
||||
|
||||
payment_option_ids = fields.Many2many('payment.option', string='Supported Payment Option')
|
||||
|
||||
def _search_is_tokenized(self, operator, value):
|
||||
tokenized = self._get_feature_support()['tokenize']
|
||||
if (operator, value) in [('=', True), ('!=', False)]:
|
||||
@@ -394,6 +396,35 @@ class PaymentAcquirer(models.Model):
|
||||
'context': context,
|
||||
}
|
||||
|
||||
class PaymentOption(models.Model):
|
||||
_name = 'payment.option'
|
||||
_description = 'Payment Option'
|
||||
|
||||
name = fields.Char(string='Name')
|
||||
acquirer_ids = fields.Many2many('payment.acquirer', string="Acquirers", help="List of Acquirers supporting this payment option.")
|
||||
image = fields.Binary(
|
||||
"Image", attachment=True,
|
||||
help="This field holds the image used for this payment option, limited to 1024x1024px")
|
||||
image_medium = fields.Binary(
|
||||
"Medium-sized image", attachment=True,
|
||||
help="Medium-sized image of this payment option. It is automatically "
|
||||
"resized as a 128x128px image, with aspect ratio preserved. "
|
||||
"Use this field in form views or some kanban views.")
|
||||
image_small = fields.Binary(
|
||||
"Small-sized image", attachment=True,
|
||||
help="Small-sized image of this payment option. It is automatically "
|
||||
"resized as a 64x64px image, with aspect ratio preserved. "
|
||||
"Use this field anywhere a small image is required.")
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
image_resize_images(vals)
|
||||
return super(PaymentOption, self).create(vals)
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
image_resize_images(vals)
|
||||
return super(PaymentOption, self).write(vals)
|
||||
|
||||
class PaymentTransaction(models.Model):
|
||||
""" Transaction Model. Each specific acquirer can extend the model by adding
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<field name="registration_view_template_id" groups="base.group_no_one"/>
|
||||
<field name="payment_option_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
@@ -376,5 +377,44 @@
|
||||
parent='root_payment_menu'
|
||||
groups='base.group_no_one'/>
|
||||
|
||||
<!-- Payment options -->
|
||||
<record model="ir.ui.view" id="payment_option_form_view">
|
||||
<field name="name">payment.option.form</field>
|
||||
<field name="model">payment.option</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Payment Option">
|
||||
<sheet>
|
||||
<field name="image" widget="image" class="oe_avatar" options='{"preview_image": "image_medium"}'/>
|
||||
<div class="oe_title">
|
||||
<h1><field name="name" placeholder="Name"/></h1>
|
||||
</div>
|
||||
<group group="base.group_no_one">
|
||||
<notebook>
|
||||
<page string="Acquirers list">
|
||||
<field nolabel="1" name="acquirer_ids"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_payment_option" model="ir.actions.act_window">
|
||||
<field name="name">Payment Options</field>
|
||||
<field name="res_model">payment.option</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="help" type="html">
|
||||
<p class="oe_view_nocontent_create">
|
||||
Click to create a payment acquirer.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
action="action_payment_option"
|
||||
id="payment_option_menu"
|
||||
parent="root_payment_menu"/>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -8,5 +8,8 @@ class Website(models.Model):
|
||||
_inherit = "website"
|
||||
|
||||
@api.model
|
||||
def payment_acquirers(self):
|
||||
return list(self.env['payment.acquirer'].sudo().search([('website_published', '=', True)]))
|
||||
def payment_options(self):
|
||||
""" This function returns the list of payment options which are supported by payment acquirers that are published
|
||||
"""
|
||||
options = self.env['payment.option'].sudo().search([('acquirer_ids', '!=', False)])
|
||||
return [opt for opt in options if any(acq.website_published for acq in opt.acquirer_ids)]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="header_footer_custom_payment" inherit_id="website.footer_default" customize_show="True" active="False" name="Payment Methods">
|
||||
<template id="header_footer_custom_payment" inherit_id="website.footer_default" customize_show="True" active="False" name="Payment Options">
|
||||
<xpath expr="//div[@id='info']" position="inside">
|
||||
<h4 class="payment_method_title">Payment Methods</h4>
|
||||
<h4 class="payment_method_title">Payment Options</h4>
|
||||
<ul class="payment_method_list list-inline">
|
||||
<t t-foreach="request.website.payment_acquirers()" t-as="acquirer">
|
||||
<t t-foreach="request.website.payment_options()" t-as="option">
|
||||
<li>
|
||||
<span t-field="acquirer.image_small" t-options='{"widget": "image", "alt-field": "name"}' />
|
||||
<span t-field="option.image_small" t-options='{"widget": "image", "alt-field": "name"}' />
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user