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 10, 2023
1 parent 2507767 commit e8a43ca
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions sale_financial_risk_pos_compatibility/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions sale_financial_risk_pos_compatibility/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Sale Financial Risk Pos Compatibility",
"version": "16.0.1.0.0",
"category": "Sales/Point of Sale",
"summary": "Sale Financial Risk Pos Compatibility",
"depends": ["pos_financial_risk", "pos_order_to_sale_order"],
"website": "https://github.com/OCA/pos",
"author": "Cetmix,Odoo Community Association (OCA)",
"maintainers": ["geomer198", "CetmixGitDrone"],
"data": [
"views/res_config_settings_view.xml",
],
"installable": True,
"assets": {
"point_of_sale.assets": [
"sale_financial_risk_pos_compatibility/static/src/js/CreateOrderButton.esm.js",
],
"web.assets_tests": [
"sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js", # noqa
],
},
"license": "AGPL-3",
}
2 changes: 2 additions & 0 deletions sale_financial_risk_pos_compatibility/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import pos_config
from . import res_config_settings
7 changes: 7 additions & 0 deletions sale_financial_risk_pos_compatibility/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class PosConfig(models.Model):
_inherit = "pos.config"

active_financial_risk = fields.Boolean()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

pos_active_financial_risk = fields.Boolean(
related="pos_config_id.active_financial_risk", readonly=False
)
2 changes: 2 additions & 0 deletions sale_financial_risk_pos_compatibility/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Go to Point of Sale's settings page and activate financial risk functional for a
specific PoS configuration.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @odoo-module **/

import CreateOrderButton from "point_of_sale.CreateOrderButton";
import Registries from "point_of_sale.Registries";
import {_t} from "web.core";

export const CreateOrderRiskButton = (CreateOrderButton) =>
class CreateOrderRiskButton extends CreateOrderButton {
async onClick() {
if (!this.env.pos.config.active_financial_risk) {
return super.onClick();
}
const order = this.env.pos.get_order();
const partner = order.partner;
if (!partner) {
return super.onClick();
}
const partnerFields = await this.rpc({
model: "res.partner",
method: "read",
args: [partner.id, ["risk_total"]],
});
if (
order.get_total_with_tax() + order.get_rounding_applied() >
partnerFields[0].risk_total
) {
return await this.showPopup("ErrorPopup", {
title: _t("Cannot confirm order"),
body: _t("Order total exceeds customer credit limit"),
});
}
return super.onClick();
}
};

Registries.Component.extend(CreateOrderButton, CreateOrderRiskButton);
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 'Addison Olson'",
trigger: "tr.partner-line td div:contains('Addison Olson')",
},
{
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: Error popup click on 'Ok' Button",
trigger: "div.popup-error .button: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
16 changes: 16 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,16 @@
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.active_financial_risk = True
self.main_pos_config.open_ui()

self.start_tour(
f"/pos/ui?config_id={self.main_pos_config.id}",
"SaleFinancialRiskPosCompatibility",
login="accountman",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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</field>
<field name="model">res.config.settings</field>
<field
name="inherit_id"
ref="pos_order_to_sale_order.view_res_config_settings_form"
/>
<field name="arch" type="xml">
<xpath expr="//h2[@name='create_sale_order']" position="after">
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="pos_active_financial_risk" />
</div>
<div class="o_setting_right_pane">
<label for="pos_active_financial_risk" />
<div class="text-muted" />
</div>
</div>
</div>
</xpath>
</field>
</record>

</odoo>
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-pos_financial_risk @ git+https://github.com/OCA/pos.git@refs/pull/1018/head#subdirectory=setup/pos_financial_risk

0 comments on commit e8a43ca

Please sign in to comment.