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 @@ + @@ -376,5 +377,44 @@ parent='root_payment_menu' groups='base.group_no_one'/> + + + payment.option.form + payment.option + +
+ + +
+

+
+ + + + + + + +
+
+
+
+ + + Payment Options + payment.option + form + tree,form + +

+ Click to create a payment acquirer. +

+
+
+ + 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 @@ -