SambaPOS Forum

English Boards => V3 Development => Topic started by: JohnS on July 02, 2013, 06:19:33 am

Title: Rules Custom Constraint
Post by: JohnS on July 02, 2013, 06:19:33 am
Emre,

How do you use the Custom Constraint field in Rules?
I need to make a rule execute only if a customer has been selected.
Title: Re: Rules Custom Constraint
Post by: emre on July 02, 2013, 06:46:23 am
It depends. Which rule is that?
Title: Re: Rules Custom Constraint
Post by: JohnS on July 02, 2013, 07:21:26 am
Order Added to Ticket.

I am working on cash discounts based on the item/item group selected but only if a customer has been selected. So I need to check the value of a variable I created with Update System Settings.
Title: Re: Rules Custom Constraint
Post by: emre on July 02, 2013, 07:38:09 am
You can use it on custom constraint area like

{:MySetting} == 1

Rule executes if MySetting equals 1;
Title: Re: Rules Custom Constraint
Post by: emre on July 02, 2013, 07:40:50 am
Another Alternative might be using Ticket States

Ticket.IsInState("Promotion")

Rule executes if Any ticket state have Promotion Value.
Title: Re: Rules Custom Constraint
Post by: JohnS on July 02, 2013, 07:49:25 am
That's the only thing I didn't try ==

Thx Emre
Title: Re: Rules Custom Constraint
Post by: JohnS on July 02, 2013, 09:38:37 am
You can use it on custom constraint area like

{:MySetting} == 1

Rule executes if MySetting equals 1;

What about strings? Do we need to enclose them in quotes?
Title: Re: Rules Custom Constraint
Post by: JohnS on July 02, 2013, 10:28:17 am
Another Alternative might be using Ticket States

Ticket.IsInState("Promotion")

Rule executes if Any ticket state have Promotion Value.

And now I can't get this working.
I have set the Ticket State to Member: Discount when a customer is selected - This works.
The rule for applying item discounts has Ticket.IsInState("Discount") set as the Custom Constraint and the rule executes whether a customer has been selected or not.
Title: Re: Rules Custom Constraint
Post by: emre on July 02, 2013, 01:08:06 pm
Let me test that. I'll be back.

Edit: Which rule are you using to apply item discounts?

Edit 2: I've tested it and it works fine for me. There might be two reasons.

1. There might be a typo. Check Trailing spaces.
2. Not every rules can access Ticket info. You can access Ticket data from rules related with tickets like "Ticket Closed, Ticket Created, Order Added, etc."
Title: Re: Rules Custom Constraint
Post by: emre on July 02, 2013, 01:16:03 pm
You can use it on custom constraint area like

{:MySetting} == 1

Rule executes if MySetting equals 1;

What about strings? Do we need to enclose them in quotes?

It should be:

"{:MySetting}" == "Blah"

That means we should enclose both parts.

When you have free time check http://fluentscript.codeplex.com/documentation. (http://fluentscript.codeplex.com/documentation) We are using it as the Expression Evaluator :)
Title: Re: Rules Custom Constraint
Post by: JohnS on July 02, 2013, 03:23:52 pm
1. There might be a typo. Check Trailing spaces.
Done.
2. Not every rules can access Ticket info. You can access Ticket data from rules related with tickets like "Ticket Closed, Ticket Created, Order Added, etc."
Rule I'm using is Order Added to Ticket

The process is

Customer is selected
- Update Ticket State, Statename Member, State Discount

- Order Added to Ticket, Constraint Ticket.IsInState("Discount"), and MenuItemGroupCode matches, give $ discount & tag item as discounted
Title: Re: Rules Custom Constraint
Post by: JohnS on July 28, 2013, 09:36:22 am
Emre,

I still don't get what I'm doing wrong here.

I can set a Ticket State when I select a Member -> Discount: Member
But I cannot use - Ticket.IsInState("Member") as a constraint. The Rule always executes even when no Member has been selected.

What am I missing?
Title: Re: Rules Custom Constraint
Post by: emre on July 29, 2013, 04:59:00 am
My bad. It looks like our script engine does not support overloaded methods. On next release it should work.
You'll be able to use:

Ticket.InState(StateName,State)
or
Ticket.IsInState(State)