Hi community,

We want to set the default currency in the Opportunity Mini Page (front end event), based on the Org Role of a user (oob functionality is based on the Base Currency system setting).

Is there any code implementation of a similar request ?

Sasori

Like 0

Like

2 comments
Best reply

Hello Sasori!

1) Add MultiCurrencyEditUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["MultiCurrencyEditUtilities"] ...

2) Add MultiCurrencyEditUtilities as a mixing to the minipage schema. Example:

...
mixins: {
  MultiCurrencyEditUtilities: "Terrasoft.MultiCurrencyEditUtilities",
  ...

3) Instead of using roles check you can use operation permission check. To use it you need to add RightUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["RightUtilities"], function(RightUtilities) { ...

4) Use the following methods in your minipage:

...
onEntityInitialized: function() {
  this.callParent(arguments);
  this.checkCurrencyForUser();
},
checkCurrencyForUser: function() {
  RightUtilities.checkCanExecuteOperation({
  operation: "NeedToUseEuro"
}, function(result) {
  if (result) {
    var euroId = "c0057119-53e6-df11-971b-001d60e938c6";
    this.onCurrencyMenuItemClick(euroId);
  }
 }, this);
}
...

The logic above will check if the user has access to the "NeedToUseEuro" operation (or this user role has access to the operation) and if so we will call the onCurrencyMenuItemClick method and pass euroId as an argument (see the onCurrencyMenuItemClick method signature in the MultiCurrencyEditUtilities module).

c0057119-53e6-df11-971b-001d60e938c6 is an Id of the "Euro" currency from the "Currency" table in the database. All you need to do is:

1. Correctly specify operation permissions (check if your user is not in several roles that are used in different operation permissions check)

2. Correctly setup a chain of operation permissions checks in the context of the checkCurrencyForUser method execution

P.S. Article about adding a multi-currency field: 

https://academy.creatio.com/docs/developer/interface_elements/record_page/field/overview#case-1915

Hi community,

Any update ?

Sasori

Hello Sasori!

1) Add MultiCurrencyEditUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["MultiCurrencyEditUtilities"] ...

2) Add MultiCurrencyEditUtilities as a mixing to the minipage schema. Example:

...
mixins: {
  MultiCurrencyEditUtilities: "Terrasoft.MultiCurrencyEditUtilities",
  ...

3) Instead of using roles check you can use operation permission check. To use it you need to add RightUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["RightUtilities"], function(RightUtilities) { ...

4) Use the following methods in your minipage:

...
onEntityInitialized: function() {
  this.callParent(arguments);
  this.checkCurrencyForUser();
},
checkCurrencyForUser: function() {
  RightUtilities.checkCanExecuteOperation({
  operation: "NeedToUseEuro"
}, function(result) {
  if (result) {
    var euroId = "c0057119-53e6-df11-971b-001d60e938c6";
    this.onCurrencyMenuItemClick(euroId);
  }
 }, this);
}
...

The logic above will check if the user has access to the "NeedToUseEuro" operation (or this user role has access to the operation) and if so we will call the onCurrencyMenuItemClick method and pass euroId as an argument (see the onCurrencyMenuItemClick method signature in the MultiCurrencyEditUtilities module).

c0057119-53e6-df11-971b-001d60e938c6 is an Id of the "Euro" currency from the "Currency" table in the database. All you need to do is:

1. Correctly specify operation permissions (check if your user is not in several roles that are used in different operation permissions check)

2. Correctly setup a chain of operation permissions checks in the context of the checkCurrencyForUser method execution

P.S. Article about adding a multi-currency field: 

https://academy.creatio.com/docs/developer/interface_elements/record_page/field/overview#case-1915

Show all comments

Hello 

 

As i was strugle on this issue and finaly figure this out... i belive that this will be helpfull for others...

 

We have 3 currencies that involve on our process.

US Dollar, ILS - Israel Shekel, and ERU

we neede to translate the relevant currency from 1$ into 3.2 ILS (3.2 as the current rate)

when we try to approach the currency table - the Rate field was 0.0

when we try to approach the Currency Rate Table - the Rate field showed unreasonble number.

 

so... we checked and we didn't understand why and what. and eventualy, with a GREAT help of creatio represntative, we got this solution:

 

Preparations:

1. setup the base currency to our currency - in our case is ILS

2. setup the other currencies as follows.

    example - US Dollar:   setup the Ratio = 1000,  setup the rate value to = 3289.000 (in case the 1$=3.289 ILS)

What happened on the back end is that the Currency Rate table is getting the values from this update, and setup the field "Rate" into 304.000 (in that case)

