Skip to content

Commit

Permalink
[ADD] pos_financial_risk: Module add.
Browse files Browse the repository at this point in the history
  • Loading branch information
geomer198 committed Oct 16, 2023
1 parent 2f827c1 commit 6414b7d
Show file tree
Hide file tree
Showing 20 changed files with 294 additions and 0 deletions.
Empty file added pos_financial_risk/README.rst
Empty file.
1 change: 1 addition & 0 deletions pos_financial_risk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions pos_financial_risk/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
4 changes: 4 additions & 0 deletions pos_financial_risk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import pos_config
from . import pos_payment_method
from . import pos_session
from . import res_config_settings
13 changes: 13 additions & 0 deletions pos_financial_risk/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -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",
)
7 changes: 7 additions & 0 deletions pos_financial_risk/models/pos_payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class PosPaymentMethod(models.Model):
_inherit = "pos.payment.method"

credit_limit_restricted = fields.Boolean()
10 changes: 10 additions & 0 deletions pos_financial_risk/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions pos_financial_risk/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -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,
)
13 changes: 13 additions & 0 deletions pos_financial_risk/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions pos_financial_risk/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Cetmix <https://cetmix.com/>
* Maksim Shurupov
7 changes: 7 additions & 0 deletions pos_financial_risk/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions pos_financial_risk/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
76 changes: 76 additions & 0 deletions pos_financial_risk/static/src/js/PaymentScreen.esm.js
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions pos_financial_risk/static/src/scss/pos.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pos .button.error_risk {
background: $warning !important;
border-color: $warning !important;
color: black !important;
}
45 changes: 45 additions & 0 deletions pos_financial_risk/static/src/xml/PaymentScreen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t t-inherit="point_of_sale.PaymentScreen" t-inherit-mode="extension" owl="1">
<xpath
expr="//t[@t-foreach='payment_methods_from_config']"
position="attributes"
>
<attribute name="t-foreach">paymentMethodsUnlock</attribute>
</xpath>
<xpath expr="//div[hasclass('paymentmethods')]" position="after">
<div class="paymentmethods" t-if="paymentMethodsLock.length > 0">
<p class="title-category">Blocked due to credit limit reached</p>
<t
t-foreach="paymentMethodsLock"
t-as="paymentMethod"
t-key="paymentMethod.id"
>
<div class="button paymentmethod">
<div
class="payment-name"
style="background: rgba(255, 0, 0, 0.6); cursor: not-allowed;"
>
<s t-esc="paymentMethod.name" />
</div>
</div>
</t>
</div>
</xpath>
<xpath
expr="//div[hasclass('payment-buttons')]/div[hasclass('partner-button')]/div[hasclass('button')]"
position="attributes"
>
<attribute name="t-att-class">{
highlight: currentOrder.get_partner(),
error_risk: currentOrder.get_partner() &amp;&amp; riskLimit > 0 &amp;&amp; remainderLimit &lt;= 0 }
</attribute>
</xpath>
<xpath
expr="//div[hasclass('payment-buttons')]/div[hasclass('partner-button')]//t[@t-esc='partner.name']"
position="after"
>
<span t-if="riskLimit > 0"> (remainder <t t-esc="remainderLimit" />$)</span>
</xpath>
</t>
</templates>
26 changes: 26 additions & 0 deletions pos_financial_risk/views/pos_payment_method_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="pos_payment_method_view_form" model="ir.ui.view">
<field name="name">pos.payment.method.inherit.form</field>
<field name="model">pos.payment.method</field>
<field name="inherit_id" ref="point_of_sale.pos_payment_method_view_form" />
<field name="arch" type="xml">
<field name="split_transactions" position="after">
<field name="credit_limit_restricted" />
</field>
</field>
</record>

<record id="pos_payment_method_view_tree" model="ir.ui.view">
<field name="name">pos.payment.method.inherit.tree</field>
<field name="model">pos.payment.method</field>
<field name="inherit_id" ref="point_of_sale.pos_payment_method_view_tree" />
<field name="arch" type="xml">
<tree position="inside">
<field name="credit_limit_restricted" optional="hide" />
</tree>
</field>
</record>

</odoo>
37 changes: 37 additions & 0 deletions pos_financial_risk/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="res_config_settings_view_form" model="ir.ui.view">
<field
name="name"
>res.config.settings.view.form.inherit.pos_financial_risk</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="payment_methods_new" position="after">
<div
class="col-12 col-lg-6 o_setting_box"
id="payment_methods_restricted"
>
<div class="o_setting_right_pane">
<span class="o_form_label">Credit Limit Restricted</span>
<div class="text-muted">
Payment methods with credit limit restricted
</div>
<div class="content-group mt16">
<field
name="pos_payment_credit_limit_restricted_ids"
colspan="4"
nolabel="1"
widget="many2many_tags"
attrs="{'readonly': [('pos_has_active_session','=', True)]}"
options="{'no_create': True}"
/>
</div>
</div>
</div>
</div>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions setup/pos_financial_risk/odoo/addons/pos_financial_risk
6 changes: 6 additions & 0 deletions setup/pos_financial_risk/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6414b7d

Please sign in to comment.