diff options
| author | tbe-odoo <tbe@odoo.com> | 2017-08-07 14:35:14 +0200 |
|---|---|---|
| committer | tbe-odoo <tbe@odoo.com> | 2017-08-29 17:11:23 +0200 |
| commit | 64ae5e2bc32eb99b6a6b470a9aed3803a8ecda0f (patch) | |
| tree | 6ef480cdd807c81cb750fce7cee5c2ae1e3aa3c0 | |
| parent | 5fb121e77384a158d8cb1f7ad6a078e7c54df8ac (diff) | |
[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.
| -rw-r--r-- | addons/payment/models/payment_acquirer.py | 31 | ||||
| -rw-r--r-- | addons/payment/views/payment_views.xml | 40 | ||||
| -rw-r--r-- | addons/website_payment/models/website.py | 7 | ||||
| -rw-r--r-- | addons/website_payment/views/website_payment_templates.xml | 8 |
4 files changed, 80 insertions, 6 deletions
diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 2e36d891344..325f58c3aff 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -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 diff --git a/addons/payment/views/payment_views.xml b/addons/payment/views/payment_views.xml index c626657bc42..6b67db74ec6 100644 --- a/addons/payment/views/payment_views.xml +++ b/addons/payment/views/payment_views.xml @@ -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> diff --git a/addons/website_payment/models/website.py b/addons/website_payment/models/website.py index 540277d79c2..0bb533cd1c9 100644 --- a/addons/website_payment/models/website.py +++ b/addons/website_payment/models/website.py @@ -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)] diff --git a/addons/website_payment/views/website_payment_templates.xml b/addons/website_payment/views/website_payment_templates.xml index c49937bb83f..95d5d44cbf2 100644 --- a/addons/website_payment/views/website_payment_templates.xml +++ b/addons/website_payment/views/website_payment_templates.xml @@ -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> |