when we want to setup a calculation that uses this rate - whats needed to be done is:

A = get the ratio number from the relevant currency, from the currency lookup table.

B = get the Exchange Rate from the Currency Rate table, for this specific currency.

and do this math:  A/B   >>> and the result will give you the correct rate !

in this example the rate will be:   1000/304  =  3.289   (1000=Ratio from currency table, 304=Exchange Rate from currency rate)

 

Then we take the value from that result, and use it in the process.

actualy - when i come to think about it - we need to do this process in the currency table, and save this value for all uses... 

 

If someone has bump into this issue and would like to share her/his opinion... i will be happy to see... maybe we did it all so complex for no reason ... but it works :-) 

 

Thanks 

 

 

Like 0

Like

2 comments

Julius,

Thanks, I actually saw that article. i am not sure whether we need to integrate to this site of the the central bank in Israel... 

 

Show all comments

Hi all,

 

I am trying to understand the Price field in ProductPageV2. How is this implemented? How is the Price field(which is a Currency data type) is linked with Currency Lookup ?

 

I am trying to replicate the same with a custom field which should have the same dropdown as similar to Price in ProductPageV2.

 

Can some one share any reference links which has more details. 

Thank you

Like 0

Like

1 comments

Hi,

 

All the information about currencies and price of a product is available in the following Academy articles:

 

1) Work with currencies - https://academy.creatio.com/docs/user/platform_basics/user_interface/cu…

2) Managing the price - https://academy.creatio.com/docs/user/sales_tools/products_and_prices/m…

 

For more details you will need to study the implementation of the "Price" column in the ProductPageV2 schemas:

Best regards,

Oscar

Show all comments

Hi,

I'm currently trying to add multiple multi-currency fields in the same page. I manage to create one following the developer guide https://academy.creatio.com/documents/technic-sdk/7-12/how-add-multi-cu….

But when i create other multi-currency field, both of them share the currency (not intended).

I would like to create another multi-currency field, independent from the first one.

Best regards.

 

 

Like 0

Like

1 comments

Hi Pedro,



I was able to come up with an example on Order page for fields Amount and Payment Amount. General idea is to duplicate logic for each field separately.



