Online Book Reader

Home Category

Beautiful Code [255]

By Root 5350 0
These classes, also part of the UBM, are containers for Order Line and Delivery Line objects, which in turn are Movements that contain ordered and delivered items, as shown in Figure 21-4. In that figure, the subclasses at the lowest level are all portal types. Therefore, they have basically the same structure as their superclasses, but each portal type has a different GUI and modifications in its workflow to act according to project management logic.

Figure 21-4. Relations between Trade and Project

The relation between Order and Delivery is maintained by causalities, which basically determine that for every confirmed order there will be a mirroring delivery sometime in the future. Tasks and task reports inherit the same behavior. Accordingly, order lines represent planned movements of resources between two nodes, which, after being confirmed, will be executed and generate delivery lines. Therefore, from a project management point of view, tasks implement project planning, and task reports implement project control.

ERP5: Designing for Maximum Adaptability > Coding the ERP5 Project

21.5. Coding the ERP5 Project

The first thing we thought about in creating the Project BT was the main project class. Initially, instead of creating a new class, we decided to simply use Order itself, without change. But after some time, we realized that the business definitions for an order and a project are so different that we should simply create Project as a subclass of Order, without any new code in it, just for the sake of separating concerns. In this design, a project is an object that is described by a series of goals or milestones with one or more tasks associated with each of them.

Then, we had to decide how to implement task management since there are differences between a project and a trade operation. The first thing to consider is that tasks can occur outside projects—for instance, in production planning. Therefore, we consider a task as a composition of task lines, or smaller activities inside a task. In that way, we decouple tasks from projects, allowing them to be used in other situations, while keeping the relation with Project through source_project and destination_project base categories.

Tasks are implemented through configuration, as we did for Task Report Line in Figure 21-2, with the difference of using Order as a metaclass. The creation of a task associated with a project is shown here:

Code View: Scroll / Show All

# Add a task in task_module. Context represents the current project object.

context_obj = context.getObject()

# newContent is an ERP5 API method that creates a new content.

task = context.task_module.newContent(portal_type = 'Task')

# Set the source_project reference to the task.

task.setSourceProjectValue(context_obj)

# Redirect the user to Task GUI, so that the user can edit its properties.

return context.REQUEST.RESPONSE.redirect(task.absolute_url() + '?portal_status_

message=Created+Task.')

Remember that for retrieving the tasks of a certain project, the programmer needs to use only the base category source_project. With this category, ERP5 RAD automatically generates signatures and algorithms of accessors. It is interesting to note that the same accessors will be created for both Task and Project. The programmer decides which ones to use through configuration, using the Actions tab shown in Figure 21-3. In that tab, the programmer can define a new GUI for using the following methods:

### These accessors are used to navigate from task to project

# This method returns the related Project reference

getSourceProject()

# This method sets the related Project reference

setSourceProject()

# This method returns the related Project object

getSourceProjectValue()

# This method sets the related Project object

setSourceProjectValue()

### These accessors are used to navigate from project to task

# This method returns references to related tasks

getSourceProjectRelated()

# This method is not generated in order to avoid an encapsulation break

Return Main Page Previous Page Next Page

®Online Book Reader