[Erp5-dev] additional properties for a stock object

Jérôme Perrin jerome at nexedi.com
Wed Jan 11 09:07:34 CET 2006


Le Mardi 10 Janvier 2006 16:28, Bartłomiej Górny a écrit :
> We've talked about it briefly in December - what to do if I need to add
> properties to a stock ERP5 object? I can add or modify a property sheet,
> but this means changing the code. I'd rather keep the code intact and
> make everything installable via business templates.
>
> Is there a reasonable way to achieve this? The only solution I can think
> of is set/get the attribute directly, but the documentation says "NEVER
> do that" :)
>
> The current need is the following: Polish tax form requires a complete
> address, split into street name, house number and appartment number,
> plus name of the city AND name of the post office, which is usually the
> same as city, but sometimes it is different. I need to assign these to
> the Organisation.

The easiest way is to use portal_classes (refer to kevin's tutorial about 
business template for an introduction to this tool).

1. create a new PropertySheet, name it for example "PolishAddress"

2. add some entries in _properties, like this dummy example :
    { 'id'          : 'house_number',
      'description' : 'house number',
      'type'        : 'int',
      'mode'        : 'w' },

3. make zope read this property sheet, either by restarting or clicking the 
reload button from portal_classes UI. Keep an eye on the log to check for 
errors, especially if you restarted, because if your property sheet syntax is 
invalid, the server will start but will not add this property sheet in the 
registry.

4. Associate this property sheet to the Organisation portal_types from the  
ZMI. ( portal_types/Organisation/manage_workspace )

Now, some methods are generated on Organisation documents, getHouseNumber and 
setHouseNumber .

The problem is that house_number is not a property of the Organisation itself, 
but rather a property of an Address object. Organisations have a 
`default_address` sub object. 

Rather than adding PolishAddress property sheet to the Organisation portal 
type, you should add it to the Address portal type, and create yet another 
property sheet for Organisation portal type, so that it can access directly 
the house address of it's default address using getAddressHouseNumber.

The property sheet must contain something like that :

class PolishOrganisation :
    _properties = (
       { 'id'                       : 'address'
        , 'storage_id'          : 'default_address'
        , 'description'         : 'Gives access to default address polish 
specific properties.'
        , 'type'                    : 'content'
        , 'portal_type'         : ( 'Address', )
        , 'acquired_property_id': ( 'house_number', )
        , 'mode'                : 'w'
       },
    )

Then setAddressHouseNumber is also available for Organisation, and create the 
contained Address document on demand.

If you want more information on this, I suggest you take a look at 
Products/ERP5Type/help/001-overview.stx 

-- 
Jérome



More information about the Erp5-dev mailing list