Commit 95256d9f authored by Fabien Morin's avatar Fabien Morin

- change destination, destination is now used to designe the employee :

   the employee is the destination of the social services
- change variable name base_amount_current_value_dict in base_amount_dict and
  use the share.
- use the cartesian product instead of lot of for loops. It's more efficient
  and more evolutive in the sense that it could handle new categories without
  modify the source code
- change the update of the base_participation to use the share in the
  base_amount_dict.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18102 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 884646ef
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5.Document.Invoice import Invoice from Products.ERP5.Document.Invoice import Invoice
from Products.ERP5Type.Utils import cartesianProduct
from zLOG import LOG from zLOG import LOG
class PaySheetTransaction(Invoice): class PaySheetTransaction(Invoice):
...@@ -128,11 +129,11 @@ class PaySheetTransaction(Invoice): ...@@ -128,11 +129,11 @@ class PaySheetTransaction(Invoice):
portal_type = 'Pay Sheet Line', portal_type = 'Pay Sheet Line',
title = title, title = title,
description = description, description = description,
destination = self.getSourceSection(),
source_section = \ source_section = \
self.getPortalObject().restrictedTraverse(res).getSource(), self.getPortalObject().restrictedTraverse(res).getSource(),
resource = res, resource = res,
destination_section = self.getDestinationSection(), destination_section = self.getDestinationSection(),
destination = self.getDestinationSection(),
variation_base_category_list = ('tax_category', 'salary_range'), variation_base_category_list = ('tax_category', 'salary_range'),
variation_category_list = var_cat_list, variation_category_list = var_cat_list,
base_amount_list = base_amount_list, base_amount_list = base_amount_list,
...@@ -243,8 +244,8 @@ class PaySheetTransaction(Invoice): ...@@ -243,8 +244,8 @@ class PaySheetTransaction(Invoice):
# in this dictionary will be saved the current amount corresponding to # in this dictionary will be saved the current amount corresponding to
# the tuple (tax_category, base_amount) : # the tuple (tax_category, base_amount) :
# current_amount = base_amount_current_value_dict[base_amount] # current_amount = base_amount_dict[base_amount][share]
base_amount_current_value_dict = {} base_amount_dict = {}
def sortByIntIndex(a, b): def sortByIntIndex(a, b):
return cmp(a.getIntIndex(), return cmp(a.getIntIndex(),
...@@ -269,19 +270,23 @@ class PaySheetTransaction(Invoice): ...@@ -269,19 +270,23 @@ class PaySheetTransaction(Invoice):
for paysheetcell in paysheetcell_list: for paysheetcell in paysheetcell_list:
tax_category = paysheetcell.getTaxCategory(base=1) tax_category = paysheetcell.getTaxCategory(base=1)
if tax_category and paysheetcell.getQuantity(): if tax_category and paysheetcell.getQuantity():
if base_amount_current_value_dict.has_key(base_amount): if base_amount_dict.has_key(base_amount) and \
old_val = base_amount_current_value_dict[base_amount] base_amount_dict[base_amount].has_key(tax_category):
old_val = base_amount_dict[base_amount][tax_category]
else: else:
old_val = 0 old_val = 0
new_val = old_val + paysheetcell.getQuantity() new_val = old_val + paysheetcell.getQuantity()
if not base_amount_dict.has_key(base_amount):
base_amount_dict[base_amount]={}
# increment the corresponding amount # increment the corresponding amount
base_amount_current_value_dict[base_amount] = new_val base_amount_dict[base_amount][tax_category] = new_val
# get not editables model lines # get not editables model lines
model = self.getSpecialiseValue() model = self.getSpecialiseValue()
model_line_list = model.contentValues(portal_type='Pay Sheet Model Line', model_line_list = model.contentValues(portal_type='Pay Sheet Model Line',
sort_on='int_index') sort_on='int_index')
model_line_list = [line for line in model_line_list if not line.getEditable()] model_line_list = [line for line in model_line_list \
if not line.getEditable()]
pay_sheet_line_list = [] pay_sheet_line_list = []
...@@ -305,85 +310,112 @@ class PaySheetTransaction(Invoice): ...@@ -305,85 +310,112 @@ class PaySheetTransaction(Invoice):
# description is used # description is used
else: else:
desc = ''.join(service.getDescription()) desc = ''.join(service.getDescription())
variation_share_list = model_line.getVariationCategoryList(\
base_category_list=['tax_category',])
variation_slice_list = model_line.getVariationCategoryList(\ base_category_list = model_line.getVariationBaseCategoryList()
base_category_list=['salary_range',]) list_of_list = []
for base_cat in base_category_list:
for slice in variation_slice_list: list = model_line.getVariationCategoryList(base_category_list=base_cat)
for share in variation_share_list: list_of_list.append(list)
cell = model_line.getCell(slice, share) cartesian_product = cartesianProduct(list_of_list)
if cell is None:
LOG('createNotEditablePaySheetLineList : cell is None') slice = None
continue indice = 0
# get the slice : for tuple in cartesian_product:
model_slice = model_line.getParentValue().getCell(slice) indice += 1
quantity = 0.0 cell = model_line.getCell(*tuple)
price = 0.0 if cell is None:
if model_slice is None: continue
LOG('createNotEditablePaySheetLineList : model_slice %s is None' %\
slice) tuple_dict = {}
continue for item in tuple:
# the dict key is the base category and value is the category path
tuple_dict[item.split('/')[0]] = \
self.portal_categories.restrictedTraverse(item).getTitle()
tuple_dict[item.split('/')[0]+'_relative_url']=item
#get the slice
if tuple_dict.has_key('salary_range'):
slice = tuple_dict['salary_range_relative_url']
#get the share
if tuple_dict.has_key('tax_category'):
share = tuple_dict['tax_category_relative_url']
# get the slice :
model_slice = model_line.getParentValue().getCell(slice)
quantity = 0.0
price = 0.0
model_slice_min = 0
model_slice_max = 0
if model_slice is None:
LOG('createNotEditablePaySheetLineList :', 0, 'model_slice %s is None'
% slice)
else:
model_slice_min = model_slice.getQuantityRangeMin() model_slice_min = model_slice.getQuantityRangeMin()
model_slice_max = model_slice.getQuantityRangeMax() model_slice_max = model_slice.getQuantityRangeMax()
###################### ######################
# calculation part : # # calculation part : #
###################### ######################
# get script in this order # get script in this order
# 1 - model_line script # 1 - model_line script
# 2 - model script # 2 - model script
# 3 - get the default calculation script # 3 - get the default calculation script
# get the model line script # get the model line script
script_name = model_line.getCalculationScriptId() script_name = model_line.getCalculationScriptId()
if script_name is None: if script_name is None:
# if model line script is None, get the default model script # if model line script is None, get the default model script
script_name = model.getDefaultCalculationScriptId() script_name = model.getDefaultCalculationScriptId()
if script_name is None: if script_name is None:
# if no calculation script found, use a default script : # if no calculation script found, use a default script :
script_name = 'PaySheetTransaction_defaultCalculationScript' script_name = 'PaySheetTransaction_defaultCalculationScript'
if getattr(self, script_name, None) is None: if getattr(self, script_name, None) is None:
raise ValueError, "Unable to find `%s` calculation script" % \ raise ValueError, "Unable to find `%s` calculation script" % \
script_name script_name
calculation_script = getattr(self, script_name, None) calculation_script = getattr(self, script_name, None)
quantity=0 quantity=0
price=0 price=0
#LOG('script_name :', 0, script_name) #LOG('script_name :', 0, script_name)
result = calculation_script(\ result = calculation_script(\
base_amount_current_value_dict=base_amount_current_value_dict, base_amount_dict=base_amount_dict,
model_slice_min=model_slice_min, model_slice_min=model_slice_min,
model_slice_max=model_slice_max, model_slice_max=model_slice_max,
cell=cell,) cell=cell,)
quantity = result['quantity'] quantity = result['quantity']
price = result['price'] price = result['price']
# Cell creation : # Cell creation :
# Define an empty new cell # Define an empty new cell
new_cell = { 'axe_list' : [share, slice], new_cell = { 'axe_list' : tuple, # share, slice
'quantity' : quantity, 'quantity' : quantity,
'price' : price, 'price' : price,
} }
cell_list.append(new_cell) cell_list.append(new_cell)
# update base participation
base_participation_list = service.getBaseAmountList(base=1) base_participation_list = service.getBaseAmountList(base=1)
for base_participation in base_participation_list: for base_participation in base_participation_list:
if quantity: if quantity:
if base_amount_current_value_dict.has_key(base_participation): if base_amount_dict.has_key(base_participation) and \
old_val = base_amount_current_value_dict[base_participation] base_amount_dict[base_participation].has_key(share):
old_val = base_amount_dict[base_participation][share]
else: else:
old_val = 0 old_val = 0
new_val = old_val + quantity new_val = old_val + quantity
if not base_amount_dict.has_key(base_participation):
base_amount_dict[base_participation]={}
if price: if price:
new_val = round((old_val + quantity*price), precision) new_val = round((old_val + quantity*price), precision)
base_amount_current_value_dict[base_participation] = new_val base_amount_dict[base_participation][share] = new_val
if cell_list: if cell_list:
# create the PaySheetLine # create the PaySheetLine
......
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