Commit d0468102 authored by Fabien Morin's avatar Fabien Morin

lot of changes, including :

- remove script_id from updateCellRange() calling because it was not usefull
  and makes log warnings
- add getEditableModelLineAsDict and getNotEditableModelLineAsDict function
  -> getNotEditableModelLineAsDict is not yet used but it's written if there is
  some needs in the future...
- change createNotEditablePaySheetLineList main function in
  createPaySheetLineList. Now, there is just one function that can handle all
  type cases (editable or not). There is a new parameter : batch_mode that
  permit to generate Pay Sheet Lines without fill in the Editable Model Lines
  (default vaules are take).
- remove model_slice_min and model_slice_max values from calculationScript
  parameters because they could be get on the cell
- add comments
- remove some parts that are now unused
- typo


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18258 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0eb92e2e
...@@ -30,6 +30,7 @@ from AccessControl import ClassSecurityInfo ...@@ -30,6 +30,7 @@ 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 Products.ERP5Type.Utils import cartesianProduct
import pprint
from zLOG import LOG from zLOG import LOG
class PaySheetTransaction(Invoice): class PaySheetTransaction(Invoice):
...@@ -141,8 +142,7 @@ class PaySheetTransaction(Invoice): ...@@ -141,8 +142,7 @@ class PaySheetTransaction(Invoice):
**kw) **kw)
base_id = 'movement' base_id = 'movement'
a = payline.updateCellRange(script_id = 'PaySheetLine_asCellRange', a = payline.updateCellRange(base_id = base_id)
base_id = base_id)
# create cell_list # create cell_list
for cell in good_cell_list: for cell in good_cell_list:
cell_cat_list = cell['axe_list'] cell_cat_list = cell['axe_list']
...@@ -162,74 +162,111 @@ class PaySheetTransaction(Invoice): ...@@ -162,74 +162,111 @@ class PaySheetTransaction(Invoice):
return payline return payline
security.declareProtected(Permissions.AccessContentsInformation,
security.declareProtected(Permissions.AddPortalContent, 'getEditableModelLineAsDict')
'createEditablePaySheetLineList') def getEditableModelLineAsDict(self, listbox, paysheet):
def createEditablePaySheetLineList(self, listbox, **kw):
''' '''
this script is called by the preview form to ask to the accountable listbox is composed by one line for each slice of editables model_lines
the values of the editables lines and create corresponding this script will return editable model lines as a dict with the
PaySheetLines with this values properties that could/have be modified.
''' '''
paysheet = self portal = paysheet.getPortalObject()
item_dict = {}
model_line_id_list = [] model_line_dict = {}
for cell in listbox: for line in listbox:
model_line = paysheet.getPortalObject().restrictedTraverse(\ model_line_url = line['model_line']
cell['model_line']) model_line = portal.restrictedTraverse(model_line_url)
model_line_id = model_line.getId()
quantity = cell['quantity'] salary_range_relative_url=line['salary_range_relative_url']
price = cell['price'] if salary_range_relative_url == '':
tax_category = cell['tax_category_relative_url'] salary_range_relative_url='no_slice'
salary_range = cell['salary_range_relative_url']
# if this is the first slice of the model_line, create the dict
new_cell = { 'axe_list' : [salary_range, tax_category], if not model_line_dict.has_key(model_line_url):
'quantity' : quantity, model_line_dict[model_line_url] = {'int_index' :\
'price' : price, model_line.getIntIndex()}
}
model_line_dict[model_line_url][salary_range_relative_url] = {}
if item_dict.has_key(model_line_id): slice_dict = model_line_dict[model_line_url][salary_range_relative_url]
# an item for this model_line_id already exists for tax_category in model_line.getTaxCategoryList():
item_dict[model_line_id]['cell_list'].append(new_cell) if line.has_key('%s_quantity' % tax_category) and \
else: line.has_key('%s_price' % tax_category):
if model_line.getDescription(): slice_dict[tax_category]=\
desc = model_line.getDescription() {
'quantity' : line['%s_quantity' % tax_category],
'price' : line['%s_price' % tax_category],
}
else: else:
desc = model_line.getResourceValue().getDescription() LOG('Warning, no atribute %s_quantity or %s_price for model_line %s' %
tax_category, tax_category, model_line_url, 0, '')
model_line_id_list.append(model_line_id)
# create a new item return model_line_dict
item_dict[model_line_id]={\
'title' : model_line.getTitleOrId(),
'res' : model_line.getResourceValue().getRelativeUrl(),
'desc' : desc,
'cell_list' : [new_cell],
'int_index' : model_line.getFloatIndex(),
'base_amount_list' : model_line.getBaseAmountList(),
}
for model_line_id in model_line_id_list:
item = item_dict[model_line_id]
paysheet.createPaySheetLine(title = item['title'],
res = item['res'],
desc = item['desc'],
cell_list = item['cell_list'],
int_index = item['int_index'],
base_amount_list = item['base_amount_list'])
security.declareProtected(Permissions.AccessContentsInformation,
'getNotEditableModelLineAsDict')
def getNotEditableModelLineAsDict(self, paysheet):
'''
return the not editable lines as dict
'''
model = paysheet.getSpecialiseValue()
model_line_list = model.contentValues(portal_type='Pay Sheet Model Line')
model_line_dict = {}
for model_line in model_line_list:
model_line_url = model_line.getRelativeUrl()
cell_list = model_line.contentValues(portal_type='Pay Sheet Cell')
for cell in cell_list:
salary_range_relative_url = \
cell.getVariationCategoryList(base_category_list='salary_range')
tax_category = cell.getTaxCategory()
if len(salary_range_relative_url):
salary_range_relative_url = salary_range_relative_url[0]
else:
salary_range_relative_url = 'no_slice'
# if this is the first slice of the model_line, create the dict
if not model_line_dict.has_key(model_line_url):
model_line_dict[model_line_url] = {'int_index' :\
model_line.getIntIndex()}
model_line_dict[model_line_url][salary_range_relative_url] = {}
slice_dict = model_line_dict[model_line_url][salary_range_relative_url]
slice_dict[tax_category]=\
{
'quantity' : cell.getQuantity(),
'price' : cell.getPrice(),
}
return model_line_dict
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'createNotEditablePaySheetLineList') 'createPaySheetLineList')
def createNotEditablePaySheetLineList(self, **kw): def createPaySheetLineList(self, listbox=None, batch_mode=0, **kw):
''' '''
get all data required to create not editable paysheet lines and create it create all Pay Sheet Lines (editable or not)
editable paysheet lines have been created by a script
parameters :
- batch_mode :if batch_mode is enabled (=1) then there is no preview view,
and editable lines are considered as not editable lines.
This is usefull to generate all PaySheet of a company.
Modification values can be made on each paysheet after, by
using the "Calculation of the Pay Sheet Transaction"
action button. (concerned model lines must be editable)
''' '''
paysheet = self
if not batch_mode and listbox is not None:
model_line_dict = paysheet.getEditableModelLineAsDict(listbox=listbox,
paysheet=paysheet)
# Get Precision # Get Precision
precision = self.getPriceCurrencyValue().getQuantityPrecision() precision = paysheet.getPriceCurrencyValue().getQuantityPrecision()
# in this dictionary will be saved the current amount corresponding to # in this dictionary will be saved the current amount corresponding to
...@@ -238,45 +275,17 @@ class PaySheetTransaction(Invoice): ...@@ -238,45 +275,17 @@ class PaySheetTransaction(Invoice):
base_amount_dict = {} base_amount_dict = {}
def sortByIntIndex(a, b): def sortByIntIndex(a, b):
return cmp(a.getIntIndex(), return cmp(a.getIntIndex(), b.getIntIndex())
b.getIntIndex())
base_amount_list = self.portal_categories['base_amount'].contentValues() base_amount_list = paysheet.portal_categories['base_amount'].contentValues()
base_amount_list.sort(sortByIntIndex) base_amount_list.sort(sortByIntIndex)
# it's important to get the editable lines to know if they contribute to
# a base_amount (this is required to do the calcul later) # get model lines
model = paysheet.getSpecialiseValue()
# get edited lines:
paysheetline_list = self.contentValues(portal_type = ['Pay Sheet Line'])
for paysheetline in paysheetline_list:
service = paysheetline.getResourceValue()
base_amount_list = service.getBaseAmountList(base=1)
for base_amount in base_amount_list:
paysheetcell_list = paysheetline.contentValues(portal_type = \
['Pay Sheet Cell'])
for paysheetcell in paysheetcell_list:
tax_category = paysheetcell.getTaxCategory(base=1)
if tax_category and paysheetcell.getQuantity():
if base_amount_dict.has_key(base_amount) and \
base_amount_dict[base_amount].has_key(tax_category):
old_val = base_amount_dict[base_amount][tax_category]
else:
old_val = 0
new_val = old_val + paysheetcell.getQuantity()
if not base_amount_dict.has_key(base_amount):
base_amount_dict[base_amount]={}
# increment the corresponding amount
base_amount_dict[base_amount][tax_category] = new_val
# get not editables model lines
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()]
pay_sheet_line_list = [] pay_sheet_line_list = []
...@@ -284,8 +293,11 @@ class PaySheetTransaction(Invoice): ...@@ -284,8 +293,11 @@ class PaySheetTransaction(Invoice):
for model_line in model_line_list: for model_line in model_line_list:
cell_list = [] cell_list = []
# test with predicate if this model line could be applied # test with predicate if this model line could be applied
if not model_line.test(self,): if not model_line.test(paysheet,):
# This line should not be used # This model_line should not be applied
LOG('createPaySheetLineList :', 0,
'Model Line %s will not be applied, because predicates not match' %
model_line.getTitle())
continue continue
service = model_line.getResourceValue() service = model_line.getResourceValue()
...@@ -294,6 +306,7 @@ class PaySheetTransaction(Invoice): ...@@ -294,6 +306,7 @@ class PaySheetTransaction(Invoice):
id = model_line.getId() id = model_line.getId()
base_amount_list = model_line.getBaseAmountList() base_amount_list = model_line.getBaseAmountList()
res = service.getRelativeUrl() res = service.getRelativeUrl()
if model_line.getDescription(): if model_line.getDescription():
desc = ''.join(model_line.getDescription()) desc = ''.join(model_line.getDescription())
# if the model_line description is empty, the payroll service # if the model_line description is empty, the payroll service
...@@ -301,8 +314,6 @@ class PaySheetTransaction(Invoice): ...@@ -301,8 +314,6 @@ class PaySheetTransaction(Invoice):
else: else:
desc = ''.join(service.getDescription()) desc = ''.join(service.getDescription())
base_category_list = model_line.getVariationBaseCategoryList() base_category_list = model_line.getVariationBaseCategoryList()
list_of_list = [] list_of_list = []
for base_cat in base_category_list: for base_cat in base_category_list:
...@@ -310,29 +321,48 @@ class PaySheetTransaction(Invoice): ...@@ -310,29 +321,48 @@ class PaySheetTransaction(Invoice):
list_of_list.append(list) list_of_list.append(list)
cartesian_product = cartesianProduct(list_of_list) cartesian_product = cartesianProduct(list_of_list)
slice = None share = None
slice = 'no_slice'
indice = 0 indice = 0
for tuple in cartesian_product: for tuple in cartesian_product:
indice += 1 indice += 1
cell = model_line.getCell(*tuple) cell = model_line.getCell(*tuple)
if cell is None: if cell is None:
LOG("Warning ! can't find the cell corresponding to this tuple : %s",
0, tuple)
continue continue
tuple_dict = {} if len(cell.getVariationCategoryList(base_category_list='tax_category')):
for item in tuple: share = \
# the dict key is the base category and value is the category path cell.getVariationCategoryList(base_category_list='tax_category')[0]
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 len(cell.getVariationCategoryList(base_category_list='salary_range')):
if tuple_dict.has_key('tax_category'): slice = \
share = tuple_dict['tax_category_relative_url'] cell.getVariationCategoryList(base_category_list='salary_range')[0]
# get the edited values if this model_line is editable
# and replace the original cell values by this ones
if model_line.isEditable() and not batch_mode:
tax_category = cell.getTaxCategory()
# get the dict who contain modified values
line_dict = model_line_dict[model_line.getRelativeUrl()]
def getModifiedCell(cell, slice_dict, tax_category):
'''
return a cell with the modified values (conained in slice_dict)
'''
if slice_dict:
if slice_dict.has_key(tax_category):
if slice_dict[tax_category].has_key('quantity'):
cell = cell.asContext(\
quantity=slice_dict[tax_category]['quantity'])
if slice_dict[tax_category].has_key('price'):
cell = cell.asContext(price=slice_dict[tax_category]['price'])
return cell
cell = getModifiedCell(cell, line_dict[slice], tax_category)
# get the slice : # get the slice :
model_slice = model_line.getParentValue().getCell(slice) model_slice = model_line.getParentValue().getCell(slice)
quantity = 0.0 quantity = 0.0
...@@ -340,8 +370,12 @@ class PaySheetTransaction(Invoice): ...@@ -340,8 +370,12 @@ class PaySheetTransaction(Invoice):
model_slice_min = 0 model_slice_min = 0
model_slice_max = 0 model_slice_max = 0
if model_slice is None: if model_slice is None:
LOG('createNotEditablePaySheetLineList :', 0, 'model_slice %s is None' pass # that's not a problem :)
% slice)
#LOG('createPaySheetLineList :', 0, 'model_slice of slice '
# '"%s" of the model_line "%s" is None' % (slice,
# model_line.getTitle()))
else: 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()
...@@ -365,18 +399,14 @@ class PaySheetTransaction(Invoice): ...@@ -365,18 +399,14 @@ class PaySheetTransaction(Invoice):
# 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(paysheet, 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(paysheet, 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_dict=base_amount_dict, cell=cell,)
base_amount_dict=base_amount_dict,
model_slice_min=model_slice_min,
model_slice_max=model_slice_max,
cell=cell,)
quantity = result['quantity'] quantity = result['quantity']
price = result['price'] price = result['price']
...@@ -389,8 +419,7 @@ class PaySheetTransaction(Invoice): ...@@ -389,8 +419,7 @@ class PaySheetTransaction(Invoice):
} }
cell_list.append(new_cell) cell_list.append(new_cell)
# update the 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:
...@@ -409,20 +438,19 @@ class PaySheetTransaction(Invoice): ...@@ -409,20 +438,19 @@ class PaySheetTransaction(Invoice):
if cell_list: if cell_list:
# create the PaySheetLine # create the PaySheetLine
pay_sheet_line = self.createPaySheetLine( pay_sheet_line = paysheet.createPaySheetLine(
title = title, title = title,
res = res, res = res,
int_index = int_index, int_index = int_index,
desc = desc, desc = desc,
base_amount_list = base_amount_list, base_amount_list = base_amount_list,
cell_list = cell_list, cell_list = cell_list,)
)
pay_sheet_line_list.append(pay_sheet_line) pay_sheet_line_list.append(pay_sheet_line)
# this script is used to add a line that permit to have good accounting # this script is used to add a line that permit to have good accounting
# lines # lines
post_calculation_script = getattr(self, post_calculation_script = getattr(paysheet,
'PaySheetTransaction_postCalculation', None) 'PaySheetTransaction_postCalculation', None)
if post_calculation_script: if post_calculation_script:
post_calculation_script() post_calculation_script()
......
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