Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] pos_order_to_sale_order_sale_financial_risk: Sale Financial Risk in POS #1024

Conversation

geomer198
Copy link
Contributor

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.

@geomer198 geomer198 marked this pull request as draft July 10, 2023 19:09
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from feff0b6 to c46c303 Compare July 10, 2023 19:52
@geomer198 geomer198 marked this pull request as ready for review July 10, 2023 20:50
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from e463155 to e8a43ca Compare July 10, 2023 22:02
@geomer198 geomer198 marked this pull request as draft July 13, 2023 20:16
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from 6127e03 to e514684 Compare July 17, 2023 22:07
@geomer198 geomer198 marked this pull request as ready for review July 17, 2023 22:12
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch 6 times, most recently from 06b627c to ed68499 Compare July 24, 2023 17:33
Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review ok

@@ -0,0 +1,23 @@
{
"name": "Sale Financial Risk Pos Compatibility",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name: "Sale Financial Risk in POS"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

"name": "Sale Financial Risk Pos Compatibility",
"version": "16.0.1.0.0",
"category": "Sales/Point of Sale",
"summary": "Sale Financial Risk Pos Compatibility",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sale Financial Risk control for Sales Orders created from POS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment on lines 8 to 16
user_dict = super(PosSession, self)._get_pos_ui_res_users(params)
user_id = user_dict.get("id")
if user_id and (user := self.env["res.users"].browse(user_id)).exists():
user_dict.update(
has_role_risk_manager=user.has_group(
"account_financial_risk.group_overpass_partner_risk_exception"
)
)
return user_dict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user will exist because the id is from the current user

Suggested change
user_dict = super(PosSession, self)._get_pos_ui_res_users(params)
user_id = user_dict.get("id")
if user_id and (user := self.env["res.users"].browse(user_id)).exists():
user_dict.update(
has_role_risk_manager=user.has_group(
"account_financial_risk.group_overpass_partner_risk_exception"
)
)
return user_dict
data = super()._get_pos_ui_res_users(params)
user = self.env["res.users"].browse(data["id"])
data["has_role_risk_manager"] = user.has_group(
"account_financial_risk.group_overpass_partner_risk_exception",
)
return data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved


import CreateOrderPopup from "point_of_sale.CreateOrderPopup";
import Registries from "point_of_sale.Registries";
import {_t} from "web.core";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use this.env._t instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

],
],
});
console.log(this.env.pos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

],
],
});
console.log(this.env.pos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from ed68499 to 0e7ce01 Compare July 25, 2023 18:01
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from 642e150 to bc18518 Compare August 16, 2023 14:25
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from c66a0f0 to 95c1ae6 Compare September 2, 2023 21:40
Copy link
Member

@GabbasovDinar GabbasovDinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename sale_financial_risk_pos_compatibility to pos_sale_financial_risk

Copy link
Member

@GabbasovDinar GabbasovDinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes are needed regarding the overriding of the createSaleOrder method

} else {
return await super._actionCreateSaleOrder(order_state);
}
const {confirmed} = await this.showPopup("ConfirmRiskPopup", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        it seems to be necessary to show different popup depending on the settings
            if (this.env.pos.user.has_role_risk_manager) {
                const {confirmed} = await  this.showPopup("ConfirmPopup", {
                    title: this.env._t("Partner risk exceeded"),
                    body: exception_msg,
                });
                if (confirmed) {
                    return await super._actionCreateSaleOrder(order_state);
                } 
            } else {
                await this.showPopup("ErrorPopup", {
                    title: this.env._t("Partner risk exceeded"),
                    body: exception_msg,
                });
            }
            return await this.cancel();

creating a new popup is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

showButton: this.env.pos.user.has_role_risk_manager,
});
if (confirmed) {
this.extraContext = {context: {bypass_risk: true}};
Copy link
Member

@GabbasovDinar GabbasovDinar Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this variable, I suggest setting this value as an order property;

order.set_bypass_risk(true);

and order model:

const PosSaleFinancialRiskOrder = (Order) =>
    class PosSaleFinancialRiskOrder extends Order {
        constructor() {
            super(...arguments);
            this.bypass_risk = false;
        }
        set_bypass_risk(bypass_risk) {
            this.bypass_risk = bypass_risk
        }
        export_as_JSON() {
            const result = super.export_as_JSON(...arguments);
            result.bypass_risk = this.bypass_risk;
            return result;
        }
        init_from_JSON(json) {
            super.init_from_JSON(...arguments);
            this.bypass_risk = json.bypass_risk;
        }
    }
    
Registries.Model.extend(Order, PosSaleFinancialRiskOrder);

export default PosSaleFinancialRiskOrder;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this values will available in order_data of def create_order_from_pos(self, order_data, action) method

and you can check:

if "bypass_risk" in order_data:
    self = self.with_context(bypass_risk=bypass_risk)
return super(SaleOrder, self).create_order_from_pos(order_data, action)

please check this way

})
.finally(function () {
framework.unblockUI();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to override this method if you will be using the order

Copy link
Member

@GabbasovDinar GabbasovDinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check comments

showButton: false,
};

Registries.Component.add(ConfirmRiskPopup);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not need create new popup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from bbbff55 to 8cf2faa Compare September 6, 2023 00:59
@legalsylvain legalsylvain added this to the 16.0 milestone Sep 26, 2023
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from 8cf2faa to b1bc5ca Compare September 27, 2023 14:17
@geomer198
Copy link
Contributor Author

@ivantodorovich, @ivs-cetmix, @GabbasovDinar, @DemchukM Could you please make code review again?

@ivantodorovich
Copy link
Contributor

Thanks a lot @geomer198 !

Looks great to me 👍🏻

Before merging, could you squash the 2 commits and reword the first one to account for the new module name? 🙏🏻

@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from 1f864b2 to d66b2fb Compare December 26, 2023 19:48
@geomer198
Copy link
Contributor Author

@ivantodorovich Is all okay?

@ivantodorovich
Copy link
Contributor

Perfect, thanks!!

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 16.0-ocabot-merge-pr-1024-by-ivantodorovich-bump-nobump, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Dec 26, 2023
Signed-off-by ivantodorovich
@OCA-git-bot
Copy link
Contributor

@ivantodorovich your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-1024-by-ivantodorovich-bump-nobump.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@ivantodorovich
Copy link
Contributor

The merge command failed with some error.

Could you rebase?

I'll try with ocabot but it can fail depending on the PR permissions

/ocabot rebase

@OCA-git-bot
Copy link
Contributor

@ivantodorovich The rebase process failed, because command git push --force cetmix tmp-pr-1024:16.0-t2682-sale_financial_risk_pos_compatibility-add failed with output:

remote: Repository not found.
fatal: repository 'https://github.com/cetmix/pos/' not found

@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from d66b2fb to ea24bab Compare December 27, 2023 12:16
@geomer198
Copy link
Contributor Author

@ivantodorovich There is a problem with tests, tests that do not depend on this module are not run.

@ivantodorovich
Copy link
Contributor

It may be related to this warning:
Tour PosOrderToSaleOrderTour is already defined

You probably have to choose a different and unique name for the test tours

@ivantodorovich ivantodorovich changed the title [16.0][ADD] sale_financial_risk_pos_compatibility [16.0][ADD] pos_order_to_sale_order_sale_financial_risk: Sale Financial Risk in POS Dec 27, 2023
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from e9ef3cc to 397df34 Compare December 28, 2023 15:56
@geomer198 geomer198 force-pushed the 16.0-t2682-sale_financial_risk_pos_compatibility-add branch from 830b7a4 to 88e4a95 Compare December 28, 2023 16:16
@geomer198
Copy link
Contributor Author

@ivantodorovich Is all good now?

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@ivantodorovich
Copy link
Contributor

Looks great! Thanks!

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-1024-by-ivantodorovich-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 71488e4 into OCA:16.0 Dec 28, 2023
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 1af25ee. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants