Commit dc26ced4 authored by Rafael Monnerat's avatar Rafael Monnerat

ERP5 Configurator Product initial commit.

ERP5 Configurator allows developer creates configuration wizards for configure an ERP5 Instance. 


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41680 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c12fa76d
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class AccountConfiguratorItem(ConfiguratorItemMixin, XMLObject):
""" Setup an Accounting Account. """
meta_type = 'ERP5 Account Configurator Item'
portal_type = 'Account Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Account )
def build(self, business_configuration):
portal = self.getPortalObject()
account_module = portal.account_module
extra_kw = {}
account_id = getattr(self, 'account_id', None)
if account_id:
# XXX FIXME This cause conflict when use configuration
# more then once.
#extra_kw['id'] = account_id
pass
account = account_module.newContent(
portal_type='Account',
title=self.getTitle(),
account_type=self.getAccountType(),
gap=self.getGap(),
financial_section=self.getFinancialSection(),
credit_account=self.isCreditAccount(),
description=self.getDescription(),
**extra_kw)
## add to customer template
self.install(account, business_configuration)
##############################################################################
#
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
# Jerome Perrin <jerome@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class AccountingPeriodConfiguratorItem(ConfiguratorItemMixin, XMLObject):
""" Setup an Accounting Period. """
meta_type = 'ERP5 Accounting Period Configurator Item'
portal_type = 'Accounting Period Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Task )
def build(self, business_configuration):
portal = self.getPortalObject()
organisation_id = business_configuration.\
getGlobalConfigurationAttr('organisation_id')
organisation = portal.organisation_module._getOb(organisation_id)
period = organisation.newContent(
portal_type='Accounting Period',
start_date=self.getStartDate(),
stop_date=self.getStopDate(),
short_title=self.getShortTitle(),
title=self.getTitle())
# no need to 'install' in the business template, because it's contain as
# subobject of an organisation we already added.
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2008 Nexedi SARL and Contributors. All Rights Reserved.
# Yoshinori Okuji <yo@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class CatalogKeywordKeyConfiguratorItem(ConfiguratorItemMixin, XMLObject):
"""Set up catalog keyword keys."""
meta_type = 'ERP5 Catalog Keyword Key Configurator Item'
portal_type = 'Catalog Keyword Key Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def build(self, business_configuration):
portal = self.getPortalObject()
catalog = portal.portal_catalog.getSQLCatalog()
key_list = list(catalog.getProperty('sql_catalog_keyword_search_keys', ()))
for k in self.key_list:
if k not in key_list:
key_list.append(k)
key_list = tuple(key_list)
catalog._setPropValue('sql_catalog_keyword_search_keys', key_list)
bt = business_configuration.getSpecialiseValue()
bt.edit(template_catalog_keyword_key_list=key_list)
##############################################################################
#
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
# Jerome Perrin <jerome@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from StringIO import StringIO
from Acquisition import aq_base
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class UnrestrictedStringIO(StringIO):
__allow_access_to_unprotected_subobjects__ = 1
class CategoriesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObject):
"""Import a categories spreadsheet.
"""
meta_type = 'ERP5 Categories Spreadsheet Configurator Item'
portal_type = 'Categories Spreadsheet Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.CategoriesSpreadsheetConfiguratorItem
)
def build(self, business_configuration):
portal = self.getPortalObject()
ctool = portal.portal_categories
self._readSpreadSheet()
cache = self._category_cache
for bc_id, category_list in cache.items():
if bc_id in ctool.objectIds():
bc = ctool._getOb(bc_id)
else:
# TODO: test bc creation
# the bc should be added as base category in bt5 ?
bc = ctool.newContent(id=bc_id)
for category_info in category_list:
path = bc
for cat in category_info['path'].split("/")[1:]:
if not cat in path.objectIds():
path = path.newContent(
portal_type='Category',
id=cat,)
else:
path = path[cat]
edit_dict = category_info.copy()
edit_dict.pop('path')
path.edit(**edit_dict)
## add to customer template
self.install(path, business_configuration)
def _readSpreadSheet(self):
"""Read the spreadsheet and prepare internal category cache.
"""
aq_self = aq_base(self)
if getattr(aq_self, '_category_cache', None) is None:
# TODO use a invalid_spreadsheet_error_handler to report invalid
# spreadsheet messages (see http://svn.erp5.org?rev=24908&view=rev )
aq_self._category_cache = self.Base_getCategoriesSpreadSheetMapping(
UnrestrictedStringIO(self.getDefaultCategoriesSpreadsheetData()))
security.declareProtected(Permissions.ModifyPortalContent,
'setDefaultCategoriesSpreadsheetFile')
def setDefaultCategoriesSpreadsheetFile(self, *args, **kw):
"""Reset the spreadsheet cache."""
self._setDefaultCategoriesSpreadsheetFile(*args, **kw)
self._category_cache = None
self.reindexObject()
security.declareProtected(Permissions.ModifyPortalContent,
'setCategoriesSpreadsheetFile')
setCategoriesSpreadsheetFile = setDefaultCategoriesSpreadsheetFile
security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryTitleItemList')
def getCategoryTitleItemList(self, base_category_id, base=0):
"""Returns title item list for a base category contained in this
spreadsheet.
"""
self._readSpreadSheet()
cache = self._category_cache
result = [('', '')]
if base_category_id not in cache:
return result # TODO: return some kind of default. Where is this
# default ??? configurator_%s % base_category_id ?
# If we add default here, it should also be used in build
# ...
category_path_dict = dict()
for item in cache[base_category_id]:
category_path_dict[item['path']] = item
for item in cache[base_category_id]:
# the first item in this list is the base category itself, so we skip it.
if item['path'] == base_category_id:
continue
# recreate logical path
path_element_list = []
title_list = []
for path_element in item['path'].split('/'):
path_element_list.append(path_element)
title_list.append(category_path_dict['/'.join(path_element_list)]['title'])
if base:
result.append(('/'.join(title_list[1:]), item['path']))
else:
result.append(('/'.join(title_list[1:]),
'/'.join(item['path'].split('/')[1:])))
return result
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class CategoryConfiguratorItem(ConfiguratorItemMixin, XMLObject):
"""This class is meta build step for customization of ERP5 site."""
meta_type = 'ERP5 Category Configurator Item'
portal_type = 'Category Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore)
def build(self, business_configuration):
portal = self.getPortalObject()
category_root = portal.portal_categories[self.category_root]
object_id = self.object_id
if object_id in category_root.objectIds():
category_root.manage_delObjects(object_id)
category = category_root.newContent(portal_type='Category',
id = object_id,
title = self.getTitle())
## add to customer template
self.install(category, business_configuration)
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Romain Courteaud <romain@nexedi.com>
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.Path import Path
class ConfigurationSave(Path):
""" This class is the base class for all template items. """
portal_type = 'Configuration Save'
meta_type = 'ERP5 Configuration Save'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.SortIndex )
def addConfigurationItem(self, configuration_item_class_name, **kw):
""" Add new configuration item. """
## remove manually specified a configration title
if kw.has_key('conf_title'):
self.setTitle(kw['conf_title'])
kw.pop('conf_title')
conf_item = self.newContent(portal_type = configuration_item_class_name, **kw)
return conf_item
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class CurrencyConfiguratorItem(ConfiguratorItemMixin, XMLObject):
""" Setup currency. """
meta_type = 'ERP5 Currency Configurator Item'
portal_type = 'Currency Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Price
, PropertySheet.Resource
, PropertySheet.Reference )
def build(self, business_configuration):
portal = self.getPortalObject()
currency_module = portal._getOb('currency_module')
title = self.getTitle()
reference = self.getReference()
base_unit_quantity = self.getBaseUnitQuantity()
# XXX FIXME This is not exactly desired behaviour
currency = self.portal_catalog.getResultValue(id=reference,
portal_type="Currency")
if currency is None:
currency = currency_module.newContent(portal_type = "Currency",
id = reference,
title = title,
reference = reference,
base_unit_quantity = base_unit_quantity)
## add to customer template
self.install(currency, business_configuration)
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.CMFCore.utils import getToolByName
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class CustomerBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject):
""" Create a new bt5 for customer configuration.
This business template is not installed locally, only build.
"""
meta_type = 'ERP5 Customer BT5 Configurator Item'
portal_type = 'Customer BT5 Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def build(self, business_configuration):
template_tool = getToolByName(self.getPortalObject(),
'portal_templates')
bt5 = template_tool.newContent(portal_type="Business Template", \
title=self.bt5_id)
## ..and set it as current
business_configuration.setSpecialise(bt5.getRelativeUrl())
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Ivan Tyagov <ivan@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.CMFCore.utils import getToolByName
from Products.ERP5Configurator.mixin.configurator_item import ConfiguratorItemMixin
class ExportCustomerBT5ConfiguratorItem(XMLObject, ConfiguratorItemMixin):
""" Create a new bt5 for customer configuration. """
meta_type = 'ERP5 Export Customer BT5 Configurator Item'
portal_type = 'Export Customer BT5 Configurator Item'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()