##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
#
# 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 proopgram 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.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import WorkflowMethod
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5.Document.Delivery import Delivery
from Products.ERP5Type.Document.DeliveryCell import DeliveryCell
from Products.ERP5.Document.Movement import Movement
from Products.ERP5.Document.Container import Container
from Products.ERP5.Document.AccountingTransaction import AccountingTransaction
from AccessControl.PermissionRole import PermissionRole
from Products.ERP5Type.Utils import convertToMixedCase, convertToUpperCase
from Products.ERP5Banking.BaobabMixin import BaobabMixin

class BankingOperation(BaobabMixin, AccountingTransaction):

  # CMF Type Definition
  meta_type = 'ERP5Banking Banking Operation'
  portal_type = 'Banking Operation'
  isPortalContent = 1
  isRADContent = 1

  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.View)

  # Default Properties
  property_sheets = ( PropertySheet.Base
                    , PropertySheet.XMLObject
                    , PropertySheet.CategoryCore
                    , PropertySheet.DublinCore
                    , PropertySheet.Task
                    , PropertySheet.Arrow
                    , PropertySheet.BankingOperation
                    , PropertySheet.ItemAggregation
                    , PropertySheet.Amount
                    )


### Dynamic patch
Delivery.getBaobabSourceUid = lambda x: x.getSourceUid()
Delivery.getBaobabSourceUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabDestinationUid = lambda x: x.getDestinationUid()
Delivery.getBaobabDestinationUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabSourceSectionUid = lambda x: x.getSourceSectionUid()
Delivery.getBaobabSourceSectionUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabDestinationSectionUid = lambda x: x.getDestinationSectionUid()
Delivery.getBaobabDestinationSectionUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabSourcePaymentUid = lambda x: x.getSourcePaymentUid()
Delivery.getBaobabSourcePaymentUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabDestinationPaymentUid = lambda x: x.getDestinationPaymentUid()
Delivery.getBaobabDestinationPaymentUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabSourceFunctionUid = lambda x: x.getSourceFunctionUid()
Delivery.getBaobabSourceFunctionUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabDestinationFunctionUid = lambda x: x.getDestinationFunctionUid()
Delivery.getBaobabDestinationFunctionUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabSourceProjectUid = lambda x: x.getSourceProjectUid()
Delivery.getBaobabSourceProjectUid__roles__ = PermissionRole(Permissions.View)

Delivery.getBaobabDestinationProjectUid = lambda x: x.getDestinationProjectUid()
Delivery.getBaobabDestinationProjectUid__roles__ = PermissionRole(Permissions.View)

### Overload Movement
Movement.getBaobabSourceUid = lambda x: x.getSourceUid()
Movement.getBaobabSourceUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabDestinationUid = lambda x: x.getDestinationUid()
Movement.getBaobabDestinationUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabSourceSectionUid = lambda x: x.getSourceSectionUid()
Movement.getBaobabSourceSectionUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabDestinationSectionUid = lambda x: x.getDestinationSectionUid()
Movement.getBaobabDestinationSectionUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabSourcePaymentUid = lambda x: x.getSourcePaymentUid()
Movement.getBaobabSourcePaymentUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabDestinationPaymentUid = lambda x: x.getDestinationPaymentUid()
Movement.getBaobabDestinationPaymentUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabSourceFunctionUid = lambda x: x.getSourceFunctionUid()
Movement.getBaobabSourceFunctionUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabDestinationFunctionUid = lambda x: x.getDestinationFunctionUid()
Movement.getBaobabDestinationFunctionUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabSourceProjectUid = lambda x: x.getSourceProjectUid()
Movement.getBaobabSourceProjectUid__roles__ = PermissionRole(Permissions.View)

Movement.getBaobabDestinationProjectUid = lambda x: x.getDestinationProjectUid()
Movement.getBaobabDestinationProjectUid__roles__ = PermissionRole(Permissions.View)

### Acquire Baobab source / destination uids from parent line
DeliveryCell.getBaobabSourceUid = lambda x: x.getSourceUid()
DeliveryCell.getBaobabSourceUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabDestinationUid = lambda x: x.getDestinationUid()
DeliveryCell.getBaobabDestinationUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabSourceSectionUid = lambda x: x.getSourceSectionUid()
DeliveryCell.getBaobabSourceSectionUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabDestinationSectionUid = lambda x: x.getDestinationSectionUid()
DeliveryCell.getBaobabDestinationSectionUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabSourcePaymentUid = lambda x: x.getSourcePaymentUid()
DeliveryCell.getBaobabSourcePaymentUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabDestinationPaymentUid = lambda x: x.getDestinationPaymentUid()
DeliveryCell.getBaobabDestinationPaymentUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabSourceFunctionUid = lambda x: x.getSourceFunctionUid()
DeliveryCell.getBaobabSourceFunctionUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabDestinationFunctionUid = lambda x: x.getDestinationFunctionUid()
DeliveryCell.getBaobabDestinationFunctionUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabSourceProjectUid = lambda x: x.getSourceProjectUid()
DeliveryCell.getBaobabSourceProjectUid__roles__ = PermissionRole(Permissions.View)

DeliveryCell.getBaobabDestinationProjectUid = lambda x: x.getDestinationProjectUid()
DeliveryCell.getBaobabDestinationProjectUid__roles__ = PermissionRole(Permissions.View)



### Dynamic patch
Container.getBaobabSourceUid = lambda x: x.getSourceUid()
Container.getBaobabSourceUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabDestinationUid = lambda x: x.getDestinationUid()
Container.getBaobabDestinationUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabSourceSectionUid = lambda x: x.getSourceSectionUid()
Container.getBaobabSourceSectionUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabDestinationSectionUid = lambda x: x.getDestinationSectionUid()
Container.getBaobabDestinationSectionUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabSourcePaymentUid = lambda x: x.getSourcePaymentUid()
Container.getBaobabSourcePaymentUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabDestinationPaymentUid = lambda x: x.getDestinationPaymentUid()
Container.getBaobabDestinationPaymentUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabSourceFunctionUid = lambda x: x.getSourceFunctionUid()
Container.getBaobabSourceFunctionUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabDestinationFunctionUid = lambda x: x.getDestinationFunctionUid()
Container.getBaobabDestinationFunctionUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabSourceProjectUid = lambda x: x.getSourceProjectUid()
Container.getBaobabSourceProjectUid__roles__ = PermissionRole(Permissions.View)

Container.getBaobabDestinationProjectUid = lambda x: x.getDestinationProjectUid()
Container.getBaobabDestinationProjectUid__roles__ = PermissionRole(Permissions.View)