How to use _render method in avocado

Best Python code snippet using avocado_python

project_report.py

Source:project_report.py Github

copy

Full Screen

...63 # XLS Template64 self.col_specs_template = {65 66 'col1': {67 'header': [1, 24, 'text', _render("_('Project Name')")],68 'lines': [1, 0, 'text', _render("''")],69 'totals': [1, 0, 'text', None]}, 70 'col2': {71 'header': [1, 24, 'text', _render("_('Assigned To')")],72 'lines': [1,0, 'text', _render("''")],73 'totals': [1, 0, 'text', None]}, 74 'col3': {75 'header': [1, 24, 'text', _render("_('Task Name')")],76 'lines': [1, 0, 'text', _render("''")],77 'totals': [1,0, 'text', None]},78 'col4': {79 'header': [1, 15, 'text', _render("_('Planned Hours (Hrs.)')")],80 'lines': [1,0, 'text', _render("''")],81 'totals': [1, 0, 'text', None]}, 82 'col5': {83 'header': [1, 16, 'text', _render("_('Time Remaining (Hrs.)')")],84 'lines': [1, 0, 'text', _render("''")],85 'totals': [1, 0, 'text', None]}, 86 'col6': {87 'header': [1, 14, 'text', _render("_('Starting Date')")],88 'lines': [1, 0, 'text', _render("''")],89 'totals': [1, 0, 'text', None]},90 'col7': {91 'header': [1, 14, 'text', _render("_('Deadline Date')")],92 'lines': [1, 0, 'text', _render("''")],93 'totals': [1, 0, 'text', None]}, 94 'col8': {95 'header': [1, 14, 'text', _render("_('Ending Date')")],96 'lines': [1, 0, 'text', _render("''")],97 'totals': [1, 0, 'text', None]}, 98 'col9': {99 'header': [1, 12, 'text', _render("_('Stage')")],100 'lines': [1, 0, 'text', _render("''")],101 'totals': [1, 0, 'text', None]}, 102 'col10': {103 'header': [1, 24, 'text', _render("_('Work Summary')")],104 'lines': [1, 0, 'text',_render("work_summary or ''")],105 'totals': [1, 0, 'text', None]},106 'col11': {107 'header': [1, 14, 'text', _render("_('Task Date')")],108 'lines': [1, 0, 'text', _render("date")],109 'totals': [1, 0, 'text', None]}, 110 'col12': {111 'header': [1, 15, 'text', _render("_('Time Spent (Hrs.)')")],112 'lines': [1,0, 'number', _render("time_spent")],113 'totals': [1, 0, 'text', None]}, 114 'col13': {115 'header': [1, 20, 'text', _render("_('Description')")],116 'lines': [1, 0, 'text', _render("''")],117 'totals': [1, 0, 'text', None]}, 118 119 120 }121 self.col_specs_template1 = {122 123 'col1': {124 'header': [1, 24, 'text', _render("_('')")],125 'lines': [1, 0, 'text', _render("project or ''")],126 'totals': [1, 0, 'text', None]}, 127 'col2': {128 'header': [1, 24, 'text', _render("_('')")],129 'lines': [1,0, 'text', _render("''")],130 'totals': [1, 0, 'text', None]}, 131 'col3': {132 'header': [1, 24, 'text', _render("_('')")],133 'lines': [1, 0, 'text', _render("''")],134 'totals': [1,0, 'text', None]},135 'col4': {136 'header': [1, 15, 'text', _render("_('')")],137 'lines': [1,0, 'text', _render("''")],138 'totals': [1, 0, 'text', None]}, 139 'col5': {140 'header': [1, 16, 'text', _render("_('')")],141 'lines': [1, 0, 'text', _render("''")],142 'totals': [1, 0, 'text', None]}, 143 'col6': {144 'header': [1, 14, 'text', _render("_('')")],145 'lines': [1, 0, 'text', _render("''")],146 'totals': [1, 0, 'text', None]}, 147 'col7': {148 'header': [1, 14, 'text', _render("_('')")],149 'lines': [1, 0, 'text', _render("''")],150 'totals': [1, 0, 'text', None]},151 'col8': {152 'header': [1, 14, 'text', _render("_('')")],153 'lines': [1, 0, 'text', _render("''")],154 'totals': [1, 0, 'text', None]}, 155 'col9': {156 'header': [1, 12, 'text', _render("_('')")],157 'lines': [1, 0, 'text', _render("''")],158 'totals': [1, 0, 'text', None]}, 159 'col10': {160 'header': [1, 24, 'text', _render("_('')")],161 'lines': [1, 0, 'text',_render("''")],162 'totals': [1, 0, 'text', None]},163 'col11': {164 'header': [1, 14, 'text', _render("_('')")],165 'lines': [1, 0, 'text', _render("''")],166 'totals': [1, 0, 'text', None]}, 167 'col12': {168 'header': [1, 15, 'text', _render("_('')")],169 'lines': [1,0, 'text', _render("''")],170 'totals': [1, 0, 'text', None]}, 171 'col13': {172 'header': [1, 20, 'text', _render("_('')")],173 'lines': [1, 0, 'text', _render("''")],174 'totals': [1, 0, 'text', None]}, 175 176 177 178 }179 self.col_specs_template2 = {180 181 'col1': {182 'header': [1, 24, 'text', _render("_('')")],183 'lines': [1, 0, 'text', _render("''")],184 'totals': [1, 0, 'text', None]}, 185 'col2': {186 'header': [1, 24, 'text', _render("_('')")],187 'lines': [1,0, 'text', _render("done_by or ''")],188 'totals': [1, 0, 'text', None]}, 189 'col3': {190 'header': [1, 24, 'text', _render("_('')")],191 'lines': [1, 0, 'text', _render("''")],192 'totals': [1,0, 'text', None]},193 'col4': {194 'header': [1, 15, 'text', _render("_('')")],195 'lines': [1,0, 'text', _render("''")],196 'totals': [1, 0, 'text', None]}, 197 'col5': {198 'header': [1, 16, 'text', _render("_('')")],199 'lines': [1, 0, 'text', _render("''")],200 'totals': [1, 0, 'text', None]}, 201 'col6': {202 'header': [1, 14, 'text', _render("_('')")],203 'lines': [1, 0, 'text', _render("''")],204 'totals': [1, 0, 'text', None]}, 205 'col7': {206 'header': [1, 14, 'text', _render("_('')")],207 'lines': [1, 0, 'text', _render("''")],208 'totals': [1, 0, 'text', None]}, 209 'col8': {210 'header': [1, 14, 'text', _render("_('')")],211 'lines': [1, 0, 'text', _render("''")],212 'totals': [1, 0, 'text', None]}, 213 'col9': {214 'header': [1, 12, 'text', _render("_('')")],215 'lines': [1, 0, 'text', _render("''")],216 'totals': [1, 0, 'text', None]}, 217 'col10': {218 'header': [1, 24, 'text', _render("_('')")],219 'lines': [1, 0, 'text',_render("''")],220 'totals': [1, 0, 'text', None]},221 'col11': {222 'header': [1, 14, 'text', _render("_('')")],223 'lines': [1, 0, 'text', _render("''")],224 'totals': [1, 0, 'text', None]}, 225 'col12': {226 'header': [1, 15, 'text', _render("_('')")],227 'lines': [1,0, 'text', _render("''")],228 'totals': [1, 0, 'text', None]}, 229 'col13': {230 'header': [1, 20, 'text', _render("_('')")],231 'lines': [1, 0, 'text', _render("''")],232 'totals': [1, 0, 'text', None]}, 233 234 235 }236 237 238 self.col_specs_template3 = {239 240 'col1': {241 'header': [1, 24, 'text', _render("_('')")],242 'lines': [1, 0, 'text', _render("''")],243 'totals': [1, 0, 'text', None]}, 244 'col2': {245 'header': [1, 24, 'text', _render("_('')")],246 'lines': [1,0, 'text', _render("''")],247 'totals': [1, 0, 'text', None]}, 248 'col3': {249 'header': [1, 24, 'text', _render("_('')")],250 'lines': [1, 0, 'text', _render("task or ''")],251 'totals': [1,0, 'text', None]},252 'col4': {253 'header': [1, 15, 'text', _render("_('')")],254 'lines': [1,0, 'number', _render("planned_hours")],255 'totals': [1, 0, 'text', None]}, 256 'col5': {257 'header': [1, 16, 'text', _render("_('')")],258 'lines': [1, 0, 'number', _render("remaining_hours")],259 'totals': [1, 0, 'text', None]}, 260 'col6': {261 'header': [1, 14, 'text', _render("_('')")],262 'lines': [1, 0, 'text', _render("starting_date")],263 'totals': [1, 0, 'text', None]}, 264 'col7': {265 'header': [1, 14, 'text', _render("_('')")],266 'lines': [1, 0, 'text', _render("deadline_date")],267 'totals': [1, 0, 'text', None]}, 268 'col8': {269 'header': [1, 14, 'text', _render("_('')")],270 'lines': [1, 0, 'text', _render("ending_date")],271 'totals': [1, 0, 'text', None]}, 272 'col9': {273 'header': [1, 12, 'text', _render("_('')")],274 'lines': [1, 0, 'text', _render("stage or ''")],275 'totals': [1, 0, 'text', None]}, 276 'col10': {277 'header': [1, 24, 'text', _render("_('')")],278 'lines': [1, 0, 'text',_render("''")],279 'totals': [1, 0, 'text', None]},280 'col11': {281 'header': [1, 14, 'text', _render("_('')")],282 'lines': [1, 0, 'text', _render("''")],283 'totals': [1, 0, 'text', None]}, 284 'col12': {285 'header': [1, 15, 'text', _render("_('')")],286 'lines': [1,0, 'text', _render("''")],287 'totals': [1, 0, 'text', None]}, 288 'col13': {289 'header': [1, 20, 'text', _render("_('')")],290 'lines': [1, 0, 'text', _render("description")],291 'totals': [1, 0, 'text', None]}, 292 293 294 }295 self.col_specs_template4 = {296 297 'col1': {298 'header': [1, 24, 'text', _render("_('')")],299 'lines': [1, 0, 'text', _render("from_date_print or ''")],300 'totals': [1, 0, 'text', None]}, 301 'col2': {302 'header': [1, 24, 'text', _render("_('')")],303 'lines': [1,0, 'text', _render("from_date_print or ''")],304 'totals': [1, 0, 'text', None]}, 305 'col3': {306 'header': [1, 24, 'text', _render("_('')")],307 'lines': [1, 0, 'text', _render("''")],308 'totals': [1,0, 'text', None]},309 'col4': {310 'header': [1, 15, 'text', _render("_('')")],311 'lines': [1,0, 'text', _render("''")],312 'totals': [1, 0, 'text', None]}, 313 'col5': {314 'header': [1, 16, 'text', _render("_('')")],315 'lines': [1, 0, 'text', _render("''")],316 'totals': [1, 0, 'text', None]}, 317 'col6': {318 'header': [1, 14, 'text', _render("_('')")],319 'lines': [1, 0, 'text', _render("''")],320 'totals': [1, 0, 'text', None]}, 321 'col7': {322 'header': [1, 14, 'text', _render("_('')")],323 'lines': [1, 0, 'text', _render("''")],324 'totals': [1, 0, 'text', None]}, 325 'col8': {326 'header': [1, 14, 'text', _render("_('')")],327 'lines': [1, 0, 'text', _render("''")],328 'totals': [1, 0, 'text', None]}, 329 'col9': {330 'header': [1, 12, 'text', _render("_('')")],331 'lines': [1, 0, 'text', _render("''")],332 'totals': [1, 0, 'text', None]}, 333 'col10': {334 'header': [1, 24, 'text', _render("_('')")],335 'lines': [1, 0, 'text',_render("''")],336 'totals': [1, 0, 'text', None]},337 'col11': {338 'header': [1, 14, 'text', _render("_('')")],339 'lines': [1, 0, 'text', _render("''")],340 'totals': [1, 0, 'text', None]}, 341 'col12': {342 'header': [1, 15, 'text', _render("_('')")],343 'lines': [1,0, 'text', _render("''")],344 'totals': [1, 0, 'text', None]}, 345 'col13': {346 'header': [1, 20, 'text', _render("_('')")],347 'lines': [1, 0, 'text', _render("''")],348 'totals': [1, 0, 'text', None]}, 349 350 351 } 352 def generate_xls_report(self, _p, _xs, data, objects, wb):353 wanted_list = _p.wanted_list354 self.col_specs_template.update(_p.template_changes)355 _ = _p._356 wage_pos = 'wage' in wanted_list and wanted_list.index('wage')357 epf_deduction_pos = 'epf_deduction' in wanted_list and wanted_list.index('epf_deduction')358# if not (credit_pos and debit_pos) and 'balance' in wanted_list:359# raise oproject.task.report.wizardrm.except_orm(_('Customisation Error!'),360# _("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))361 #report_name = objects[0]._description or objects[0]._name362 report_name = _("Project Status Report - Details")363 ws = wb.add_sheet(report_name[:31])364 ws.panes_frozen = True365 ws.remove_splits = True366 ws.portrait = 0 # Landscape367 ws.fit_width_to_pages = 1368 row_pos = 0369 # set print header/footer370 ws.header_str = self.xls_headers['standard']371 ws.footer_str = self.xls_footers['standard']372 # Title373 cell_style = xlwt.easyxf(_xs['xls_title'])374 c_specs = [375 ('report_name', 1, 0, 'text', report_name),376 ]377 row_data = self.xls_row_template(c_specs, ['report_name'])378 print"-------------*************",ws, row_pos, row_data,cell_style379 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)380# row_pos += 1381 row_pos = 1382 383 # Column headers384 # c_specs = map(lambda x: self.render(x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list)385 # row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])386 # row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)387 # ws.set_horz_split_pos(row_pos)388# row_data = self.xls_row_template(c_specs, _("Grand Total"))389# print"-------------*************",ws, row_pos, row_data,cell_style390# row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)391# row_pos += 1392 # account move lines393 394 for line in objects:395 print"line===================",line,"object",objects396 397 task_work_ids = []398 task_ids = []399 list2 = []400 list3 = []401 list4 = []402 list5 = []403 project = ''404 work_summary = ''405 done_by = ''406 time_spent = 0.0407 date = ''408 task = ''409 deadline_date = ''410 planned_hours = 0.0411 remaining_hours = 0.0412 starting_date = ''413 ending_date = ''414 reviewer = ''415 description = ''416 stage = ''417 418 from_date = line.from_date419 till_date = line.till_date 420 till_datetime = datetime.strptime(till_date,"%Y-%m-%d")421 till_datetime = till_datetime.strftime("%Y-%m-%d 23:59:59") 422 from_date_format = datetime.strptime(from_date,"%Y-%m-%d")423 from_date_format = from_date_format.strftime("%d-%m-%Y")424 till_date_format = datetime.strptime(till_date,"%Y-%m-%d")425 till_date_format = till_date_format.strftime("%d-%m-%Y")426 from_date_print = 'From Date: ' + str(from_date_format)427 till_date_print = 'To Date: ' + str(till_date_format)428 c_specs = map(lambda x: self.render(x, self.col_specs_template4, 'lines'), wanted_list)429 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])430 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style) 431 c_specs = map(lambda x: self.render(x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list)432 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])433 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)434 ws.set_horz_split_pos(row_pos)435 if line.project_idss:436 for proj in line.project_idss:437 438 task_work_ids = []439 task_ids = []440 list2 = []441 list3 = []442 list4 = []443 list5 = []444 project = ''445 work_summary = ''446 done_by = ''447 time_spent = 0.0448 date = ''449 task = ''450 deadline_date = ''451 planned_hours = 0.0452 remaining_hours = 0.0453 starting_date = ''454 ending_date = ''455 reviewer = ''456 description = '' 457 stage = '' 458 cmp_date = '' 459 460 task_work_ids = self.pool.get('project.task.work').search(self.cr,1,[('project_id','=',proj.id),('date','>=',from_date),('date','<=',till_datetime)], order='user_id,task_id,date') 461 task_ids = self.pool.get('project.task').search(self.cr,1,[('project_id','=',proj.id),('date_deadline','<=',till_date),('stage_id','in',[28,11])], order='user_id,id,date_deadline') 462 project = proj.name or ''463 464 c_specs = map(lambda x: self.render(x, self.col_specs_template1, 'lines'), wanted_list)465 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])466 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style) 467 468 if task_ids:469 for tasks in task_ids:470 val4 = self.pool.get('project.task').browse(self.cr, 1, tasks)471 user1 = val4.user_id and val4.user_id.id or False472 list5.append(user1) 473 474 if task_work_ids:475 for task_work in task_work_ids:476 val3 = self.pool.get('project.task.work').browse(self.cr, 1, task_work)477 tw = val3.user_id and val3.user_id.id or False478 task1 = val3.task_id and val3.task_id.id or False479 list4.append(task1)480 list3.append(tw)481 total_task = list4 + task_ids 482 if total_task:483 total_task = list(set(total_task)) 484 total_user = list3 + list5485 if total_user:486 total_user = list(set(total_user))487 for val1 in total_user:488 val2 = self.pool.get('res.users').browse(self.cr, 1, val1)489 done_by = val2.name or '' 490 491 c_specs = map(lambda x: self.render(x, self.col_specs_template2, 'lines'), wanted_list)492 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])493 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)494 495 list2 = self.pool.get('project.task').search(self.cr, 1, [('id','in',total_task),('user_id','=',val1)]) 496 if list2:497 for val_task in list2:498 val = self.pool.get('project.task').browse(self.cr, 1, val_task) 499 task = val.name or '' 500 planned_hours = val.planned_hours501 remaining_hours = val.remaining_hours502 description = val.description or ''503 504 starting_date = val.date_start or ''505 if starting_date=='':506 starting_date = '' 507 else: 508 starting_date = datetime.strptime(starting_date,"%Y-%m-%d %H:%M:%S")509 starting_date = starting_date.strftime("%d-%b-%Y")510 511 deadline_date = val.date_deadline or ''512 if deadline_date=='':513 deadline_date = ''514 else:515 deadline_date = datetime.strptime(deadline_date,"%Y-%m-%d")516 deadline_date = deadline_date.strftime("%d-%b-%Y")517 518 ending_date = val.date_end or ''519 if ending_date=='':520 ending_date = ''521 else: 522 ending_date = datetime.strptime(ending_date,"%Y-%m-%d %H:%M:%S")523 ending_date = ending_date.strftime("%d-%b-%Y")524 525 526 stage = val.stage_id and val.stage_id.name or ''527 528 c_specs = map(lambda x: self.render(x, self.col_specs_template3, 'lines'), wanted_list)529 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])530 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)531 532 if val.work_ids:533 for val6 in val.work_ids:534 535 if val6.date>=from_date and val6.date<=till_datetime:536 work_summary = val6.name or ''537 time_spent = round(val6.hours,2) or 0.0538 539 date = val6.date or ''540 date = datetime.strptime(date,"%Y-%m-%d %H:%M:%S")541 date = date.strftime("%d-%b-%Y")542 543 reviewer = val6.task_id and val6.task_id.reviewer_id and val6.task_id.reviewer_id.name or ''544 545 c_specs = map(lambda x: self.render(x, self.col_specs_template, 'lines'), wanted_list)546 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])547 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style) 548 549work_summary_xls('report.work.summary.xls',550 'project.task.report.wizard',551 parser=work_summary_xls_parser)552_ir_translation_name = 'work.summary.report.xls'553class work_summary_report_xls_parser(report_sxw.rml_parse):554 def __init__(self, cr, uid, name, context):555 super(work_summary_report_xls_parser, self).__init__(cr, uid, name, context=context)556 wiz_obj = self.pool.get('project.task.report.wizard')557 self.context = context558 wanted_list = wiz_obj._report_xls_work_summary_report_fields(cr, uid, context)559 template_changes = wiz_obj._report_xls_template(cr, uid, context)560 self.localcontext.update({561 'datetime': datetime,562 'wanted_list': wanted_list,563 'template_changes': template_changes,564 '_': self._,565 })566 567 def _(self, src):568 lang = self.context.get('lang', 'en_US')569 return translate(self.cr, _ir_translation_name, 'report', lang, src) or src570class work_summary_report_xls(report_xls):571 def __init__(self, name, table, rml=False, parser=False, header=True, store=False):572 super(work_summary_report_xls, self).__init__(name, table, rml, parser, header, store)573 # Cell Styles574 _xs = self.xls_styles575 # header576 rh_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']577 self.rh_cell_style = xlwt.easyxf(rh_cell_format)578 self.rh_cell_style_center = xlwt.easyxf(rh_cell_format + _xs['center'])579 self.rh_cell_style_right = xlwt.easyxf(rh_cell_format + _xs['right'])580 # lines581 aml_cell_format = _xs['borders_all']582 self.aml_cell_style = xlwt.easyxf(aml_cell_format)583 self.aml_cell_style_center = xlwt.easyxf(aml_cell_format + _xs['center'])584 self.aml_cell_style_date = xlwt.easyxf(aml_cell_format + _xs['left'], num_format_str=report_xls.date_format)585 self.aml_cell_style_decimal = xlwt.easyxf(aml_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)586 # totals587 rt_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']588 self.rt_cell_style = xlwt.easyxf(rt_cell_format)589 self.rt_cell_style_right = xlwt.easyxf(rt_cell_format + _xs['right'])590 self.rt_cell_style_decimal = xlwt.easyxf(rt_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)591 # XLS Template592 self.col_specs_template = {593 594 'col1': {595 'header': [1, 30, 'text', _render("_('Employee Name')")],596 'lines': [1, 0, 'text', _render("user_name or ''")],597 'totals': [1, 0, 'text', None]}, 598 'col2': {599 'header': [1, 30, 'text', _render("_('Estimated Effort (Hrs.)')")],600 'lines': [1,0, 'number', _render("planned_hrs_total")],601 'totals': [1, 0, 'text', None]}, 602 'col3': {603 'header': [1, 24, 'text', _render("_('Time Spent (Hrs.)')")],604 'lines': [1, 0, 'number', _render("time_spent_total")],605 'totals': [1,0, 'text', None]}, 606 607 608 }609 self.col_specs_template1 = {610 611 'col1': {612 'header': [1, 30, 'text', _render("_('')")],613 'lines': [1, 0, 'text', _render("from_date_print or ''")],614 'totals': [1, 0, 'text', None]}, 615 'col2': {616 'header': [1, 30, 'text', _render("_('')")],617 'lines': [1,0, 'text', _render("till_date_print or ''")],618 'totals': [1, 0, 'text', None]}, 619 'col3': {620 'header': [1, 24, 'text', _render("_('')")],621 'lines': [1, 0, 'text', _render("''")],622 'totals': [1,0, 'text', None]}, 623 624 625 } 626 def generate_xls_report(self, _p, _xs, data, objects, wb):627 wanted_list = _p.wanted_list628 self.col_specs_template.update(_p.template_changes)629 _ = _p._630 wage_pos = 'wage' in wanted_list and wanted_list.index('wage')631 epf_deduction_pos = 'epf_deduction' in wanted_list and wanted_list.index('epf_deduction')632# if not (credit_pos and debit_pos) and 'balance' in wanted_list:633# raise oproject.task.report.wizardrm.except_orm(_('Customisation Error!'),634# _("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))635 #report_name = objects[0]._description or objects[0]._name636 report_name = _("Employee Productivity Report - Summary")637 ws = wb.add_sheet(report_name[:31])638 ws.panes_frozen = True639 ws.remove_splits = True640 ws.portrait = 0 # Landscape641 ws.fit_width_to_pages = 1642 row_pos = 0643 # set print header/footer644 ws.header_str = self.xls_headers['standard']645 ws.footer_str = self.xls_footers['standard']646 # Title647 cell_style = xlwt.easyxf(_xs['xls_title'])648 c_specs = [649 ('report_name', 1, 0, 'text', report_name),650 ]651 row_data = self.xls_row_template(c_specs, ['report_name'])652 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)653# row_pos += 1654 row_pos = 1655 656 # Column headers657 # c_specs = map(lambda x: self.render(x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list)658 # row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])659 # row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)660 # ws.set_horz_split_pos(row_pos)661# row_data = self.xls_row_template(c_specs, _("Grand Total"))662# print"-------------*************",ws, row_pos, row_data,cell_style663# row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)664# row_pos += 1665 # account move lines666 667 time_spent_total = 0.0668 planned_hrs_total = 0.0669 total_users = []670 task_work_ids = []671 task_list = []672 for line in objects:673 print"line===================",line,"object",objects674 from_date = line.from_date675 till_date = line.till_date 676 till_datetime = datetime.strptime(till_date,"%Y-%m-%d")677 till_datetime = till_datetime.strftime("%Y-%m-%d 23:59:59")678 from_date_format = datetime.strptime(from_date,"%Y-%m-%d")679 from_date_format = from_date_format.strftime("%d-%m-%Y")680 till_date_format = datetime.strptime(till_date,"%Y-%m-%d")681 till_date_format = till_date_format.strftime("%d-%m-%Y")682 from_date_print = 'From Date: ' + str(from_date_format)683 till_date_print = 'To Date: ' + str(till_date_format)684 c_specs = map(lambda x: self.render(x, self.col_specs_template1, 'lines'), wanted_list)685 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])686 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)687 688 c_specs = map(lambda x: self.render(x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list)689 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])690 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)691 ws.set_horz_split_pos(row_pos)692 user = self.pool.get('res.users').browse(self.cr, 1, self.uid)693 company_id = user.company_id.id or False694 total_users = self.pool.get('res.users').search(self.cr,1,[('company_id','=',company_id)], order='name')695 if total_users:696 for val in self.pool.get('res.users').browse(self.cr, 1, total_users):697 user_name = val.name or ''698 time_spent_total = 0.0699 planned_hrs_total = 0.0700 task_list = []701 task_work_ids = self.pool.get('project.task.work').search(self.cr,1,[('user_id','=',val.id),('date','>=',from_date),('date','<=',till_datetime)])702 if task_work_ids:703 for twork in self.pool.get('project.task.work').browse(self.cr, 1, task_work_ids):704 time_spent_total = time_spent_total + twork.hours 705 task_id=twork.task_id and twork.task_id.id or False706 if task_id not in task_list:707 task_list.append(task_id)708 planned_hrs_total = planned_hrs_total + twork.task_id.planned_hours709 planned_hrs_total = round(planned_hrs_total,2) or 0.0710 time_spent_total = round(time_spent_total,2) or 0.0 711 c_specs = map(lambda x: self.render(x, self.col_specs_template, 'lines'), wanted_list)712 row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])713 row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style) 714 715work_summary_report_xls('report.work.summary.report.xls',716 'project.task.report.wizard',717 parser=work_summary_report_xls_parser)718_ir_translation_name = 'project.status.report.summary.xls'719class project_status_report_summary_xls_parser(report_sxw.rml_parse):720 def __init__(self, cr, uid, name, context):721 super(project_status_report_summary_xls_parser, self).__init__(cr, uid, name, context=context)722 wiz_obj = self.pool.get('project.task.report.wizard')723 self.context = context724 wanted_list = wiz_obj._report_xls_project_status_report_summary_fields(cr, uid, context)725 template_changes = wiz_obj._report_xls_template(cr, uid, context)726 self.localcontext.update({727 'datetime': datetime,728 'wanted_list': wanted_list,729 'template_changes': template_changes,730 '_': self._,731 })732 733 def _(self, src):734 lang = self.context.get('lang', 'en_US')735 return translate(self.cr, _ir_translation_name, 'report', lang, src) or src736class project_status_report_summary_xls(report_xls):737 def __init__(self, name, table, rml=False, parser=False, header=True, store=False):738 super(project_status_report_summary_xls, self).__init__(name, table, rml, parser, header, store)739 # Cell Styles740 _xs = self.xls_styles741 # header742 rh_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']743 self.rh_cell_style = xlwt.easyxf(rh_cell_format)744 self.rh_cell_style_center = xlwt.easyxf(rh_cell_format + _xs['center'])745 self.rh_cell_style_right = xlwt.easyxf(rh_cell_format + _xs['right'])746 # lines747 aml_cell_format = _xs['borders_all']748 self.aml_cell_style = xlwt.easyxf(aml_cell_format)749 self.aml_cell_style_center = xlwt.easyxf(aml_cell_format + _xs['center'])750 self.aml_cell_style_date = xlwt.easyxf(aml_cell_format + _xs['left'], num_format_str=report_xls.date_format)751 self.aml_cell_style_decimal = xlwt.easyxf(aml_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)752 # totals753 rt_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']754 self.rt_cell_style = xlwt.easyxf(rt_cell_format)755 self.rt_cell_style_right = xlwt.easyxf(rt_cell_format + _xs['right'])756 self.rt_cell_style_decimal = xlwt.easyxf(rt_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)757 # XLS Template758 self.col_specs_template = {759 760 'col1': {761 'header': [1, 24, 'text', _render("_('Project Name')")],762 'lines': [1, 0, 'text', _render("''")],763 'totals': [1, 0, 'text', None]}, 764 'col2': {765 'header': [1, 24, 'text', _render("_('Task Name')")],766 'lines': [1, 0, 'text', _render("''")],767 'totals': [1,0, 'text', None]},768 'col3': {769 'header': [1, 12, 'text', _render("_('Stage')")],770 'lines': [1, 0, 'text', _render("''")],771 'totals': [1, 0, 'text', None]}, 772 'col4': {773 'header': [1, 15, 'text', _render("_('Planned Hours (Hrs.)')")],774 'lines': [1,0, 'text', _render("''")],775 'totals': [1, 0, 'text', None]}, 776 'col5': {777 'header': [1, 16, 'text', _render("_('Time Remaining (Hrs.)')")],778 'lines': [1, 0, 'text', _render("''")],779 'totals': [1, 0, 'text', None]}, 780 'col6': {781 'header': [1, 16, 'text', _render("_('Logged Hours (Hrs.)')")],782 'lines': [1, 0, 'text', _render("''")],783 'totals': [1, 0, 'text', None]}, 784 'col7': {785 'header': [1, 14, 'text', _render("_('Starting Date')")],786 'lines': [1, 0, 'text', _render("''")],787 'totals': [1, 0, 'text', None]},788 'col8': {789 'header': [1, 14, 'text', _render("_('Deadline Date')")],790 'lines': [1, 0, 'text', _render("''")],791 'totals': [1, 0, 'text', None]}, 792 'col9': {793 'header': [1, 14, 'text', _render("_('Ending Date')")],794 'lines': [1, 0, 'text', _render("''")],795 'totals': [1, 0, 'text', None]}, 796 'col10': {797 'header': [1, 30, 'text', _render("_('Description')")],798 'lines': [1, 0, 'text', _render("''")],799 'totals': [1, 0, 'text', None]}, 800 'col11': {801 'header': [1, 35, 'text', _render("_('Audit log Details')")],802 'lines': [1, 0, 'text', _render("''")],803 'totals': [1, 0, 'text', None]}, 804 805 806 }807 self.col_specs_template1 = {808 809 'col1': {810 'header': [1, 24, 'text', _render("_('')")],811 'lines': [1, 0, 'text', _render("project or ''")],812 'totals': [1, 0, 'text', None]}, 813 'col2': {814 'header': [1, 24, 'text', _render("_('')")],815 'lines': [1, 0, 'text', _render("''")],816 'totals': [1,0, 'text', None]},817 'col3': {818 'header': [1, 12, 'text', _render("_('')")],819 'lines': [1, 0, 'text', _render("''")],820 'totals': [1, 0, 'text', None]}, 821 'col4': {822 'header': [1, 15, 'text', _render("_('')")],823 'lines': [1,0, 'text', _render("''")],824 'totals': [1, 0, 'text', None]}, 825 'col5': {826 'header': [1, 16, 'text', _render("_('')")],827 'lines': [1, 0, 'text', _render("''")],828 'totals': [1, 0, 'text', None]}, 829 'col6': {830 'header': [1, 16, 'text', _render("_('')")],831 'lines': [1, 0, 'text', _render("''")],832 'totals': [1, 0, 'text', None]}, 833 'col7': {834 'header': [1, 14, 'text', _render("_('')")],835 'lines': [1, 0, 'text', _render("''")],836 'totals': [1, 0, 'text', None]}, 837 'col8': {838 'header': [1, 14, 'text', _render("_('')")],839 'lines': [1, 0, 'text', _render("''")],840 'totals': [1, 0, 'text', None]},841 'col9': {842 'header': [1, 14, 'text', _render("_('')")],843 'lines': [1, 0, 'text', _render("''")],844 'totals': [1, 0, 'text', None]}, 845 'col10': {846 'header': [1, 30, 'text', _render("_('')")],847 'lines': [1, 0, 'text', _render("''")],848 'totals': [1, 0, 'text', None]}, 849 'col11': {850 'header': [1, 35, 'text', _render("_('')")],851 'lines': [1, 0, 'text', _render("''")],852 'totals': [1, 0, 'text', None]}, 853 854 855 856 }857 858 self.col_specs_template2 = {859 860 'col1': {861 'header': [1, 24, 'text', _render("_('')")],862 'lines': [1, 0, 'text', _render("''")],863 'totals': [1, 0, 'text', None]}, 864 'col2': {865 'header': [1, 24, 'text', _render("_('')")],866 'lines': [1, 0, 'text', _render("''")],867 'totals': [1,0, 'text', None]},868 'col3': {869 'header': [1, 12, 'text', _render("_('')")],870 'lines': [1, 0, 'text', _render("''")],871 'totals': [1, 0, 'text', None]}, 872 'col4': {873 'header': [1, 15, 'text', _render("_('')")],874 'lines': [1,0, 'text', _render("''")],875 'totals': [1, 0, 'text', None]}, 876 'col5': {877 'header': [1, 16, 'text', _render("_('')")],878 'lines': [1, 0, 'text', _render("''")],879 'totals': [1, 0, 'text', None]}, 880 'col6': {881 'header': [1, 16, 'text', _render("_('')")],882 'lines': [1, 0, 'text', _render("''")],883 'totals': [1, 0, 'text', None]}, 884 'col7': {885 'header': [1, 14, 'text', _render("_('')")],886 'lines': [1, 0, 'text', _render("''")],887 'totals': [1, 0, 'text', None]},888 'col8': {889 'header': [1, 14, 'text', _render("_('')")],890 'lines': [1, 0, 'text', _render("''")],891 'totals': [1, 0, 'text', None]}, 892 'col9': {893 'header': [1, 14, 'text', _render("_('')")],894 'lines': [1, 0, 'text', _render("''")],895 'totals': [1, 0, 'text', None]}, 896 'col10': {897 'header': [1, 30, 'text', _render("_('')")],898 'lines': [1, 0, 'text', _render("''")],899 'totals': [1, 0, 'text', None]}, 900 'col11': {901 'header': [1, 35, 'text', _render("_('')")],902 'lines': [1, 0, 'text', _render("msg_body or ''")],903 'totals': [1, 0, 'text', None]}, 904 905 906 } 907 908 self.col_specs_template3 = {909 910 'col1': {911 'header': [1, 24, 'text', _render("_('')")],912 'lines': [1, 0, 'text', _render("''")],913 'totals': [1, 0, 'text', None]}, 914 'col2': {915 'header': [1, 24, 'text', _render("_('')")],916 'lines': [1, 0, 'text', _render("task or ''")],917 'totals': [1,0, 'text', None]},918 'col3': {919 'header': [1, 12, 'text', _render("_('')")],920 'lines': [1, 0, 'text', _render("stage or ''")],921 'totals': [1, 0, 'text', None]}, 922 'col4': {923 'header': [1, 15, 'text', _render("_('')")],924 'lines': [1,0, 'number', _render("planned_hours")],925 'totals': [1, 0, 'text', None]}, 926 'col5': {927 'header': [1, 16, 'text', _render("_('')")],928 'lines': [1, 0, 'number', _render("remaining_hours")],929 'totals': [1, 0, 'text', None]}, 930 'col6': {931 'header': [1, 16, 'text', _render("_('')")],932 'lines': [1, 0, 'number', _render("logged_hours")],933 'totals': [1, 0, 'text', None]}, 934 'col7': {935 'header': [1, 14, 'text', _render("_('')")],936 'lines': [1, 0, 'text', _render("starting_date")],937 'totals': [1, 0, 'text', None]}, 938 'col8': {939 'header': [1, 14, 'text', _render("_('')")],940 'lines': [1, 0, 'text', _render("deadline_date")],941 'totals': [1, 0, 'text', None]}, 942 'col9': {943 'header': [1, 14, 'text', _render("_('')")],944 'lines': [1, 0, 'text', _render("ending_date")],945 'totals': [1, 0, 'text', None]}, 946 'col10': {947 'header': [1, 30, 'text', _render("_('')")],948 'lines': [1, 0, 'text', _render("description")],949 'totals': [1, 0, 'text', None]}, 950 'col11': {951 'header': [1, 35, 'text', _render("_('')")],952 'lines': [1, 0, 'text', _render("''")],953 'totals': [1, 0, 'text', None]},954 955 } 956 self.col_specs_template4 = {957 958 'col1': {959 'header': [1, 24, 'text', _render("_('')")],960 'lines': [1, 0, 'text', _render("from_date_print or ''")],961 'totals': [1, 0, 'text', None]}, 962 'col2': {963 'header': [1, 24, 'text', _render("_('')")],964 'lines': [1, 0, 'text', _render("till_date_print or ''")],965 'totals': [1,0, 'text', None]},966 'col3': {967 'header': [1, 12, 'text', _render("_('')")],968 'lines': [1, 0, 'text', _render("''")],969 'totals': [1, 0, 'text', None]}, 970 'col4': {971 'header': [1, 15, 'text', _render("_('')")],972 'lines': [1,0, 'text', _render("''")],973 'totals': [1, 0, 'text', None]}, 974 'col5': {975 'header': [1, 16, 'text', _render("_('')")],976 'lines': [1, 0, 'text', _render("''")],977 'totals': [1, 0, 'text', None]}, 978 'col6': {979 'header': [1, 16, 'text', _render("_('')")],980 'lines': [1, 0, 'text', _render("''")],981 'totals': [1, 0, 'text', None]}, 982 'col7': {983 'header': [1, 14, 'text', _render("_('')")],984 'lines': [1, 0, 'text', _render("''")],985 'totals': [1, 0, 'text', None]},986 'col8': {987 'header': [1, 14, 'text', _render("_('')")],988 'lines': [1, 0, 'text', _render("''")],989 'totals': [1, 0, 'text', None]}, 990 'col9': {991 'header': [1, 14, 'text', _render("_('')")],992 'lines': [1, 0, 'text', _render("''")],993 'totals': [1, 0, 'text', None]}, 994 'col10': {995 'header': [1, 30, 'text', _render("_('')")],996 'lines': [1, 0, 'text', _render("''")],997 'totals': [1, 0, 'text', None]}, 998 'col11': {999 'header': [1, 35, 'text', _render("_('')")],1000 'lines': [1, 0, 'text', _render("''")],1001 'totals': [1, 0, 'text', None]}, 1002 1003 1004 } 1005 def generate_xls_report(self, _p, _xs, data, objects, wb):1006 wanted_list = _p.wanted_list1007 self.col_specs_template.update(_p.template_changes)1008 _ = _p._1009 wage_pos = 'wage' in wanted_list and wanted_list.index('wage')1010 epf_deduction_pos = 'epf_deduction' in wanted_list and wanted_list.index('epf_deduction')1011# if not (credit_pos and debit_pos) and 'balance' in wanted_list:1012# raise oproject.task.report.wizardrm.except_orm(_('Customisation Error!'),1013# _("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))1014 #report_name = objects[0]._description or objects[0]._name...

