Online Book Reader

Home Category

Beautiful Code [253]

By Root 5334 0
and they inherit from XMLObject, which means that every object can be serialized into XML for synchronization or exporting.

Class attributes are organized into property sheets. Property sheets are configurable sets of attributes that facilitate the creation of different object views, potentially manipulated by different sets of class methods. Moreover, these views allow system administrators to set up security in a very flexible and sophisticated way.

For instance, the SimpleItem sheet bears title, short_title, and description attributes. The system administrator can set a security scheme where some users can only view these attributes, while others can write to them:

Code View: Scroll / Show All

class Movement(XMLObject):

"""

Movement of a quantity of a resource in a given variation

from a source to a destination.

"""

# defines the name of the type

meta_type = 'ERP5 Movement'

# defines the CMF type name

portal_type = 'Movement'

# adds basic Zope security configuration

add_permission = Permissions.AddPortalContent

# the type is listed as a valid content type

isPortalContent = 1

# this type is enabled for ERP5 Rapid Application Development facilities

isRADContent = 1

# used for trade and inventory operations

isMovement = 1

# Declarative security

# stores basic class's security information

security = ClassSecurityInfo()

# as default, allows authenticated users to view the object

security.declareObjectProtected(Permissions.AccessContentsInformation)

# Declarative properties

property_sheets = ( PropertySheet.Base

, PropertySheet.SimpleItem

, PropertySheet.Amount

, PropertySheet.Task

, PropertySheet.Arrow

, PropertySheet.Movement

, PropertySheet.Price

)

The third level holds the Meta classes, which are instantiable classes. At this tier, classes already represent specific business entities:

Code View: Scroll / Show All

class DeliveryLine(Movement):

"""

A DeliveryLine object allows lines to be implemented in

Deliveries (packing list, order, invoice etc).

It may include a price (for insurance, for customs, for invoices,

for orders etc).

"""

meta_type = 'ERP5 Delivery Line'

portal_type = 'Delivery Line'

# Declarative properties

# it is necessary the overload the property_sheets property

# inherited from Movement

property_sheets = ( PropertySheet.Base

, PropertySheet.XMLObject

, PropertySheet.CategoryCore

, PropertySheet.Amount

, PropertySheet.Task

, PropertySheet.Arrow

, PropertySheet.Movement

, PropertySheet.Price

, PropertySheet.VariationRange

, PropertySheet.ItemAggregation

, PropertySheet.SortIndex

)

Finally, at the fourth level are the Portal classes, which are CMF-based. This is the level at which configuration takes place. For instance, Figure 21-2 shows the main part of the Properties tab. This screenshot shows, in particular, the properties of Task Report Line. This type is an implementation of the Delivery Line Meta type. It is interesting to note that new property sheets can be added at this tab, but they are not needed for our project tool.

Figure 21-2. Properties tab

Figure 21-3 shows the Actions tab, listing actions associated with the Task Report Line type. Actions implement specific services for this type. In the figure, you can see the View and Print services.

Figure 21-3. Actions tab

The four-level structure representing system classes makes it easy to add functionality and platform features incrementally. It also allows a practice that is very common in ERP5: implementing new portal types without creating new classes in the system. All the programmer has to do is change the appearance of one, because ERP5's core concepts can represent entities of specific business domains.

For instance, a Movement can be used to represent both a cash withdrawal in the finances module and a transference of material from the warehouse to the factory in the inventory module. To do so, we create one portal type to represent a cash

Return Main Page Previous Page Next Page

®Online Book Reader