diff --git a/pos_financial_risk/README.rst b/pos_financial_risk/README.rst new file mode 100644 index 0000000000..7eba509b08 --- /dev/null +++ b/pos_financial_risk/README.rst @@ -0,0 +1,122 @@ +============================ +Point of Sale Financial Risk +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:fb8495a13cf20e3ad4d1b279ec17e2e541168b09533d33a7870480db35107179 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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/16.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-16-0/pos-16-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=16.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..a3e7038123 --- /dev/null +++ b/pos_financial_risk/__manifest__.py @@ -0,0 +1,23 @@ +{ + "name": "Point of Sale Financial Risk", + "version": "16.0.1.0.0", + "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_financial_risk/static/src/js/*.js", + "pos_financial_risk/static/src/scss/*.scss", + "pos_financial_risk/static/src/xml/*.xml", + ], + }, + "license": "AGPL-3", +} 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..b2c43181a3 --- /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(PosSession, self)._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/readme/CONFIGURE.rst b/pos_financial_risk/readme/CONFIGURE.rst new file mode 100644 index 0000000000..9b99712e94 --- /dev/null +++ b/pos_financial_risk/readme/CONFIGURE.rst @@ -0,0 +1,13 @@ +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.rst b/pos_financial_risk/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..2475e6bb07 --- /dev/null +++ b/pos_financial_risk/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Cetmix +* Maksim Shurupov diff --git a/pos_financial_risk/readme/DESCRIPTION.rst b/pos_financial_risk/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..f1461f4e40 --- /dev/null +++ b/pos_financial_risk/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +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.rst b/pos_financial_risk/readme/USAGE.rst new file mode 100644 index 0000000000..815a134131 --- /dev/null +++ b/pos_financial_risk/readme/USAGE.rst @@ -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/index.html b/pos_financial_risk/static/description/index.html new file mode 100644 index 0000000000..dd1d432d1f --- /dev/null +++ b/pos_financial_risk/static/description/index.html @@ -0,0 +1,445 @@ + + + + + + +Point of Sale Financial Risk + + + +
+

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/js/PaymentScreen.esm.js b/pos_financial_risk/static/src/js/PaymentScreen.esm.js new file mode 100644 index 0000000000..f6c23b3048 --- /dev/null +++ b/pos_financial_risk/static/src/js/PaymentScreen.esm.js @@ -0,0 +1,76 @@ +/** @odoo-module **/ + +import PaymentScreen from "point_of_sale.PaymentScreen"; +import Registries from "point_of_sale.Registries"; + +export const PaymentScreenRisk = (PaymentScreen) => + class PaymentScreenRisk extends PaymentScreen { + setup() { + super.setup(); + this.paymentMethodsFromConfigBase = this.payment_methods_from_config; + this.paymentMethodsUnlock = []; + this.paymentMethodsLock = []; + this.remainderLimit = 0.0; + this.riskLimit = 0.0; + this.updatePaymentMethod(); + } + + async selectPartner() { + await super.selectPartner(); + await this.updatePaymentMethod(); + } + + updatePaymentMethod() { + const order = this.currentOrder; + const partner = order.partner; + if (!partner) { + this.paymentMethodsUnlock = this.paymentMethodsFromConfigBase; + this.paymentMethodsLock = []; + this.render(true); + return; + } + const paymentCreditLimit = + this.env.pos.config.payment_credit_limit_restricted_ids; + const orderTotal = + order.get_total_with_tax() + order.get_rounding_applied(); + this.rpc({ + model: "res.partner", + method: "read", + args: [ + 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.id) + ); + } 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) + ); + this.render(true); + }); + } + }; + +Registries.Component.extend(PaymentScreen, PaymentScreenRisk); diff --git a/pos_financial_risk/static/src/scss/pos.scss b/pos_financial_risk/static/src/scss/pos.scss new file mode 100644 index 0000000000..ac10697b5d --- /dev/null +++ b/pos_financial_risk/static/src/scss/pos.scss @@ -0,0 +1,10 @@ +.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; +} diff --git a/pos_financial_risk/static/src/xml/PaymentScreen.xml b/pos_financial_risk/static/src/xml/PaymentScreen.xml new file mode 100644 index 0000000000..98bf550668 --- /dev/null +++ b/pos_financial_risk/static/src/xml/PaymentScreen.xml @@ -0,0 +1,42 @@ + + + + + paymentMethodsUnlock + + +
+

Blocked due to credit limit reached

+ +
+
+ +
+
+
+
+
+ + { + highlight: currentOrder.get_partner(), + error_risk: currentOrder.get_partner() && riskLimit > 0 && remainderLimit <= 0 } + + + + (remainder $) + +
+
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..a78963ad95 --- /dev/null +++ b/pos_financial_risk/views/pos_payment_method_views.xml @@ -0,0 +1,26 @@ + + + + + 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..0bcb35bb33 --- /dev/null +++ b/pos_financial_risk/views/res_config_settings_views.xml @@ -0,0 +1,37 @@ + + + + + res.config.settings.view.form.inherit.pos_financial_risk + res.config.settings + + +
+
+
+ Credit Limit Restricted +
+ Payment methods with credit limit restricted +
+
+ +
+
+
+
+
+
+ +
diff --git a/setup/pos_financial_risk/odoo/addons/pos_financial_risk b/setup/pos_financial_risk/odoo/addons/pos_financial_risk new file mode 120000 index 0000000000..5f79377ed8 --- /dev/null +++ b/setup/pos_financial_risk/odoo/addons/pos_financial_risk @@ -0,0 +1 @@ +../../../../pos_financial_risk \ No newline at end of file diff --git a/setup/pos_financial_risk/setup.py b/setup/pos_financial_risk/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_financial_risk/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)