Full Screen

Full Screen

move_line_list_xls.py

Source:move_line_list_xls.py Github

copy

Full Screen

...61 num_format_str=report_xls.decimal_format)62 # XLS Template63 self.col_specs_template = {64 'move': {65 'header': [1, 20, 'text', _render("_('Entry')")],66 'lines': [1, 0, 'text', _render("line.move_id.name or ''")],67 'totals': [1, 0, 'text', None]},68 'name': {69 'header': [1, 42, 'text', _render("_('Name')")],70 'lines': [1, 0, 'text', _render("line.name or ''")],71 'totals': [1, 0, 'text', None]},72 'ref': {73 'header': [1, 42, 'text', _render("_('Reference')")],74 'lines': [1, 0, 'text', _render("line.ref or ''")],75 'totals': [1, 0, 'text', None]},76 'date': {77 'header': [1, 13, 'text', _render("_('Effective Date')")],78 'lines': [1, 0, 'date',79 _render("datetime.strptime(line.date,'%Y-%m-%d')"),80 None, self.aml_cell_style_date],81 'totals': [1, 0, 'text', None]},82 'period': {83 'header': [1, 12, 'text', _render("_('Period')")],84 'lines':85 [1, 0, 'text',86 _render("line.period_id.code or line.period_id.name")],87 'totals': [1, 0, 'text', None]},88 'partner': {89 'header': [1, 36, 'text', _render("_('Partner')")],90 'lines':91 [1, 0, 'text',92 _render("line.partner_id and line.partner_id.name or ''")],93 'totals': [1, 0, 'text', None]},94 'partner_ref': {95 'header': [1, 36, 'text', _render("_('Partner Reference')")],96 'lines':97 [1, 0, 'text',98 _render("line.partner_id and line.partner_id.ref or ''")],99 'totals': [1, 0, 'text', None]},100 'account': {101 'header': [1, 12, 'text', _render("_('Account')")],102 'lines': [1, 0, 'text', _render("line.account_id.code")],103 'totals': [1, 0, 'text', None]},104 'date_maturity': {105 'header': [1, 13, 'text', _render("_('Maturity Date')")],106 'lines':107 [1, 0,108 _render("line.date_maturity and 'date' or 'text'"),109 _render(110 "line.date_maturity"111 " and datetime.strptime(line.date_maturity,'%Y-%m-%d')"112 " or None"),113 None, self.aml_cell_style_date],114 'totals': [1, 0, 'text', None]},115 'debit': {116 'header': [1, 18, 'text', _render("_('Debit')"), None,117 self.rh_cell_style_right],118 'lines': [1, 0, 'number', _render("line.debit"), None,119 self.aml_cell_style_decimal],120 'totals': [1, 0, 'number', None, _render("debit_formula"),121 self.rt_cell_style_decimal]},122 'credit': {123 'header': [1, 18, 'text', _render("_('Credit')"), None,124 self.rh_cell_style_right],125 'lines': [1, 0, 'number', _render("line.credit"), None,126 self.aml_cell_style_decimal],127 'totals': [1, 0, 'number', None, _render("credit_formula"),128 self.rt_cell_style_decimal]},129 'balance': {130 'header': [1, 18, 'text', _render("_('Balance')"), None,131 self.rh_cell_style_right],132 'lines': [1, 0, 'number', None, _render("bal_formula"),133 self.aml_cell_style_decimal],134 'totals': [1, 0, 'number', None, _render("bal_formula"),135 self.rt_cell_style_decimal]},136 'reconcile': {137 'header': [1, 12, 'text', _render("_('Rec.')"), None,138 self.rh_cell_style_center],139 'lines': [1, 0, 'text',140 _render("line.reconcile_id.name or ''"), None,141 self.aml_cell_style_center],142 'totals': [1, 0, 'text', None]},143 'reconcile_partial': {144 'header': [1, 12, 'text', _render("_('Part. Rec.')"), None,145 self.rh_cell_style_center],146 'lines': [1, 0, 'text',147 _render("line.reconcile_partial_id.name or ''"),148 None, self.aml_cell_style_center],149 'totals': [1, 0, 'text', None]},150 'tax_code': {151 'header': [1, 12, 'text', _render("_('Tax Code')"), None,152 self.rh_cell_style_center],153 'lines': [1, 0, 'text', _render("line.tax_code_id.code or ''"),154 None, self.aml_cell_style_center],155 'totals': [1, 0, 'text', None]},156 'tax_amount': {157 'header': [1, 18, 'text', _render("_('Tax/Base Amount')"),158 None, self.rh_cell_style_right],159 'lines': [1, 0, 'number', _render("line.tax_amount"), None,160 self.aml_cell_style_decimal],161 'totals': [1, 0, 'text', None]},162 'amount_currency': {163 'header': [1, 18, 'text', _render("_('Am. Currency')"), None,164 self.rh_cell_style_right],165 'lines':166 [1, 0,167 _render("line.amount_currency and 'number' or 'text'"),168 _render("line.amount_currency or None"),169 None, self.aml_cell_style_decimal],170 'totals': [1, 0, 'text', None]},171 'currency_name': {172 'header': [1, 6, 'text', _render("_('Curr.')"), None,173 self.rh_cell_style_center],174 'lines':175 [1, 0, 'text',176 _render("line.currency_id and line.currency_id.name or ''"),177 None, self.aml_cell_style_center],178 'totals': [1, 0, 'text', None]},179 'journal': {180 'header': [1, 12, 'text', _render("_('Journal')")],181 'lines': [1, 0, 'text', _render("line.journal_id.code or ''")],182 'totals': [1, 0, 'text', None]},183 'company_currency': {184 'header': [1, 10, 'text', _render("_('Comp. Curr.')")],185 'lines': [1, 0, 'text',186 _render("line.company_id.currency_id.name or ''"),187 None, self.aml_cell_style_center],188 'totals': [1, 0, 'text', None]},189 'analytic_account': {190 'header': [1, 36, 'text', _render("_('Analytic Account')")],191 'lines': [1, 0, 'text',192 _render("line.analytic_account_id.code or ''")],193 'totals': [1, 0, 'text', None]},194 'product': {195 'header': [1, 36, 'text', _render("_('Product')")],196 'lines': [1, 0, 'text', _render("line.product_id.name or ''")],197 'totals': [1, 0, 'text', None]},198 'product_ref': {199 'header': [1, 36, 'text', _render("_('Product Reference')")],200 'lines': [1, 0, 'text',201 _render("line.product_id.default_code or ''")],202 'totals': [1, 0, 'text', None]},203 'product_uom': {204 'header': [1, 20, 'text', _render("_('Unit of Measure')")],205 'lines': [1, 0, 'text',206 _render("line.product_uom_id.name or ''")],207 'totals': [1, 0, 'text', None]},208 'quantity': {209 'header': [1, 8, 'text', _render("_('Qty')"), None,210 self.rh_cell_style_right],211 'lines': [1, 0,212 _render("line.quantity and 'number' or 'text'"),213 _render("line.quantity or None"), None,214 self.aml_cell_style_decimal],215 'totals': [1, 0, 'text', None]},216 'statement': {217 'header': [1, 20, 'text', _render("_('Statement')")],218 'lines':219 [1, 0, 'text',220 _render("line.statement_id and line.statement_id.name or ''")221 ],222 'totals': [1, 0, 'text', None]},223 'invoice': {224 'header': [1, 20, 'text', _render("_('Invoice')")],225 'lines':226 [1, 0, 'text',227 _render("line.invoice and line.invoice.number or ''")],228 'totals': [1, 0, 'text', None]},229 'amount_residual': {230 'header': [1, 18, 'text', _render("_('Residual Amount')"),231 None, self.rh_cell_style_right],232 'lines':233 [1, 0,234 _render("line.amount_residual and 'number' or 'text'"),235 _render("line.amount_residual or None"),236 None, self.aml_cell_style_decimal],237 'totals': [1, 0, 'text', None]},238 'amount_residual_currency': {239 'header': [1, 18, 'text', _render("_('Res. Am. in Curr.')"),240 None, self.rh_cell_style_right],241 'lines':242 [1, 0,243 _render(244 "line.amount_residual_currency and 'number' or 'text'"),245 _render("line.amount_residual_currency or None"),246 None, self.aml_cell_style_decimal],247 'totals': [1, 0, 'text', None]},248 'narration': {249 'header': [1, 42, 'text', _render("_('Notes')")],250 'lines': [1, 0, 'text',251 _render("line.move_id.narration or ''")],252 'totals': [1, 0, 'text', None]},253 'blocked': {254 'header': [1, 4, 'text', _('Lit.'),255 None, self.rh_cell_style_right],256 'lines': [1, 0, 'text', _render("line.blocked and 'x' or ''"),257 None, self.aml_cell_style_center],258 'totals': [1, 0, 'text', None]},259 }260 def generate_xls_report(self, _p, _xs, data, objects, wb):261 wanted_list = _p.wanted_list262 self.col_specs_template.update(_p.template_changes)263 _ = _p._264 debit_pos = 'debit' in wanted_list and wanted_list.index('debit')265 credit_pos = 'credit' in wanted_list and wanted_list.index('credit')266 if not (credit_pos and debit_pos) and 'balance' in wanted_list:267 raise orm.except_orm(268 _('Customisation Error!'),269 _("The 'Balance' field is a calculated XLS field requiring \270 the presence of the 'Debit' and 'Credit' fields !"))...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...8 with b.IF(sym.foo + 1 < sym.bar):9 b += sym.print('ok')10 result = b.source_code().strip()11 assert result == "if ((foo + 1) < bar):\n print('ok')"12def _render(expr):13 b = CodeBuilder()14 b += expr15 return b.source_code().strip()16def test_simple_literals():17 assert _render([]) == '[]'18 assert _render(()) == '()'19 assert _render(['ok']) == "['ok']"20 assert _render(('ok',)) == "('ok',)"21 assert _render([1, 2, 3]) == '[1, 2, 3]'22 assert _render((1, 2, 3)) == '(1, 2, 3)'23def test_collections_with_expressions():24 assert _render([sym.foo + 1, sym.bar('ok')]) == "[(foo + 1), bar('ok')]"25 assert _render([sym.foo({'key': sym.bar / 2})]) == "[foo({'key': (bar / 2)})]"26def test_function_calls():27 foo, bar = sym.foo, sym.bar28 assert _render(foo(bar, 'baz')) == "foo(bar, 'baz')"29 assert _render(foo(bar(foo))) == 'foo(bar(foo))'30 assert _render(foo(True, msg='hi', count=1)) == "foo(True, msg='hi', count=1)"31def test_simple_operators():32 foo, bar = sym.foo, sym.bar33 assert _render(foo + bar) == '(foo + bar)'34 assert _render(foo + 'bar') == "(foo + 'bar')"35 assert _render('foo' + bar) == "('foo' + bar)"36 assert _render(foo - bar) == '(foo - bar)'37 assert _render(foo - 10) == '(foo - 10)'38 assert _render(20 - bar) == '(20 - bar)'39 assert _render(foo * 30) == '(foo * 30)'40 assert _render(40 * foo) == '(40 * foo)'41 assert _render(bar @ 50) == '(bar @ 50)'42 assert _render(60 @ bar) == '(60 @ bar)'43 assert _render(foo / 70) == '(foo / 70)'44 assert _render(80 / foo) == '(80 / foo)'45 assert _render(bar // 90) == '(bar // 90)'46 assert _render(11 // bar) == '(11 // bar)'47 assert _render(foo & 12) == '(foo & 12)'48 assert _render(13 & foo) == '(13 & foo)'49 assert _render(bar | 14) == '(bar | 14)'50 assert _render(15 | bar) == '(15 | bar)'51 assert _render(foo ^ 16) == '(foo ^ 16)'52 assert _render(17 ^ foo) == '(17 ^ foo)'53 assert _render(foo > 18) == '(foo > 18)'54 assert _render(19 > foo) == '(foo < 19)'55 assert _render(bar < 20) == '(bar < 20)'56 assert _render(21 < bar) == '(bar > 21)'57 assert _render(foo >= 22) == '(foo >= 22)'58 assert _render(23 >= foo) == '(foo <= 23)'59 assert _render(bar <= 24) == '(bar <= 24)'60 assert _render(25 <= bar) == '(bar >= 25)'61 assert _render(foo == 26) == '(foo == 26)'62 assert _render(27 == foo) == '(foo == 27)'63 assert _render(bar != 28) == '(bar != 28)'64 assert _render(29 != bar) == '(bar != 29)'65 assert _render(foo % 10) == '(foo % 10)'66 assert _render(11 % foo) == '(11 % foo)'67 assert _render(bar ** 12) == '(bar ** 12)'68 assert _render(13 ** bar) == '(13 ** bar)'69 assert _render(foo >> 14) == '(foo >> 14)'70 assert _render(15 >> bar) == '(15 >> bar)'71 assert _render(foo.baz) == 'foo.baz'72 assert _render(foo[30]) == 'foo[30]'73 assert _render(foo.baz[31].fiz[32]) == 'foo.baz[31].fiz[32]'74 assert _render(-bar) == '(-bar)'75 assert _render(+bar) == '(+bar)'76 assert _render(~bar) == '(~bar)'77 assert _render(abs(foo)) == 'abs(foo)'78def test_for_statement():79 foo, bar = Code('foo'), Code('bar')80 b = CodeBuilder()81 b += bar << sym.baz()82 with b.FOR(foo, in_=bar):83 b += sym.print(foo)84 result = b.source_code().strip()85 assert result == 'bar = baz()\nfor foo in bar:\n print(foo)'86def test_extend_method():87 fiz, buz = sym('fiz'), sym('buz')88 b = CodeBuilder()89 b.extend([90 fiz << 'ok',91 buz << fiz.upper(),92 ])93 result = b.source_code().strip()94 assert result == "fiz = 'ok'\nbuz = fiz.upper()"95def test_unpacking_assignment():96 zim, zam, zoom = Code('zim'), Code('zam'), Code('zoom')97 assert _render((zim, zam) << zoom()) == '(zim, zam) = zoom()'98 assert _render([zim, zam] << zoom[0]) == '[zim, zam] = zoom[0]'99def test_slice_expression():100 foo, bar = sym.foo, sym.bar101 assert _render(foo[bar : 10]) == 'foo[slice(bar, 10, None)]'102 assert _render(bar[11 : foo]) == 'bar[slice(11, foo, None)]'103 assert _render(foo[1:9]) == 'foo[slice(1, 9, None)]'104def test_add_global_method():105 fiz, baz, buz = Code('fiz'), Code('baz'), Code('buz')106 b = CodeBuilder()107 with b.DEF('foo', ['bar', 'bam']):108 bar, bam = Code('bar'), Code('bam')109 b += fiz << bar + 1110 b.append_global(baz << 100)111 b.RETURN(bam < baz - fiz)112 b.append_global(Code('assert baz > 50'))113 assert b.source_code().strip() == dedent('''114 baz = 100115 assert baz > 50116 def foo(bar, bam):117 fiz = (bar + 1)118 return (bam < (baz - fiz))119 ''').strip()120def test_has_available_blocks():121 b = CodeBuilder()122 with ExitStack() as stack:123 for i in range(1, 20):124 assert b.current_num_blocks() == i125 assert b.has_available_blocks()126 stack.enter_context(b.IF(True))127 assert not b.has_available_blocks()128 assert b.current_num_blocks() == 1129 assert b.has_available_blocks()130 # Make sure that we can compile a source with 20 blocks.131 module = b.compile(source_var='_source_code')132 assert isinstance(module._source_code, str)133def test_var_method():134 b = CodeBuilder()135 b.var('foo', 1)136 b.var('foo', 2)137 foo = b.var('foo')138 b += foo << 3139 bar = b.var('bar')140 assert b.source_code().strip() == dedent('''141 foo1 = 1142 foo2 = 2143 foo3 = 3144 ''').strip()145def test_comment_methods():146 b = CodeBuilder()147 b.add_docstring('This is a docstring.\nTry using """triple quotes"""...')148 b.add_newline()149 with b.CLASS('Foo'):150 b.add_docstring('This is another docstring.')151 b.add_newline()152 with b.DEF('bar', ['self', 'baz', 'fiz']):153 fiz, baz, buz = Code('fiz'), Code('baz'), Code('buz')154 b.add_docstring('One more docstring.')155 b += Code('buz') << 123156 b.add_comment('This is a normal comment.\nThis is a second line.')157 b.RETURN(fiz + baz + buz)158 assert b.source_code().strip() == dedent(r'''159 """160 This is a docstring.161 Try using \"\"\"triple quotes\"\"\"...162 """163 class Foo:164 """165 This is another docstring.166 """167 def bar(self, baz, fiz):168 """169 One more docstring.170 """171 buz = 123172 # This is a normal comment.173 # This is a second line.174 return ((fiz + baz) + buz)175 ''').strip()176def test_control_flow_statements():177 zim, zam, zom = Code('zim'), Code('zam'), Code('zom')178 b = CodeBuilder()179 with b.WHILE(True): pass180 assert b.source_code().strip() == dedent('''181 while True:182 pass183 ''').strip()184 b = CodeBuilder()185 with b.WITH(zim(True), as_='fiz'): pass186 assert b.source_code().strip() == dedent('''187 with zim(True) as fiz:188 pass189 ''').strip()190 b = CodeBuilder()191 with b.WHILE(zim() > 0):192 with b.IF(zam(1, 2, 3) == 'ok'):193 b.ASSERT(Code('something') == Code('value'))194 b += zom('hi')195 with b.ELIF(zam(4, 5, 6) == 'fine'):196 b += zom('well')197 with b.ELSE():198 b += zom('bye')199 assert b.source_code().strip() == dedent('''200 while (zim() > 0):201 if (zam(1, 2, 3) == 'ok'):202 assert (something == value)203 zom('hi')204 elif (zam(4, 5, 6) == 'fine'):205 zom('well')206 else:207 zom('bye')208 ''').strip()209 b = CodeBuilder()210 with b.FOR(zim, in_=[1, 2, 3]):211 with b.IF_NOT(zam('ok')):212 with b.IF(zom('so')):213 b.YIELD('waiting')214 with b.ELIF_NOT(zam('fine')):215 with b.WHILE(zom('continue')):216 b.YIELD('running')217 assert b.source_code().strip() == dedent('''218 for zim in [1, 2, 3]:219 if not (zam('ok')):220 if zom('so'):221 yield 'waiting'222 elif not (zam('fine')):223 while zom('continue'):224 yield 'running'225 ''').strip()226 b = CodeBuilder()227 Foo, Bar = Code('Foo'), Code('Bar')228 with b.TRY():229 b.RAISE(Foo('fail'))230 with b.EXCEPT((Foo, Bar), as_='exc'):231 b += zim(1, 2, 3)232 with b.FINALLY():233 b.RETURN(zam(True))234 assert b.source_code().strip() == dedent('''235 try:236 raise Foo('fail')237 except (Foo, Bar) as exc:238 zim(1, 2, 3)239 finally:240 return zam(True)241 ''').strip()242def test_except_without_type_but_with_name():243 b = CodeBuilder()244 with pytest.raises(TypeError):245 b.EXCEPT(as_='foo')246def test_global_section():247 b = CodeBuilder()248 with b.DEF('foo', ['bar', 'baz']):249 with b.IF(Code('fiz')):250 with b.global_section():251 b += Code('bam') << 100252 b += Code('zim')(1, 2, 3)253 with b.ELSE():254 with b.global_section():255 b += Code('buz') << 200256 b += Code('zam')(4, 5, 6)257 assert b.source_code().strip() == dedent('''258 bam = 100259 buz = 200260 def foo(bar, baz):261 if fiz:262 zim(1, 2, 3)263 else:264 zam(4, 5, 6)265 ''').strip()266def test_yield_expression():267 expr = sym.foo << Yield(sym.bar(1, 2, 3))...

