diff --git a/eslint.config.cjs b/eslint.config.cjs index dd0cbe0aef..b9138c305c 100644 --- a/eslint.config.cjs +++ b/eslint.config.cjs @@ -194,7 +194,7 @@ const config = [{ }, }, { - files: ["**/*.esm.js", "**/*test.js"], + files: ["**/*.js"], languageOptions: { ecmaVersion: 2024, diff --git a/pos_financial_risk/README.rst b/pos_financial_risk/README.rst new file mode 100644 index 0000000000..22da5e3b85 --- /dev/null +++ b/pos_financial_risk/README.rst @@ -0,0 +1,129 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================ +Point of Sale Financial Risk +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6849547ab12c33aedfe65b29213299ed41bd7383e89a935d32f6d337c685d6c5 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/19.0/pos_financial_risk + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-19-0/pos-19-0-pos_financial_risk + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Extends Partner Financial Risk to manage POS orders. + +If POS order exceeds partner credit limit POS only non restricted +payment methods will remain available. + +Payment method availability can be specified both system wide and for a +particular POS. + +If no restrictions are specified for a POS global ones will be applied. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To restrict a payment method for all POS: + +Go to **Post of Sale**/**Configuration**/**Payment Methods** and select +a payment method. + +Enable **Credit Limit Restricted** to restrict usage of this payment +method if credit limit threshold is overrun. + +To specify restriction for a selected POS: + +Go to **Settings**/**Point of Sale** select a POS and scroll down to the +**Payment** section. + +Add payment methods to the **Credit Limit Restricted** field. + +Usage +===== + +To use this module, you need to: + +Go to Customers > Financial Risk + +Set limits and choose options to compute in credit limit. + +Go to POS -> Open POS and create a new order. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Cetmix + +Contributors +------------ + +- Cetmix +- Maksim Shurupov + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-geomer198| image:: https://github.com/geomer198.png?size=40px + :target: https://github.com/geomer198 + :alt: geomer198 +.. |maintainer-CetmixGitDrone| image:: https://github.com/CetmixGitDrone.png?size=40px + :target: https://github.com/CetmixGitDrone + :alt: CetmixGitDrone + +Current `maintainers `__: + +|maintainer-geomer198| |maintainer-CetmixGitDrone| + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_financial_risk/__init__.py b/pos_financial_risk/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_financial_risk/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_financial_risk/__manifest__.py b/pos_financial_risk/__manifest__.py new file mode 100644 index 0000000000..1827e87f06 --- /dev/null +++ b/pos_financial_risk/__manifest__.py @@ -0,0 +1,21 @@ +{ + "name": "Point of Sale Financial Risk", + "version": "19.0.1.0.1", + "category": "Sales/Point of Sale", + "summary": "Point of Sale Fonancial Risk", + "depends": ["point_of_sale", "account_financial_risk"], + "website": "https://github.com/OCA/pos", + "author": "Cetmix,Odoo Community Association (OCA)", + "maintainers": ["geomer198", "CetmixGitDrone"], + "data": [ + "views/pos_payment_method_views.xml", + "views/res_config_settings_views.xml", + ], + "installable": True, + "assets": { + "point_of_sale._assets_pos": [ + "pos_financial_risk/static/src/**/*", + ], + }, + "license": "AGPL-3", +} diff --git a/pos_financial_risk/i18n/es.po b/pos_financial_risk/i18n/es.po new file mode 100644 index 0000000000..91efe2ae7b --- /dev/null +++ b/pos_financial_risk/i18n/es.po @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_financial_risk +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-08 22:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: pos_financial_risk +#. odoo-javascript +#: code:addons/pos_financial_risk/static/src/xml/PaymentScreen.xml:0 +#, python-format +msgid "(remainder" +msgstr "(resto" + +#. module: pos_financial_risk +#: model_terms:ir.ui.view,arch_db:pos_financial_risk.res_config_settings_view_form +msgid "Credit Limit Restricted" +msgstr "Límite de Crédito Restringido" + +#. module: pos_financial_risk +#. odoo-javascript +#: code:addons/pos_financial_risk/static/src/xml/PaymentScreen.xml:0 +#, python-format +msgid "Blocked due to credit limit reached" +msgstr "Bloqueado por haber alcanzado el límite de crédito" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_res_config_settings +msgid "Config Settings" +msgstr "Ajustes Config" + +#. module: pos_financial_risk +#: model:ir.model.fields,field_description:pos_financial_risk.field_pos_config__payment_credit_limit_restricted_ids +#: model:ir.model.fields,field_description:pos_financial_risk.field_pos_payment_method__credit_limit_restricted +#: model:ir.model.fields,field_description:pos_financial_risk.field_res_config_settings__pos_payment_credit_limit_restricted_ids +msgid "Credit Limit Restricted" +msgstr "Límite de Crédito Restringido" + +#. module: pos_financial_risk +#: model_terms:ir.ui.view,arch_db:pos_financial_risk.res_config_settings_view_form +msgid "Payment methods with credit limit restricted" +msgstr "Métodos de pago con límite de crédito restringido" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Configuración de Punto de Venta" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_payment_method +msgid "Point of Sale Payment Methods" +msgstr "Métodos de Pago en el Punto de Venta" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_session +msgid "Point of Sale Session" +msgstr "Sesión del Punto de Venta" diff --git a/pos_financial_risk/i18n/it.po b/pos_financial_risk/i18n/it.po new file mode 100644 index 0000000000..faf24e577f --- /dev/null +++ b/pos_financial_risk/i18n/it.po @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_financial_risk +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-26 15:34+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: pos_financial_risk +#. odoo-javascript +#: code:addons/pos_financial_risk/static/src/xml/PaymentScreen.xml:0 +#, python-format +msgid "(remainder" +msgstr "(promemoria" + +#. module: pos_financial_risk +#: model_terms:ir.ui.view,arch_db:pos_financial_risk.res_config_settings_view_form +msgid "Credit Limit Restricted" +msgstr "Limite credito ridotto" + +#. module: pos_financial_risk +#. odoo-javascript +#: code:addons/pos_financial_risk/static/src/xml/PaymentScreen.xml:0 +#, python-format +msgid "Blocked due to credit limit reached" +msgstr "Bloccato per limite credito raggiunto" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_res_config_settings +msgid "Config Settings" +msgstr "Impostazioni configurazione" + +#. module: pos_financial_risk +#: model:ir.model.fields,field_description:pos_financial_risk.field_pos_config__payment_credit_limit_restricted_ids +#: model:ir.model.fields,field_description:pos_financial_risk.field_pos_payment_method__credit_limit_restricted +#: model:ir.model.fields,field_description:pos_financial_risk.field_res_config_settings__pos_payment_credit_limit_restricted_ids +msgid "Credit Limit Restricted" +msgstr "Limite credito ridotto" + +#. module: pos_financial_risk +#: model_terms:ir.ui.view,arch_db:pos_financial_risk.res_config_settings_view_form +msgid "Payment methods with credit limit restricted" +msgstr "Metodi di pagamento con limite credito ridotto" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Configurazione punto vendita" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_payment_method +msgid "Point of Sale Payment Methods" +msgstr "Metodi di pagamento punto vendita" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_session +msgid "Point of Sale Session" +msgstr "Sessione punto vendita" diff --git a/pos_financial_risk/i18n/pos_financial_risk.pot b/pos_financial_risk/i18n/pos_financial_risk.pot new file mode 100644 index 0000000000..99d41fb8b3 --- /dev/null +++ b/pos_financial_risk/i18n/pos_financial_risk.pot @@ -0,0 +1,65 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_financial_risk +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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: pos_financial_risk +#. odoo-javascript +#: code:addons/pos_financial_risk/static/src/xml/PaymentScreen.xml:0 +#, python-format +msgid "(remainder" +msgstr "" + +#. module: pos_financial_risk +#: model_terms:ir.ui.view,arch_db:pos_financial_risk.res_config_settings_view_form +msgid "Credit Limit Restricted" +msgstr "" + +#. module: pos_financial_risk +#. odoo-javascript +#: code:addons/pos_financial_risk/static/src/xml/PaymentScreen.xml:0 +#, python-format +msgid "Blocked due to credit limit reached" +msgstr "" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: pos_financial_risk +#: model:ir.model.fields,field_description:pos_financial_risk.field_pos_config__payment_credit_limit_restricted_ids +#: model:ir.model.fields,field_description:pos_financial_risk.field_pos_payment_method__credit_limit_restricted +#: model:ir.model.fields,field_description:pos_financial_risk.field_res_config_settings__pos_payment_credit_limit_restricted_ids +msgid "Credit Limit Restricted" +msgstr "" + +#. module: pos_financial_risk +#: model_terms:ir.ui.view,arch_db:pos_financial_risk.res_config_settings_view_form +msgid "Payment methods with credit limit restricted" +msgstr "" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_config +msgid "Point of Sale Configuration" +msgstr "" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_payment_method +msgid "Point of Sale Payment Methods" +msgstr "" + +#. module: pos_financial_risk +#: model:ir.model,name:pos_financial_risk.model_pos_session +msgid "Point of Sale Session" +msgstr "" diff --git a/pos_financial_risk/models/__init__.py b/pos_financial_risk/models/__init__.py new file mode 100644 index 0000000000..3263adbd64 --- /dev/null +++ b/pos_financial_risk/models/__init__.py @@ -0,0 +1,4 @@ +from . import pos_config +from . import pos_payment_method +from . import pos_session +from . import res_config_settings diff --git a/pos_financial_risk/models/pos_config.py b/pos_financial_risk/models/pos_config.py new file mode 100644 index 0000000000..a06eb278b5 --- /dev/null +++ b/pos_financial_risk/models/pos_config.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class PosConfig(models.Model): + _inherit = "pos.config" + + payment_credit_limit_restricted_ids = fields.Many2many( + comodel_name="pos.payment.method", + relation="pos_config_payment_method_restricted_rel", + column1="config_id", + column2="payment_method_id", + string="Credit Limit Restricted", + ) diff --git a/pos_financial_risk/models/pos_payment_method.py b/pos_financial_risk/models/pos_payment_method.py new file mode 100644 index 0000000000..c99dc313ea --- /dev/null +++ b/pos_financial_risk/models/pos_payment_method.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class PosPaymentMethod(models.Model): + _inherit = "pos.payment.method" + + credit_limit_restricted = fields.Boolean() diff --git a/pos_financial_risk/models/pos_session.py b/pos_financial_risk/models/pos_session.py new file mode 100644 index 0000000000..204b5b38d5 --- /dev/null +++ b/pos_financial_risk/models/pos_session.py @@ -0,0 +1,10 @@ +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _loader_params_pos_payment_method(self): + params = super()._loader_params_pos_payment_method() + params["search_params"]["fields"].append("credit_limit_restricted") + return params diff --git a/pos_financial_risk/models/res_config_settings.py b/pos_financial_risk/models/res_config_settings.py new file mode 100644 index 0000000000..f22aca10f5 --- /dev/null +++ b/pos_financial_risk/models/res_config_settings.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + pos_payment_credit_limit_restricted_ids = fields.Many2many( + related="pos_config_id.payment_credit_limit_restricted_ids", + readonly=False, + ) diff --git a/pos_financial_risk/pyproject.toml b/pos_financial_risk/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/pos_financial_risk/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_financial_risk/readme/CONFIGURE.md b/pos_financial_risk/readme/CONFIGURE.md new file mode 100644 index 0000000000..336cb1d9df --- /dev/null +++ b/pos_financial_risk/readme/CONFIGURE.md @@ -0,0 +1,14 @@ +To restrict a payment method for all POS: + +Go to **Post of Sale**/**Configuration**/**Payment Methods** and select +a payment method. + +Enable **Credit Limit Restricted** to restrict usage of this payment +method if credit limit threshold is overrun. + +To specify restriction for a selected POS: + +Go to **Settings**/**Point of Sale** select a POS and scroll down to the +**Payment** section. + +Add payment methods to the **Credit Limit Restricted** field. diff --git a/pos_financial_risk/readme/CONTRIBUTORS.md b/pos_financial_risk/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..9db3173836 --- /dev/null +++ b/pos_financial_risk/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Cetmix \<\> +- Maksim Shurupov diff --git a/pos_financial_risk/readme/DESCRIPTION.md b/pos_financial_risk/readme/DESCRIPTION.md new file mode 100644 index 0000000000..6bba370e95 --- /dev/null +++ b/pos_financial_risk/readme/DESCRIPTION.md @@ -0,0 +1,9 @@ +Extends Partner Financial Risk to manage POS orders. + +If POS order exceeds partner credit limit POS only non restricted +payment methods will remain available. + +Payment method availability can be specified both system wide and for a +particular POS. + +If no restrictions are specified for a POS global ones will be applied. diff --git a/pos_financial_risk/readme/USAGE.md b/pos_financial_risk/readme/USAGE.md new file mode 100644 index 0000000000..97ba920969 --- /dev/null +++ b/pos_financial_risk/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, you need to: + +Go to Customers \> Financial Risk + +Set limits and choose options to compute in credit limit. + +Go to POS -\> Open POS and create a new order. diff --git a/pos_financial_risk/static/description/icon.png b/pos_financial_risk/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/pos_financial_risk/static/description/icon.png differ diff --git a/pos_financial_risk/static/description/index.html b/pos_financial_risk/static/description/index.html new file mode 100644 index 0000000000..88b19efcac --- /dev/null +++ b/pos_financial_risk/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Point of Sale Financial Risk

+ +

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

Extends Partner Financial Risk to manage POS orders.

+

If POS order exceeds partner credit limit POS only non restricted +payment methods will remain available.

+

Payment method availability can be specified both system wide and for a +particular POS.

+

If no restrictions are specified for a POS global ones will be applied.

+

Table of contents

+ +
+

Configuration

+

To restrict a payment method for all POS:

+

Go to Post of Sale/Configuration/Payment Methods and select +a payment method.

+

Enable Credit Limit Restricted to restrict usage of this payment +method if credit limit threshold is overrun.

+

To specify restriction for a selected POS:

+

Go to Settings/Point of Sale select a POS and scroll down to the +Payment section.

+

Add payment methods to the Credit Limit Restricted field.

+
+
+

Usage

+

To use this module, you need to:

+

Go to Customers > Financial Risk

+

Set limits and choose options to compute in credit limit.

+

Go to POS -> Open POS and create a new order.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Cetmix
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainers:

+

geomer198 CetmixGitDrone

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.js b/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.js new file mode 100644 index 0000000000..bd5609bb3f --- /dev/null +++ b/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.js @@ -0,0 +1,21 @@ +import {PaymentScreen} from "@point_of_sale/app/screens/payment_screen/payment_screen"; +import {patch} from "@web/core/utils/patch"; + +patch(PaymentScreen.prototype, { + setup() { + super.setup(...arguments); + this.pos.updatePaymentMethod(); + }, + + get paymentMethodsUnlock() { + return this.pos.paymentMethodsUnlock; + }, + + get paymentMethodsLock() { + return this.pos.paymentMethodsLock; + }, + + get remainderLimitFormatted() { + return this.env.utils.formatCurrency(this.pos.remainderLimit); + }, +}); diff --git a/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.scss b/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.scss new file mode 100644 index 0000000000..729ada17f6 --- /dev/null +++ b/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.scss @@ -0,0 +1,15 @@ +.pos .button.error_risk { + background: $warning !important; + border-color: $warning !important; + color: black !important; +} + +.payment-red { + background: rgba(255, 0, 0, 0.6); + cursor: not-allowed; +} + +.payment-lock-title { + background-color: gray; + font-size: 1rem; +} diff --git a/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.xml b/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.xml new file mode 100644 index 0000000000..cfb1dc2110 --- /dev/null +++ b/pos_financial_risk/static/src/app/screens/payment_screen/payment_screen.xml @@ -0,0 +1,66 @@ + + + + + paymentMethodsUnlock + + +
+ + Remainder + +
+
+ + +
+
+ Blocked due to credit limit reached +
+ +
+
+ + +
+ +
+
+
+
+
+ + + { + highlight: currentOrder.getPartner(), + error_risk: currentOrder.getPartner() && pos.riskLimit > 0 && pos.remainderLimit <= 0 } + + + +
diff --git a/pos_financial_risk/static/src/app/services/pos_store.js b/pos_financial_risk/static/src/app/services/pos_store.js new file mode 100644 index 0000000000..3c9418c8ea --- /dev/null +++ b/pos_financial_risk/static/src/app/services/pos_store.js @@ -0,0 +1,69 @@ +import {PosStore} from "@point_of_sale/app/services/pos_store"; +import {patch} from "@web/core/utils/patch"; + +patch(PosStore.prototype, { + setup() { + super.setup(...arguments); + this.paymentMethodsFromConfigBase = this.config.payment_method_ids + .slice() + .sort((a, b) => a.sequence - b.sequence); + + this.paymentMethodsUnlock = []; + this.paymentMethodsLock = []; + this.remainderLimit = 0.0; + this.riskLimit = 0.0; + this.updatePaymentMethod(); + }, + + async selectPartner() { + await super.selectPartner(...arguments); + await this.updatePaymentMethod(); + }, + + updatePaymentMethod() { + const order = this.getOrder(); + const partner = order?.getPartner(); + if (!partner) { + this.paymentMethodsUnlock = this.paymentMethodsFromConfigBase; + this.paymentMethodsLock = []; + return; + } + const paymentCreditLimit = this.config.payment_credit_limit_restricted_ids; + const orderTotal = order.getTotalWithTax() + order.getRoundingApplied(); + this.data + .read( + "res.partner", + [partner.id], + ["risk_remaining_value", "risk_exception", "credit_limit"] + ) + .then((partnerFields) => { + const riskRemainingValue = partnerFields[0].risk_remaining_value; + const riskException = partnerFields[0].risk_exception; + const creditLimit = partnerFields[0].credit_limit; + + if ( + riskException || + (creditLimit > 0 && orderTotal > riskRemainingValue) + ) { + if (paymentCreditLimit.length > 0) { + this.paymentMethodsUnlock = + this.paymentMethodsFromConfigBase.filter( + (method) => !paymentCreditLimit.includes(method) + ); + } else { + this.paymentMethodsUnlock = + this.paymentMethodsFromConfigBase.filter( + (method) => !method.credit_limit_restricted + ); + } + } else { + this.paymentMethodsUnlock = this.paymentMethodsFromConfigBase; + } + this.riskLimit = riskRemainingValue; + this.remainderLimit = (riskRemainingValue - orderTotal).toFixed(2); + this.paymentMethodsLock = this.paymentMethodsFromConfigBase.filter( + (method) => !this.paymentMethodsUnlock.includes(method) + ); + }); + }, +}); diff --git a/pos_financial_risk/views/pos_payment_method_views.xml b/pos_financial_risk/views/pos_payment_method_views.xml new file mode 100644 index 0000000000..d3906410cf --- /dev/null +++ b/pos_financial_risk/views/pos_payment_method_views.xml @@ -0,0 +1,24 @@ + + + + pos.payment.method.inherit.form + pos.payment.method + + + + + + + + + + pos.payment.method.inherit.tree + pos.payment.method + + + + + + + + diff --git a/pos_financial_risk/views/res_config_settings_views.xml b/pos_financial_risk/views/res_config_settings_views.xml new file mode 100644 index 0000000000..58a8f4c881 --- /dev/null +++ b/pos_financial_risk/views/res_config_settings_views.xml @@ -0,0 +1,28 @@ + + + + res.config.settings.view.form.inherit.pos_financial_risk + res.config.settings + + + + + + + + + +