diff --git a/pos_financial_risk/README.rst b/pos_financial_risk/README.rst new file mode 100644 index 0000000000..e69de29bb2 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/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..0a5c5869e6 --- /dev/null +++ b/pos_financial_risk/static/src/scss/pos.scss @@ -0,0 +1,5 @@ +.pos .button.error_risk { + background: $warning !important; + border-color: $warning !important; + color: black !important; +} 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..87bb86ceb0 --- /dev/null +++ b/pos_financial_risk/static/src/xml/PaymentScreen.xml @@ -0,0 +1,45 @@ + + + + + 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, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..74fe75a4f7 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-account_financial_risk @ git+https://github.com/OCA/credit-control.git@refs/pull/272/head#subdirectory=setup/account_financial_risk
Blocked due to credit limit reached