Full Screen

Full Screen

render_servlet_test.py

Source:render_servlet_test.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright 2013 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5import unittest6from extensions_paths import EXAMPLES, PUBLIC_TEMPLATES, STATIC_DOCS7from local_file_system import LocalFileSystem8from render_servlet import RenderServlet9from server_instance import ServerInstance10from servlet import Request, Response11from test_util import ReadFile12class _RenderServletDelegate(RenderServlet.Delegate):13 def CreateServerInstance(self):14 return ServerInstance.ForTest(LocalFileSystem.Create())15class RenderServletTest(unittest.TestCase):16 def _Render(self, path, headers=None, host=None):17 return RenderServlet(Request.ForTest(path, headers=headers, host=host),18 _RenderServletDelegate()).Get()19 def testExtensionAppRedirect(self):20 self.assertEqual(21 Response.Redirect('/apps/storage', permanent=False),22 self._Render('storage'))23 def testChannelRedirect(self):24 for channel in ('stable', 'beta', 'dev', 'master'):25 self.assertEqual(26 Response.Redirect('/extensions/storage', permanent=True),27 self._Render('%s/extensions/storage' % channel))28 def testOldHostsRedirect(self):29 self.assertEqual(30 Response.Redirect('https://developer.chrome.com/extensions',31 permanent=False),32 self._Render('/chrome/extensions', host='http://code.google.com'))33 self.assertEqual(34 Response.Redirect('https://developer.chrome.com/extensions',35 permanent=False),36 self._Render('/chrome/extensions', host='https://code.google.com'))37 def testNotFound(self):38 def create_404_response(real_path):39 real_404 = self._Render(real_path)40 self.assertEqual(200, real_404.status)41 real_404.status = 40442 return real_40443 root_404 = create_404_response('404')44 extensions_404 = create_404_response('extensions/404')45 apps_404 = create_404_response('apps/404')46 self.assertEqual(root_404, self._Render('not_found'))47 self.assertEqual(root_404, self._Render('not_found/not_found'))48 self.assertEqual(extensions_404, self._Render('extensions/not_found'))49 self.assertEqual(50 extensions_404, self._Render('extensions/manifest/not_found'))51 self.assertEqual(52 extensions_404,53 self._Render('extensions/manifest/not_found/not_found'))54 self.assertEqual(apps_404, self._Render('apps/not_found'))55 self.assertEqual(apps_404, self._Render('apps/manifest/not_found'))56 self.assertEqual(57 apps_404, self._Render('apps/manifest/not_found/not_found'))58 def testSampleFile(self):59 sample_file = 'extensions/talking_alarm_clock/background.js'60 response = self._Render('extensions/examples/%s' % sample_file)61 self.assertEqual(200, response.status)62 self.assertTrue(response.headers['Content-Type'] in (63 'application/javascript; charset=utf-8',64 'application/x-javascript; charset=utf-8'))65 self.assertEqual(ReadFile('%s%s' % (EXAMPLES, sample_file)),66 response.content.ToString())67 def testSampleZip(self):68 sample_dir = 'extensions/talking_alarm_clock'69 response = self._Render('extensions/examples/%s.zip' % sample_dir)70 self.assertEqual(200, response.status)71 self.assertEqual('application/zip', response.headers['Content-Type'])72 def testStaticFile(self):73 static_file = 'css/out/site.css'74 response = self._Render('static/%s' % static_file)75 self.assertEqual(200, response.status)76 self.assertEqual('text/css; charset=utf-8',77 response.headers['Content-Type'])78 self.assertEqual(ReadFile('%s%s' % (STATIC_DOCS, static_file)),79 response.content.ToString())80 def testHtmlTemplate(self):81 html_file = 'extensions/storage'82 response = self._Render(html_file)83 self.assertEqual(200, response.status)84 self.assertEqual('text/html; charset=utf-8',85 response.headers.get('Content-Type'))86 # Can't really test rendering all that well.87 self.assertTrue(len(response.content) >88 len(ReadFile('%s%s.html' % (PUBLIC_TEMPLATES, html_file))))89 def testIndexRender(self):90 response = self._Render('extensions')91 self.assertEqual(200, response.status)92 self.assertEqual(self._Render('extensions/index').content.ToString(),93 response.content.ToString())94 def testOtherRedirectsJsonRedirect(self):95 response = self._Render('apps/webview_tag')96 self.assertEqual(('/apps/tags/webview', False),97 response.GetRedirect())98 def testDirectories(self):99 # Directories should be redirected to a URL that doesn't end in a '/'100 # whether or not that exists.101 self.assertEqual(('/dir', False), self._Render('dir/').GetRedirect())102 def testEtags(self):103 def test_path(path, content_type):104 # Render without etag.105 response = self._Render(path)106 self.assertEqual(200, response.status)107 etag = response.headers.get('ETag')108 self.assertTrue(etag is not None)109 # Render with an If-None-Match which doesn't match.110 response = self._Render(path, headers={111 'If-None-Match': '"fake etag"',112 })113 self.assertEqual(200, response.status)114 self.assertEqual(content_type, response.headers.get('Content-Type'))115 self.assertEqual(etag, response.headers.get('ETag'))116 # Render with the correct matching If-None-Match.117 response = self._Render(path, headers={118 'If-None-Match': etag,119 })120 self.assertEqual(304, response.status)121 self.assertEqual('Not Modified', response.content.ToString())122 self.assertEqual(content_type, response.headers.get('Content-Type'))123 self.assertEqual(etag, response.headers.get('ETag'))124 # Test with a static path and a dynamic path.125 test_path('static/css/out/site.css', 'text/css; charset=utf-8')126 test_path('extensions/storage', 'text/html; charset=utf-8')127if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful