Commit 91b1f311 authored by Fabien Morin's avatar Fabien Morin

- change the method for saving the current base_amount, now it used a simple

  dict instead of the hard-to-understand previous method and list of lists
- change parameters passed to the model_line script and remove parts that are
  now in this script


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17754 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3726df26
...@@ -251,39 +251,11 @@ class PaySheetTransaction(Invoice): ...@@ -251,39 +251,11 @@ class PaySheetTransaction(Invoice):
# Get Precision # Get Precision
precision = self.getPriceCurrencyValue().getQuantityPrecision() precision = self.getPriceCurrencyValue().getQuantityPrecision()
def getDictList(category_list):
''' # in this dictionary will be saved the current amount corresponding to
This method return a list of dict wich are composed with the given # the tuple (tax_category, base_amount) :
category as key and an integer as value. It's used to find datas # current_amount = base_amount_table[(tax_category, base_amount)]
in a two-dimensional table base_amount_table = {}
'''
list_of_dict = []
for category in category_list:
base_amount_list=[x.getRelativeUrl() for x in\
self.portal_categories[category].objectValues()]
list_of_dict.append(dict([[base, base_amount_list.index(base)] \
for base in base_amount_list]))
return list_of_dict
def getEmptyTwoDimentionalTable(nb_columns=0, nb_rows=0):
'''
create a two-dimentional table with nb_columns columns and nb_rows rows
all item of this table are set to None
ex : with nb_columns=2 and nb_rows=4, this function returns :
[[None, None, None, None], [None, None, None, None]]
'''
base_amount = []
for i in range(nb_columns):
line = []
for j in range(nb_rows):
line.append(None)
base_amount.append(line)
return base_amount
# this dict permit to have the index of the category in the table
column, row = getDictList(['tax_category', 'base_amount'])
base_amount_table = getEmptyTwoDimentionalTable(nb_columns=len(column),
nb_rows=len(row))
def sortByIntIndex(a, b): def sortByIntIndex(a, b):
return cmp(a.getIntIndex(), return cmp(a.getIntIndex(),
...@@ -303,20 +275,17 @@ class PaySheetTransaction(Invoice): ...@@ -303,20 +275,17 @@ class PaySheetTransaction(Invoice):
service = paysheetline.getResourceValue() service = paysheetline.getResourceValue()
base_amount_list = service.getBaseAmountList(base=1) base_amount_list = service.getBaseAmountList(base=1)
for base_amount in base_amount_list: for base_amount in base_amount_list:
if not row.has_key(base_amount):
raise ValueError, "Unable to find `%s` base_amount category" % \
base_amount
paysheetcell_list = paysheetline.contentValues(portal_type = \ paysheetcell_list = paysheetline.contentValues(portal_type = \
['Pay Sheet Cell']) ['Pay Sheet Cell'])
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():
old_val = base_amount_table[column[tax_category]][row[base_amount]] if base_amount_table.has_key((tax_category, base_amount)):
if old_val is not None: old_val = base_amount_table[(tax_category, base_amount)]
new_val = old_val + paysheetcell.getQuantity() else:
else: old_val = 0
new_val = paysheetcell.getQuantity() new_val = old_val + paysheetcell.getQuantity()
base_amount_table[column[tax_category]][row[base_amount]] = new_val base_amount_table[(tax_category, base_amount)] = new_val
# get not editables model lines # get not editables model lines
model = self.getSpecialiseValue() model = self.getSpecialiseValue()
...@@ -353,20 +322,8 @@ class PaySheetTransaction(Invoice): ...@@ -353,20 +322,8 @@ class PaySheetTransaction(Invoice):
base_category_list=['salary_range',]) base_category_list=['salary_range',])
for share in variation_share_list: for share in variation_share_list:
base_application = None
for slice in variation_slice_list: for slice in variation_slice_list:
#get the amount of application for this line
base_application_list = model_line.getBaseAmountList(base=1)
if base_application is None:
base_application = 0
for base in model_line.getBaseAmountList(base=1):
if base_amount_table[column[share]][row[base]] is not None:
base_application += \
base_amount_table[column[share]][row[base]]
cell = model_line.getCell(slice, share) cell = model_line.getCell(slice, share)
if cell is not None: if cell is not None:
# get the slice : # get the slice :
model_slice = None model_slice = None
...@@ -376,8 +333,6 @@ class PaySheetTransaction(Invoice): ...@@ -376,8 +333,6 @@ class PaySheetTransaction(Invoice):
if model_slice is not None: if model_slice is not None:
model_slice_min = model_slice.getQuantityRangeMin() model_slice_min = model_slice.getQuantityRangeMin()
model_slice_max = model_slice.getQuantityRangeMax() model_slice_max = model_slice.getQuantityRangeMax()
quantity = cell.getQuantity()
price = cell.getPrice()
###################### ######################
# calculation part : # # calculation part : #
...@@ -397,13 +352,14 @@ class PaySheetTransaction(Invoice): ...@@ -397,13 +352,14 @@ class PaySheetTransaction(Invoice):
script_name script_name
LOG('script_name :',0,script_name) LOG('script_name :',0,script_name)
calculation_script = getattr(self, script_name, None) calculation_script = getattr(self, script_name, None)
quantity, price = calculation_script(\ result = calculation_script(\
base_application=base_application, base_amount_table=base_amount_table,
model_slice_min = model_slice_min, share=share,
model_slice_min=model_slice_min,
model_slice_max=model_slice_max, model_slice_max=model_slice_max,
quantity=quantity, cell=cell,)
price=price, quantity = result['quantity']
model_line=model_line) price = result['price']
# Cell creation : # Cell creation :
# Define an empty new cell # Define an empty new cell
...@@ -424,21 +380,17 @@ class PaySheetTransaction(Invoice): ...@@ -424,21 +380,17 @@ class PaySheetTransaction(Invoice):
# update base participation # 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:
old_val = \
base_amount_table[column[share]][row[base_participation]]
if quantity: if quantity:
if old_val is not None: if base_amount_table.has_key((share, base_participation)):
new_val = old_val + quantity old_val = base_amount_table[(share, base_participation)]
else: else:
new_val = quantity old_val = 0
new_val = old_val + quantity
if price: if price:
if old_val is not None: if old_val != 0:
new_val = round((old_val + quantity*price), precision) new_val = round((old_val + quantity*price), precision)
base_amount_table[column[share]][row[base_participation]]= \ base_amount_table[(share, base_participation)] = new_val
new_val
base_amount_table[column[share]][row[base_participation]] = \
new_val
if cell_list: if cell_list:
# create the PaySheetLine # create the PaySheetLine
...@@ -457,7 +409,6 @@ class PaySheetTransaction(Invoice): ...@@ -457,7 +409,6 @@ class PaySheetTransaction(Invoice):
# lines # lines
localized_add_end_line_script = getattr(self, localized_add_end_line_script = getattr(self,
'PaySheetTransaction_postCalculation', None) 'PaySheetTransaction_postCalculation', None)
LOG('localized_add_end_line_script :', 0, localized_add_end_line_script)
if localized_add_end_line_script: if localized_add_end_line_script:
localized_add_end_line_script(employee_tax_amount) localized_add_end_line_script(employee_tax_amount)
......
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