What I was not able to achieve is working with triangle as well (https://prnt.sc/qf6y2b), so I removed it. Also, as I am using Order page it has logic behind with Products detail which should be implemented for different currency fields, but I skipped it. In the custom section it should be all good.



Also note, that after adding new fields to the object, they will be empty. So to make it work, after adding fields you should fill them in using db script for example and then set default value for them (as in the article you mentioned) to make it filled in for all new records.



So here are the steps that I followed:

1. Created new fields in the object for Currency and Currency rate separately for each field. https://prnt.sc/qf6znu

2. Created a generator for field.

 

define("UsrMultiCurrencyEditViewGenerator", ["MultiCurrencyEditViewGenerator"], function() {
 
	Ext.define("Terrasoft.configuration.UsrMultiCurrencyEditViewGenerator", {
		extend: "Terrasoft.MultiCurrencyEditViewGenerator",
		alternateClassName: "Terrasoft.UsrMultiCurrencyEditViewGenerator",
 
		generateCurrencyButton: function(config) {
			var buttonConfig = {
				id: "multiCurrencyButton-currency" + config.name,
				className: "Terrasoft.Button",
				classes: {
					wrapperClass: ["currency-button"]
				},
				style: Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
				menu: {
					items: this.getPropertyBindingConfig(config, "currencyButtonMenuList")
				},
				enabled: true,
				markerValue: config.name + " MultiCurrencyButton"
			};
			return this.generateButton(buttonConfig);
		}
	});
	return Ext.create(Terrasoft.UsrMultiCurrencyEditViewGenerator);
});

3. Modified order page:

 

define("OrderPageV2", ["MoneyModule", "MultiCurrencyEdit", "MultiCurrencyEditUtilities",
"UsrMultiCurrencyEditViewGenerator"],
	function(MoneyModule, MultiCurrencyEdit, MultiCurrencyEditUtilities) {
	return {
		entitySchemaName: "Order",
		attributes: {
			"UsrAmountCurrencyRate": {
				"dependencies": [{
					"columns": ["UsrAmountCurrency"],
					"methodName": "usrSetAmountCurrencyRate"
				}]
			},
			"Amount": {
				"dependencies" : [{
					"columns": ["Amount"],
					"methodName": "usrRecalculateAmount"
				}]
			},
			"UsrPaymentAmountCurrencyRate": {
				"dependencies": [{
					"columns": ["UsrAmountCurrency"],
					"methodName": "usrSetPaymentAmountCurrencyRate"
				}]
			},
			"PaymentAmount": {
				"dependencies" : [{
					"columns": ["PaymentAmount"],
					"methodName": "usrRecalculatePaymentAmount"
				}]
			}
		},
		mixins: {
			MultiCurrencyEditUtilities: "Terrasoft.MultiCurrencyEditUtilities"
		},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			onEntityInitialized: function() {
				this.callParent(arguments);
				this.mixins.MultiCurrencyEditUtilities.init.call(this);
			},
			usrSetAmountCurrencyRate: function() {
				MoneyModule.LoadCurrencyRate.call(this, "UsrAmountCurrency", "UsrAmountCurrencyRate",
					new Date(), function() {
						var currency = this.get("UsrAmountCurrency");
						var division = currency && currency.Division;
						MoneyModule.RecalcCurrencyValue.call(this, "UsrAmountCurrencyRate",
							"Amount", "PrimaryAmount", division);
					}
				);
			},
			usrRecalculateAmount: function() {
				var currency = this.get("UsrAmountCurrency");
				var division = currency && currency.Division;
				MoneyModule.RecalcBaseValue.call(this, "UsrAmountCurrencyRate", "Amount",
					"PrimaryAmount", division);
			},
			usrSetPaymentAmountCurrencyRate: function() {
				MoneyModule.LoadCurrencyRate.call(this, "UsrPaymentAmountCurrency", "UsrPaymentAmountCurrencyRate",
					new Date(), function() {
						var currency = this.get("UsrPaymentAmountCurrency");
						var division = currency && currency.Division;
						MoneyModule.RecalcCurrencyValue.call(this, "UsrPaymentAmountCurrencyRate",
							"PaymentAmount", "PrimaryPaymentAmount", division);
					}
				);
			},
			usrRecalculatePaymentAmount: function() {
				var currency = this.get("UsrPaymentAmountCurrency");
				var division = currency && currency.Division;
				MoneyModule.RecalcBaseValue.call(this, "UsrPaymentAmountCurrencyRate", "PaymentAmount",
					"PrimaryPaymentAmount", division);
			},
 
			onPaymentAmountCurrencyMenuItemClick: function(menuItem) {
				var currency = this.get("CurrencyRateList").find(menuItem);
				this.set("UsrAmountCurrency", currency);
			},
			onAmountCurrencyMenuItemClick: function(menuItem) {
				var currency = this.get("CurrencyRateList").find(menuItem);
				this.set("UsrPaymentAmountCurrency", currency);
			},
			prepareCurrencyMenu: function() {
				this.mixins.MultiCurrencyEditUtilities.prepareCurrencyMenu.call(this);
				var currencyRateList = this.get("CurrencyRateList");
				if (!currencyRateList) {
					return;
				}
				var columnsList = ["Amount", "PaymentAmount"];
				this.Terrasoft.each(columnsList, function(column) {
					var menu = this.Ext.create(this.Terrasoft.BaseViewModelCollection);
					currencyRateList.each(function(item) {
						var menuItem = Ext.create("Terrasoft.BaseViewModel", {
							values: {
								Id: item.value,
								Caption: item.Symbol || item.displayValue,
								MarkerValue: item.Symbol || item.displayValue,
								Tag: item.value,
								Click: {"bindTo": "on" + column + "CurrencyMenuItemClick"}
							}
						});
						menu.addItem(menuItem);
					}, this);
					this.set(column + "CurrencyRateList", menu);
				}, this);
			},
		},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "Amount",
				"values": {
					"bindTo": "Amount",
					"primaryAmount": "PrimaryAmount",
					"currency": "UsrAmountCurrency",
					"rate": "UsrAmountCurrencyRate",
					"generator": "UsrMultiCurrencyEditViewGenerator.generate"
				}
			},
			{
				"operation": "merge",
				"name": "PaymentAmount",
				"values": {
					"bindTo": "PaymentAmount",
					"primaryAmount": "PrimaryPaymentAmount",
					"currency": "UsrPaymentAmountCurrency",
					"rate": "UsrPaymentAmountCurrencyRate",
					"generator": "UsrMultiCurrencyEditViewGenerator.generate"
				}
			}
		]/**SCHEMA_DIFF*/
	};
});



Results:

https://prnt.sc/qf723t



Triangle is removed. If you want to still have it - you would need to improve this sample further and check how to make it work.



Regards,

Dmytro

Show all comments