Skip to content

Commit

Permalink
[ADD] sale_financial_risk_pos_compatibility: Module added
Browse files Browse the repository at this point in the history
  • Loading branch information
geomer198 committed Jul 17, 2023
1 parent 2507767 commit e514684
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 0 deletions.
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions sale_financial_risk_pos_compatibility/__manifest__.py
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",
}
10 changes: 10 additions & 0 deletions sale_financial_risk_pos_compatibility/data/demo.xml
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>
2 changes: 2 additions & 0 deletions sale_financial_risk_pos_compatibility/readme/DESCRIPTION.rst
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.
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);
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
);
}
);
1 change: 1 addition & 0 deletions sale_financial_risk_pos_compatibility/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
15 changes: 15 additions & 0 deletions sale_financial_risk_pos_compatibility/tests/test_module.py
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",
)
6 changes: 6 additions & 0 deletions setup/sale_financial_risk_pos_compatibility/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-sale_financial_risk @ git+https://github.com/OCA/credit-control.git@refs/pull/280/head#subdirectory=setup/sale_financial_risk

0 comments on commit e514684

Please sign in to comment.