-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sale_financial_risk_pos_compatibility: Module added
- Loading branch information
Showing
13 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,21 @@ | ||
{ | ||
"name": "Sale Financial Risk Pos Compatibility", | ||
"version": "16.0.1.0.0", | ||
"category": "Sales/Point of Sale", | ||
"summary": "Sale Financial Risk Pos Compatibility", | ||
"depends": ["sale_financial_risk", "pos_order_to_sale_order"], | ||
"website": "https://github.com/OCA/pos", | ||
"author": "Cetmix,Odoo Community Association (OCA)", | ||
"maintainers": ["geomer198", "CetmixGitDrone"], | ||
"data": ["data/demo.xml"], | ||
"installable": True, | ||
"assets": { | ||
"point_of_sale.assets": [ | ||
"sale_financial_risk_pos_compatibility/static/src/js/CreateOrderPopup.esm.js", | ||
], | ||
"web.assets_tests": [ | ||
"sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js", # noqa | ||
], | ||
}, | ||
"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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="test_partner" model="res.partner"> | ||
<field name="name">Test Partner</field> | ||
<field name="risk_sale_order_limit">1.0</field> | ||
<field name="credit_limit">1.0</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,2 @@ | ||
This module is a bridging module between **sale_financial_risk** and **pos_order_to_sale_order**. It implements control for the Sale Orders created from POS. | ||
Same warning or blocking message will be displayed in POS as if an order was created from the backend. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
sale_financial_risk_pos_compatibility/static/src/js/CreateOrderPopup.esm.js
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,57 @@ | ||
/** @odoo-module **/ | ||
|
||
import CreateOrderPopup from "point_of_sale.CreateOrderPopup"; | ||
import Registries from "point_of_sale.Registries"; | ||
import {_t} from "web.core"; | ||
|
||
export const CreateOrderPopupRisk = (CreateOrderPopup) => | ||
class CreateOrderPopupRisk extends CreateOrderPopup { | ||
async _createSaleOrder(order_state) { | ||
if (order_state === "draft") { | ||
return await super._createSaleOrder(order_state); | ||
} | ||
const order = this.env.pos.get_order(); | ||
const risk_amount = | ||
order.get_total_with_tax() + order.get_rounding_applied(); | ||
const [partner] = await this.rpc({ | ||
model: "res.partner", | ||
method: "read", | ||
args: [ | ||
order.partner.id, | ||
[ | ||
"risk_exception", | ||
"risk_sale_order_limit", | ||
"risk_sale_order", | ||
"risk_sale_order_include", | ||
"risk_total", | ||
"credit_limit", | ||
], | ||
], | ||
}); | ||
let exception_msg = ""; | ||
if (partner.risk_exception) { | ||
exception_msg = _t("Financial risk exceeded.\n"); | ||
} else if ( | ||
partner.risk_sale_order_limit && | ||
partner.risk_sale_order + risk_amount > partner.risk_sale_order_limit | ||
) { | ||
exception_msg = _t("This sale order exceeds the sales orders risk.\n"); | ||
} else if ( | ||
partner.risk_sale_order_include && | ||
partner.risk_total + risk_amount > partner.credit_limit | ||
) { | ||
exception_msg = _t("This sale order exceeds the financial risk.\n"); | ||
} else { | ||
return await super._createSaleOrder(order_state); | ||
} | ||
const {confirmed} = await this.showPopup("ConfirmPopup", { | ||
title: "Partner risk exceeded", | ||
body: exception_msg, | ||
}); | ||
if (confirmed) { | ||
return await super._createSaleOrder(order_state); | ||
} | ||
} | ||
}; | ||
|
||
Registries.Component.extend(CreateOrderPopup, CreateOrderPopupRisk); |
94 changes: 94 additions & 0 deletions
94
...l_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js
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,94 @@ | ||
odoo.define( | ||
"sale_financial_risk_pos_compatibility.SaleFinancialRiskPosCompatibility", | ||
function (require) { | ||
"use strict"; | ||
|
||
const Tour = require("web_tour.tour"); | ||
|
||
const steps = [ | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Waiting for loading to finish", | ||
trigger: "body:not(:has(.loader))", | ||
// eslint-disable-next-line no-empty-function | ||
run: () => {}, | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Close Opening cashbox popup", | ||
trigger: "div.opening-cash-control .button:contains('Open session')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Leave category displayed by default", | ||
trigger: ".breadcrumb-home", | ||
// eslint-disable-next-line no-empty-function | ||
run: () => {}, | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Order a 'Whiteboard Pen' (price 3.20)", | ||
trigger: ".product-list .product-name:contains('Whiteboard Pen')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Click on 'Customer' Button", | ||
trigger: "button.set-partner", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Select a customer 'Test Partner'", | ||
trigger: "tr.partner-line td div:contains('Test Partner')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Order set count 1", | ||
trigger: ".numpad button.input-button:visible:contains('1')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Order set count 0", | ||
trigger: ".numpad button.input-button:visible:contains('0')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Order set count 0", | ||
trigger: ".numpad button.input-button:visible:contains('0')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Click on 'Create Order' Button", | ||
trigger: "span.control-button span:contains('Create Order')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Click on 'Create Confirmed Sale Order' Button", | ||
trigger: | ||
"div.button-sale-order span:contains('Create Confirmed Sale Order')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Confirm popup click on 'Ok' Button", | ||
trigger: ".popup-confirm .footer div:contains('Ok')", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Close the Point of Sale frontend", | ||
trigger: ".header-button", | ||
}, | ||
{ | ||
content: | ||
"Test sale_financial_risk_pos_compatibility: Confirm closing the frontend", | ||
trigger: ".header-button", | ||
// eslint-disable-next-line no-empty-function | ||
run: () => {}, | ||
}, | ||
]; | ||
|
||
Tour.register( | ||
"SaleFinancialRiskPosCompatibility", | ||
{test: true, url: "/pos/ui"}, | ||
steps | ||
); | ||
} | ||
); |
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 test_module |
15 changes: 15 additions & 0 deletions
15
sale_financial_risk_pos_compatibility/tests/test_module.py
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,15 @@ | ||
from odoo.tests import tagged | ||
|
||
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestUI(TestPointOfSaleHttpCommon): | ||
def test_sale_financial_risk_pos_compatibility(self): | ||
self.main_pos_config.open_ui() | ||
|
||
self.start_tour( | ||
f"/pos/ui?config_id={self.main_pos_config.id}", | ||
"SaleFinancialRiskPosCompatibility", | ||
login="accountman", | ||
) |
1 change: 1 addition & 0 deletions
1
...p/sale_financial_risk_pos_compatibility/odoo/addons/sale_financial_risk_pos_compatibility
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 @@ | ||
../../../../sale_financial_risk_pos_compatibility |
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-sale_financial_risk @ git+https://github.com/OCA/credit-control.git@refs/pull/280/head#subdirectory=setup/sale_financial_risk |