Commit 09fdb23c authored by Kevin Deldycke's avatar Kevin Deldycke

Do not call initializePreview anylonger. Use data from the listbox instead...

Do not call initializePreview anylonger. Use data from the listbox instead (much more flexible way to analyze data).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10844 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 94c8aa64
......@@ -68,7 +68,14 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
<value> <string>"""\n
This script get lines and cells from the PaySheetTransaction_viewPreview Fast Input and\n
contruct the Pay Sheet Lines object according their own data model.\n
TODO: this script is too complicated and should be refactor a little to reduce is uneeded\n
complexity (and increase its maintainability).\n
"""\n
\n
portal = context.getPortalObject()\n
N_ = portal.Base_translateString\n
\n
# Get Precision\n
......@@ -78,7 +85,7 @@ r_ = lambda x: context.Base_getRoundValue(x, precision)\n
# Delete all objects in the paysheet\n
id_list = []\n
for paysheet_item in context.objectValues(portal_type=[\'Pay Sheet Transaction Line\', \'Pay Sheet Line\']):\n
# Delete Line to keep the payment_condition_payment_date sub-object\n
# Delete lines which became outdated and keep the payment_condition_payment_date sub-object\n
id_list.append(paysheet_item.getId())\n
context.manage_delObjects(id_list)\n
\n
......@@ -125,8 +132,8 @@ def createPaySheetItem(title=\'\', res=\'\', dest_org=\'\', cells=[]):\n
)\n
\n
# Set the title of the paysheet if empty\n
months = [ \'January\', \'February\', \'March\', \'April\', \'May\', \'June\', \'July\'\n
, \'August\', \'September\', \'October\', \'November\', \'December\'\n
months = [ \'january\', \'february\', \'march\', \'april\', \'may\', \'june\', \'july\'\n
, \'august\', \'september\', \'october\', \'november\', \'december\'\n
]\n
if context.getTitle() in (\'\', None):\n
new_title = \'%s %s\' % ( N_(\'Salary\')\n
......@@ -139,9 +146,6 @@ if context.getTitle() in (\'\', None):\n
)\n
context.setTitle(new_title)\n
\n
# Get the ordered list of standard preview line objects\n
std_lines = context.PaySheetTransaction_initializePreview()\n
\n
# This list contain all paysheet items, indexed by service\n
paysheet_items = {}\n
\n
......@@ -149,57 +153,57 @@ paysheet_items = {}\n
user_line_index = 0\n
total_employee_share = 0.0\n
\n
# Scan every standard preview line to create an item for each service\n
for std_line in std_lines:\n
# get the service url (unique because containing the id)\n
service = std_line.getProperty(\'service_url\')\n
# define some values related to current standard preview line\n
salary_range_cat = std_line.getProperty(\'salary_range_cat\')\n
tax_cat = std_line.getProperty(\'tax_cat\')\n
# verify that the service is not existing\n
if not paysheet_items.has_key(service):\n
paysheet_items[service] = { \'title\' : std_line.getTitle()\n
, \'res\' : std_line.getProperty(\'service_url\')\n
, \'dest_org\': std_line.getProperty(\'organisation_url\')\n
, \'cells\' : []\n
}\n
# Increment the user line index: we can use this strategy because preview lines (user or standard ones) are sorted\n
user_line_index += 1\n
# Get user paysheet parameters stored in user preview line (=listbox)\n
for user_line in listbox:\n
# Base_viewSearchResultList the user preview line corresponding to the standard preview line\n
if user_line.has_key(\'listbox_key\') and int(user_line[\'listbox_key\'])==user_line_index:\n
# Got it ! we have the right line\n
if user_line[\'base\'] not in (None, \'\'):\n
# Get the base salary if given by the user\n
base = r_(user_line[\'base\'])\n
# Scan allowed tax categories to get employee and/or employer share rate\n
for cat in tax_cat:\n
# Define an empty new cell\n
new_cell = None\n
# Convert rate from percent\n
employer_rate = user_line[\'employer_share_rate\']\n
employee_rate = user_line[\'employee_share_rate\']\n
if str(cat).endswith(\'employer_share\') and employer_rate not in (None, \'\'):\n
rate = float(employer_rate) / 100.0\n
new_cell = { "x" : cat\n
, "y" : salary_range_cat\n
, "base" : -base\n
, "rate" : rate # XXX Bad use of % (JPS)\n
}\n
if str(cat).endswith(\'employee_share\') and employee_rate not in (None, \'\'):\n
rate = float(employee_rate) / 100.0\n
new_cell = { "x" : cat\n
, "y" : salary_range_cat\n
, "base" : -base\n
, "rate" : rate # XXX Bad use of % (JPS)\n
}\n
context.log("PaySheetTransaction_postCalculation","cat=%s base=%s rate=%s" % (cat, base, rate))\n
# Scan every preview line to create an item for each service\n
for line in listbox:\n
service_id = line[\'service_id\']\n
salary_range = line[\'salary_range\']\n
tax_categories = line[\'tax_category\']\n
# Get the service object\n
service = context.restrictedTraverse("payroll_service_module/%s" % service_id)\n
# Check that the service doesn\'t exist\n
if not paysheet_items.has_key(service_id):\n
paysheet_items[service_id] = { \'title\' : service.getTitleOrId()\n
, \'res\' : service.getRelativeUrl()\n
, \'dest_org\': service.getSource()\n
, \'cells\' : []\n
}\n
\n
# Get user paysheet parameters stored in listbox\n
for line in listbox:\n
service_id = line[\'service_id\']\n
base = line[\'base\']\n
if base not in (None, \'\'):\n
# Get the base salary if given by the user\n
base = r_(base)\n
# Scan allowed tax categories to get employee and/or employer share rate\n
tax_categories = line[\'tax_category\']\n
for cat in tax_categories:\n
salary_range = line[\'salary_range\']\n
# Define an empty new cell\n
new_cell = None\n
# Convert rate from percent\n
employer_share = line[\'employer_share\']\n
employee_share = line[\'employee_share\']\n
if cat.endswith(\'/employer_share\') and employer_share not in (None, \'\'):\n
share = float(employer_share)\n
new_cell = { "x" : cat\n
, "y" : salary_range\n
, "base" : -base\n
, "rate" : share\n
}\n
if cat.endswith(\'/employee_share\') and employee_share not in (None, \'\'):\n
share = float(employee_share)\n
new_cell = { "x" : cat\n
, "y" : salary_range\n
, "base" : -base\n
, "rate" : share\n
}\n
#context.log("PaySheetTransaction_postCalculation","cat=%s base=%s rate=%s" % (cat, base, rate))\n
\n
total_employee_share = r_(total_employee_share + r_(base * float(rate)))\n
# Add the cell to the conresponding paysheet item\n
if new_cell != None:\n
paysheet_items[service][\'cells\'].append(new_cell)\n
total_employee_share = r_(total_employee_share + r_(base * float(share)))\n
# Add the cell to the conresponding paysheet item\n
if new_cell != None:\n
paysheet_items[service_id][\'cells\'].append(new_cell)\n
\n
# Create a paysheet item for each service with user data in it\n
for item in paysheet_items.values():\n
......@@ -303,25 +307,22 @@ if not(kw.has_key(\'skip_redirect\') and kw[\'skip_redirect\'] == True):\n
<string>new_title</string>
<string>payroll_date</string>
<string>_getitem_</string>
<string>std_lines</string>
<string>paysheet_items</string>
<string>user_line_index</string>
<string>total_employee_share</string>
<string>std_line</string>
<string>line</string>
<string>service_id</string>
<string>salary_range</string>
<string>tax_categories</string>
<string>service</string>
<string>salary_range_cat</string>
<string>tax_cat</string>
<string>_write_</string>
<string>user_line</string>
<string>int</string>
<string>base</string>
<string>cat</string>
<string>new_cell</string>
<string>employer_rate</string>
<string>employee_rate</string>
<string>str</string>
<string>employer_share</string>
<string>employee_share</string>
<string>float</string>
<string>rate</string>
<string>share</string>
<string>item</string>
<string>labour_service</string>
<string>ValueError</string>
......
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