RemiFr82
4 months ago
8 changed files with 184 additions and 0 deletions
-
2product_category_acquirer/__init__.py
-
51product_category_acquirer/__manifest__.py
-
37product_category_acquirer/i18n/fr.po
-
3product_category_acquirer/models/__init__.py
-
41product_category_acquirer/models/payment_provider.py
-
17product_category_acquirer/models/product_category.py
-
15product_category_acquirer/views/payment_provider.xml
-
18product_category_acquirer/views/product_category.xml
@ -0,0 +1,2 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from . import models |
@ -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": [], |
|||
} |
@ -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" |
@ -0,0 +1,3 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from . import payment_provider |
|||
from . import product_category |
@ -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 |
@ -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"])], |
|||
) |
@ -0,0 +1,15 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="view_payment_provider_form_inherit_account" model="ir.ui.view"> |
|||
<field name="name">payment.provider.view.form.inherit</field> |
|||
<field name="model">payment.provider</field> |
|||
<field name="inherit_id" ref="payment.payment_provider_form" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="available_country_ids" position="after"> |
|||
<field name="forbidden_category_ids" widget="many2many_tags" options="{'no_create': 1}" /> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
@ -0,0 +1,18 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="view_category_property_form_inherit_account" model="ir.ui.view"> |
|||
<field name="name">product.category.view.form.inherit</field> |
|||
<field name="model">product.category</field> |
|||
<field name="inherit_id" ref="account.view_category_property_form" /> |
|||
<field name="arch" type="xml"> |
|||
<group name="account_property" position="inside"> |
|||
<group name="providers" string="Forbidden providers"> |
|||
<field name="forbidden_provider_ids" nolabel="1" colspan="2" widget="many2many_tags" |
|||
options="{'no_create': 1}" /> |
|||
</group> |
|||
</group> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue