From f8aa0da5eabc02b6e8aaee040ce37436303606fc Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Fri, 19 Jul 2024 22:19:58 +0200 Subject: [PATCH] [ADD] product_category_acquirer module --- product_category_acquirer/__init__.py | 2 + product_category_acquirer/__manifest__.py | 51 +++++++++++++++++++ product_category_acquirer/i18n/fr.po | 37 ++++++++++++++ product_category_acquirer/models/__init__.py | 3 ++ .../models/payment_provider.py | 41 +++++++++++++++ .../models/product_category.py | 17 +++++++ .../views/payment_provider.xml | 15 ++++++ .../views/product_category.xml | 18 +++++++ 8 files changed, 184 insertions(+) create mode 100644 product_category_acquirer/__init__.py create mode 100644 product_category_acquirer/__manifest__.py create mode 100644 product_category_acquirer/i18n/fr.po create mode 100644 product_category_acquirer/models/__init__.py create mode 100644 product_category_acquirer/models/payment_provider.py create mode 100644 product_category_acquirer/models/product_category.py create mode 100644 product_category_acquirer/views/payment_provider.xml create mode 100644 product_category_acquirer/views/product_category.xml diff --git a/product_category_acquirer/__init__.py b/product_category_acquirer/__init__.py new file mode 100644 index 0000000..a0fdc10 --- /dev/null +++ b/product_category_acquirer/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/product_category_acquirer/__manifest__.py b/product_category_acquirer/__manifest__.py new file mode 100644 index 0000000..e919a3c --- /dev/null +++ b/product_category_acquirer/__manifest__.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +{ + "name": "Payment acquirer per product category", + "version": "1.0.0", + "summary": "Forbidden acquirers on product categories", + "description": """ +This module allows you to set fobidden acquirers on prduct categories. + """, + "author": "RemiFr82", + "contributors": "", + "maintainer": "RemiFr82", + "website": "https://remifr82.me", + "license": "LGPL-3", + "category": "Website", + # "price": 0, + # "currency": "EUR", + "application": False, + "installable": True, + "auto_install": False, + # "pre_init_hook": "", + # "post_init_hook": "", + # "uninstall_hook": "", + # "excludes": [], + # "external_dependencies": [], + "depends": [ + "website_sale", + ], + "data": [ + # Base data + # "data/ir_model.xml", + # Security + # 'security/res_groups.xml', + # 'security/ir.model.access.csv', + # 'security/ir_rule.xml', + # Views + "views/payment_provider.xml", + "views/product_category.xml", + # Wizards + # 'wizards/transient_model.xml', + # Reports + # 'reports/report_templates.xml', + # 'reports/sql_view.xml', + ], + "assets": {}, + "css": [], + "images": [], + "js": [], + "test": [], + "demo": [], +} diff --git a/product_category_acquirer/i18n/fr.po b/product_category_acquirer/i18n/fr.po new file mode 100644 index 0000000..46c0e0c --- /dev/null +++ b/product_category_acquirer/i18n/fr.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_category_acquirer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0-20230613\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-19 20:17+0000\n" +"PO-Revision-Date: 2024-07-19 20:17+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: product_category_acquirer +#: model:ir.model.fields,field_description:product_category_acquirer.field_payment_provider__forbidden_category_ids +msgid "Forbidden categories" +msgstr "Catégories interdisant ce fournisseur" + +#. module: product_category_acquirer +#: model:ir.model.fields,field_description:product_category_acquirer.field_product_category__forbidden_provider_ids +#: model_terms:ir.ui.view,arch_db:product_category_acquirer.view_category_property_form_inherit_account +msgid "Forbidden providers" +msgstr "Fournisseurs de paiement interdits" + +#. module: product_category_acquirer +#: model:ir.model,name:product_category_acquirer.model_payment_provider +msgid "Payment Provider" +msgstr "Fournisseur de paiement" + +#. module: product_category_acquirer +#: model:ir.model,name:product_category_acquirer.model_product_category +msgid "Product Category" +msgstr "Catégorie de produit" diff --git a/product_category_acquirer/models/__init__.py b/product_category_acquirer/models/__init__.py new file mode 100644 index 0000000..28e0bd7 --- /dev/null +++ b/product_category_acquirer/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import payment_provider +from . import product_category diff --git a/product_category_acquirer/models/payment_provider.py b/product_category_acquirer/models/payment_provider.py new file mode 100644 index 0000000..515fda7 --- /dev/null +++ b/product_category_acquirer/models/payment_provider.py @@ -0,0 +1,41 @@ +import logging +from odoo import models, fields, api, _ + +_logger = logging.getLogger(__name__) + + +class PaymentProvider(models.Model): + _inherit = "payment.provider" + + forbidden_category_ids = fields.Many2many( + comodel_name="product.category", + column1="provider_id", + column2="category_id", + relation="forbidden_category_provider_rel", + string="Forbidden categories", + ) + + @api.model + def _get_compatible_providers( + self, *args, sale_order_id=None, website_id=None, **kwargs + ): + """Override of payment to exclude forbidden providers set ont order products categories. + + :param int sale_order_id: The sale order to be paid, if any, as a `sale.order` id + :param int website_id: The provided website, as a `website` id + :return: The compatible providers + :rtype: recordset of `payment.provider` + """ + compatible_providers = super()._get_compatible_providers( + *args, sale_order_id=sale_order_id, website_id=website_id, **kwargs + ) + + # Get order if set int the args + order = self.env["sale.order"].browse(sale_order_id).exists() + # If order exists, remove forbidden providers from the list + if order: + compatible_providers -= order.order_line.mapped( + "product_id.categ_id.forbidden_provider_ids" + ) + + return compatible_providers diff --git a/product_category_acquirer/models/product_category.py b/product_category_acquirer/models/product_category.py new file mode 100644 index 0000000..1b40c05 --- /dev/null +++ b/product_category_acquirer/models/product_category.py @@ -0,0 +1,17 @@ +import logging +from odoo import models, fields, api, _ + +_logger = logging.getLogger(__name__) + + +class ProductCategory(models.Model): + _inherit = "product.category" + + forbidden_provider_ids = fields.Many2many( + comodel_name="payment.provider", + column1="category_id", + column2="provider_id", + relation="forbidden_category_provider_rel", + string="Forbidden providers", + domain=[("state", "in", ["enabled", "test"])], + ) diff --git a/product_category_acquirer/views/payment_provider.xml b/product_category_acquirer/views/payment_provider.xml new file mode 100644 index 0000000..533cef6 --- /dev/null +++ b/product_category_acquirer/views/payment_provider.xml @@ -0,0 +1,15 @@ + + + + + payment.provider.view.form.inherit + payment.provider + + + + + + + + + \ No newline at end of file diff --git a/product_category_acquirer/views/product_category.xml b/product_category_acquirer/views/product_category.xml new file mode 100644 index 0000000..681555a --- /dev/null +++ b/product_category_acquirer/views/product_category.xml @@ -0,0 +1,18 @@ + + + + + product.category.view.form.inherit + product.category + + + + + + + + + + + \ No newline at end of file