I am trying to add a discount field to the opportunity product. I want this discount to affect the amount field. Amount is already a calculated field which uses the price and quanity in a replacing module (OpportunityProductPageV2), so I want this discount logic to take place in a replacing module. I have tried creating this replacing module but I receive no response from it, or any errors.
The OpportunityProductPageV2 I created.
define("OpportunityProductPageV2", [], function() { return { // Edit page object schema name. entitySchemaName: "Opportunity", details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/, // The attributes property of the view model. attributes: { "Amount": { dependencies: [ { columns: ["Price", "Quantity", "UsrDiscount"], methodName: "recalculateAmount" } ] } }, // Collection of the edit page view model methods. methods: { // Overriding the base Terrasoft.BasePageV2.onEntityInitialized method, which // is triggerd after the edit page object schema has been initialized. onEntityInitialized: function() { // Method parent implementation is called. this.callParent(arguments); // Calling the handler method, which calculates the value in the [UsrBalance] column. this.recalculateAmount(); }, // Handler method that calculates the value in the [UsrBalance] column. recalculateAmount: function() { // Getting individual opportunity product values var quanity = this.get("Quanity"); var price = this.get("Price"); var discountPercent = this.get("UsrDiscount"); // If there is no discount no point in recalculating if (discountPercent === 0) { return; } // Calculating the new price with the discount var totalPrice = quanity * price; var discountDecimal = parseFloat(discountPercent) / 100.0; var discountedPrice = totalPrice - (totalPrice * discountDecimal); if (discountedPrice) { this.set("Amount", discountedPrice); } }, // Visual display of the [UsrBalance] column on the edit page. diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/ }; });
The parent object inheritance is set to OpportunityProductPageV2.
Any help is appreciated, thanks!
Like
1 comments
22:36 Oct 16, 2019
The code is not valid. Please make sure that all open { have their closed }.
entitySchemaName in the OpportunityProductPageV2 should be OpportunityProductInterest
Show all comments