-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] pos_financial_risk: Module add.
- Loading branch information
Showing
20 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Cetmix <https://cetmix.com/> | ||
* Maksim Shurupov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() && riskLimit > 0 && remainderLimit <= 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../pos_financial_risk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |