Commit d902cc55 authored by Guillaume Michon's avatar Guillaume Michon

Moved "immobilisation movement" code to ImmobilisationMovement.py


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5891 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f4e89c72
......@@ -36,17 +36,18 @@ from Products.CMFCore.WorkflowCore import WorkflowMethod
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Amount import Amount
from Products.ERP5.Document.Movement import Movement
from Products.ERP5.Document.Delivery import Delivery
from string import capitalize
from zLOG import LOG
class Immobilisation(Movement, XMLObject):
class Immobilisation(XMLObject, Delivery):
"""
An Immobilisation object holds the information about
an accounting immobilisation (in order to amortise an object)
It is an instant movement without source or destination, but which
implies a state change and a source_decision and a source_destination
implies a state change and a source_decision and a destination_decision
Do not index in stock table
"""
meta_type = 'ERP5 Immobilisation'
......@@ -54,7 +55,7 @@ class Immobilisation(Movement, XMLObject):
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
isMovement = 1
isMovement = 0
# Declarative security
security = ClassSecurityInfo()
......@@ -78,318 +79,10 @@ class Immobilisation(Movement, XMLObject):
, PropertySheet.Amortisation
)
# Factory Type Information
factory_type_information = \
{ 'id' : portal_type
, 'meta_type' : meta_type
, 'description' : """\
An Immobilisation object holds the information about
an accounting immobilisation (in order to amortise an object)
"""
, 'icon' : 'segment_icon.gif'
, 'product' : 'ERP5'
, 'factory' : 'addImmobilisation'
, 'immediate_view' : 'predicate_view'
, 'actions' :
( { 'id' : 'view'
, 'name' : 'View'
, 'category' : 'object_view'
, 'action' : 'predicate_view'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'print'
, 'name' : 'Print'
, 'category' : 'object_print'
, 'action' : 'segment_print'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'metadata'
, 'name' : 'Metadata'
, 'category' : 'object_view'
, 'action' : 'metadata_edit'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'translate'
, 'name' : 'Translate'
, 'category' : 'object_action'
, 'action' : 'segment_view'
, 'permissions' : (
Permissions.TranslateContent, )
}
)
}
security.declareProtected(Permissions.View, 'getDefaultDurability')
def getDefaultDurability(self, **kw):
"""
Returns a calculated value of the remaining durability
of the item at the immobilisation movement date
"""
item = self.getParent()
current_date = self.getStopDate()
if current_date is None or item is None:
return None
return item.getRemainingDurability(current_date, from_immobilisation=1, **kw)
security.declareProtected(Permissions.View, 'getDurabilityOrDefaultDurability')
def getDurabilityOrDefaultDurability(self, **kw):
"""
Returns the remaining durability.
If it is None, returns the default durability
"""
durability = self.getDurability()
if durability is None:
durability = self.getDefaultDurability(**kw)
return durability
security.declareProtected(Permissions.View, 'getDefaultAmortisationDuration')
def getDefaultAmortisationDuration(self, **kw):
"""
Returns a calculated value of amortisation duration
at the immobilisation movement date
"""
item = self.getParent()
current_date = self.getStopDate()
if current_date is None or item is None:
return None
return item.getRemainingAmortisationDuration(current_date, from_immobilisation=1, **kw)
security.declareProtected(Permissions.View, 'getAmortisationOrDefaultAmortisationDuration')
def getAmortisationOrDefaultAmortisationDuration(self, **kw):
"""
Returns the remaining amortisation duration.
If it is None, returns the default remaining amortisation duration.
"""
amortisation_duration = self.getAmortisationDuration()
if amortisation_duration is None:
amortisation_duration = self.getDefaultAmortisationDuration(**kw)
return amortisation_duration
security.declareProtected(Permissions.ModifyPortalContent, 'getDefaultAmortisationPrice')
def getDefaultAmortisationPrice(self, with_currency=0, **kw):
"""
Returns a calculated value of amortisation value
at the immobilisation movement date
"""
item = self.getParent()
current_date = self.getStopDate()
if current_date is None or item is None:
return None
returned_value = item.getAmortisationPrice(current_date, from_immobilisation=1, with_currency=with_currency, **kw)
return returned_value
security.declareProtected(Permissions.View, 'getAmortisationOrDefaultAmortisationPrice')
def getAmortisationOrDefaultAmortisationPrice(self, with_currency=0, **kw):
"""
Returns the amortisation value.
If it is None, returns the default amortisation value.
"""
amortisation_price = self.getAmortisationStartPrice()
if amortisation_price is None:
amortisation_price = self.getDefaultAmortisationPrice(with_currency=with_currency, **kw)
return amortisation_price
security.declarePrivate('_checkConsistency')
def _checkConsistency(self, fixit=0, mapped_value_property_list=()):
relative_url = self.getRelativeUrl()
def checkValue(property_dict):
"""
property_dict must have the following format :
{ "property_name" : { "values" : [list of forbidden values], "message" :
["type of error", degree, "Error message"] },
...
}
"""
errors = []
for property in property_dict.keys():
getter = getattr(self, "get" + ''.join( [capitalize(x) for x in property.split("_")] ), None)
if getter is None:
errors += [(relative_url, "Accessor inconsistency", 100, "No accessor for property %s" % property)]
else:
property_value = getter()
forbidden_value_list = property_dict[property]["values"]
if property_value in forbidden_value_list:
message = property_dict[property]["message"]
errors += [(relative_url, message[0], message[1], message[2])]
return errors
errors = []
# Checks common to every amortisation method
errors.extend( checkValue( { "parent" : { "values": [None], "message":
[ "Property value inconsistency", 100,
"The immobilisation movement does not apply on an item" ] },
"stop_date" : { "values": [None], "message":
[ "Property value inconsistency", 100,
"Date property is empty" ] },
"durability": { "values": [None], "message":
[ "Property value inconsistency", 100,
"Durability property is empty" ] },
} ) )
if self.getImmobilisation():
errors.extend( checkValue( { "amortisation_duration" : { "values" : [None], "message":
[ "Property value inconsistency", 100,
"Amortisation duration property is empty"] },
"amortisation_start_price" : { "values" : [None], "message":
[ "Property value inconsistency", 100,
"Amortisation price property is empty"] },
"amortisation_method" : { "values" : [None, ""], "message":
[ "Property value inconsistency", 100,
"No amortisation method"] },
"vat" : { "values" : [None], "message":
[ "Property value inconsistency", 100,
"VAT Amount property is empty"] },
"section_value" : { "values" : [None], "message":
[ "Property value inconsistency", 100,
"The corresponding item does not belong to an organisation at this date"] },
"disposal_price" : { "values": [None], "message":
[ "Property value inconsistency", 100,
"Disposal price property is empty" ] },
"price_currency" : { "values" : [None], "message":
[ "Property value inconsistency", 100,
"The organisation which owns the item at this date has no amortisation currency"]
} } ) )
for (account, text) in ( (self.getInputAccount() , "Input Account"),
(self.getOutputAccount() , "Output Account"),
(self.getImmobilisationAccount(), "Immobilisation Account"),
(self.getAmortisationAccount() , "Amortisation Account"),
(self.getDepreciationAccount() , "Deprecisation Account"),
(self.getVatAccount() , "VAT Account") ):
if account is None or account is "":
errors += [(relative_url, "Property value inconsistency", 100, text + ' property is empty')]
section = self.getSectionValue()
if section is not None:
financial_date = section.getFinancialYearStopDate()
if financial_date is None:
errors += [(relative_url, "Property value inconsistency", 100,
"The organisation which owns the item at this date has no financial year end date")]
# Checks specific to each amortisation method
if self.getAmortisationMethod():
specific_parameter_list = self.getAmortisationMethodParameter("specific_parameter_list")["specific_parameter_list"]
for parameter in specific_parameter_list:
errors.extend( checkValue( { parameter : { "values" : [None], 'message':
["Property value inconsistency", 100,
"%s property is empty" % parameter ] } } ) )
if errors:
LOG("errors :", 0, repr(errors))
return errors
security.declareProtected(Permissions.View, 'getSectionValue')
def getSectionValue(self):
"""
Returns the organisation which owns the item on which the
immobilisation movement applies, at the time of the immobilisation
movement
See Item.getSectionValue for more details
"""
item = self.getParent()
date = self.getStopDate()
if item is None or date is None:
return None
return item.getSectionValue(at_date = date)
security.declareProtected(Permissions.View, 'getSectionTitle')
def getSectionTitle(self):
"""
Returns the name of the organisation which owns the
item on which the immobilisation movement applies, at the
time of the immobilisation movement
"""
section = self.getSectionValue()
if section is None:
return None
return section.getTitle()
security.declareProtected(Permissions.View, 'getPriceCurrency')
def getPriceCurrency(self):
"""
Returns the used currency id for this particular immobilisation movement
security.declareProtected(Permissions.View, 'isMovement')
def isMovement(self, **kw):
"""
section = self.getSectionValue()
if section is not None:
return section.getSocialCapitalCurrencyId()
return None
security.declareProtected(Permissions.View, 'checkImmobilisationConsistency')
def checkImmobilisationConsistency(self, *args, **kw):
"""
Checks the consistency about immobilisation values
"""
return self._checkConsistency(*args, **kw)
security.declareProtected(Permissions.View, 'getAmortisationMethodParameter')
def getAmortisationMethodParameter(self, parameter_list):
"""
Returns a dictionary containing the value of each parameter
whose name is given in parameter_list.
The value is get from the amortisation method parameter folder
(e.g. portal_skins/erp5_immobilisation/eu/linear)
This folder has specifical parameters needed for calculation
"""
if type(parameter_list) == type(""):
parameter_list = [parameter_list]
parameter_dict = {}
for parameter in parameter_list:
parameter_dict[parameter] = None
amortisation_method = self.getAmortisationMethod()
parameter_object = self.restrictedTraverse("erp5_accounting_" + amortisation_method)
if parameter_object is not None:
for parameter in parameter_list:
parameter_dict[parameter] = getattr(parameter_object, parameter, None)
return parameter_dict
security.declareProtected(Permissions.View, 'isUsingAmortisationMethod')
def isUsingAmortisationMethod(self, method):
An Immobilisation must not be indexed in stock table, so it is not a Movement
"""
Return true if this item is using the given method
"""
if self.getAmortisationMethod() == method:
return 1
return 0
security.declareProtected(Permissions.View, 'isUsingEuLinearAmortisationMethod')
def isUsingEuLinearAmortisationMethod(self):
"""
Return true if this item is using this method
"""
return self.isUsingAmortisationMethod('eu/linear')
security.declareProtected(Permissions.View, 'isUsingFrDegressiveAmortisationMethod')
def isUsingFrDegressiveAmortisationMethod(self):
"""
Return true if this item is using this method
"""
return self.isUsingAmortisationMethod('fr/degressive')
security.declareProtected(Permissions.View, 'isUsingFrActualUseAmortisationMethod')
def isUsingFrActualUseAmortisationMethod(self):
"""
Return true if this item is using this method
"""
return self.isUsingAmortisationMethod('fr/actual_use')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment