This document will describe how to well define a predicate, and wich tools are used in order to find a predicate for a particular context. ('seb',) Predicates text/html None seb en None 2005-06-13 10:38:10 2005-05-24 13:49:49 () 0 What's a Mapped Value ? A mapped value allow to define some values (properties or categories) corresponding to some conditions. For example, you may need to define the price (the value) corresponding to a resource and a range of quantities (conditions). The idea is to create in many places into ERP5 mapped values. Let's say you have a document, if you are looking for a value (for example a price) for this document, then a tool will look at all mapped value stored in ERP5, and it will give you all mapped value (most of the time you will get only one) where the conditions corresponds to your document, so you can know wich value you can take. The document on wich you are looking for a value is usually called the "context". If you want to define a mapped value, there is two different set of properties to update. The first set of properties defines the Value, the second set of properties defines the conditions. There is two classes in ERP5 corresponding to the two sets, the first one is MappedValue, the second one wich defines condition is Predicate. On each predicate, there is a method called test defined like this:: def test(self, context,**kw): This method returns True if the context corresponds to this predicate, or it returns False otherwise. For example, you have a mapped value A defined like this :: value: base_price : 23 conditions: 5 < quantity < 23 resource = product/openbrick Then let's say you have an order whith a line (this is your context), the resource of this line is an openbrick and the quantity is 10. What is the base_price for this context ? You can look at all mapped value in your ERP5 site, then run the test method on each of them, if the result is true, you can see if the mapped value define a price. You will see later you the portal_domains tool will do all that for you. Define the Mapped Value : Here you will define value. There is two things to do. The first step is to define wich property or category you want to specify, then you have to store values. In order to tell wich properties you want to define, you have to use the method *setMappeValuePropertyList*, like this :: mapped_value.setMappedValuePropertyList(['base_price']) In order to tell wich categories you want to define, you have to use the method *setMappedValueBaseCategoryList*, like this:: mapped_value.setMappedValueBaseCategoryList(['destination']) Finally, you can store values and categories, like it is already done everywhere in ERP5, with default setters :: mapped_value.setBasePrice(34.5) mapped_value.setProperty('base_price',34.5) mapped_value.setDefaultDestination('person/111') Once values are stored, you may want to define conditions, we usually said that we will define the Predicate. Define Predicates : First, you will learn how to define conditions based on properties and then conditions based on categories. About, properties, you may want to define different types of conditions :: - equality - more than - less than - a range You first need to define what are the properties used in order to create your condition. This method is called *setCriterionPropertyList* and you can use it like this:: mapped_value.setCriterionPropertyList(['quantity']) Then, there is a method called setCriterion, defined like this :: setCriterion(self, property, identity=None, min=None, max=None, **kw) The name of arguments are quite obvious, it is easy to use, this is some examples:: quantity==4: mapped_value.setCriterion('quantity',identity=4) quantity>=4: mapped_value.setCriterion('quantity',min=4) quantity<5: mapped_value.setCriterion('quantity',max=5) 2 normal stx normal html