def process_bom(bom, currency_id, factor=1): xml = '<row>' sum = 0 sum_strd = 0 prod = product_pool.browse(cr, uid, bom['product_id']) prod_name = to_xml(bom['name']) prod_qtty = factor * bom['product_qty'] product_uom = product_uom_pool.browse(cr, uid, bom['product_uom'], context=context) product_uom_name = to_xml(product_uom.name) main_sp_price, main_sp_name, main_strd_price = '', '', '' sellers, sellers_price = '', '' if prod.seller_id: main_sp_name = '- <b>' + to_xml( prod.seller_id.name) + '</b>\r\n' pricelist = prod.seller_id.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, prod.seller_id.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] main_sp_price = """<b>""" + rml_obj.formatLang(price) + ' ' + ( company_currency_symbol) + """</b>\r\n""" sum += prod_qtty * price std_price = product_uom_pool._compute_price( cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id) main_strd_price = str(std_price) + '\r\n' sum_strd = prod_qtty * std_price for seller_id in prod.seller_ids: sellers += '- <i>' + to_xml(seller_id.name.name) + '</i>\r\n' pricelist = seller_id.name.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, seller_id.name.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] sellers_price += """<i>""" + rml_obj.formatLang( price) + ' ' + (company_currency_symbol) + """</i>\r\n""" xml += """<col para='yes'> """ + prod_name + """ </col> <col para='yes'> """ + main_sp_name + sellers + """ </col> <col f='yes'>""" + rml_obj.formatLang( prod_qtty) + ' ' + product_uom_name + """</col> <col f='yes'>""" + rml_obj.formatLang( float(main_strd_price)) + ' ' + ( company_currency_symbol) + """</col> <col f='yes'>""" + main_sp_price + sellers_price + """</col>'""" xml += '</row>' return xml, sum, sum_strd
def fields_view_get(self, cr, uid, view_id=None, view_type="form", context=None, toolbar=False, submenu=False): if context is None: context = {} wiz_id = self.pool.get("ir.actions.act_window").search( cr, uid, [("name", "=", "analytic.plan.create.model.action")], context=context ) res = super(account_analytic_plan_instance, self).fields_view_get( cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu ) journal_obj = self.pool.get("account.journal") analytic_plan_obj = self.pool.get("account.analytic.plan") if res["type"] == "form": plan_id = False if context.get("journal_id", False): plan_id = journal_obj.browse(cr, uid, int(context["journal_id"]), context=context).plan_id elif context.get("plan_id", False): plan_id = analytic_plan_obj.browse(cr, uid, int(context["plan_id"]), context=context) if plan_id: i = 1 res[ "arch" ] = """<form string="%s"> <field name="name"/> <field name="code"/> <field name="journal_id"/> <button name="%d" string="Save This Distribution as a Model" type="action" colspan="2"/> """ % ( tools.to_xml(plan_id.name), wiz_id[0], ) for line in plan_id.plan_ids: res[ "arch" ] += """ <field name="account%d_ids" string="%s" nolabel="1" colspan="4"> <tree string="%s" editable="bottom"> <field name="rate"/> <field name="analytic_account_id" domain="[('parent_id','child_of',[%d])]" groups="analytic.group_analytic_accounting"/> </tree> </field> <newline/>""" % ( i, tools.to_xml(line.name), tools.to_xml(line.name), line.root_analytic_id and line.root_analytic_id.id or 0, ) i += 1 res["arch"] += "</form>" doc = etree.fromstring(res["arch"].encode("utf8")) xarch, xfields = self._view_look_dom_arch(cr, uid, doc, view_id, context=context) res["arch"] = xarch res["fields"] = xfields return res else: return res
def process_bom(bom, currency_id, factor=1): xml = '<row>' sum = 0 sum_strd = 0 prod = product_pool.browse(cr, uid, bom['product_id']) prod_name = to_xml(bom['name']) prod_qtty = factor * bom['product_qty'] product_uom = product_uom_pool.browse(cr, uid, bom['product_uom'], context=context) product_uom_name = to_xml(product_uom.name) main_sp_price, main_sp_name , main_strd_price = '','','' sellers, sellers_price = '','' if prod.seller_id: main_sp_name = '- <b>'+ to_xml(prod.seller_id.name) +'</b>\r\n' pricelist = prod.seller_id.property_product_pricelist_purchase price = pricelist_pool.price_get(cr,uid,[pricelist.id], prod.id, number*prod_qtty or 1.0, prod.seller_id.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] main_sp_price = """<b>"""+rml_obj.formatLang(price)+' '+ (company_currency_symbol)+"""</b>\r\n""" sum += prod_qtty*price std_price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id) main_strd_price = str(std_price) + '\r\n' sum_strd = prod_qtty*std_price for seller_id in prod.seller_ids: if seller_id.name.id == prod.seller_id.id: continue sellers += '- <i>'+ to_xml(seller_id.name.name) +'</i>\r\n' pricelist = seller_id.name.property_product_pricelist_purchase price = pricelist_pool.price_get(cr,uid,[pricelist.id], prod.id, number*prod_qtty or 1.0, seller_id.name.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] sellers_price += """<i>"""+rml_obj.formatLang(price) +' '+ (company_currency_symbol) +"""</i>\r\n""" xml += """<col para='yes'> """+ prod_name +""" </col> <col para='yes'> """+ main_sp_name + sellers + """ </col> <col f='yes'>"""+ rml_obj.formatLang(prod_qtty) +' '+ product_uom_name +"""</col> <col f='yes'>"""+ rml_obj.formatLang(float(main_strd_price)) +' '+ (company_currency_symbol) +"""</col> <col f='yes'>""" + main_sp_price + sellers_price + """</col>'""" xml += '</row>' return xml, sum, sum_strd
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): if context is None: context = {} wiz_id = self.pool.get('ir.actions.act_window').search(cr, uid, [("name","=","analytic.plan.create.model.action")], context=context) res = super(account_analytic_plan_instance,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu) journal_obj = self.pool.get('account.journal') analytic_plan_obj = self.pool.get('account.analytic.plan') if (res['type']=='form'): plan_id = False if context.get('journal_id', False): plan_id = journal_obj.browse(cr, uid, int(context['journal_id']), context=context).plan_id elif context.get('plan_id', False): plan_id = analytic_plan_obj.browse(cr, uid, int(context['plan_id']), context=context) if plan_id: i=1 res['arch'] = """<form string="%s"> <field name="name"/> <field name="code"/> <field name="journal_id"/> <button name="%d" string="Save This Distribution as a Model" type="action" colspan="2"/> """% (tools.to_xml(plan_id.name), wiz_id[0]) for line in plan_id.plan_ids: res['arch']+=""" <field name="account%d_ids" string="%s" nolabel="1" colspan="4"> <tree string="%s" editable="bottom"> <field name="rate"/> <field name="analytic_account_id" domain="[('parent_id','child_of',[%d])]" groups="analytic.group_analytic_accounting"/> </tree> </field> <newline/>"""%(i,tools.to_xml(line.name),tools.to_xml(line.name),line.root_analytic_id and line.root_analytic_id.id or 0) i+=1 res['arch'] += "</form>" doc = etree.fromstring(res['arch'].encode('utf8')) xarch, xfields = self._view_look_dom_arch(cr, uid, doc, view_id, context=context) res['arch'] = xarch res['fields'] = xfields return res else: return res
def process_workcenter(wrk): workcenter = workcenter_pool.browse(cr, uid, wrk['workcenter_id']) cost_cycle = wrk['cycle']*workcenter.costs_cycle cost_hour = wrk['hour']*workcenter.costs_hour total = cost_cycle + cost_hour xml = '<row>' xml += "<col para='yes'>" + to_xml(workcenter.name) + '</col>' xml += "<col/>" xml += """<col f='yes'>"""+rml_obj.formatLang(cost_cycle)+' '+ (company_currency_symbol) + """</col>""" xml += """<col f='yes'>"""+rml_obj.formatLang(cost_hour)+' '+ (company_currency_symbol) + """</col>""" xml += """<col f='yes'>"""+rml_obj.formatLang(cost_hour + cost_cycle)+' '+ (company_currency_symbol) + """</col>""" xml += '</row>' return xml, total
def process_workcenter(wrk): workcenter = workcenter_pool.browse(cr, uid, wrk["workcenter_id"]) cost_cycle = wrk["cycle"] * workcenter.costs_cycle cost_hour = wrk["hour"] * workcenter.costs_hour total = cost_cycle + cost_hour xml = "<row>" xml += "<col para='yes'>" + to_xml(workcenter.name) + "</col>" xml += "<col/>" xml += """<col f='yes'>""" + rml_obj.formatLang(cost_cycle) + " " + (company_currency_symbol) + """</col>""" xml += """<col f='yes'>""" + rml_obj.formatLang(cost_hour) + " " + (company_currency_symbol) + """</col>""" xml += ( """<col f='yes'>""" + rml_obj.formatLang(cost_hour + cost_cycle) + " " + (company_currency_symbol) + """</col>""" ) xml += "</row>" return xml, total
def create(self, cr, uid, ids, datas, context): surv_obj = pooler.get_pool(cr.dbname).get('survey') user_obj = pooler.get_pool(cr.dbname).get('res.users') rml_obj=report_sxw.rml_parse(cr, uid, surv_obj._name,context) company=user_obj.browse(cr,uid,[uid],context)[0].company_id rml ="""<document filename="Survey Analysis Report.pdf"> <template pageSize="(595.0,842.0)" title="Survey Analysis" author="OpenERP S.A.([email protected])" allowSplitting="20"> <pageTemplate> <frame id="first" x1="1.3cm" y1="1.5cm" width="18.4cm" height="26.5cm"/> <pageGraphics> <fill color="black"/> <stroke color="black"/> <setFont name="DejaVu Sans" size="8"/> <drawString x="1.3cm" y="28.3cm"> """+to_xml(rml_obj.formatLang(time.strftime("%Y-%m-%d %H:%M:%S"),date_time=True))+"""</drawString> <setFont name="DejaVu Sans Bold" size="10"/> <drawString x="9.8cm" y="28.3cm">"""+ to_xml(company.name) +"""</drawString> <stroke color="#000000"/> <lines>1.3cm 28.1cm 20cm 28.1cm</lines> </pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="Table1"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6"/> </blockTableStyle> <blockTableStyle id="Table2"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table3"> <blockAlignment value="LEFT"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table4"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="Table5"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="Table_heading"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table_head_2"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="answer_right" alignment="RIGHT" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="Standard1" fontName="Helvetica-Bold" alignment="RIGHT" fontSize="09.0"/> <paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/> <paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/> <paraStyle name="response" fontName="Helvetica-Oblique" fontSize="9.5"/> <paraStyle name="response-bold" fontName="Helvetica-Bold" fontSize="9" alignment="RIGHT" /> <paraStyle name="page" fontName="Helvetica" fontSize="11.0" leftIndent="0.0"/> <paraStyle name="question" fontName="Helvetica-BoldOblique" fontSize="10.0" leftIndent="3.0"/> <paraStyle name="answer_bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="answer" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="title" fontName="Helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Center_heading" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> </stylesheet> <images/> """ if datas.has_key('form') and datas['form']['survey_ids']: ids = datas['form']['survey_ids'] for survey in surv_obj.browse(cr, uid, ids): rml += """<story> <para style="title">Answers Summary</para> <para style="Standard"><font></font></para> <para style="P2"> <font color="white"> </font> </para> <blockTable colWidths="280.0,100.0,120.0" style="Table_heading"> <tr> <td> <para style="terp_tblheader_General_Centre">Survey Title </para> </td> <td> <para style="terp_tblheader_General_Centre">Total Started Survey </para> </td> <td> <para style="terp_tblheader_General_Centre">Total Completed Survey </para> </td> </tr> </blockTable> <blockTable colWidths="280.0,100.0,120.0" style="Table_head_2"> <tr> <td> <para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para> </td> <td> <para style="terp_default_Centre_8">""" + str(survey.tot_start_survey) + """</para> </td> <td> <para style="terp_default_Centre_8">""" + str(survey.tot_comp_survey) + """</para> </td> </tr> </blockTable> <para style="P2"> <font color="white"> </font> </para>""" for page in survey.page_ids: rml += """ <blockTable colWidths="500" style="Table4"> <tr> <td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td> </tr> </blockTable>""" for que in page.question_ids: rml +="""<blockTable colWidths="500" style="Table5"> <tr> <td><para style="question">""" + to_xml(tools.ustr(que.question)) + """</para></td> </tr> </blockTable>""" cols_widhts = [] if que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans']: cols_widhts.append(200) for col in range(0, len(que.column_heading_ids) + 1): cols_widhts.append(float(300 / (len(que.column_heading_ids) + 1))) colWidths = ",".join(map(tools.ustr, cols_widhts)) matrix_ans = [(0,'')] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append((col.id,col.title)) rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>""" for mat_col in range(0, len(matrix_ans)): rml+="""<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>""" rml += """<td><para style="response-bold">Answer Count</para></td> </tr>""" last_col = cols_widhts[-1] for ans in que.answer_choice_ids: rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>""" cr.execute("select count(id) from survey_response_answer sra where sra.answer_id = %s", (ans.id,)) tot_res = cr.fetchone()[0] cr.execute("select count(id) ,sra.column_id from survey_response_answer sra where sra.answer_id=%s group by sra.column_id", (ans.id,)) calc_res = cr.dictfetchall() for mat_col in range(1, len(matrix_ans)): percantage = 0.0 cal_count = 0 for cal in calc_res: if cal['column_id'] == matrix_ans[mat_col][0]: cal_count = cal['count'] if tot_res: percantage = round(float(cal_count)*100 / tot_res,2) if percantage: rml += """<td color="#FFF435"><para style="answer_bold">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>""" else: rml += """<td color="#FFF435"><para style="answer">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>""" rml += """<td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td> </tr>""" rml += """</blockTable>""" if que.is_comment_require: cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''",(que.id,)) tot_res = cr.fetchone()[0] rml += """<blockTable colWidths=" """+ str(500 - last_col) +"," + str(last_col) + """ " style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td> <td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>""" elif que.type in['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'multiple_textboxes','date_and_time','date','multiple_textboxes_diff_type']: rml += """<blockTable colWidths="240.0,210,50.0" style="Table1">""" rml += """ <tr> <td> <para style="Standard"> </para></td> <td> <para style="terp_default_Center_heading">Answer Percentage</para></td> <td> <para style="response-bold">Answer Count</para></td> </tr>""" for ans in que.answer_choice_ids: progress = ans.average * 7 / 100 rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td> <td> <illustration> <stroke color="lightslategray"/> <rect x="0.1cm" y="-0.45cm" width="7.2 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/> """ if progress: rml += """<fill color="lightsteelblue"/> <rect x="0.2cm" y="-0.35cm" width='""" + tools.ustr(str(float(progress)) +'cm') + """' height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>""" rml += """ <fill color="black"/> <setFont name="Helvetica" size="9"/> <drawString x="3.2cm" y="-0.30cm">""" + tools.ustr(ans.average) + """%</drawString></illustration> </td> <td><para style="answer_right">""" + tools.ustr(ans.response) + """</para></td></tr>""" rml += """</blockTable>""" if que.is_comment_require: # if que.make_comment_field: # cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,)) # tot_res = cr.fetchone()[0] # tot_avg = 0.00 # if que.tot_resp: # tot_avg = round(float(tot_res * 100)/ que.tot_resp,2) # rml+="""<blockTable colWidths="280.0,120,100.0" style="Table1"><tr><td><para style="answer">""" +to_xml(tools.ustr(que.comment_label)) + """</para></td> # <td><para style="answer">""" + str(tot_avg) + """%</para></td> # <td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>""" # else: cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,)) tot_res = cr.fetchone()[0] rml += """<blockTable colWidths="450.0,50.0" style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td> <td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>""" elif que.type in['single_textbox']: cr.execute("select count(id) from survey_response_line where question_id = %s and single_text!=''",(que.id,)) rml += """<blockTable colWidths="400.0,100.0" style="Table1"> <tr> <td> <para style="Standard"> </para></td> <td> <para style="response-bold">Answer Count</para></td> </tr> <tr><td><para style="answer"></para></td> <td><para style="answer_right">""" + tools.ustr(cr.fetchone()[0]) + """ </para></td></tr> </blockTable>""" elif que.type in['comment']: cr.execute("select count(id) from survey_response_line where question_id = %s and comment !=''", (que.id,)) rml += """<blockTable colWidths="400.0,100.0" style="Table1"> <tr> <td> <para style="Standard"> </para></td> <td> <para style="response-bold">Answer Count</para></td> </tr> <tr><td><para style="answer"></para></td> <td><para style="answer_right">""" + tools.ustr(cr.fetchone()[0]) + """ </para></td></tr> </blockTable>""" elif que.type in['rating_scale']: cols_widhts.append(200) for col in range(0,len(que.column_heading_ids) + 2): cols_widhts.append(float(300 / (len(que.column_heading_ids) + 2))) colWidths = ",".join(map(tools.ustr, cols_widhts)) matrix_ans = [(0,'')] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append((col.id,col.title)) rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>""" for mat_col in range(0,len(matrix_ans)): rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>""" rml += """<td><para style="response-bold">Rating Average</para></td> <td><para style="response-bold">Answer Count</para></td> </tr>""" for ans in que.answer_choice_ids: rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>""" res_count = 0 rating_weight_sum = 0 for mat_col in range(1, len(matrix_ans)): cr.execute("select count(sra.answer_id) from survey_response_line sr, survey_response_answer sra\ where sr.id = sra.response_id and sra.answer_id = %s and sra.column_id ='%s'", (ans.id,matrix_ans[mat_col][0])) tot_res = cr.fetchone()[0] cr.execute("select count(sra.answer_id),sqc.rating_weight from survey_response_line sr, survey_response_answer sra ,\ survey_question_column_heading sqc where sr.id = sra.response_id and \ sqc.question_id = sr.question_id and sra.answer_id = %s and sqc.title ='%s'\ + group by sra.answer_id,sqc.rating_weight", (ans.id,matrix_ans[mat_col][1])) col_weight = cr.fetchone() if not col_weight: col_weight= (0,0) elif not col_weight[1]: col_weight = (col_weight[0],0) res_count = col_weight[0] if tot_res and res_count: rating_weight_sum += int(col_weight[1]) * tot_res tot_per = round((float(tot_res) * 100) / int(res_count), 2) else: tot_per = 0.0 if tot_res: rml += """<td><para style="answer_bold">""" + tools.ustr(tot_per) + "%(" + tools.ustr(tot_res) + """)</para></td>""" else: rml += """<td><para style="answer">""" + tools.ustr(tot_per)+"%(" + tools.ustr(tot_res) + """)</para></td>""" percantage = 0.00 if res_count: percantage = round((float(rating_weight_sum)/res_count), 2) rml += """<td><para style="answer_right">""" + tools.ustr(percantage) + """</para></td> <td><para style="answer_right">""" + tools.ustr(res_count) + """</para></td></tr>""" rml += """</blockTable>""" elif que.type in['matrix_of_drop_down_menus']: for column in que.column_heading_ids: rml += """<blockTable colWidths="500" style="Table1"><tr> <td><para style="answer">""" + to_xml(tools.ustr(column.title)) + """</para></td></tr></blockTable>""" menu_choices = column.menu_choice.split('\n') cols_widhts = [] cols_widhts.append(200) for col in range(0, len(menu_choices) + 1): cols_widhts.append(float(300 / (len(menu_choices) + 1))) colWidths = ",".join(map(tools.ustr, cols_widhts)) rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr> <td><para style="response"></para></td>""" for menu in menu_choices: rml += """<td><para style="response">""" + to_xml(tools.ustr(menu)) + """</para></td>""" rml += """<td><para style="response-bold">Answer Count</para></td></tr>""" cr.execute("select count(id), sra.answer_id from survey_response_answer sra \ where sra.column_id='%s' group by sra.answer_id ", (column.id,)) res_count = cr.dictfetchall() cr.execute("select count(sra.id),sra.value_choice, sra.answer_id, sra.column_id from survey_response_answer sra \ where sra.column_id='%s' group by sra.value_choice ,sra.answer_id, sra.column_id", (column.id,)) calc_percantage = cr.dictfetchall() for ans in que.answer_choice_ids: rml += """<tr><td><para style="answer_right">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>""" for mat_col in range(0, len(menu_choices)): calc = 0 response = 0 for res in res_count: if res['answer_id'] == ans.id: response = res['count'] for per in calc_percantage: if ans.id == per['answer_id'] and menu_choices[mat_col] == per['value_choice']: calc = per['count'] percantage = 0.00 if calc and response: percantage = round((float(calc)* 100) / response,2) if calc: rml += """<td><para style="answer_bold">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>""" else: rml += """<td><para style="answer">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>""" response = 0 for res in res_count: if res['answer_id'] == ans.id: response = res['count'] rml += """<td><para style="answer_right">""" + tools.ustr(response) + """</para></td></tr>""" rml += """</blockTable>""" elif que.type in['numerical_textboxes']: rml += """<blockTable colWidths="240.0,20,100.0,70,70.0" style="Table1"> <tr> <td> <para style="Standard"> </para></td> <td> <para style="Standard"> </para></td> <td> <para style="response">Answer Average</para></td> <td> <para style="response">Answer Total</para></td> <td> <para style="response-bold">Answer Count</para></td> </tr>""" for ans in que.answer_choice_ids: cr.execute("select answer from survey_response_answer where answer_id=%s group by answer", (ans.id,)) tot_res = cr.dictfetchall() total = 0 for tot in tot_res: total += int(tot['answer']) per = 0.00 if len(tot_res): per = round((float(total) / len(tot_res)),2) rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td> <td> <para style="Standard"> </para></td> <td> <para style="answer">""" + tools.ustr(per) +"""</para></td> <td><para style="answer">""" + tools.ustr(total) + """</para></td> <td><para style="answer_right">""" + tools.ustr(len(tot_res)) + """</para></td></tr>""" rml+="""</blockTable>""" rml +="""<blockTable colWidths="300,100,100.0" style="Table3"> <tr> <td><para style="Standard1"></para></td> <td><para style="Standard1">Answered Question</para></td> <td><para style="Standard1">""" + tools.ustr(que.tot_resp) + """</para></td> </tr> <tr> <td><para style="Standard1"></para></td> <td><para style="Standard1">Skipped Question</para></td> <td><para style="Standard1">""" + tools.ustr(survey.tot_start_survey - que.tot_resp) + """</para></td> </tr> </blockTable>""" rml += """</story>""" rml += """</document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] self.internal_header=True pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create(self, cr, uid, ids, datas, context): _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 _pageSize = ('29.7cm', '21.1cm') if datas.has_key('form') and datas['form'].get('orientation', '') == 'vertical': if datas['form'].get('paper_size', '') == 'letter': _pageSize = ('21.6cm', '27.9cm') elif datas['form'].get('paper_size', '') == 'legal': _pageSize = ('21.6cm', '35.6cm') elif datas['form'].get('paper_size', '') == 'a4': _pageSize = ('21.1cm', '29.7cm') elif datas.has_key('form') and datas['form'].get('orientation', '') == 'horizontal': if datas['form'].get('paper_size', '') == 'letter': _pageSize = ('27.9cm', '21.6cm') elif datas['form'].get('paper_size', '') == 'legal': _pageSize = ('35.6cm', '21.6cm') elif datas['form'].get('paper_size', '') == 'a4': _pageSize = ('29.7cm', '21.1cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.90)) + 'cm' _tbl_widths = tools.ustr( float(_pageSize[0].replace('cm', '')) - float(2.10)) + 'cm' rml = """<document filename="Survey Form.pdf"> <template pageSize="(""" + _pageSize[0] + """,""" + _pageSize[ 1] + """)" title='Survey Form' author="OpenERP S.A.([email protected])" allowSplitting="20" > <pageTemplate id="first"> <frame id="first" x1="0.0cm" y1="1.0cm" width='""" + _frame_width + """' height='""" + _frame_height + """'/> <pageGraphics> <lineMode width="1.0"/> <lines>1.0cm """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """</lines> <lines>1.0cm """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00) ) + 'cm' + """ 1.0cm 1.00cm</lines> <lines>""" + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ 1.00cm</lines> <lines>1.0cm 1.00cm """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00) ) + 'cm' + """ 1.00cm</lines>""" if datas.has_key('form') and datas['form']['page_number']: rml += """ <fill color="gray"/> <setFont name="Helvetica" size="10"/> <drawRightString x='""" + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00) ) + 'cm' + """' y="0.6cm">Page : <pageNumber/> </drawRightString>""" rml += """</pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="ans_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="page_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="gray" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="title_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="black" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="question_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="note_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/> <paraStyle name="page" fontName="helvetica-bold" fontSize="15.0" leftIndent="0.0" textColor="white"/> <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leading="15" leftIndent="0.0" textColor="white"/> <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/> <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="0.0"/> <paraStyle name="descriptive_text" fontName="helvetica" fontSize="10.0" leftIndent="0.0"/> <paraStyle name="answer_left" alignment="LEFT" fontName="helvetica-bold" fontSize="8.0" leftIndent="0.0"/> <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> </stylesheet> <story>""" surv_obj = pooler.get_pool(cr.dbname).get('survey') for survey in surv_obj.browse(cr, uid, ids): rml += """ <blockTable colWidths='""" + _tbl_widths + """' style="title_tbl"> <tr><td><para style="title">""" + to_xml( tools.ustr(survey.title) ) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" if survey.note: rml += """ <para style="P2"></para> <blockTable colWidths='""" + _tbl_widths + """' style="note_table"> <tr><td><para style="descriptive_text">""" + to_xml( tools.ustr(survey.note) ) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" seq = 0 for page in survey.page_ids: seq += 1 rml += """ <blockTable colWidths='""" + _tbl_widths + """' style="page_tbl"> <tr><td><para style="page">""" + tools.ustr( seq ) + """. """ + to_xml( tools.ustr(page.title) ) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" if page.note: rml += """<para style="P2"></para><blockTable colWidths='""" + _tbl_widths + """' style="note_table"> <tr><td><para style="descriptive_text">""" + to_xml( tools.ustr(page.note or '')) + """</para></td></tr> </blockTable>""" for que in page.question_ids: cols_widhts = [] rml += """ <para style="P2"><font></font></para> <blockTable colWidths='""" + _tbl_widths + """' style="question_tbl"> <tr><td><para style="question">""" + to_xml( tools.ustr(que.question)) + """</para></td></tr> </blockTable> <para style="P2"><font></font></para>""" if que.type in ['descriptive_text']: cols_widhts.append(float(_tbl_widths.replace('cm', ''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' rml += """ <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr> <td> <para style="descriptive_text">""" + to_xml( tools.ustr(que.descriptive_text)) + """</para> </td> </tr> </blockTable>""" elif que.type in [ 'multiple_choice_multiple_ans', 'multiple_choice_only_one_ans' ]: answer = [] for ans in que.answer_choice_ids: answer.append(to_xml(tools.ustr((ans.answer)))) def divide_list(lst, n): return [lst[i::n] for i in range(n)] divide_list = divide_list(answer, _display_ans_in_rows) for lst in divide_list: if que.type == 'multiple_choice_multiple_ans': if len(lst) <> 0 and len(lst) <> int( round( float(len(answer)) / _display_ans_in_rows, 0)): lst.append('') if not lst: del divide_list[divide_list.index(lst):] for divide in divide_list: a = _divide_columns_for_matrix * len(divide) b = float(_tbl_widths.replace('cm', '')) - float(a) cols_widhts = [] for div in range(0, len(divide)): cols_widhts.append(float(a / len(divide))) cols_widhts.append(float(b / len(divide))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' rml += """<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr>""" for div in range(0, len(divide)): if divide[div] != '': if que.type == 'multiple_choice_multiple_ans': rml += """ <td> <illustration> <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/> </illustration> </td> <td><para style="answer">""" + divide[ div] + """</para></td>""" else: rml += """ <td> <illustration> <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/> </illustration> </td> <td><para style="answer">""" + divide[ div] + """</para></td>""" else: rml += """ <td></td> <td></td>""" rml += """ </tr></blockTable>""" elif que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus' ]: if len(que.column_heading_ids): cols_widhts.append( float(_tbl_widths.replace('cm', '')) / float(2.0)) for col in que.column_heading_ids: cols_widhts.append( float( (float(_tbl_widths.replace('cm', '')) / float(2.0)) / len(que.column_heading_ids))) else: cols_widhts.append( float(_tbl_widths.replace('cm', ''))) tmp = 0.0 sum = 0.0 i = 0 if que.comment_column: for col in cols_widhts: if i == 0: cols_widhts[i] = cols_widhts[i] / 2.0 tmp = cols_widhts[i] sum += col i += 1 cols_widhts.append(round(tmp, 2)) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' matrix_ans = [ '', ] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append(col.title) if que.comment_column: matrix_ans.append( to_xml(tools.ustr(que.column_name))) rml += """<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"><tr>""" for mat_col in matrix_ans: rml += """<td><para style="response">""" + to_xml( tools.ustr(mat_col)) + """</para></td>""" rml += """</tr></blockTable>""" i = 0 for ans in que.answer_choice_ids: if i % 2 != 0: style = 'ans_tbl_white' else: style = 'ans_tbl_gainsboro' i += 1 rml += """ <blockTable colWidths=" """ + colWidths + """ " style='""" + style + """'> <tr><td><para style="answer">""" + to_xml( tools.ustr(ans.answer)) + """</para></td>""" rec_width = float((sum - tmp) * 10 + 100) value = "" if que.type in ['matrix_of_drop_down_menus']: value = """ <fill color="white"/> <rect x="-0.1cm" y="-0.45cm" width='""" + tools.ustr( cols_widhts[-1] - 0.5 ) + "cm" + """' height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>""" elif que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ]: value = """ <fill color="white"/> <circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>""" else: value = """ <fill color="white"/> <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>""" for mat_col in range(1, len(matrix_ans)): if matrix_ans[mat_col] == que.column_name: if mat_col == 1: rml += """ <td><para style="answer_left">""" + to_xml( tools.ustr(que.column_name) ) + """</para></td>""" else: rml += """<td></td>""" else: rml += """<td><illustration>""" + value + """</illustration></td>""" rml += """</tr></blockTable>""" elif que.type in [ 'multiple_textboxes', 'numerical_textboxes', 'date_and_time', 'date', 'multiple_textboxes_diff_type' ]: cols_widhts.append( float(_tbl_widths.replace('cm', '')) / 2) cols_widhts.append( float(_tbl_widths.replace('cm', '')) / 2) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = tools.ustr(colWidths) + 'cm' for ans in que.answer_choice_ids: rml += """<para style="P1"></para> <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr> <td><para style="answer">""" + to_xml( tools.ustr(ans.answer) ) + """</para></td> <td> <illustration> <rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr( str(cols_widhts[0] - 0.3) + "cm" ) + """' height="0.6cm" fill="no" stroke="yes"/> </illustration> </td> </tr> </blockTable>""" elif que.type in ['comment']: cols_widhts.append(float(_tbl_widths.replace('cm', ''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) rml += """<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl"> <tr> <td><para style="comment"><font color="white"> </font></para> <illustration> <rect x="0.1cm" y="0.3cm" width='""" + tools.ustr( str(float(colWidths) - 0.6) + 'cm' ) + """' height="1.5cm" fill="no" stroke="yes"/> </illustration> </td> </tr> </blockTable>""" elif que.type in ['single_textbox']: cols_widhts.append(float(_tbl_widths.replace('cm', ''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) rml += """<para style="P2"><font color="white"> </font></para> <blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl"> <tr> <td> <illustration> <rect x="0.2cm" y="0.3cm" width='""" + tools.ustr( str(float(colWidths) - 0.7) + 'cm' ) + """' height="0.6cm" fill="no" stroke="yes"/> </illustration> </td> </tr> </blockTable>""" elif que.type in ['table']: tbl_width = float(_tbl_widths.replace('cm', '')) for i in range(0, len(que.column_heading_ids)): cols_widhts.append( tbl_width / float(len(que.column_heading_ids))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' rml += """<blockTable colWidths=" """ + colWidths + """ " style="tbl"><tr>""" for col in que.column_heading_ids: rml += """<td><para style="terp_tblheader_Details">""" + to_xml( tools.ustr(col.title)) + """</para></td>""" rml += """</tr></blockTable>""" i = 0 for r in range(0, que.no_of_rows): if i % 2 != 0: style = 'tbl_white' else: style = 'tbl_gainsboro' i += 1 rml += """<blockTable colWidths=" """ + colWidths + """ " style='""" + style + """'><tr>""" for c in que.column_heading_ids: rml += """ <td><para style="terp_default_9"><font color="white"> </font></para></td>""" rml += """</tr></blockTable>""" if datas.has_key( 'form') and not datas['form']['without_pagebreak']: rml += """<pageBreak/>""" elif not datas.has_key('form'): rml += """<pageBreak/>""" else: rml += """<para style="P2"><font></font></para>""" rml += """</story></document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create_xml(self,cr,uid,ids,datas,context={}): def _thousand_separator(decimal,amount): if not amount: amount = 0.0 if type(amount) is float : amount = str(decimal%amount) else : amount = str(amount) if (amount == '0'): return ' ' orig = amount new = re.sub("^(-?\d+)(\d{3})", "\g<1>.\g<2>", amount) if orig == new: return new else: return _thousand_separator(decimal,new) pool = openerp.registry(cr.dbname) order_obj = pool.get('sale.order') wh_obj = pool.get('stock.warehouse') session_obj = pool.get('pos.session') user_obj = pool.get('res.users') users = user_obj.browse(cr,uid,uid) warehouse_ids = datas['form']['warehouse_ids'] or wh_obj.search(cr, uid, []) company = users.company_id rml_parser = report_sxw.rml_parse(cr, uid, 'edukits_total_retail', context=context) rml = """ <document filename="test.pdf"> <template pageSize="(21.0cm,29.7cm)" title="Total Retail Report" author="SGEEDE" allowSplitting="20"> <pageTemplate id="first"> <frame id="first" x1="50.0" y1="0.0" width="500" height="830"/> </pageTemplate> </template> <stylesheet> <blockTableStyle id="Table1"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="parent_table"> <blockAlignment value="LEFT"/> <blockLeftPadding start="0,0" length="0.1cm"/> <blockRightPadding start="0,0" length="0.1cm"/> <blockTopPadding start="0,0" length="0.15cm"/> <blockBottomPadding start="0,0" length="0.15cm"/> </blockTableStyle> <blockTableStyle id="Table2"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table3"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table3_Normal"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding start="0,0" length="-0.15cm"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,1" stop="0,1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table3_PARENT"> <blockAlignment value="CENTER"/> <blockValign value="TOP"/> </blockTableStyle> """ for warehouse in wh_obj.browse(cr,uid,warehouse_ids): if warehouse.color: rml += """ <blockTableStyle id="Table3""" + to_xml(str(warehouse.color.name)) + """"> <blockBackground colorName="#"""+ to_xml(str(warehouse.color.color)) + """" start="0,0" stop="0,-1"/> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding start="0,0" length="0.1cm"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,1" stop="0,1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="0,0" stop="-1,-1"/> </blockTableStyle> """ if not warehouse.color: rml += """ <blockTableStyle id="Table3False"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding start="0,0" length="0.1cm"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,1" stop="0,1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="0,0" stop="-1,-1"/> </blockTableStyle> """ rml += """ <blockTableStyle id="Table3_LINE"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="2,0" stop="2,3"/> </blockTableStyle> <blockTableStyle id="Table3_LINE2"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table3_LINE2W"> <blockBackground colorName="white"/> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table1_line"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="2,0"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="2,0"/> </blockTableStyle> <blockTableStyle id="Table1_lines"> <blockBackground colorName="white"/> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="2,0"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="2,0"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="2,0"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="0,0" stop="2,0"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P2" fontName="Helvetica-Bold" fontSize="14.0" leading="17" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P3" fontName="Times-Roman" fontSize="11.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P4" fontName="Times-Roman" fontSize="11.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P5" fontName="Times-Roman" fontSize="11.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P6" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="P7" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="P8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="P9" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P10" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P11" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P12" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="P13" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P14" fontName="Helvetica-Bold" fontSize="12.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P15" textColor="black" fontName="Helvetica" fontSize="10.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P15_W" textColor="white" fontName="Helvetica" fontSize="10.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P15_RIGHT" textColor="black" fontName="Helvetica" fontSize="10.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P15_CENTER" textColor="black" fontName="Helvetica-Bold" fontSize="12.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P15_CENTER_2" textColor="black" fontName="Helvetica-Bold" fontSize="14.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P16" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P17" fontName="Times-Roman" fontSize="8.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P19" rightIndent="0.0" leftIndent="0.0" fontName="Times-Roman" fontSize="10.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P20" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="12.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="Standard" fontName="Times-Roman"/> <paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Table Contents" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Caption" fontName="Times-Roman" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="Index" fontName="Times-Roman"/> <paraStyle name="Heading" fontName="Helvetica" fontSize="15.0" leading="19" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="Footer" fontName="Times-Roman"/> <paraStyle name="Horizontal Line" fontName="Times-Roman" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/> <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_8" fontName="Helvetica" fontSize="9.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_8" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_Right_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="CENTER" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_header_Centre2" fontName="Helvetica-Bold" fontSize="12.0" leading="19" alignment="CENTER" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_header_Centre3" fontName="Helvetica-Bold" fontSize="12.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_default_address" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_12" fontName="Helvetica" fontSize="12.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_9" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_9_Right" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Centre_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="Heading 1" fontName="Times-Bold" fontSize="24.0" leading="29" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="Heading 2" fontName="Times-Bold" fontSize="20.0" leading="29" spaceBefore="0.0" spaceAfter="0.0"/> <images/> </stylesheet> <story> """ no_total = 1 rml += """ <blockTable colWidths="250,250" style="Table3_PARENT"> """ # Day transaction for batamcentre center = False currency_amount = 0 currency_symbol ='' bank_ids = [] date_end = datetime.strptime(datas['form']['date_end'],"%Y-%m-%d") for warehousebtc in wh_obj.browse(cr,uid,warehouse_ids): currency_amount = warehousebtc.currency_id.rate_silent currency_symbol = warehousebtc.currency_id.symbol location_id = warehousebtc.lot_stock_id date_start = datetime.strptime(datas['form']['date_end']+ ' 00:00:00',"%Y-%m-%d %H:%M:%S") date_stop = datetime.strptime(datas['form']['date_end']+ ' 17:59:59',"%Y-%m-%d %H:%M:%S") if warehousebtc.is_split: center = True sessionbtc_ids = session_obj.search(cr,uid,[('stock_location_rel','=',location_id.id),('stop_at','!=',False)]) session_ids = [] results = [] for sessions in session_obj.browse(cr,uid,sessionbtc_ids): stop_temp=datetime.strptime(sessions.stop_at,"%Y-%m-%d %H:%M:%S") tz_count = 0 hour_offset = "" minute_offset = "" for tz_offset in users.tz_offset: tz_count +=1 if tz_count <= 3: hour_offset += tz_offset elif tz_count <= 5: minute_offset +=tz_offset stop_at= stop_temp + relativedelta(hours=int(hour_offset)) if (stop_at >= date_start) and (stop_at <= date_stop): session_ids.append(sessions.id) if len(warehouse_ids) == 1: rml += """ <tr> <td> """ elif no_total % 2 == 0: rml += """<td>""" else: rml += """ <tr> <td> """ if warehousebtc.color: rml += """ <blockTable colWidths="210" style="Table3"> """ if not warehousebtc.color: rml += """ <blockTable colWidths="210" style="Table3_Normal"> """ rml += """ <tr> </tr> <tr> <td> <blockTable rowHeights="38" colWidths="198" style="Table3""" + to_xml(str(warehousebtc.color.name)) + """"> <tr> <td> <para style="P15_CENTER_2">"""+ to_xml(str(warehousebtc.name)) + """</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td> <para style="P15">TGL: """+ to_xml(str(format(date_end,'%d-%B-%y')))+"""</para> </td> </tr> </blockTable> <blockTable rowHeights="17" colWidths="198" style="Table3""" + to_xml(str(warehousebtc.color.name)) + """"> <tr> <td background="pink"> <para style="P15_CENTER">SETORAN</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td> """ total_card = 0.0 if not session_ids: rml +=""" <para style="P15">-</para> """ total_amount = 0.0 for session in session_obj.browse(cr,uid,session_ids): for bank in session.statement_ids: if bank.journal_id.type == 'bank': total_card +=bank.balance_end if session.cashier_deposit_ids: for cashier in session.cashier_deposit_ids: total_amount += cashier.amount_total rml += """ <para style="P15">""" + rml_parser.formatLang(total_amount+0, currency_obj=company.currency_id) + """</para> """ if session_ids: sessions = session_obj.browse(cr,uid,session_ids[0]) rml += """ </td> </tr> </blockTable> """ rml += """ <blockTable rowHeights="17" colWidths="198" style="Table3""" + to_xml(str(warehousebtc.color.name)) + """"> <tr> <td background="pink"> <para style="P15_CENTER">PENGELUARAN</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td background="pink"> <para style="P15_W">Table</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td background="pink"> <para style="P15_W">Table</para> </td> </tr> </blockTable> <blockTable colWidths="80,118" style="Table1_lines"> <tr> <td> <para style="P15">MAITRI</para> </td> <td> <para style="P15_RIGHT"></para> <para style="P15_RIGHT">""" + rml_parser.formatLang(total_amount+0, currency_obj=company.currency_id) +"""</para> </td> </tr> </blockTable> <blockTable colWidths="80,118" style="Table1_lines"> <tr> <td> <para style="P15">KURS :""" + rml_parser.formatLang(currency_amount,) +"""</para> </td> <td> <para style="P15_RIGHT">""" + rml_parser.formatLang(total_amount*currency_amount, currency_obj=warehousebtc.currency_id) +"""</para> </td> </tr> </blockTable> <blockTable colWidths="80,5,110" style="Table3_LINE2"> <tr> <td> <para style="P15"></para> </td> <td> <para style="P15"></para> </td> <td> <para style="P15_CENTER"></para> </td> </tr> </blockTable> </td> </tr> </blockTable> <spacer length="0.5cm"/>""" rml += """</td>""" if len(warehouse_ids) == 1: rml += """<td></td>""" rml += """ </tr> """ elif ( (no_total % 2 == 1 ) and (len(warehouse_ids) == no_total)): rml += """<td></td>""" rml += """ </tr> """ elif no_total % 2 == 0: rml += """ </tr> """ else: if len(warehouse_ids) == no_total: rml += """ </tr> """ no_total += 1 # Normal transaction for warehouse in wh_obj.browse(cr,uid,warehouse_ids): currency_amount = warehouse.currency_id.rate_silent location_id = warehouse.lot_stock_id.id results = [] total_bank = 0.0 if warehouse.is_split: date_start_day = datetime.strptime(datas['form']['date_end']+ ' 00:00:00',"%Y-%m-%d %H:%M:%S") date_stop_day = datetime.strptime(datas['form']['date_end']+ ' 17:59:59',"%Y-%m-%d %H:%M:%S") date_start = datetime.strptime(datas['form']['date_end']+ ' 18:00:00',"%Y-%m-%d %H:%M:%S") date_stop = datetime.strptime(datas['form']['date_end']+ ' 23:59:59',"%Y-%m-%d %H:%M:%S") sessions_ids = session_obj.search(cr,uid,[('stock_location_rel','=',location_id),('stop_at','!=',False)]) session_ids = [] session_day_ids = [] for sessions in session_obj.browse(cr,uid,sessions_ids): stop_temp=datetime.strptime(sessions.stop_at,"%Y-%m-%d %H:%M:%S") tz_count = 0 hour_offset = "" minute_offset = "" for tz_offset in users.tz_offset: tz_count +=1 if tz_count <= 3: hour_offset += tz_offset elif tz_count <= 5: minute_offset +=tz_offset stop_at= stop_temp + relativedelta(hours=int(hour_offset)) if (stop_at >= date_start) and (stop_at <= date_stop): session_ids.append(sessions.id) if (stop_at >= date_start_day) and (stop_at <= date_stop_day): session_day_ids.append(sessions.id) if not warehouse.is_split: session_ids = session_obj.search(cr,uid,[('stop_at','>=',datas['form']['date_end']+ ' 00:00:00'),('stop_at','<=',datas['form']['date_end']+ ' 23:59:59'),('stock_location_rel','=',location_id)]) if len(warehouse_ids) == 1: rml += """ <tr> <td> """ elif no_total % 2 == 0: rml += """<td>""" else: rml += """ <tr> <td> """ if warehouse.color: rml += """ <blockTable colWidths="210" style="Table3"> """ if not warehouse.color: rml += """ <blockTable colWidths="210" style="Table3_Normal"> """ rml += """ <tr> </tr> <tr> <td> <blockTable rowHeights="38" colWidths="198" style="Table3""" + to_xml(str(warehouse.color.name)) + """"> <tr> <td> <para style="P15_CENTER_2">"""+ to_xml(str(warehouse.name)) + """</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td> <para style="P15">TGL: """+ to_xml(str(format(date_end,'%d-%B-%y')))+"""</para> </td> </tr> </blockTable> <blockTable rowHeights="17" colWidths="198" style="Table3""" + to_xml(str(warehouse.color.name)) + """"> <tr> <td background="pink"> <para style="P15_CENTER">SETORAN</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td> """ total_card = 0.0 # if not session_ids: # rml +=""" # <para style="P15">-</para> # """ total_amount = 0.0 for session in session_obj.browse(cr,uid,session_ids): for bank in session.statement_ids: if bank.journal_id.type == 'bank': total_card +=bank.balance_end if session.cashier_deposit_ids: for cashier in session.cashier_deposit_ids: total_amount += cashier.amount_total rml += """ <para style="P15">""" + rml_parser.formatLang(total_amount+0, currency_obj=company.currency_id) + """</para> """ # if warehouse.is_split: if session_ids: sessions = session_obj.browse(cr,uid,session_ids[0]) if warehouse.is_split: rml += """ </td> </tr> </blockTable> <blockTable rowHeights="17" colWidths="198" style="Table3""" + to_xml(str(warehouse.color.name)) + """"> <tr> <td background="pink"> <para style="P15_CENTER">CC and DC (Siang)</para> </td> </tr> </blockTable> <blockTable colWidths="100,98" style="Table1_lines"> <tr> <td> """ if not session_day_ids: rml +=""" <para style="P15">-</para> """ session_list_day = [] bank_day_ids = [] for session in session_obj.browse(cr,uid,session_day_ids): session_list_day.append(session.id) if len(session_list_day) == 1: cr.execute(""" SELECT sum(abs.balance_end), aj.name from account_bank_statement abs inner join account_journal aj on abs.journal_id = aj.id where pos_session_id = %s and aj.type != 'cash' group by aj.name; """ % (tuple(session_list_day)[0],)) bank_ids = cr.fetchall() if len(session_list_day) > 1: cr.execute(""" SELECT sum(abs.balance_end), aj.name from account_bank_statement abs inner join account_journal aj on abs.journal_id = aj.id where pos_session_id in %s and aj.type != 'cash' group by aj.name; """ % (tuple(session_list_day),)) bank_ids = cr.fetchall() if bank_ids: for edukits_bank in bank_ids: rml +=""" <para style="P15">""" + to_xml(str(edukits_bank[1])) + """</para> """ rml +=""" </td> <td> """ if not session_day_ids: rml +=""" <para style="P15">-</para> """ if bank_ids: for edukits_bank in bank_ids: total_bank_amount = 0 if edukits_bank[0]: total_bank += edukits_bank[0] total_bank_amount = edukits_bank[0] rml +=""" <para style="P15">""" + rml_parser.formatLang(total_bank_amount,currency_obj=company.currency_id) + """</para> """ #normal transaction rml += """ </td> </tr> </blockTable> <blockTable rowHeights="17" colWidths="198" style="Table3""" + to_xml(str(warehouse.color.name)) + """"> <tr> <td background="pink"> <para style="P15_CENTER">CC and DC</para> </td> </tr> </blockTable> <blockTable colWidths="100,98" style="Table1_lines"> <tr> <td> """ if not session_ids: rml +=""" <para style="P15">-</para> """ session_list = [] bank_ids = [] for session in session_obj.browse(cr,uid,session_ids): session_list.append(session.id) # for bank in session.statement_ids: # if bank.journal_id.type == 'bank': # rml +=""" # <para style="P15">""" + to_xml(str(bank.journal_id.name)) + """</para> # """ if len(session_list) == 1: cr.execute(""" SELECT sum(abs.balance_end), aj.name from account_bank_statement abs inner join account_journal aj on abs.journal_id = aj.id where pos_session_id = %s and aj.type != 'cash' group by aj.name; """ % (tuple(session_list)[0],)) bank_ids = cr.fetchall() if len(session_list) > 1: cr.execute(""" SELECT sum(abs.balance_end), aj.name from account_bank_statement abs inner join account_journal aj on abs.journal_id = aj.id where pos_session_id in %s and aj.type != 'cash' group by aj.name; """ % (tuple(session_list),)) bank_ids = cr.fetchall() if bank_ids: for edukits_bank in bank_ids: rml +=""" <para style="P15">""" + to_xml(str(edukits_bank[1])) + """</para> """ rml +=""" </td> <td> """ if not session_ids: rml +=""" <para style="P15">-</para> """ if bank_ids: for edukits_bank in bank_ids: total_bank_amount = 0 if edukits_bank[0]: total_bank_amount = edukits_bank[0] total_bank += edukits_bank[0] rml +=""" <para style="P15">""" + rml_parser.formatLang(total_bank_amount+0,currency_obj=company.currency_id) + """</para> """ rml +=""" </td> </tr> </blockTable> <blockTable rowHeights="17" colWidths="198" style="Table3""" + to_xml(str(warehouse.color.name)) + """"> <tr> <td background="pink"> <para style="P15_CENTER">PENGELUARAN</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td background="pink"> <para style="P15_W">Table</para> </td> </tr> </blockTable> <blockTable colWidths="198" style="Table1_lines"> <tr> <td background="pink"> <para style="P15_W">Table</para> </td> </tr> </blockTable> <blockTable colWidths="80,118" style="Table1_lines"> <tr> <td> <para style="P15">MAITRI</para> </td> <td> <para style="P15_RIGHT"></para> <para style="P15_RIGHT">""" + rml_parser.formatLang(total_amount + total_bank+0, currency_obj=company.currency_id) +"""</para> </td> </tr> </blockTable> <blockTable colWidths="80,118" style="Table1_lines"> <tr> <td> <para style="P15">KURS :""" + rml_parser.formatLang(currency_amount,) +"""</para> </td> <td> <para style="P15_RIGHT">""" + rml_parser.formatLang(total_amount*currency_amount, currency_obj=warehouse.currency_id) +"""</para> </td> </tr> </blockTable> <blockTable colWidths="80,5,110" style="Table3_LINE2"> <tr> <td> <para style="P15"></para> </td> <td> <para style="P15"></para> </td> <td> <para style="P15_CENTER"></para> </td> </tr> </blockTable> </td> </tr> </blockTable> <spacer length="0.5cm"/>""" rml += """ </td> """ if center: if len(warehouse_ids) == 1: rml += """<td></td>""" rml += """ </tr> """ elif ( (no_total % 2 == 1 ) and (len(warehouse_ids)+1 == no_total)): rml += """<td></td>""" rml += """ </tr> """ elif no_total % 2 == 0: rml += """ </tr> """ else: if len(warehouse_ids)+1 == no_total: rml += """ </tr> """ else: if len(warehouse_ids) == 1: rml += """<td></td>""" rml += """ </tr> """ elif ( (no_total % 2 == 1 ) and (len(warehouse_ids) == no_total)): rml += """<td></td>""" rml += """ </tr> """ elif no_total % 2 == 0: rml += """ </tr> """ else: if len(warehouse_ids) == no_total: rml += """ </tr> """ no_total += 1 rml += """ </blockTable> </story> </document>""" date_cur = time.strftime('%Y-%m-%d %H:%M:%S') return rml
def process_bom(bom, currency_id, factor=1): xml = "<row>" sum = 0 sum_strd = 0 prod = product_pool.browse(cr, uid, bom["product_id"]) prod_name = to_xml(bom["name"]) prod_qtty = factor * bom["product_qty"] product_uom = product_uom_pool.browse(cr, uid, bom["product_uom"], context=context) product_uom_name = to_xml(product_uom.name) main_sp_price, main_sp_name, main_strd_price = "", "", "" sellers, sellers_price = "", "" if prod.seller_id: main_sp_name = "- <b>" + to_xml(prod.seller_id.name) + "</b>\r\n" pricelist = prod.seller_id.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, prod.seller_id.id, {"uom": prod.uom_po_id.id, "date": time.strftime("%Y-%m-%d")}, )[pricelist.id] main_sp_price = """<b>""" + rml_obj.formatLang(price) + " " + (company_currency_symbol) + """</b>\r\n""" sum += prod_qtty * price std_price = product_uom_pool._compute_price( cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id ) main_strd_price = str(std_price) + "\r\n" sum_strd = prod_qtty * std_price for seller_id in prod.seller_ids: if seller_id.name.id == prod.seller_id.id: continue sellers += "- <i>" + to_xml(seller_id.name.name) + "</i>\r\n" pricelist = seller_id.name.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, seller_id.name.id, {"uom": prod.uom_po_id.id, "date": time.strftime("%Y-%m-%d")}, )[pricelist.id] sellers_price += ( """<i>""" + rml_obj.formatLang(price) + " " + (company_currency_symbol) + """</i>\r\n""" ) xml += ( """<col para='yes'> """ + prod_name + """ </col> <col para='yes'> """ + main_sp_name + sellers + """ </col> <col f='yes'>""" + rml_obj.formatLang(prod_qtty) + " " + product_uom_name + """</col> <col f='yes'>""" + rml_obj.formatLang(float(main_strd_price)) + " " + (company_currency_symbol) + """</col> <col f='yes'>""" + main_sp_price + sellers_price + """</col>'""" ) xml += "</row>" return xml, sum, sum_strd
def create(self, cr, uid, ids, datas, context): del_obj = pooler.get_pool(cr.dbname).get('stock.picking.out') user_obj = pooler.get_pool(cr.dbname).get('res.users') rml_obj = report_sxw.rml_parse(cr, uid, del_obj._name, context) company = user_obj.browse(cr, uid, [uid], context)[0].company_id rml = """<document filename="QC Documents.pdf"> <template pageSize="(595.0,842.0)" title="QC Documents" author="OpenERP S.A.([email protected])" allowSplitting="20"> <pageTemplate> <frame id="first" x1="1.3cm" y1="1.5cm" width="18.4cm" height="26.5cm"/> <stylesheet> <blockTableStyle id="Table4"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="3,0" stop="3,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="4,0" stop="4,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="4,0" stop="4,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="4,0" stop="4,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="5,0" stop="5,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="5,0" stop="5,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="5,0" stop="5,-1"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="5,-1" stop="5,-1"/> </blockTableStyle> <blockTableStyle id="Table_Title_String"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="Standard" fontName="Helvetica"/> <paraStyle name="main_footer" fontSize="8.0" alignment="CENTER"/> <paraStyle name="main_header" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica" fontSize="14.0" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="content_Details" fontName="Helvetica" fontSize="12.0" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <images/> </stylesheet> <pageGraphics> <!-- Set here the default font to use for all <drawString> tags --> <setFont name="DejaVu Sans" size="8"/> <!-- You Logo - Change X,Y,Width and Height --> <image x="1.3cm" y="27.7cm" height="40.0" >""" + to_xml( company.logo) + """</image> <fill color="black"/> <stroke color="black"/> <!-- page header --> <lines>1.3cm 27.7cm 20cm 27.7cm</lines> <drawRightString x="20cm" y="27.8cm">""" + to_xml( company.rml_header1) + """</drawRightString> <drawString x="1.3cm" y="27.3cm">""" + to_xml( company.partner_id.name) + """</drawString> <place x="1.3cm" y="25.3cm" height="1.8cm" width="15.0cm"> <para style="main_header">""" + to_xml( company.partner_id.street or '') + """</para> <para style="main_header">""" + to_xml( company.partner_id.street2 or '') + """</para> <para style="main_header">""" + to_xml( company.partner_id.city or '') + """,""" + to_xml( company.partner_id.state_id.name or '') + """</para> <para style="main_header">""" + to_xml( company.partner_id.country_id.name or '') + """ - """ + to_xml( company.partner_id.zip or '') + """</para> </place> <drawString x="1.3cm" y="25.0cm">Phone:</drawString> <drawRightString x="7cm" y="25.0cm">""" + to_xml( company.partner_id.phone or '') + """</drawRightString> <drawString x="1.3cm" y="24.6cm">Mail:</drawString> <drawRightString x="7cm" y="24.6cm">""" + to_xml( company.partner_id.email or '') + """</drawRightString> <lines>1.3cm 24.5cm 7cm 24.5cm</lines> <!-- left margin --> <rotate degrees="90"/> <fill color="grey"/> <drawString x="2.65cm" y="-0.4cm">generated by OpenERP.com</drawString> <fill color="black"/> <rotate degrees="-90"/> <!-- page footer --> <lines>1.2cm 2.65cm 19.9cm 2.65cm</lines> <place x="1.3cm" y="0cm" height="2.55cm" width="19.0cm"> <para style="main_footer">""" + to_xml( company.rml_footer or '') + """</para> <para style="main_footer">Contact : """ + to_xml( company.name ) + """- Page: <pageNumber/></para> </place> </pageGraphics> </pageTemplate> </template> """ lst = [] for line in del_obj.browse(cr, uid, ids): main_list = self.get_analysis_data(cr, uid, line.move_lines) for sub in main_list: rml += """ <story> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <blockTable colWidths="538.0" style="Table_Title_String"> <tr> <td> <para style="terp_header">Delivery Order : """ + to_xml( line.name or '') + """</para> <para style="terp_header">Sale Order : """ + to_xml( line.origin or '') + """</para> <para style="terp_header">QC Number : </para> </td> </tr> </blockTable> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <blockTable colWidths="210.0,90.0,90.0,90.0,55.0" rowHeights="40" style="Table4"> <tr> <td> <para style="terp_tblheader_Details"><b>CHARACTERISTIC</b></para> </td> <td> <para style="terp_tblheader_Details"><b>Actual Value</b></para> </td> <td> <para style="terp_tblheader_Details"><b>Upper Limit</b></para> </td> <td> <para style="terp_tblheader_Details"><b>Lower Limit</b></para> </td> <td> <para style="terp_tblheader_Details"><b>ok?</b></para> </td> </tr> </blockTable> """ for sub_list in sub: rml += """ <blockTable colWidths="210.0,90.0,90.0,90.0,55.0" style="Table4"> <tr> <td> <para style="content_Details">""" + str( sub_list['name']) + """</para> </td> <td> <para style="content_Details">""" + sub_list[ 'actual'] + """</para> </td> <td> <para style="content_Details">""" + str( sub_list['upper']) + """</para> </td> <td> <para style="content_Details">""" + str( sub_list['lower']) + """</para> </td> <td> <para style="content_Details">""" + str( sub_list['ok']) + """</para> </td> </tr> </blockTable> """ rml += """</story> """ rml += """</document> """ report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] self.internal_header = False pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create_xml(self, cr, uid, ids, data, context): registry = openerp.registry(cr.dbname) obj_dept = registry['hr.department'] obj_emp = registry['hr.employee'] depts=[] emp_id={} rpt_obj = registry['hr.holidays'] rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) cr.execute("SELECT name FROM res_company") res=cr.fetchone()[0] date_xml=[] date_today=time.strftime('%Y-%m-%d %H:%M:%S') date_xml +=['<res name="%s" today="%s" />' % (to_xml(res),date_today)] cr.execute("SELECT id, name, color_name FROM hr_holidays_status ORDER BY id") legend=cr.fetchall() today=datetime.datetime.today() first_date=data['form']['date_from'] som = strToDate(first_date) eom = som+datetime.timedelta(59) day_diff=eom-som name = '' if len(data['form'].get('emp', ())) == 1: name = obj_emp.read(cr, uid, data['form']['emp'][0], ['name'])['name'] if data['form']['holiday_type']!='both': type=data['form']['holiday_type'] if data['form']['holiday_type']=='Confirmed': holiday_type=('confirm') else: holiday_type=('validate') else: type="Confirmed and Approved" holiday_type=('confirm','validate') date_xml.append('<from>%s</from>\n'% (str(rml_obj.formatLang(som.strftime("%Y-%m-%d"),date=True)))) date_xml.append('<to>%s</to>\n' %(str(rml_obj.formatLang(eom.strftime("%Y-%m-%d"),date=True)))) date_xml.append('<type>%s</type>'%(type)) date_xml.append('<name>%s</name>'%(name)) # date_xml=[] for l in range(0,len(legend)): date_xml += ['<legend row="%d" id="%d" name="%s" color="%s" />' % (l+1,legend[l][0],_(legend[l][1]),legend[l][2])] date_xml += ['<date month="%s" year="%d" />' % (ustr(som.strftime('%B')), som.year),'<days>'] cell=1 if day_diff.days>=30: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] else: if day_diff.days>=(lengthmonth(som.year, som.month)-som.day): date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] else: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, eom.day+1)] cell=x-som.day+1 day_diff1=day_diff.days-cell+1 width_dict={} month_dict={} i=1 j=1 year=som.year month=som.month month_dict[j]=som.strftime('%B') width_dict[j]=cell while day_diff1>0: if month+i<=12: if day_diff1 > lengthmonth(year,i+month): # Not on 30 else you have problems when entering 01-01-2009 for example som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(year,i+month)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x day_diff1=day_diff1-x else: years=year+1 year=years month=0 i=1 if day_diff1>=30: som1=datetime.date(years,i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(years,i)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(years,i,1) i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] cell=cell+x width_dict[j]=x day_diff1=day_diff1-x date_xml.append('</days>') date_xml.append('<cols>3.5cm%s,0.4cm</cols>\n' % (',0.4cm' * (60))) date_xml = ''.join(date_xml) st='<cols_months>3.5cm' for m in range(1,len(width_dict)+1): st+=',' + str(0.4 *width_dict[m])+'cm' st+=',0.4cm</cols_months>\n' months_xml =['<months number="%d" name="%s"/>' % (x, _(month_dict[x])) for x in range(1,len(month_dict)+1) ] months_xml.append(st) emp_xml='' row_id=1 if data['model'] == 'hr.employee': for items in obj_emp.read(cr, uid, data['form']['emp'], ['id', 'name']): emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, items['id'], items['name'], som, eom) row_id = row_id +1 elif data['model']=='ir.ui.menu': for dept in obj_dept.browse(cr, uid, data['form']['depts'], context=context): emp_ids = obj_emp.search(cr, uid, [('department_id', '=', dept.id)], context=context) if emp_ids==[]: continue dept_done=0 for item in obj_emp.read(cr, uid, emp_ids, ['id', 'name']): if dept_done==0: emp_xml += emp_create_xml(self, cr, uid, 1, holiday_type, row_id, dept.id, dept.name, som, eom) row_id = row_id +1 dept_done=1 emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, item['id'], item['name'], som, eom) row_id = row_id +1 header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(registry['res.users'].browse(cr,uid,uid).company_id.name)) # Computing the xml xml='''<?xml version="1.0" encoding="UTF-8" ?> <report> %s %s %s %s </report> ''' % (header_xml,months_xml,date_xml, ustr(emp_xml)) return xml
def create(self, cr, uid, ids, datas, context): # data = datas['form'] design_obj = pooler.get_pool(cr.dbname).get('mto.design') data = design_obj.browse(cr, uid, ids[0], context=context) _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 #default A4 size _pageSize = ('21.1cm','29.7cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm' _tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm' rml ="""<document filename="Production Configuration.pdf"> <template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Options' author="MTT" allowSplitting="20" > <pageTemplate id="first"> <frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/> <pageGraphics> <lineMode width="1.0"/> <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+"""</lines> <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" 1.0cm 1.00cm</lines> <lines>"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines> <lines>1.0cm 1.00cm """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>""" #page number rml +=""" <fill color="gray"/> <setFont name="Helvetica" size="10"/> <drawRightString x='"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+"""' y="0.6cm">Page : <pageNumber/> </drawRightString>""" rml +="""</pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="Standard_Outline"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="0"/> <blockBottomPadding length="0"/> <blockLeftPadding length="0"/> <blockRightPadding length="0"/> </blockTableStyle> <blockTableStyle id="Table1"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="Tableau1"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="table_attr"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="0,0"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="Table_Outer_Notes"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="Table_options"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="P1" fontName="Helvetica-Bold" fontSize="20.0" leading="25" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P2" fontName="Helvetica" fontSize="6.0" leading="8" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P3" fontName="Helvetica" fontSize="16.0" leading="20" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P4" fontName="Helvetica-Bold" fontSize="18.0" leading="22" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P5" fontName="Helvetica" fontSize="14.0" leading="17" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="opt_item" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="30" spaceAfter="0.0"/> <paraStyle name="Standard" fontName="Helvetica"/> <paraStyle name="Text body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Footer" fontName="Helvetica"/> <paraStyle name="Table Contents" fontName="Helvetica"/> <paraStyle name="Table Heading" fontName="Helvetica" alignment="CENTER"/> <paraStyle name="Caption" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="Index" fontName="Helvetica"/> <paraStyle name="Horizontal Line" fontName="Helvetica" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/> <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_8" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_Right_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_address" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_9" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Centre_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_9_Right" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_8_Italic" fontName="Helvetica-Oblique" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_2" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <images/> </stylesheet> <story>""" #basic data rml += """ <blockTable colWidths="535.0" style="Table1"> <tr> <td> <para style="P1"> <font face="Helvetica" size="20.0">Production Configuration """ + to_xml(tools.ustr(data.name)) + """</font> </para> </td> </tr> </blockTable> <blockTable colWidths="180.0,159.0,195.0" style="Tableau1"> <tr> <td> <para style="P5">Model: """ + to_xml(tools.ustr(data.design_tmpl_id.name)) + """</para> </td> <td> <para style="P5">Price: """ + tools.ustr(data.design_tmpl_id.currency_id.symbol) + tools.ustr(data.list_price) + """</para> </td> <td> <para style="P5">Weight: """ + tools.ustr(data.weight) + """KG</para> </td> </tr> </blockTable> """ design_tmpl = data.design_tmpl_id opt_obj = pooler.get_pool(cr.dbname).get('attribute.option') for attr_group in design_tmpl.attribute_group_ids: rml += """ <blockTable colWidths="533.0" style="table_attr"> <tr> <td> <para style="P4">""" + to_xml(tools.ustr(attr_group.name)) + """</para> </td> </tr> """ for attr in attr_group.attribute_ids: attr_label = attr.field_description attr_type = attr.attribute_type attr_val = getattr(data,attr.name) #field label rml += """ <tr> <td> <para style="P5">%s.%s</para> </td> </tr> """%(attr.sequence,to_xml(design_obj._get_attr_pw_name(data,attr)),) #field value if attr_type in ('char','text','boolean','integer','date','datetime','float'): if attr_val : rml += """ <tr> <td> <para style="opt_item">%s</para> </td> </tr> """%(to_xml(attr_val),) elif attr_type == 'select': rml += """ <tr> <td> <blockTable colWidths="18.0,516.0" style="Table_options"> """ for sel_opt in attr.option_ids: rml += """ <tr> <td> <illustration> <fill color="white"/> <circle x="0.3cm" y="-0.2cm" radius="0.18 cm" fill="yes" stroke="yes" round="0.1cm"/> """ if attr_val and attr_val.id == sel_opt.id: rml += """ <fill color="black"/> <circle x="0.3cm" y="-0.2cm" radius="0.13 cm" fill="yes" stroke="no" round="0.1cm"/> """ rml += """ </illustration> </td> <td> <para style="opt_item">%s</para> </td> </tr> """%(to_xml(opt_obj.name_get(cr,uid,sel_opt.id,context)[0][1]),) rml += """ </blockTable> </td> </tr> """ elif attr_type == 'multiselect': attr_val_ids = [val.id for val in attr_val] rml += """ <tr> <td> <blockTable colWidths="18.0,516.0" style="Table_options"> """ for sel_opt in attr.option_ids: rml += """ <tr> <td> <illustration> <fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.4 cm" height="0.4cm" fill="yes" stroke="yes" round="0.1cm"/> """ if sel_opt.id in attr_val_ids: rml += """ <fill color="black"/> <rect x="0.15cm" y="-0.4cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> """ rml += """ </illustration> </td> <td> <para style="opt_item">%s</para> </td> </tr> """%(to_xml(opt_obj.name_get(cr,uid,sel_opt.id,context)[0][1]),) rml += """ </blockTable> </td> </tr> """ rml += """ </blockTable> """ #the description rml += """ <blockTable colWidths="535.0" style="Table_Outer_Notes"> <tr> <td> <para style="terp_default_9">Description:</para> </td> </tr> <tr> <td> <para style="terp_default_9">%s</para> </td> </tr> </blockTable> """%(data.description and data.description or '',) rml += """</story></document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create_xml(self, cr, uid, ids, data, context): registry = openerp.registry(cr.dbname) obj_emp = registry['hr.employee'] depts = [] emp_id = {} rpt_obj = registry['hr_attendance.record.report'] rml_obj = report_sxw.rml_parse(cr, uid, rpt_obj._name, context) cr.execute("SELECT name FROM res_company") res = cr.fetchone()[0] date_xml = [] date_today = time.strftime('%Y-%m-%d %H:%M:%S') date_xml += [ '<res name="%s" today="%s" />' % (to_xml(res), date_today) ] legend = { 'Present': 'green', 'Weekends': 'lightgrey', 'Absent': 'red', 'Leave': 'violet', 'Public Holiday': 'blue' } today = datetime.datetime.today() today_year = today.strftime('%Y-%m-%d %H:%M:%S')[0:4] #### Check for Filter in Wizard to get Start and end date ##### if data['form']['filter_by_date'] == True: first_date = datetime.datetime.strptime( data['form']['date_from'], '%Y-%m-%d') + datetime.timedelta() last_date = datetime.datetime.strptime( data['form']['date_to'], '%Y-%m-%d') + datetime.timedelta() else: month_selected = data['form']['monthly_status'] first_date = datetime.datetime(int(today_year), int(month_selected), 1) number_of_days = lengthmonth(int(today_year), int(month_selected)) last_date = datetime.datetime(int(today_year), int(month_selected), number_of_days) day_diff = last_date - first_date name = '' if len(data['form'].get('emp_id', ())) == 1: name = obj_emp.read(cr, uid, data['form']['emp_id'][0], ['name'])['name'] date_xml.append('<from>%s</from>\n' % (str( rml_obj.formatLang(first_date.strftime("%Y-%m-%d"), date=True)))) date_xml.append('<to>%s</to>\n' % (str( rml_obj.formatLang(last_date.strftime("%Y-%m-%d"), date=True)))) date_xml.append('<name>%s</name>' % (name)) # date_xml=[] for l in range(0, len(legend)): date_xml += [ '<legend row="%d" id="%d" name="%s" color="%s" />' % (l + 1, l + 1, legend.keys()[l], legend.values()[l]) ] date_xml += [ '<date month="%s" year="%d" />' % (ustr(first_date.strftime('%B')), first_date.year), '<days>' ] cell = 1 if day_diff.days >= 31: date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x - first_date.day + 1) for x in range(first_date.day, day_diff.days + 1) ] else: #date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x-first_date.day+1) for x in range(first_date.day, last_date.day+1)] if day_diff.days >= (lengthmonth(first_date.year, first_date.month) - first_date.day): date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x - first_date.day + 1) for x in range( first_date.day, lengthmonth(first_date.year, first_date.month) + 1) ] else: date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x - first_date.day + 1) for x in range(first_date.day, last_date.day + 1) ] cell = x - first_date.day + 1 day_diff1 = day_diff.days - cell + 1 width_dict = {} month_dict = {} i = 1 j = 1 year = first_date.year month = first_date.month month_dict[j] = first_date.strftime('%B') width_dict[j] = cell while day_diff1 > 0: if month + i <= 12: # If month + i <=12 if day_diff1 > lengthmonth( year, i + month ): # Not on 30 else you have problems when entering 01-01-2009 for example som1 = datetime.date(year, month + i, 1) date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')), cell + x) for x in range(1, lengthmonth(year, i + month) + 1) ] i = i + 1 j = j + 1 month_dict[j] = som1.strftime('%B') cell = cell + x width_dict[j] = x else: som1 = datetime.date(year, month + i, 1) date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')), cell + x) for x in range(1, last_date.day + 1) ] i = i + 1 j = j + 1 month_dict[j] = som1.strftime('%B') cell = cell + x width_dict[j] = x day_diff1 = day_diff1 - x date_xml.append('</days>') date_xml.append('<cols>3.5cm%s,1.0cm</cols>\n' % (',0.7cm' * (day_diff.days + 1))) date_xml = ''.join(date_xml) st = '<cols_months>3.5cm' for m in range(1, len(width_dict) + 1): st += ',' + str(0.7 * width_dict[m]) + 'cm' st += ',1.0cm</cols_months>\n' months_xml = [ '<months number="%d" name="%s"/>' % (x, _(month_dict[x])) for x in range(1, len(month_dict) + 1) ] months_xml.append(st) emp_xml = '' row_id = 1 if data['model'] == 'hr.employee': for items in obj_emp.read(cr, uid, data['form']['emp_id'], ['id', 'name']): emp_xml += emp_create_xml(self, cr, uid, 0, row_id, items['id'], items['name'], first_date, last_date) row_id = row_id + 1 header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"), date=True)) + ' ' + str(time.strftime("%H:%M")), to_xml(registry['res.users'].browse(cr, uid, uid).company_id.name)) # Computing the xml xml = '''<?xml version="1.0" encoding="UTF-8" ?> <report> %s %s %s %s </report> ''' % (header_xml, months_xml, date_xml, ustr(emp_xml)) return xml
def create(self, cr, uid, ids, datas, context): # data = datas['form'] design_obj = pooler.get_pool(cr.dbname).get('mto.design') data = design_obj.browse(cr, uid, ids[0], context=context) _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 #default A4 size _pageSize = ('21.1cm', '29.7cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.90)) + 'cm' _tbl_widths = tools.ustr( float(_pageSize[0].replace('cm', '')) - float(2.10)) + 'cm' rml = """<document filename="Production Configuration.pdf"> <template pageSize="(""" + _pageSize[0] + """,""" + _pageSize[ 1] + """)" title='Options' author="MTT" allowSplitting="20" > <pageTemplate id="first"> <frame id="first" x1="0.0cm" y1="1.0cm" width='""" + _frame_width + """' height='""" + _frame_height + """'/> <pageGraphics> <lineMode width="1.0"/> <lines>1.0cm """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """</lines> <lines>1.0cm """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00) ) + 'cm' + """ 1.0cm 1.00cm</lines> <lines>""" + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ 1.00cm</lines> <lines>1.0cm 1.00cm """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00) ) + 'cm' + """ 1.00cm</lines>""" #page number rml += """ <fill color="gray"/> <setFont name="Helvetica" size="10"/> <drawRightString x='""" + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00) ) + 'cm' + """' y="0.6cm">Page : <pageNumber/> </drawRightString>""" rml += """</pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="Standard_Outline"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="0"/> <blockBottomPadding length="0"/> <blockLeftPadding length="0"/> <blockRightPadding length="0"/> </blockTableStyle> <blockTableStyle id="Table1"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="Tableau1"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="table_attr"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="0,0"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="Table_Outer_Notes"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <blockTableStyle id="Table_options"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <blockTopPadding length="1"/> <blockBottomPadding length="1"/> <blockLeftPadding length="1"/> <blockRightPadding length="1"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="P1" fontName="Helvetica-Bold" fontSize="20.0" leading="25" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P2" fontName="Helvetica" fontSize="6.0" leading="8" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P3" fontName="Helvetica" fontSize="16.0" leading="20" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P4" fontName="Helvetica-Bold" fontSize="18.0" leading="22" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P5" fontName="Helvetica" fontSize="14.0" leading="17" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="opt_item" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="30" spaceAfter="0.0"/> <paraStyle name="Standard" fontName="Helvetica"/> <paraStyle name="Text body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/> <paraStyle name="Footer" fontName="Helvetica"/> <paraStyle name="Table Contents" fontName="Helvetica"/> <paraStyle name="Table Heading" fontName="Helvetica" alignment="CENTER"/> <paraStyle name="Caption" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="Index" fontName="Helvetica"/> <paraStyle name="Horizontal Line" fontName="Helvetica" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/> <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_8" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_Right_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_address" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_9" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Centre_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_Bold_9_Right" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_8_Italic" fontName="Helvetica-Oblique" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_2" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <images/> </stylesheet> <story>""" #basic data rml += """ <blockTable colWidths="535.0" style="Table1"> <tr> <td> <para style="P1"> <font face="Helvetica" size="20.0">Production Configuration """ + to_xml( tools.ustr(data.name)) + """</font> </para> </td> </tr> </blockTable> <blockTable colWidths="180.0,159.0,195.0" style="Tableau1"> <tr> <td> <para style="P5">Model: """ + to_xml( tools.ustr(data.design_tmpl_id.name)) + """</para> </td> <td> <para style="P5">Price: """ + tools.ustr( data.design_tmpl_id.currency_id.symbol) + tools.ustr( data.list_price) + """</para> </td> <td> <para style="P5">Weight: """ + tools.ustr( data.weight) + """KG</para> </td> </tr> </blockTable> """ design_tmpl = data.design_tmpl_id opt_obj = pooler.get_pool(cr.dbname).get('attribute.option') for attr_group in design_tmpl.attribute_group_ids: rml += """ <blockTable colWidths="533.0" style="table_attr"> <tr> <td> <para style="P4">""" + to_xml( tools.ustr(attr_group.name)) + """</para> </td> </tr> """ for attr in attr_group.attribute_ids: attr_label = attr.field_description attr_type = attr.attribute_type attr_val = getattr(data, attr.name) #field label rml += """ <tr> <td> <para style="P5">%s.%s</para> </td> </tr> """ % ( attr.sequence, to_xml(design_obj._get_attr_pw_name(data, attr)), ) #field value if attr_type in ('char', 'text', 'boolean', 'integer', 'date', 'datetime', 'float'): if attr_val: rml += """ <tr> <td> <para style="opt_item">%s</para> </td> </tr> """ % (to_xml(attr_val), ) elif attr_type == 'select': rml += """ <tr> <td> <blockTable colWidths="18.0,516.0" style="Table_options"> """ for sel_opt in attr.option_ids: rml += """ <tr> <td> <illustration> <fill color="white"/> <circle x="0.3cm" y="-0.2cm" radius="0.18 cm" fill="yes" stroke="yes" round="0.1cm"/> """ if attr_val and attr_val.id == sel_opt.id: rml += """ <fill color="black"/> <circle x="0.3cm" y="-0.2cm" radius="0.13 cm" fill="yes" stroke="no" round="0.1cm"/> """ rml += """ </illustration> </td> <td> <para style="opt_item">%s</para> </td> </tr> """ % (to_xml( opt_obj.name_get(cr, uid, sel_opt.id, context)[0][1]), ) rml += """ </blockTable> </td> </tr> """ elif attr_type == 'multiselect': attr_val_ids = [val.id for val in attr_val] rml += """ <tr> <td> <blockTable colWidths="18.0,516.0" style="Table_options"> """ for sel_opt in attr.option_ids: rml += """ <tr> <td> <illustration> <fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.4 cm" height="0.4cm" fill="yes" stroke="yes" round="0.1cm"/> """ if sel_opt.id in attr_val_ids: rml += """ <fill color="black"/> <rect x="0.15cm" y="-0.4cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> """ rml += """ </illustration> </td> <td> <para style="opt_item">%s</para> </td> </tr> """ % (to_xml( opt_obj.name_get(cr, uid, sel_opt.id, context)[0][1]), ) rml += """ </blockTable> </td> </tr> """ rml += """ </blockTable> """ #the description rml += """ <blockTable colWidths="535.0" style="Table_Outer_Notes"> <tr> <td> <para style="terp_default_9">Description:</para> </td> </tr> <tr> <td> <para style="terp_default_9">%s</para> </td> </tr> </blockTable> """ % (data.description and data.description or '', ) rml += """</story></document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ Fields View Get method :- generate the new view and display the survey pages of selected survey. """ if context is None: context = {} result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, \ view_type, {}, toolbar,submenu) surv_name_wiz = self.pool.get('survey.name.wiz') survey_obj = self.pool.get('survey') page_obj = self.pool.get('survey.page') que_obj = self.pool.get('survey.question') ans_obj = self.pool.get('survey.answer') sur_response_obj = self.pool.get('survey.response') que_col_head = self.pool.get('survey.question.column.heading') user_obj = self.pool.get('res.users') mail_message = self.pool.get('mail.message') if view_type in ['form']: wiz_id = 0 sur_name_rec = None if 'sur_name_id' in context: sur_name_rec = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) elif 'survey_id' in context: res_data = { 'survey_id': context.get('survey_id', False), 'page_no': -1, 'page': 'next', 'transfer': 1, 'response': 0 } wiz_id = surv_name_wiz.create(cr, uid, res_data) sur_name_rec = surv_name_wiz.browse(cr, uid, wiz_id, context=context) context.update({'sur_name_id' :wiz_id}) if context.has_key('active_id'): context.pop('active_id') survey_id = context.get('survey_id', False) if not survey_id: # Try one more time to find it if sur_name_rec and sur_name_rec.survey_id: survey_id = sur_name_rec.survey_id.id else: # raise osv.except_osv(_('Error!'), _("Cannot locate survey for the question wizard!")) # If this function is called without a survey_id in # its context, it makes no sense to return any view. # Just return the default, empty view for this object, # in order to please random calls to this fn(). return super(survey_question_wiz, self).\ fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) sur_rec = survey_obj.browse(cr, uid, survey_id, context=context) p_id = map(lambda x:x.id, sur_rec.page_ids) total_pages = len(p_id) pre_button = False readonly = 0 if context.get('response_id', False) \ and int(context['response_id'][0]) > 0: readonly = 1 if not sur_name_rec.page_no + 1 : surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'store_ans':{}}) sur_name_read = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) page_number = int(sur_name_rec.page_no) if sur_name_read.transfer or not sur_name_rec.page_no + 1: surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer':False}) flag = False fields = {} if sur_name_read.page == "next" or sur_name_rec.page_no == -1: if total_pages > sur_name_rec.page_no + 1: if ((context.has_key('active') and not context.get('active', False)) \ or not context.has_key('active')) and not sur_name_rec.page_no + 1: if sur_rec.state != "open" : raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) cr.execute('select count(id) from survey_history where user_id=%s\ and survey_id=%s', (uid,survey_id)) res = cr.fetchone()[0] user_limit = survey_obj.browse(cr, uid, survey_id) user_limit = user_limit.response_user if user_limit and res >= user_limit: raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (user_limit)) if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1: survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")}) p_id = p_id[sur_name_rec.page_no + 1] surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'page_no' : sur_name_rec.page_no + 1}) flag = True page_number += 1 if sur_name_rec.page_no > - 1: pre_button = True else: flag = True else: if sur_name_rec.page_no != 0: p_id = p_id[sur_name_rec.page_no - 1] surv_name_wiz.write(cr, uid, [context['sur_name_id'],],\ {'page_no' : sur_name_rec.page_no - 1}) flag = True page_number -= 1 if sur_name_rec.page_no > 1: pre_button = True if flag: pag_rec = page_obj.browse(cr, uid, p_id, context=context) note = False question_ids = [] if pag_rec: title = pag_rec.title note = pag_rec.note question_ids = pag_rec.question_ids else: title = sur_rec.title form = etree.Element('form', {'class':'bs3 bs3-form-bg bs3-footer','string': tools.ustr(title)}) section = etree.SubElement(form, 'section', {'class': 'bgvauxoo'}) xml_form = etree.SubElement(section, 'div', {'class': 'container'}) if context.has_key('active') and context.get('active',False) and context.has_key('edit'): context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer}) xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)}) etree.SubElement(xml_group3, 'button', {'string' :'Edit Page','icon': "gtk-edit", 'type' :'object','name':"action_edit_page", 'context' : tools.ustr(context)}) etree.SubElement(xml_group3, 'button', {'string' :'Delete Page','icon': "gtk-delete", 'type' :'object','name':"action_delete_page", 'context' : tools.ustr(context)}) etree.SubElement(xml_group3, 'button', {'string' :'Add Question','icon': "gtk-new", 'type' :'object','name':"action_new_question", 'context' : tools.ustr(context)}) # FP Note xml_group = xml_form if context.has_key('response_id') and context.get('response_id', False) \ and int(context.get('response_id',0)[0]) > 0: # TODO: l10n, cleanup this code to make it readable. Or template? xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.user_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"}) if context.get('response_no',0) > 0: etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"}) if context.get('response_no',0) + 1 < len(context.get('response_id',0)): etree.SubElement(xml_group, 'button', {'colspan':"1",'icon': "gtk-go-forward", 'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context)}) if wiz_id: fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}} etree.SubElement(xml_form, 'field', {'widget':'FieldCharBS3','invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'}) if note: xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'}) for que_test in note.split('\n'): etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) que_ids = question_ids qu_no = 0 for que in que_ids: qu_no += 1 que_rec = que_obj.browse(cr, uid, que.id, context=context) descriptive_text = "" separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question) if ((context.has_key('active') and not context.get('active',False)) or not context.has_key('active')) and que_rec.is_require_answer: star = '*' else: star = '' if context.has_key('active') and context.get('active',False) and \ context.has_key('edit'): etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'}) context.update({'question_id' : tools.ustr(que.id),'page_number': sur_name_rec.page_no , 'transfer' : sur_name_read.transfer, 'page_id' : p_id}) etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-edit", 'type' :'object', 'name':"action_edit_question", 'context' : tools.ustr(context)}) etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-delete", 'type' :'object','name':"action_delete_question", 'context' : tools.ustr(context)}) else: etree.SubElement(xml_form, 'newline') etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) ans_ids = que_rec.answer_choice_ids xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) if que_rec.type == 'multiple_choice_only_one_ans': selection = [] for ans in ans_ids: selection.append((tools.ustr(ans.id), ans.answer)) xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) etree.SubElement(xml_group, 'field', {'nolabel':'True','class':'dropdown-menus','readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} elif que_rec.type == 'multiple_choice_multiple_ans': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in ans_ids: etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} elif que_rec.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: if que_rec.comment_column: col = "4" colspan = "4" else: col = "2" colspan = "2" xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) for row in ans_ids: etree.SubElement(xml_group, 'newline') etree.SubElement(xml_group, 'field', {'nolabel':'True','readonly': str(readonly), 'class':'dropdown-menus','name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) selection = [('','')] for col in que_rec.column_heading_ids: selection.append((str(col.id), col.title)) fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} if que_rec.comment_column: fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) elif que_rec.type == 'matrix_of_choices_only_multi_ans': xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) for col in que_rec.column_heading_ids: etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) for row in ans_ids: etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} elif que_rec.type == 'matrix_of_drop_down_menus': xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) for col in que_rec.column_heading_ids: etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) for row in ans_ids: etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer))+' :-', 'align': '0.0'}) for col in que_rec.column_heading_ids: selection = [] if col.menu_choice: for item in col.menu_choice.split('\n'): if item and not item.strip() == '': selection.append((item ,item)) etree.SubElement(xml_group, 'field', {'nolabel':'True','class':'dropdown-menus','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id),'nolabel':'1'}) fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'selection', 'string': col.title, 'selection':selection} elif que_rec.type == 'multiple_textboxes': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) type = "char" if que_rec.is_validation_require: if que_rec.validation_type in ['must_be_whole_number']: type = "integer" elif que_rec.validation_type in ['must_be_decimal_number']: type = "float" elif que_rec.validation_type in ['must_be_date']: type = "date" for ans in ans_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) if type == "char" : fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} else: fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} elif que_rec.type == 'numerical_textboxes': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in ans_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} elif que_rec.type == 'date': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in ans_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} elif que_rec.type == 'date_and_time': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in ans_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} elif que_rec.type == 'descriptive_text': if que_rec.descriptive_text: for que_test in que_rec.descriptive_text.split('\n'): etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) elif que_rec.type == 'single_textbox': etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} elif que_rec.type == 'comment': etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} elif que_rec.type == 'table': xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) for col in que_rec.column_heading_ids: etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) for row in range(0,que_rec.no_of_rows): for col in que_rec.column_heading_ids: etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} elif que_rec.type == 'multiple_textboxes_diff_type': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in ans_ids: if ans.type == "email" : fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) else: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) if ans.type == "char" : fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} elif ans.type in ['integer','float','date','datetime']: fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} else: selection = [] if ans.menu_choice: for item in ans.menu_choice.split('\n'): if item and not item.strip() == '': selection.append((item ,item)) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale'] and que_rec.is_comment_require: if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} if que_rec.comment_field_type == 'char': etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} elif que_rec.comment_field_type == 'text': etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} else: if que_rec.comment_field_type == 'char': etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) etree.SubElement(xml_group, 'field', {'widget':'FieldCharBS3','readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} elif que_rec.comment_field_type == 'text': etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) if pre_button: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'name':"action_previous",'string':"e",'type':"object",'class':"answer_exit btn btn-primary btn-large oe_e"}) but_string = "Next" if int(page_number) + 1 == total_pages: but_string = "Done" if context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages and context.has_key('response_id') and context.has_key('response_no') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"}) elif context.has_key('active') and context.get('active', False) and int(page_number) + 1 == total_pages and context.has_key('response_id'): etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) elif context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"answer_exit btn btn-primary btn-large"}) else: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'class': "btn btn-primary btn-large oe_e",'name':"action_next",'string':but_string == 'Next'and '/' or '8','type':"object",'context' : tools.ustr(context)}) etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"c",'class':"answer_exit btn btn-primary btn-large oe_e"}) etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) root = form.getroottree() result['arch'] = etree.tostring(root) result['fields'] = fields print 'rooooooooot',etree.tostring(root) print 'fields', fields result['context'] = context else: survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) # mark the survey request as done; call 'survey_req_done' on its actual model survey_req_obj = self.pool.get(context.get('active_model')) if survey_req_obj and hasattr(survey_req_obj, 'survey_req_done'): survey_req_obj.survey_req_done(cr, uid, context.get('active_ids', []), context=context) if sur_rec.send_response: survey_data = survey_obj.browse(cr, uid, survey_id) response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response'] report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context) attachments = {} pdf_filename = addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf" if os.path.exists(pdf_filename): file = open(pdf_filename) file_data = "" while 1: line = file.readline() file_data += line if not line: break attachments[survey_data.title + ".pdf"] = file_data file.close() os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") context.update({'response_id':response_id}) user_email = user_obj.browse(cr, uid, uid, context).email resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False if user_email and resp_email: user_name = user_obj.browse(cr, uid, uid, context=context).name mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." vals = {'state': 'outgoing', 'subject': "Survey Answer Of " + user_name, 'body_html': '<pre>%s</pre>' % mail, 'email_to': [resp_email], 'email_from': user_email} if attachments: vals['attachment_ids'] = [(0,0,{'name': a_name, 'datas_fname': a_name, 'datas': str(a_content).encode('base64')}) for a_name, a_content in attachments.items()] self.pool.get('mail.mail').create(cr, uid, vals, context=context) xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) etree.SubElement(xml_form, 'newline') etree.SubElement(xml_footer, 'button', {'special':"cancel",'string':"OK",'colspan':"2",'class':'oe_highlight'}) root = xml_form.getroottree() result['arch'] = etree.tostring(root) result['fields'] = {} result['context'] = context return result
def create(self, cr, uid, ids, datas, context): _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 _pageSize = ('29.7cm','21.1cm') if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('21.6cm','27.9cm') elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('21.6cm','35.6cm') elif datas['form'].get('paper_size','') == 'a4': _pageSize = ('21.1cm','29.7cm') elif datas.has_key('form') and datas['form'].get('orientation',False) == 'horizontal': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('27.9cm','21.6cm') elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('35.6cm','21.6cm') elif datas['form'].get('paper_size') == 'a4': _pageSize = ('29.7cm','21.1cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm' _tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm' rml ="""<document filename="Survey Answer Report.pdf"> <template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Answer' author="LKP([email protected])" allowSplitting="20" > <pageTemplate id="first"> <frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/> <pageGraphics> <lineMode width="1.0"/> <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+"""</lines> <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" 1.0cm 1.00cm</lines> <lines>"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines> <lines>1.0cm 1.00cm """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>""" if datas.has_key('form') and datas['form']['page_number']: rml +=""" <fill color="gray"/> <setFont name="Helvetica" size="10"/> <drawRightString x='"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+"""' y="0.6cm">Page : <pageNumber/> </drawRightString>""" rml +="""</pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="simple_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6"/> </blockTableStyle> <blockTableStyle id="note_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table2"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table3"> <blockAlignment value="LEFT"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table4"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="Table5"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="Table41"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table51"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table_heading"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="title_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="black" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="page_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="gray" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/> <paraStyle name="answer_right" alignment="RIGHT" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="Standard1" fontName="helvetica-bold" alignment="RIGHT" fontSize="09.0"/> <paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/> <paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/> <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/> <paraStyle name="page" fontName="helvetica" fontSize="11.0" leftIndent="0.0"/> <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/> <paraStyle name="answer_bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="answer1" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="Title" fontName="helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/> <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_9_Bold" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General_Centre_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_right_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_right" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="descriptive_text" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/> <paraStyle name="descriptive_text_heading" fontName="helvetica-bold" fontSize="18.0" alignment="RIGHT" leftIndent="0.0" textColor="white"/> </stylesheet> <images/> <story>""" surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response') rml_obj=report_sxw.rml_parse(cr, uid, surv_resp_obj._name,context) if datas.has_key('form') and datas['form'].has_key('response_ids'): response_id = datas['form']['response_ids'] elif context.has_key('response_id') and context['response_id']: response_id = [int(context['response_id'][0])] else: response_id = surv_resp_obj.search(cr, uid, [('survey_id', 'in', ids)]) surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line') surv_obj = pooler.get_pool(cr.dbname).get('survey') for response in surv_resp_obj.browse(cr, uid, response_id): for survey in surv_obj.browse(cr, uid, [response.survey_id.id]): tbl_width = float(_tbl_widths.replace('cm', '')) colwidth = "2.5cm,4.8cm," + str(tbl_width - 15.0) +"cm,3.2cm,4.5cm" resp_create = tools.ustr(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) rml += """<blockTable colWidths='""" + colwidth + """' style="Table_heading"> <tr> <td><para style="terp_default_9_Bold">Print Date : </para></td> <td><para style="terp_default_9">""" + to_xml(rml_obj.formatLang(time.strftime("%Y-%m-%d %H:%M:%S"),date_time=True)) + """</para></td> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9_Bold">Answered by : </para></td> <td><para style="terp_default_9">""" + to_xml(response.user_id.login or '') + """</para></td> </tr> <tr> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9_Bold">Answer Date : </para></td> <td><para style="terp_default_9">""" + to_xml(resp_create) + """</para></td> </tr> </blockTable><para style="P2"></para>""" status = "Not Finished" if response.state == "done": status = "Finished" colwidth = str(tbl_width - 7) + "cm," colwidth += "7cm" rml += """<blockTable colWidths='""" + str(colwidth) + """' style="title_tbl"> <tr> <td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td> <td><para style="descriptive_text_heading">Status :- """ + to_xml(tools.ustr(status)) + """</para><para style="P2"><font></font></para></td> </tr> </blockTable>""" if survey.note: rml += """<blockTable colWidths='""" + _tbl_widths + """' style="note_table"> <tr><td><para style="response">""" + to_xml(tools.ustr(survey.note or '')) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" for page in survey.page_ids: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="page_tbl"> <tr><td><para style="page">Page :- """ + to_xml(tools.ustr(page.title or '')) + """</para></td></tr> </blockTable>""" if page.note: rml += """<para style="P2"></para> <blockTable colWidths='""" + str(_tbl_widths) + """' style="note_table"> <tr><td><para style="response">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr> </blockTable>""" for que in page.question_ids: rml += """<para style="P2"></para> <blockTable colWidths='""" + str(_tbl_widths) + """' style="Table5"> <tr><td><para style="question">""" + to_xml(to_xml(que.question)) + """</para></td></tr> </blockTable>""" answer = surv_resp_line_obj.browse(cr ,uid, surv_resp_line_obj.search(cr, uid, [('question_id', '=', que.id),('response_id', '=', response.id)])) if que.type in ['descriptive_text']: rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr> </blockTable>""" elif que.type in ['table']: if len(answer) and answer[0].state == "done": col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading') cols_widhts = [] tbl_width = float(_tbl_widths.replace('cm', '')) for i in range(0, len(que.column_heading_ids)): cols_widhts.append(tbl_width / float(len(que.column_heading_ids))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' matrix_ans = [] rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>""" for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append(col.title) rml += """<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>""" rml += """</tr></blockTable>""" i = 0 for row in range(0, que.no_of_rows): if i%2 != 0: style = 'tbl_white' else: style = 'tbl_gainsboro' i +=1 rml += """<blockTable colWidths=" """ + str(colWidths) + """ " style='"""+style+"""'><tr>""" table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id), ('name', '=', row)])) for column in matrix_ans: value = False for col in table_data: if column == col.column_id.title: value = col.value if value: rml += """<td> <para style="terp_default_9">""" + to_xml(tools.ustr(value)) +"""</para></td>""" else: rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>""" rml += """</tr></blockTable>""" else: rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']: if len(answer) and answer[0].state == "done": ans_list = [] for ans in answer[0].response_answer_ids: ans_list.append(to_xml(tools.ustr(ans.answer_id.answer))) answer_choice=[] for ans in que['answer_choice_ids']: answer_choice.append(to_xml(tools.ustr((ans.answer)))) def divide_list(lst, n): return [lst[i::n] for i in range(n)] divide_list = divide_list(answer_choice,_display_ans_in_rows) for lst in divide_list: if que.type == 'multiple_choice_multiple_ans': if len(lst) <> 0 and len(lst) <> int(round(float(len(answer_choice)) / _display_ans_in_rows, 0)): lst.append('') if not lst: del divide_list[divide_list.index(lst):] for divide in divide_list: a = _divide_columns_for_matrix * len(divide) b = float(_tbl_widths.replace('cm', '')) - float(a) cols_widhts = [] for div in range(0, len(divide)): cols_widhts.append(float(a / len(divide))) cols_widhts.append(float(b / len(divide))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths +'cm' rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>""" for div in range(0, len(divide)): if divide[div] != '': if que.type == 'multiple_choice_multiple_ans': if divide[div] in ans_list: rml += """<td><illustration><fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <fill color="gray"/> <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> </illustration></td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml+="""<td><illustration> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/> </illustration></td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: if divide[div] in ans_list: rml += """<td><illustration><fill color="white"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/> <fill color="gray"/> <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no" round="0.1cm"/> </illustration></td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml += """<td> <illustration> <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/> </illustration> </td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml += """<td></td><td></td>""" rml += """</tr></blockTable>""" if que.is_comment_require and answer[0].comment: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr> <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>""" else: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['multiple_textboxes_diff_type','multiple_textboxes','date','date_and_time','numerical_textboxes','multiple_textboxes_diff_type']: if len(answer) and answer[0].state == "done": cols_widhts = [] cols_widhts.append(float(_tbl_widths.replace('cm',''))/2) cols_widhts.append(float(_tbl_widths.replace('cm',''))/2) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = tools.ustr(colWidths) + 'cm' answer_list = {} for ans in answer[0].response_answer_ids: answer_list[ans.answer_id.answer] = ans.answer for que_ans in que['answer_choice_ids']: if que_ans.answer in answer_list: rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td> <td> <para style="response">""" + to_xml(tools.ustr(answer_list[que_ans.answer])) + """</para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td> <td> <para style="response"></para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['single_textbox']: if len(answer) and answer[0].state == "done": rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['comment']: if len(answer) and answer[0].state == "done": rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans', 'rating_scale', 'matrix_of_drop_down_menus']: if len(answer) and answer[0].state == "done": if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column: pass cols_widhts = [] if len(que.column_heading_ids): cols_widhts.append(float(_tbl_widths.replace('cm','')) / float(2.0)) for col in que.column_heading_ids: cols_widhts.append(float((float(_tbl_widths.replace('cm','')) / float(2.0)) / len(que.column_heading_ids))) else: cols_widhts.append(float(_tbl_widths.replace('cm',''))) tmp = 0.0 sum = 0.0 i = 0 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: for col in cols_widhts: if i == 0: cols_widhts[i] = cols_widhts[i] / 2.0 tmp = cols_widhts[i] sum += col i += 1 cols_widhts.append(round(tmp, 2)) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' matrix_ans = [(0, ''),] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append((col.id, col.title)) len_matrix = len(matrix_ans) if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column: matrix_ans.append((0,que.column_name)) rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>""" for mat_col in range(0, len(matrix_ans)): rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>""" rml += """</tr>""" rml += """</blockTable>""" i = 0 for ans in que.answer_choice_ids: if i%2 != 0: style = 'ans_tbl_white' else: style = 'ans_tbl_gainsboro' i += 1 rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'> <tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>""" comment_value = "" for mat_col in range(1, len_matrix): value = """""" for res_ans in answer[0].response_answer_ids: if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[mat_col][0]: comment_value = to_xml(tools.ustr(res_ans.comment_field)) if que.type in ['matrix_of_drop_down_menus']: value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>""" elif que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: value = """<illustration><fill color="white"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/> <fill color="gray"/> <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/> </illustration>""" elif que.type in ['matrix_of_choices_only_multi_ans']: value = """<illustration> <fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <fill color="gray"/> <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> </illustration>""" break else: if que.type in ['matrix_of_drop_down_menus']: value = """""" elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: value = """<illustration><fill color="white"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/> </illustration>""" elif que.type in ['matrix_of_choices_only_multi_ans']: value = """<illustration><fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> </illustration>""" rml+= """<td>""" + value + """</td>""" if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: if comment_value == 'False': comment_value = '' rml += """<td><para style="response">""" + to_xml(tools.ustr(comment_value)) + """</para></td>""" rml += """</tr></blockTable>""" if que.is_comment_require: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr> <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment or '')) + """</para></td></tr></blockTable>""" else: rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">No Answer</para></td> </tr> </blockTable>""" if datas.has_key('form') and not datas['form']['without_pagebreak']: rml += """<pageBreak/>""" elif not datas.has_key('form'): rml += """<pageBreak/>""" else: rml += """<para style="P2"><font></font></para>""" rml += """</story></document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create(self, cr, uid, ids, datas, context): _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 _pageSize = ('29.7cm', '21.1cm') if datas.has_key('form') and datas['form'].get('orientation', '') == 'vertical': if datas['form'].get('paper_size', '') == 'letter': _pageSize = ('21.6cm', '27.9cm') elif datas['form'].get('paper_size', '') == 'legal': _pageSize = ('21.6cm', '35.6cm') elif datas['form'].get('paper_size', '') == 'a4': _pageSize = ('21.1cm', '29.7cm') elif datas.has_key('form') and datas['form'].get( 'orientation', False) == 'horizontal': if datas['form'].get('paper_size', '') == 'letter': _pageSize = ('27.9cm', '21.6cm') elif datas['form'].get('paper_size', '') == 'legal': _pageSize = ('35.6cm', '21.6cm') elif datas['form'].get('paper_size') == 'a4': _pageSize = ('29.7cm', '21.1cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.90)) + 'cm' _tbl_widths = tools.ustr( float(_pageSize[0].replace('cm', '')) - float(2.10)) + 'cm' rml = """<document filename="Survey Answer Report.pdf"> <template pageSize="(""" + _pageSize[0] + """,""" + _pageSize[ 1] + """)" title='Survey Answer' author="OpenERP S.A.([email protected])" allowSplitting="20" > <pageTemplate id="first"> <frame id="first" x1="0.0cm" y1="1.0cm" width='""" + _frame_width + """' height='""" + _frame_height + """'/> <pageGraphics> <lineMode width="1.0"/> <lines>1.0cm """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """</lines> <lines>1.0cm """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00) ) + 'cm' + """ 1.0cm 1.00cm</lines> <lines>""" + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[1].replace('cm', '')) - float(1.00)) + 'cm' + """ """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """ 1.00cm</lines> <lines>1.0cm 1.00cm """ + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00) ) + 'cm' + """ 1.00cm</lines>""" if datas.has_key('form') and datas['form']['page_number']: rml += """ <fill color="gray"/> <setFont name="Helvetica" size="10"/> <<drawRightString x='""" + tools.ustr( float(_pageSize[0].replace('cm', '')) - float(1.00)) + 'cm' + """' y="0.6cm">""" + _( 'Page : ') + """<pageNumber/> </drawRightString>""" rml += """</pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="simple_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6"/> </blockTableStyle> <blockTableStyle id="note_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table2"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table3"> <blockAlignment value="LEFT"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="Table4"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="Table5"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="Table41"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table51"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="Table_heading"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="title_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="black" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="page_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="gray" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/> <paraStyle name="answer_right" alignment="RIGHT" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="Standard1" fontName="helvetica-bold" alignment="RIGHT" fontSize="09.0"/> <paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/> <paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/> <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/> <paraStyle name="page" fontName="helvetica" fontSize="11.0" leftIndent="0.0"/> <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/> <paraStyle name="answer_bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="answer1" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="Title" fontName="helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/> <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_9_Bold" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General_Centre_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_right_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_right" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="descriptive_text" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/> <paraStyle name="descriptive_text_heading" fontName="helvetica-bold" fontSize="18.0" alignment="RIGHT" leftIndent="0.0" textColor="white"/> </stylesheet> <images/> <story>""" surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response') rml_obj = report_sxw.rml_parse(cr, uid, surv_resp_obj._name, context) if datas.has_key('form') and datas['form'].has_key('response_ids'): response_id = datas['form']['response_ids'] elif context.has_key('response_id') and context['response_id']: response_id = [int(context['response_id'][0])] else: response_id = surv_resp_obj.search(cr, uid, [('survey_id', 'in', ids)]) surv_resp_line_obj = pooler.get_pool( cr.dbname).get('survey.response.line') surv_obj = pooler.get_pool(cr.dbname).get('survey') for response in surv_resp_obj.browse(cr, uid, response_id): for survey in surv_obj.browse(cr, uid, [response.survey_id.id]): tbl_width = float(_tbl_widths.replace('cm', '')) colwidth = "2.5cm,4.8cm," + str(tbl_width - 15.0) + "cm,3.2cm,4.5cm" resp_create = tools.ustr( time.strftime( '%d-%m-%Y %I:%M:%S %p', time.strptime( response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) rml += """<blockTable colWidths='""" + colwidth + """' style="Table_heading"> <tr> <td><para style="terp_default_9_Bold">""" + _( 'Print Date : ') + """</para></td> <td><para style="terp_default_9">""" + to_xml( rml_obj.formatLang( time.strftime("%Y-%m-%d %H:%M:%S"), date_time=True)) + """</para></td> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9_Bold">""" + _( 'Answered by : ') + """</para></td> <td><para style="terp_default_9">""" + to_xml( response.user_id.login or '') + """</para></td> </tr> <tr> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9"></para></td> <td><para style="terp_default_9_Bold">""" + _( 'Answer Date : ') + """</para></td> <td><para style="terp_default_9">""" + to_xml( resp_create) + """</para></td> </tr> </blockTable><para style="P2"></para>""" status = _("Not Finished") if response.state == "done": status = _("Finished") colwidth = str(tbl_width - 7) + "cm," colwidth += "7cm" rml += """<blockTable colWidths='""" + str( colwidth) + """' style="title_tbl"> <tr> <td><para style="title">""" + to_xml( tools.ustr(survey.title) ) + """</para><para style="P2"><font></font></para></td> <td><para style="descriptive_text_heading">""" + _( 'Status :- ' ) + to_xml( tools.ustr(status) ) + """</para><para style="P2"><font></font></para></td> </tr> </blockTable>""" if survey.note: rml += """<blockTable colWidths='""" + _tbl_widths + """' style="note_table"> <tr><td><para style="response">""" + to_xml( tools.ustr(survey.note or '') ) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" for page in survey.page_ids: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="page_tbl"> <tr><td><para style="page">""" + _( 'Page :- ') + to_xml(tools.ustr( page.title or '')) + """</para></td></tr> </blockTable>""" if page.note: rml += """<para style="P2"></para> <blockTable colWidths='""" + str( _tbl_widths) + """' style="note_table"> <tr><td><para style="response">""" + to_xml( tools.ustr(page.note or '')) + """</para></td></tr> </blockTable>""" for que in page.question_ids: rml += """<para style="P2"></para> <blockTable colWidths='""" + str( _tbl_widths) + """' style="Table5"> <tr><td><para style="question">""" + to_xml( to_xml(que.question)) + """</para></td></tr> </blockTable>""" answer = surv_resp_line_obj.browse( cr, uid, surv_resp_line_obj.search( cr, uid, [('question_id', '=', que.id), ('response_id', '=', response.id)])) if que.type in ['descriptive_text']: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">""" + to_xml( tools.ustr(que.descriptive_text) ) + """</para></td> </tr> </blockTable>""" elif que.type in ['table']: if len(answer) and answer[0].state == "done": col_heading = pooler.get_pool( cr.dbname).get('survey.tbl.column.heading') cols_widhts = [] tbl_width = float(_tbl_widths.replace( 'cm', '')) for i in range(0, len(que.column_heading_ids)): cols_widhts.append( tbl_width / float(len(que.column_heading_ids))) colWidths = "cm,".join( map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' matrix_ans = [] rml += """<para style="P2"></para><blockTable colWidths=" """ + str( colWidths) + """ " style="Table41"><tr>""" for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append(col.title) rml += """<td> <para style="terp_tblheader_Details">""" + to_xml( tools.ustr(col.title) ) + """</para></td>""" rml += """</tr></blockTable>""" i = 0 for row in range(0, que.no_of_rows): if i % 2 != 0: style = 'tbl_white' else: style = 'tbl_gainsboro' i += 1 rml += """<blockTable colWidths=" """ + str( colWidths ) + """ " style='""" + style + """'><tr>""" table_data = col_heading.browse( cr, uid, col_heading.search( cr, uid, [('response_table_id', '=', answer[0].id), ('name', '=', row)])) for column in matrix_ans: value = False for col in table_data: if column == col.column_id.title: value = col.value if value: rml += """<td> <para style="terp_default_9">""" + to_xml( tools.ustr(value) ) + """</para></td>""" else: rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>""" rml += """</tr></blockTable>""" else: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">""" + _( 'No Answer') + """</para></td> </tr> </blockTable>""" elif que.type in [ 'multiple_choice_only_one_ans', 'multiple_choice_multiple_ans' ]: if len(answer) and answer[0].state == "done": ans_list = [] for ans in answer[0].response_answer_ids: ans_list.append( to_xml(tools.ustr( ans.answer_id.answer))) answer_choice = [] for ans in que['answer_choice_ids']: answer_choice.append( to_xml(tools.ustr((ans.answer)))) def divide_list(lst, n): return [lst[i::n] for i in range(n)] divide_list = divide_list( answer_choice, _display_ans_in_rows) for lst in divide_list: if que.type == 'multiple_choice_multiple_ans': if len(lst) <> 0 and len(lst) <> int( round( float(len(answer_choice)) / _display_ans_in_rows, 0)): lst.append('') if not lst: del divide_list[divide_list.index(lst ):] for divide in divide_list: a = _divide_columns_for_matrix * len( divide) b = float(_tbl_widths.replace( 'cm', '')) - float(a) cols_widhts = [] for div in range(0, len(divide)): cols_widhts.append( float(a / len(divide))) cols_widhts.append( float(b / len(divide))) colWidths = "cm,".join( map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>""" for div in range(0, len(divide)): if divide[div] != '': if que.type == 'multiple_choice_multiple_ans': if divide[div] in ans_list: rml += """<td><illustration><fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <fill color="gray"/> <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> </illustration></td> <td><para style="answer">""" + divide[ div] + """</para></td>""" else: rml += """<td><illustration> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/> </illustration></td> <td><para style="answer">""" + divide[ div] + """</para></td>""" else: if divide[div] in ans_list: rml += """<td><illustration><fill color="white"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/> <fill color="gray"/> <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no" round="0.1cm"/> </illustration></td> <td><para style="answer">""" + divide[ div] + """</para></td>""" else: rml += """<td> <illustration> <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/> </illustration> </td> <td><para style="answer">""" + divide[ div] + """</para></td>""" else: rml += """<td></td><td></td>""" rml += """</tr></blockTable>""" if que.is_comment_require and answer[0].comment: rml += """<blockTable colWidths='""" + str( _tbl_widths ) + """' style="simple_table"><tr> <td><para style="answer">""" + to_xml( tools.ustr(answer[0].comment) ) + """</para></td></tr></blockTable>""" else: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in [ 'multiple_textboxes_diff_type', 'multiple_textboxes', 'date', 'date_and_time', 'numerical_textboxes', 'multiple_textboxes_diff_type' ]: if len(answer) and answer[0].state == "done": cols_widhts = [] cols_widhts.append( float(_tbl_widths.replace('cm', '')) / 2) cols_widhts.append( float(_tbl_widths.replace('cm', '')) / 2) colWidths = "cm,".join( map(tools.ustr, cols_widhts)) colWidths = tools.ustr(colWidths) + 'cm' answer_list = {} for ans in answer[0].response_answer_ids: answer_list[ ans.answer_id.answer] = ans.answer for que_ans in que['answer_choice_ids']: if que_ans.answer in answer_list: rml += """<blockTable colWidths='""" + str( colWidths ) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml( tools.ustr(que_ans.answer) ) + """</para></td> <td> <para style="response">""" + to_xml( tools.ustr( answer_list[que_ans.answer]) ) + """</para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str( colWidths ) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml( tools.ustr(que_ans.answer) ) + """</para></td> <td> <para style="response"></para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['single_textbox']: if len(answer) and answer[0].state == "done": rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml( tools.ustr(answer[0].single_text) ) + """</para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in ['comment']: if len(answer) and answer[0].state == "done": rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">""" + to_xml( tools.ustr(answer[0].comment) ) + """</para></td></tr> </blockTable>""" else: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr> <td> <para style="response">No Answer</para></td> </tr> </blockTable>""" elif que.type in [ 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale', 'matrix_of_drop_down_menus' ]: if len(answer) and answer[0].state == "done": if que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ] and que.comment_column: pass cols_widhts = [] if len(que.column_heading_ids): cols_widhts.append( float(_tbl_widths.replace('cm', '')) / float(2.0)) for col in que.column_heading_ids: cols_widhts.append( float((float( _tbl_widths.replace('cm', '')) / float(2.0)) / len(que.column_heading_ids))) else: cols_widhts.append( float(_tbl_widths.replace('cm', ''))) tmp = 0.0 sum = 0.0 i = 0 if que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ] and que.comment_column: for col in cols_widhts: if i == 0: cols_widhts[ i] = cols_widhts[i] / 2.0 tmp = cols_widhts[i] sum += col i += 1 cols_widhts.append(round(tmp, 2)) colWidths = "cm,".join( map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' matrix_ans = [ (0, ''), ] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append((col.id, col.title)) len_matrix = len(matrix_ans) if que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ] and que.comment_column: matrix_ans.append((0, que.column_name)) rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>""" for mat_col in range(0, len(matrix_ans)): rml += """<td><para style="response">""" + to_xml( tools.ustr(matrix_ans[mat_col] [1])) + """</para></td>""" rml += """</tr>""" rml += """</blockTable>""" i = 0 for ans in que.answer_choice_ids: if i % 2 != 0: style = 'ans_tbl_white' else: style = 'ans_tbl_gainsboro' i += 1 rml += """<blockTable colWidths=" """ + colWidths + """ " style='""" + style + """'> <tr><td><para style="response">""" + to_xml( tools.ustr( ans.answer)) + """</para></td>""" comment_value = "" for mat_col in range(1, len_matrix): value = """""" for res_ans in answer[ 0].response_answer_ids: if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[ mat_col][0]: comment_value = to_xml( tools.ustr( res_ans.comment_field)) if que.type in [ 'matrix_of_drop_down_menus' ]: value = """<para style="response">""" + to_xml( tools.ustr( res_ans. value_choice) ) + """</para>""" elif que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ]: value = """<illustration><fill color="white"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/> <fill color="gray"/> <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/> </illustration>""" elif que.type in [ 'matrix_of_choices_only_multi_ans' ]: value = """<illustration> <fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <fill color="gray"/> <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> </illustration>""" break else: if que.type in [ 'matrix_of_drop_down_menus' ]: value = """""" elif que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ]: value = """<illustration><fill color="white"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/> </illustration>""" elif que.type in [ 'matrix_of_choices_only_multi_ans' ]: value = """<illustration><fill color="white"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> </illustration>""" rml += """<td>""" + value + """</td>""" if que.type in [ 'matrix_of_choices_only_one_ans', 'rating_scale' ] and que.comment_column: if comment_value == 'False': comment_value = '' rml += """<td><para style="response">""" + to_xml( tools.ustr(comment_value) ) + """</para></td>""" rml += """</tr></blockTable>""" if que.is_comment_require: rml += """<blockTable colWidths='""" + str( _tbl_widths ) + """' style="simple_table"><tr> <td><para style="answer">""" + to_xml( tools.ustr(answer[0].comment or '') ) + """</para></td></tr></blockTable>""" else: rml += """<blockTable colWidths='""" + str( _tbl_widths) + """' style="simple_table"> <tr><td> <para style="response">No Answer</para></td> </tr> </blockTable>""" if datas.has_key( 'form') and not datas['form']['without_pagebreak']: rml += """<pageBreak/>""" elif not datas.has_key('form'): rml += """<pageBreak/>""" else: rml += """<para style="P2"><font></font></para>""" rml += """</story></document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def get_name(self,data): name= to_xml('Ort & Session-Nr') return name[0:5]+name[9:20]
def create(self, cr, uid, ids, datas, context): del_obj = pooler.get_pool(cr.dbname).get('stock.picking.out') user_obj = pooler.get_pool(cr.dbname).get('res.users') rml_obj=report_sxw.rml_parse(cr, uid, del_obj._name,context) company=user_obj.browse(cr,uid,[uid],context)[0].company_id rml ="""<document filename="QC Documents.pdf"> <template pageSize="(595.0,842.0)" title="QC Documents" author="OpenERP S.A.([email protected])" allowSplitting="20"> <pageTemplate> <frame id="first" x1="1.3cm" y1="1.5cm" width="18.4cm" height="26.5cm"/> <stylesheet> <blockTableStyle id="Table4"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="3,0" stop="3,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="4,0" stop="4,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="4,0" stop="4,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="4,0" stop="4,-1"/> <lineStyle kind="LINEBEFORE" colorName="#000000" start="5,0" stop="5,-1"/> <lineStyle kind="LINEABOVE" colorName="#000000" start="5,0" stop="5,0"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="5,0" stop="5,-1"/> <lineStyle kind="LINEAFTER" colorName="#000000" start="5,-1" stop="5,-1"/> </blockTableStyle> <blockTableStyle id="Table_Title_String"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="Standard" fontName="Helvetica"/> <paraStyle name="main_footer" fontSize="8.0" alignment="CENTER"/> <paraStyle name="main_header" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica" fontSize="14.0" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="content_Details" fontName="Helvetica" fontSize="12.0" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <images/> </stylesheet> <pageGraphics> <!-- Set here the default font to use for all <drawString> tags --> <setFont name="DejaVu Sans" size="8"/> <!-- You Logo - Change X,Y,Width and Height --> <image x="1.3cm" y="27.7cm" height="40.0" >"""+ to_xml(company.logo) +"""</image> <fill color="black"/> <stroke color="black"/> <!-- page header --> <lines>1.3cm 27.7cm 20cm 27.7cm</lines> <drawRightString x="20cm" y="27.8cm">"""+ to_xml(company.rml_header1) +"""</drawRightString> <drawString x="1.3cm" y="27.3cm">"""+ to_xml(company.partner_id.name) +"""</drawString> <place x="1.3cm" y="25.3cm" height="1.8cm" width="15.0cm"> <para style="main_header">"""+ to_xml(company.partner_id.street or '') +"""</para> <para style="main_header">"""+ to_xml(company.partner_id.street2 or '') +"""</para> <para style="main_header">"""+ to_xml(company.partner_id.city or '') +""",""" + to_xml(company.partner_id.state_id.name or '') +"""</para> <para style="main_header">"""+ to_xml(company.partner_id.country_id.name or '') +""" - """+ to_xml(company.partner_id.zip or '') +"""</para> </place> <drawString x="1.3cm" y="25.0cm">Phone:</drawString> <drawRightString x="7cm" y="25.0cm">"""+ to_xml(company.partner_id.phone or '') +"""</drawRightString> <drawString x="1.3cm" y="24.6cm">Mail:</drawString> <drawRightString x="7cm" y="24.6cm">"""+ to_xml(company.partner_id.email or '') +"""</drawRightString> <lines>1.3cm 24.5cm 7cm 24.5cm</lines> <!-- left margin --> <rotate degrees="90"/> <fill color="grey"/> <drawString x="2.65cm" y="-0.4cm">generated by OpenERP.com</drawString> <fill color="black"/> <rotate degrees="-90"/> <!-- page footer --> <lines>1.2cm 2.65cm 19.9cm 2.65cm</lines> <place x="1.3cm" y="0cm" height="2.55cm" width="19.0cm"> <para style="main_footer">"""+ to_xml(company.rml_footer or '') +"""</para> <para style="main_footer">Contact : """+ to_xml(company.name) +"""- Page: <pageNumber/></para> </place> </pageGraphics> </pageTemplate> </template> """ lst = [] for line in del_obj.browse(cr, uid, ids): main_list = self.get_analysis_data(cr, uid, line.move_lines) for sub in main_list: rml += """ <story> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <blockTable colWidths="538.0" style="Table_Title_String"> <tr> <td> <para style="terp_header">Delivery Order : """+ to_xml(line.name or '') +"""</para> <para style="terp_header">Sale Order : """+ to_xml(line.origin or '') +"""</para> <para style="terp_header">QC Number : </para> </td> </tr> </blockTable> <para style="Standard"> <font color="white"> </font> </para> <para style="Standard"> <font color="white"> </font> </para> <blockTable colWidths="210.0,90.0,90.0,90.0,55.0" rowHeights="40" style="Table4"> <tr> <td> <para style="terp_tblheader_Details"><b>CHARACTERISTIC</b></para> </td> <td> <para style="terp_tblheader_Details"><b>Actual Value</b></para> </td> <td> <para style="terp_tblheader_Details"><b>Upper Limit</b></para> </td> <td> <para style="terp_tblheader_Details"><b>Lower Limit</b></para> </td> <td> <para style="terp_tblheader_Details"><b>ok?</b></para> </td> </tr> </blockTable> """ for sub_list in sub: rml += """ <blockTable colWidths="210.0,90.0,90.0,90.0,55.0" style="Table4"> <tr> <td> <para style="content_Details">""" + str(sub_list['name']) + """</para> </td> <td> <para style="content_Details">""" + sub_list['actual'] + """</para> </td> <td> <para style="content_Details">""" + str(sub_list['upper']) + """</para> </td> <td> <para style="content_Details">""" +str(sub_list['lower']) + """</para> </td> <td> <para style="content_Details">""" + str(sub_list['ok']) + """</para> </td> </tr> </blockTable> """ rml += """</story> """ rml += """</document> """ report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] self.internal_header=False pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create_xml(self, cr, uid, ids, data, context): registry = openerp.registry(cr.dbname) obj_dept = registry['hr.department'] obj_emp = registry['hr.employee'] depts=[] emp_id={} rpt_obj = registry['hr.holidays'] rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) cr.execute("SELECT name FROM res_company") res=cr.fetchone()[0] date_xml=[] date_today=time.strftime('%Y-%m-%d %H:%M:%S') date_xml +=['<res name="%s" today="%s" />' % (res,date_today)] cr.execute("SELECT id, name, color_name FROM hr_holidays_status ORDER BY id") legend=cr.fetchall() today=datetime.datetime.today() first_date=data['form']['date_from'] som = strToDate(first_date) eom = som+datetime.timedelta(59) day_diff=eom-som name = '' if len(data['form'].get('emp', ())) == 1: name = obj_emp.read(cr, uid, data['form']['emp'][0], ['name'])['name'] if data['form']['holiday_type']!='both': type=data['form']['holiday_type'] if data['form']['holiday_type']=='Confirmed': holiday_type=('confirm') else: holiday_type=('validate') else: type="Confirmed and Approved" holiday_type=('confirm','validate') date_xml.append('<from>%s</from>\n'% (str(rml_obj.formatLang(som.strftime("%Y-%m-%d"),date=True)))) date_xml.append('<to>%s</to>\n' %(str(rml_obj.formatLang(eom.strftime("%Y-%m-%d"),date=True)))) date_xml.append('<type>%s</type>'%(type)) date_xml.append('<name>%s</name>'%(name)) # date_xml=[] for l in range(0,len(legend)): date_xml += ['<legend row="%d" id="%d" name="%s" color="%s" />' % (l+1,legend[l][0],_(legend[l][1]),legend[l][2])] date_xml += ['<date month="%s" year="%d" />' % (som.strftime('%B'), som.year),'<days>'] cell=1 if day_diff.days>=30: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] else: if day_diff.days>=(lengthmonth(som.year, som.month)-som.day): date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] else: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, eom.day+1)] cell=x-som.day+1 day_diff1=day_diff.days-cell+1 width_dict={} month_dict={} i=1 j=1 year=som.year month=som.month month_dict[j]=som.strftime('%B') width_dict[j]=cell while day_diff1>0: if month+i<=12: if day_diff1 > lengthmonth(year,i+month): # Not on 30 else you have problems when entering 01-01-2009 for example som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(year,i+month)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x day_diff1=day_diff1-x else: years=year+1 year=years month=0 i=1 if day_diff1>=30: som1=datetime.date(years,i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(years,i)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(years,i,1) i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] cell=cell+x width_dict[j]=x day_diff1=day_diff1-x date_xml.append('</days>') date_xml.append('<cols>3.5cm%s,0.4cm</cols>\n' % (',0.4cm' * (60))) date_xml = ''.join(date_xml) st='<cols_months>3.5cm' for m in range(1,len(width_dict)+1): st+=',' + str(0.4 *width_dict[m])+'cm' st+=',0.4cm</cols_months>\n' months_xml =['<months number="%d" name="%s"/>' % (x, _(month_dict[x])) for x in range(1,len(month_dict)+1) ] months_xml.append(st) emp_xml='' row_id=1 if data['model']=='hr.employee': for id in data['form']['emp']: items = obj_emp.read(cr, uid, id, ['id','name']) emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, items['id'], items['name'], som, eom) row_id = row_id +1 elif data['model']=='ir.ui.menu': for id in data['form']['depts']: dept = obj_dept.browse(cr, uid, id, context=context) cr.execute("""SELECT id FROM hr_employee \ WHERE department_id = %s""", (id,)) emp_ids = [x[0] for x in cr.fetchall()] if emp_ids==[]: continue dept_done=0 for item in obj_emp.read(cr, uid, emp_ids, ['id', 'name']): if dept_done==0: emp_xml += emp_create_xml(self, cr, uid, 1, holiday_type, row_id, dept.id, dept.name, som, eom) row_id = row_id +1 dept_done=1 emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, item['id'], item['name'], som, eom) row_id = row_id +1 header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(registry['res.users'].browse(cr,uid,uid).company_id.name)) # Computing the xml xml='''<?xml version="1.0" encoding="UTF-8" ?> <report> %s %s %s %s </report> ''' % (header_xml,months_xml,date_xml, ustr(emp_xml)) return xml
def create(self, cr, uid, ids, datas, context): _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 _pageSize = ('29.7cm','21.1cm') if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('21.6cm','27.9cm') elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('21.6cm','35.6cm') elif datas['form'].get('paper_size','') == 'a4': _pageSize = ('21.1cm','29.7cm') elif datas.has_key('form') and datas['form'].get('orientation','') == 'horizontal': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('27.9cm','21.6cm') elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('35.6cm','21.6cm') elif datas['form'].get('paper_size','') == 'a4': _pageSize = ('29.7cm','21.1cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm' _tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm' rml="""<document filename="Survey Form.pdf"> <template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Form' author="OpenERP S.A.([email protected])" allowSplitting="20" > <pageTemplate id="first"> <frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/> <pageGraphics> <lineMode width="1.0"/> <lines>1.0cm """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) + 'cm' + """ """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) + 'cm' + """</lines> <lines>1.0cm """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) +'cm'+ """ 1.0cm 1.00cm</lines> <lines>""" + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm' + """ """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00)) + 'cm' + """ 1.00cm</lines> <lines>1.0cm 1.00cm """ + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>""" if datas.has_key('form') and datas['form']['page_number']: rml +=""" <fill color="gray"/> <setFont name="Helvetica" size="10"/> <drawRightString x='""" + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00)) + 'cm' + """' y="0.6cm">Page : <pageNumber/> </drawRightString>""" rml +="""</pageGraphics> </pageTemplate> </template> <stylesheet> <blockTableStyle id="ans_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_white"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="page_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="gray" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="title_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="black" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="question_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="note_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/> </blockTableStyle> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/> <paraStyle name="page" fontName="helvetica-bold" fontSize="15.0" leftIndent="0.0" textColor="white"/> <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leading="15" leftIndent="0.0" textColor="white"/> <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/> <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="0.0"/> <paraStyle name="descriptive_text" fontName="helvetica" fontSize="10.0" leftIndent="0.0"/> <paraStyle name="answer_left" alignment="LEFT" fontName="helvetica-bold" fontSize="8.0" leftIndent="0.0"/> <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> </stylesheet> <story>""" surv_obj = pooler.get_pool(cr.dbname).get('survey') for survey in surv_obj.browse(cr,uid,ids): rml += """ <blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl"> <tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" if survey.note: rml += """ <para style="P2"></para> <blockTable colWidths='"""+_tbl_widths+"""' style="note_table"> <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(survey.note)) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" seq = 0 for page in survey.page_ids: seq += 1 rml += """ <blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl"> <tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" if page.note: rml += """<para style="P2"></para><blockTable colWidths='"""+_tbl_widths+"""' style="note_table"> <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr> </blockTable>""" for que in page.question_ids: cols_widhts = [] rml += """ <para style="P2"><font></font></para> <blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl"> <tr><td><para style="question">""" + to_xml(tools.ustr(que.question)) + """</para></td></tr> </blockTable> <para style="P2"><font></font></para>""" if que.type in ['descriptive_text']: cols_widhts.append(float(_tbl_widths.replace('cm',''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' rml += """ <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr> <td> <para style="descriptive_text">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para> </td> </tr> </blockTable>""" elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']: answer = [] for ans in que.answer_choice_ids: answer.append(to_xml(tools.ustr((ans.answer)))) def divide_list(lst, n): return [lst[i::n] for i in range(n)] divide_list = divide_list(answer,_display_ans_in_rows) for lst in divide_list: if que.type == 'multiple_choice_multiple_ans': if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)): lst.append('') if not lst: del divide_list[divide_list.index(lst):] for divide in divide_list: a = _divide_columns_for_matrix*len(divide) b = float(_tbl_widths.replace('cm','')) - float(a) cols_widhts = [] for div in range(0,len(divide)): cols_widhts.append(float(a/len(divide))) cols_widhts.append(float(b/len(divide))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths +'cm' rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr>""" for div in range(0,len(divide)): if divide[div] != '': if que.type == 'multiple_choice_multiple_ans': rml += """ <td> <illustration> <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/> </illustration> </td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml += """ <td> <illustration> <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/> </illustration> </td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml += """ <td></td> <td></td>""" rml += """ </tr></blockTable>""" elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']: if len(que.column_heading_ids): cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0)) for col in que.column_heading_ids: cols_widhts.append(float((float(_tbl_widths.replace('cm',''))/float(2.0))/len(que.column_heading_ids))) else: cols_widhts.append(float(_tbl_widths.replace('cm',''))) tmp = 0.0 sum = 0.0 i = 0 if que.comment_column: for col in cols_widhts: if i == 0: cols_widhts[i] = cols_widhts[i]/2.0 tmp = cols_widhts[i] sum += col i += 1 cols_widhts.append(round(tmp,2)) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths+'cm' matrix_ans = ['',] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append(col.title) if que.comment_column: matrix_ans.append(to_xml(tools.ustr(que.column_name))) rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"><tr>""" for mat_col in matrix_ans: rml += """<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>""" rml += """</tr></blockTable>""" i = 0 for ans in que.answer_choice_ids: if i%2 != 0: style='ans_tbl_white' else: style='ans_tbl_gainsboro' i += 1 rml += """ <blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'> <tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>""" rec_width = float((sum-tmp)*10+100) value = "" if que.type in ['matrix_of_drop_down_menus']: value = """ <fill color="white"/> <rect x="-0.1cm" y="-0.45cm" width='""" + tools.ustr(cols_widhts[-1] - 0.5) +"cm" + """' height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>""" elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: value = """ <fill color="white"/> <circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>""" else: value = """ <fill color="white"/> <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>""" for mat_col in range(1,len(matrix_ans)): if matrix_ans[mat_col] == que.column_name: if mat_col == 1: rml += """ <td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>""" else: rml += """<td></td>""" else: rml += """<td><illustration>""" + value + """</illustration></td>""" rml += """</tr></blockTable>""" elif que.type in ['multiple_textboxes', 'numerical_textboxes', 'date_and_time','date','multiple_textboxes_diff_type']: cols_widhts.append(float(_tbl_widths.replace('cm',''))/2) cols_widhts.append(float(_tbl_widths.replace('cm',''))/2) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = tools.ustr(colWidths) + 'cm' for ans in que.answer_choice_ids: rml += """<para style="P1"></para> <blockTable colWidths=" """+ colWidths + """ " style="ans_tbl"> <tr> <td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td> <td> <illustration> <rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr(str(cols_widhts[0] - 0.3) + "cm") + """' height="0.6cm" fill="no" stroke="yes"/> </illustration> </td> </tr> </blockTable>""" elif que.type in ['comment']: cols_widhts.append(float(_tbl_widths.replace('cm',''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) rml += """<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl"> <tr> <td><para style="comment"><font color="white"> </font></para> <illustration> <rect x="0.1cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.6) +'cm') + """' height="1.5cm" fill="no" stroke="yes"/> </illustration> </td> </tr> </blockTable>""" elif que.type in ['single_textbox']: cols_widhts.append(float(_tbl_widths.replace('cm',''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) rml += """<para style="P2"><font color="white"> </font></para> <blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl"> <tr> <td> <illustration> <rect x="0.2cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.7) +'cm') + """' height="0.6cm" fill="no" stroke="yes"/> </illustration> </td> </tr> </blockTable>""" elif que.type in ['table']: tbl_width = float(_tbl_widths.replace('cm','')) for i in range(0,len(que.column_heading_ids)): cols_widhts.append(tbl_width/float(len(que.column_heading_ids))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths+'cm' rml += """<blockTable colWidths=" """ + colWidths + """ " style="tbl"><tr>""" for col in que.column_heading_ids: rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>""" rml += """</tr></blockTable>""" i = 0 for r in range(0,que.no_of_rows): if i%2 != 0: style = 'tbl_white' else: style = 'tbl_gainsboro' i += 1 rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'><tr>""" for c in que.column_heading_ids: rml += """ <td><para style="terp_default_9"><font color="white"> </font></para></td>""" rml += """</tr></blockTable>""" if datas.has_key('form') and not datas['form']['without_pagebreak']: rml += """<pageBreak/>""" elif not datas.has_key('form'): rml += """<pageBreak/>""" else: rml += """<para style="P2"><font></font></para>""" rml += """</story></document>""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] pdf = create_doc(rml, title=self.title) return (pdf, report_type)
def create_xml(self, cr, uid, ids, data, context): registry = openerp.registry(cr.dbname) # Get the user id from the selected employee record emp_id = data['form']['employee_id'] emp_obj = registry['hr.employee'] user_id = emp_obj.browse(cr, uid, emp_id).user_id.id empl_name = emp_obj.browse(cr, uid, emp_id).name # Computing the dates (start of month: som, and end of month: eom) som = datetime.date(data['form']['year'], data['form']['month'], 1) eom = som + datetime.timedelta(lengthmonth(som.year, som.month)) date_xml = [ '<date month="%s" year="%d" />' % (self.get_month_name( cr, uid, som.month, context=context), som.year), '<days>' ] date_xml += [ '<day number="%d" name="%s" weekday="%d" />' % (x, self.get_weekday_name( cr, uid, som.replace(day=x).weekday() + 1, context=context), som.replace(day=x).weekday() + 1) for x in range(1, lengthmonth(som.year, som.month) + 1) ] date_xml.append('</days>') date_xml.append('<cols>2.5cm%s,2cm</cols>\n' % (',0.7cm' * lengthmonth(som.year, som.month))) # Sum attendence by account, then by day accounts = {} header_xml = '' if user_id: # Computing the attendence by analytical account cr.execute( "select line.date, (unit_amount / unit.factor) as amount, account_id, account.name "\ "from account_analytic_line as line, hr_analytic_timesheet as hr, "\ "account_analytic_account as account, product_uom as unit "\ "where hr.line_id=line.id and line.account_id=account.id "\ "and product_uom_id = unit.id "\ "and line.user_id=%s and line.date >= %s and line.date < %s " "order by line.date", (user_id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d'))) for presence in cr.dictfetchall(): day = int(presence['date'][-2:]) account = accounts.setdefault( (presence['account_id'], presence['name']), {}) account[day] = account.get(day, 0.0) + presence['amount'] xml = ''' <time-element date="%s"> <amount>%.2f</amount> </time-element> ''' rpt_obj = registry['hr.employee'] rml_obj = report_sxw.rml_parse(cr, uid, rpt_obj._name, context) if user_id: header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % ( str(rml_obj.formatLang(time.strftime("%Y-%m-%d"), date=True)) + ' ' + str(time.strftime("%H:%M")), to_xml(registry['res.users'].browse(cr, uid, user_id).company_id.name)) account_xml = [] for account, telems in accounts.iteritems(): aid, aname = account aname = registry['account.analytic.account'].name_get( cr, uid, [aid], context) aname = aname[0][1] account_xml.append('<account id="%d" name="%s">' % (aid, toxml(aname))) account_xml.append('\n'.join( [xml % (day, amount) for day, amount in telems.iteritems()])) account_xml.append('</account>') # Computing the xml xml = '''<?xml version="1.0" encoding="UTF-8" ?> <report> %s <employee>%s</employee> %s </report> ''' % (header_xml, ustr( toxml(empl_name)), '\n'.join(date_xml) + '\n'.join(account_xml)) return xml
def create_xml(self, cr, uid, ids, datas, context=None): obj_emp = pooler.get_pool(cr.dbname).get('hr.employee') if context is None: context = {} month = datetime(datas['form']['year'], datas['form']['month'], 1) emp_ids = datas['active_ids'] user_xml = [ '<month>%s</month>' % _(month2name[month.month]), '<year>%s</year>' % month.year ] if emp_ids: for emp in obj_emp.read(cr, uid, emp_ids, ['name']): stop, days_xml = False, [] total_wh = 0.0 user_repr = ''' <user> <name>%s</name> %%s </user> ''' % (ustr(toxml(emp['name']))) today, tomor = month, month + one_day while today.month == month.month: #### Work hour calculation sql = ''' select action, att.name from hr_employee as emp inner join hr_attendance as att on emp.id = att.employee_id where att.name between %s and %s and emp.id = %s order by att.name ''' cr.execute( sql, (today.strftime('%Y-%m-%d %H:%M:%S'), tomor.strftime('%Y-%m-%d %H:%M:%S'), emp['id'])) attendences = cr.dictfetchall() wh = 0.0 # Fake sign ins/outs at week ends, to take attendances across week ends into account if attendences and attendences[0]['action'] == 'sign_out': attendences.insert( 0, { 'name': today.strftime('%Y-%m-%d %H:%M:%S'), 'action': 'sign_in' }) if attendences and attendences[-1]['action'] == 'sign_in': attendences.append({ 'name': tomor.strftime('%Y-%m-%d %H:%M:%S'), 'action': 'sign_out' }) # sum up the attendances' durations ldt = None for att in attendences: dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') if ldt and att['action'] == 'sign_out': if dt.date() > ldt.date(): dt = ldt wh += (float((dt - ldt).seconds) / 60 / 60) else: ldt = dt # Week xml representation total_wh += wh wh = hour2str(wh) today_xml = '<day num="%s"><wh>%s</wh></day>' % ( (today - month).days + 1, (wh)) dy = (today - month).days + 1 days_xml.append(today_xml) today, tomor = tomor, tomor + one_day total_wh = hour2str(total_wh) today_xml = '<day num="Total"><wh>%s</wh></day>' % (total_wh) days_xml.append(today_xml) user_xml.append(user_repr % '\n'.join(days_xml)) rpt_obj = pooler.get_pool(cr.dbname).get('hr.employee') rml_obj = report_sxw.rml_parse(cr, uid, rpt_obj._name, context) header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"), date=True)) + ' ' + str(time.strftime("%H:%M")), to_xml( pooler.get_pool(cr.dbname).get('res.users').browse( cr, uid, uid).company_id.name)) first_date = str(month) som = datetime.strptime(first_date, '%Y-%m-%d %H:%M:%S') eom = som + timedelta(int(dy) - 1) day_diff = eom - som date_xml = [] cell = 1 date_xml.append('<days>') if day_diff.days >= 30: date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')), x - som.day + 1) for x in range(som.day, lengthmonth(som.year, som.month) + 1) ] else: if day_diff.days >= (lengthmonth(som.year, som.month) - som.day): date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')), x - som.day + 1) for x in range(som.day, lengthmonth(som.year, som.month) + 1) ] else: date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')), x - som.day + 1) for x in range(som.day, eom.day + 1) ] cell = x - som.day + 1 day_diff1 = day_diff.days - cell + 1 width_dict = {} month_dict = {} i = 1 j = 1 year = som.year month = som.month month_dict[j] = som.strftime('%B') width_dict[j] = cell while day_diff1 > 0: if month + i <= 12: if day_diff1 > lengthmonth( year, i + month ): # Not on 30 else you have problems when entering 01-01-2009 for example som1 = datetime.date(year, month + i, 1) date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')), cell + x) for x in range(1, lengthmonth(year, i + month) + 1) ] i = i + 1 j = j + 1 month_dict[j] = som1.strftime('%B') cell = cell + x width_dict[j] = x else: som1 = datetime.date(year, month + i, 1) date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')), cell + x) for x in range(1, eom.day + 1) ] i = i + 1 j = j + 1 month_dict[j] = som1.strftime('%B') cell = cell + x width_dict[j] = x day_diff1 = day_diff1 - x else: years = year + 1 year = years month = 0 i = 1 if day_diff1 >= 30: som1 = datetime.date(years, i, 1) date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')), cell + x) for x in range(1, lengthmonth(years, i) + 1) ] i = i + 1 j = j + 1 month_dict[j] = som1.strftime('%B') cell = cell + x width_dict[j] = x else: som1 = datetime.date(years, i, 1) i = i + 1 j = j + 1 month_dict[j] = som1.strftime('%B') date_xml += [ '<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')), cell + x) for x in range(1, eom.day + 1) ] cell = cell + x width_dict[j] = x day_diff1 = day_diff1 - x date_xml += ['<dayy name="Total" cell="Total"/>'] date_xml.append('</days>') date_xml.append('<cols>3.5cm%s,1.2cm</cols>\n' % (',0.74cm' * (int(dy)))) xml = '''<?xml version="1.0" encoding="UTF-8" ?> <report> %s <title>%s</title> %s %s </report> ''' % (header_xml, _('Attendances by Month'), '\n'.join(user_xml), date_xml) return xml
def create_xml(self, cr, uid, ids, datas, context=None): number = (datas.get('form', False) and datas['form']['number']) or 1 registry = openerp.registry(cr.dbname) product_pool = registry.get('product.product') product_uom_pool = registry.get('product.uom') workcenter_pool = registry.get('mrp.workcenter') user_pool = registry.get('res.users') bom_pool = registry.get('mrp.bom') pricelist_pool = registry.get('product.pricelist') rml_obj = report_sxw.rml_parse(cr, uid, product_pool._name, context) rml_obj.localcontext.update({'lang': context.get('lang', False)}) company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id company_currency_symbol = company_currency.symbol or company_currency.name def process_bom(bom, currency_id, factor=1): xml = '<row>' sum = 0 sum_strd = 0 prod = product_pool.browse(cr, uid, bom['product_id']) prod_name = to_xml(bom['name']) prod_qtty = factor * bom['product_qty'] product_uom = product_uom_pool.browse(cr, uid, bom['product_uom'], context=context) product_uom_name = to_xml(product_uom.name) main_sp_price, main_sp_name, main_strd_price = '', '', '' sellers, sellers_price = '', '' if prod.seller_id: main_sp_name = '- <b>' + to_xml( prod.seller_id.name) + '</b>\r\n' pricelist = prod.seller_id.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, prod.seller_id.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] main_sp_price = """<b>""" + rml_obj.formatLang(price) + ' ' + ( company_currency_symbol) + """</b>\r\n""" sum += prod_qtty * price std_price = product_uom_pool._compute_price( cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id) main_strd_price = str(std_price) + '\r\n' sum_strd = prod_qtty * std_price for seller_id in prod.seller_ids: if seller_id.name.id == prod.seller_id.id: continue sellers += '- <i>' + to_xml(seller_id.name.name) + '</i>\r\n' pricelist = seller_id.name.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, seller_id.name.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] sellers_price += """<i>""" + rml_obj.formatLang( price) + ' ' + (company_currency_symbol) + """</i>\r\n""" xml += """<col para='yes'> """ + prod_name + """ </col> <col para='yes'> """ + main_sp_name + sellers + """ </col> <col f='yes'>""" + rml_obj.formatLang( prod_qtty) + ' ' + product_uom_name + """</col> <col f='yes'>""" + rml_obj.formatLang( float(main_strd_price)) + ' ' + ( company_currency_symbol) + """</col> <col f='yes'>""" + main_sp_price + sellers_price + """</col>'""" xml += '</row>' return xml, sum, sum_strd def process_workcenter(wrk): workcenter = workcenter_pool.browse(cr, uid, wrk['workcenter_id']) cost_cycle = wrk['cycle'] * workcenter.costs_cycle cost_hour = wrk['hour'] * workcenter.costs_hour total = cost_cycle + cost_hour xml = '<row>' xml += "<col para='yes'>" + to_xml(workcenter.name) + '</col>' xml += "<col/>" xml += """<col f='yes'>""" + rml_obj.formatLang( cost_cycle) + ' ' + (company_currency_symbol) + """</col>""" xml += """<col f='yes'>""" + rml_obj.formatLang( cost_hour) + ' ' + (company_currency_symbol) + """</col>""" xml += """<col f='yes'>""" + rml_obj.formatLang( cost_hour + cost_cycle) + ' ' + (company_currency_symbol) + """</col>""" xml += '</row>' return xml, total xml = '' config_start = """ <config> <date>""" + to_xml( rml_obj.formatLang(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), date_time=True)) + """</date> <company>%s</company> <PageSize>210.00mm,297.00mm</PageSize> <PageWidth>595.27</PageWidth> <PageHeight>841.88</PageHeight> <tableSize>55.00mm,58.00mm,29.00mm,29.00mm,29.00mm</tableSize> """ % to_xml(user_pool.browse(cr, uid, uid).company_id.name) config_stop = """ <report-footer>Generated by Odoo</report-footer> </config> """ workcenter_header = """ <lines style='header'> <row> <col>%s</col> <col t='yes'/> <col t='yes'>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> </row> </lines> """ % (_('Work Center name'), _('Cycles Cost'), _('Hourly Cost'), _('Work Cost')) prod_header = """ <row> <col>%s</col> <col>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> </row> """ % (_('Components'), _('Components suppliers'), _('Quantity'), _('Cost Price per Unit of Measure'), _('Supplier Price per Unit of Measure')) purchase_price_digits = rml_obj.get_digits(dp='Product Price') for product in product_pool.browse(cr, uid, ids, context=context): product_uom_name = to_xml(product.uom_id.name) bom_id = bom_pool._bom_find(cr, uid, product_id=product.id, context=context) title = "<title>%s</title>" % (_("Cost Structure")) title += "<title>%s</title>" % (to_xml(product.name)) xml += "<lines style='header'>" + title + prod_header + "</lines>" if not bom_id: total_strd = number * product.standard_price total = number * product_pool.price_get( cr, uid, [product.id], 'standard_price')[product.id] xml += """<lines style='lines'><row> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> </row></lines>""" xml += """<lines style='total'> <row> <col> """ + _('Total Cost of %s %s') % ( str(number), product_uom_name) + """: </col> <col/> <col f='yes'/> <col t='yes'>""" + rml_obj.formatLang( total_strd, digits=purchase_price_digits) + ' ' + ( company_currency_symbol) + """</col> <col t='yes'>""" + rml_obj.formatLang( total, digits=purchase_price_digits) + ' ' + ( company_currency_symbol) + """</col> </row></lines>'""" else: bom = bom_pool.browse(cr, uid, bom_id, context=context) factor = number * product.uom_id.factor / bom.product_uom.factor sub_boms = bom_pool._bom_explode(cr, uid, bom, product, factor / bom.product_qty, context=context) total = 0 total_strd = 0 parent_bom = { 'product_qty': bom.product_qty, 'name': bom.product_id.name, 'product_uom': bom.product_uom.id, 'product_id': bom.product_id.id } xml_tmp = '' for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]: txt, sum, sum_strd = process_bom(sub_bom, company_currency.id) xml_tmp += txt total += sum total_strd += sum_strd xml += "<lines style='lines'>" + xml_tmp + '</lines>' xml += """<lines style='sub_total'> <row> <col> """ + _('Components Cost of %s %s') % ( str(number), product_uom_name) + """: </col> <col/> <col t='yes'/> <col t='yes'>""" + rml_obj.formatLang( total_strd, digits=purchase_price_digits) + ' ' + ( company_currency_symbol) + """</col> <col t='yes'></col> </row></lines>'""" total2 = 0 xml_tmp = '' for wrk in (sub_boms and sub_boms[1]): txt, sum = process_workcenter(wrk) xml_tmp += txt total2 += sum if xml_tmp: xml += workcenter_header xml += "<lines style='lines'>" + xml_tmp + '</lines>' xml += """<lines style='sub_total'> <row> <col> """ + _('Work Cost of %s %s') % ( str(number), product_uom_name) + """: </col> <col/> <col/> <col/> <col t='yes'>""" + rml_obj.formatLang( total2, digits=purchase_price_digits) + ' ' + ( company_currency_symbol) + """</col> </row></lines>'""" xml += """<lines style='total'> <row> <col> """ + _('Total Cost of %s %s') % ( str(number), product_uom_name) + """: </col> <col/> <col t='yes'/> <col t='yes'>""" + rml_obj.formatLang( total_strd + total2, digits=purchase_price_digits) + ' ' + ( company_currency_symbol) + """</col> <col t='yes'></col> </row></lines>'""" xml = '<?xml version="1.0" ?><report>' + config_start + config_stop + xml + '</report>' return xml
def create_xml(self, cr, uid, ids, data, context): # Get the user id from the selected employee record emp_id = data['form']['employee_id'] emp_obj = pooler.get_pool(cr.dbname).get('hr.employee') user_id = emp_obj.browse(cr, uid, emp_id).user_id.id empl_name = emp_obj.browse(cr, uid, emp_id).name # Computing the dates (start of month: som, and end of month: eom) som = datetime.date(data['form']['year'], data['form']['month'], 1) eom = som + datetime.timedelta(lengthmonth(som.year, som.month)) date_xml = ['<date month="%s" year="%d" />' % (self.get_month_name(cr, uid, som.month, context=context), som.year), '<days>'] date_xml += ['<day number="%d" name="%s" weekday="%d" />' % (x, self.get_weekday_name(cr, uid, som.replace(day=x).weekday()+1, context=context), som.replace(day=x).weekday()+1) for x in range(1, lengthmonth(som.year, som.month)+1)] date_xml.append('</days>') date_xml.append('<cols>2.5cm%s,2cm</cols>\n' % (',0.7cm' * lengthmonth(som.year, som.month))) # Sum attendence by account, then by day accounts = {} header_xml = '' if user_id: # Computing the attendence by analytical account cr.execute( "select line.date, (unit_amount / unit.factor) as amount, account_id, account.name "\ "from account_analytic_line as line, hr_analytic_timesheet as hr, "\ "account_analytic_account as account, product_uom as unit "\ "where hr.line_id=line.id and line.account_id=account.id "\ "and product_uom_id = unit.id "\ "and line.user_id=%s and line.date >= %s and line.date < %s " "order by line.date", (user_id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d'))) for presence in cr.dictfetchall(): day = int(presence['date'][-2:]) account = accounts.setdefault((presence['account_id'], presence['name']), {}) account[day] = account.get(day, 0.0) + presence['amount'] xml = ''' <time-element date="%s"> <amount>%.2f</amount> </time-element> ''' rpt_obj = pooler.get_pool(cr.dbname).get('hr.employee') rml_obj = report_sxw.rml_parse(cr, uid, rpt_obj._name,context) if user_id: header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(pooler.get_pool(cr.dbname).get('res.users').browse(cr,uid,user_id).company_id.name)) account_xml = [] for account, telems in accounts.iteritems(): aid, aname = account aname = pooler.get_pool(cr.dbname).get('account.analytic.account').name_get(cr, uid, [aid], context) aname = aname[0][1] account_xml.append('<account id="%d" name="%s">' % (aid, toxml(aname))) account_xml.append('\n'.join([xml % (day, amount) for day, amount in telems.iteritems()])) account_xml.append('</account>') # Computing the xml xml = '''<?xml version="1.0" encoding="UTF-8" ?> <report> %s <employee>%s</employee> %s </report> ''' % (header_xml, ustr(toxml(empl_name)), '\n'.join(date_xml) + '\n'.join(account_xml)) return xml
def create_xml(self, cr, uid, ids, datas, context=None): number = (datas.get("form", False) and datas["form"]["number"]) or 1 registry = openerp.registry(cr.dbname) product_pool = registry.get("product.product") product_uom_pool = registry.get("product.uom") workcenter_pool = registry.get("mrp.workcenter") user_pool = registry.get("res.users") bom_pool = registry.get("mrp.bom") pricelist_pool = registry.get("product.pricelist") rml_obj = report_sxw.rml_parse(cr, uid, product_pool._name, context) rml_obj.localcontext.update({"lang": context.get("lang", False)}) company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id company_currency_symbol = company_currency.symbol or company_currency.name def process_bom(bom, currency_id, factor=1): xml = "<row>" sum = 0 sum_strd = 0 prod = product_pool.browse(cr, uid, bom["product_id"]) prod_name = to_xml(bom["name"]) prod_qtty = factor * bom["product_qty"] product_uom = product_uom_pool.browse(cr, uid, bom["product_uom"], context=context) product_uom_name = to_xml(product_uom.name) main_sp_price, main_sp_name, main_strd_price = "", "", "" sellers, sellers_price = "", "" if prod.seller_id: main_sp_name = "- <b>" + to_xml(prod.seller_id.name) + "</b>\r\n" pricelist = prod.seller_id.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, prod.seller_id.id, {"uom": prod.uom_po_id.id, "date": time.strftime("%Y-%m-%d")}, )[pricelist.id] main_sp_price = """<b>""" + rml_obj.formatLang(price) + " " + (company_currency_symbol) + """</b>\r\n""" sum += prod_qtty * price std_price = product_uom_pool._compute_price( cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id ) main_strd_price = str(std_price) + "\r\n" sum_strd = prod_qtty * std_price for seller_id in prod.seller_ids: if seller_id.name.id == prod.seller_id.id: continue sellers += "- <i>" + to_xml(seller_id.name.name) + "</i>\r\n" pricelist = seller_id.name.property_product_pricelist_purchase price = pricelist_pool.price_get( cr, uid, [pricelist.id], prod.id, number * prod_qtty or 1.0, seller_id.name.id, {"uom": prod.uom_po_id.id, "date": time.strftime("%Y-%m-%d")}, )[pricelist.id] sellers_price += ( """<i>""" + rml_obj.formatLang(price) + " " + (company_currency_symbol) + """</i>\r\n""" ) xml += ( """<col para='yes'> """ + prod_name + """ </col> <col para='yes'> """ + main_sp_name + sellers + """ </col> <col f='yes'>""" + rml_obj.formatLang(prod_qtty) + " " + product_uom_name + """</col> <col f='yes'>""" + rml_obj.formatLang(float(main_strd_price)) + " " + (company_currency_symbol) + """</col> <col f='yes'>""" + main_sp_price + sellers_price + """</col>'""" ) xml += "</row>" return xml, sum, sum_strd def process_workcenter(wrk): workcenter = workcenter_pool.browse(cr, uid, wrk["workcenter_id"]) cost_cycle = wrk["cycle"] * workcenter.costs_cycle cost_hour = wrk["hour"] * workcenter.costs_hour total = cost_cycle + cost_hour xml = "<row>" xml += "<col para='yes'>" + to_xml(workcenter.name) + "</col>" xml += "<col/>" xml += """<col f='yes'>""" + rml_obj.formatLang(cost_cycle) + " " + (company_currency_symbol) + """</col>""" xml += """<col f='yes'>""" + rml_obj.formatLang(cost_hour) + " " + (company_currency_symbol) + """</col>""" xml += ( """<col f='yes'>""" + rml_obj.formatLang(cost_hour + cost_cycle) + " " + (company_currency_symbol) + """</col>""" ) xml += "</row>" return xml, total xml = "" config_start = ( """ <config> <date>""" + to_xml(rml_obj.formatLang(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), date_time=True)) + """</date> <company>%s</company> <PageSize>210.00mm,297.00mm</PageSize> <PageWidth>595.27</PageWidth> <PageHeight>841.88</PageHeight> <tableSize>55.00mm,58.00mm,29.00mm,29.00mm,29.00mm</tableSize> """ % to_xml(user_pool.browse(cr, uid, uid).company_id.name) ) config_stop = """ <report-footer>Generated by Odoo</report-footer> </config> """ workcenter_header = """ <lines style='header'> <row> <col>%s</col> <col t='yes'/> <col t='yes'>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> </row> </lines> """ % ( _("Work Center name"), _("Cycles Cost"), _("Hourly Cost"), _("Work Cost"), ) prod_header = """ <row> <col>%s</col> <col>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> </row> """ % ( _("Components"), _("Components suppliers"), _("Quantity"), _("Cost Price per Unit of Measure"), _("Supplier Price per Unit of Measure"), ) purchase_price_digits = rml_obj.get_digits(dp="Product Price") for product in product_pool.browse(cr, uid, ids, context=context): product_uom_name = to_xml(product.uom_id.name) bom_id = bom_pool._bom_find(cr, uid, product_id=product.id, context=context) title = "<title>%s</title>" % (_("Cost Structure")) title += "<title>%s</title>" % (to_xml(product.name)) xml += "<lines style='header'>" + title + prod_header + "</lines>" if not bom_id: total_strd = number * product.standard_price total = number * product_pool.price_get(cr, uid, [product.id], "standard_price")[product.id] xml += """<lines style='lines'><row> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> </row></lines>""" xml += ( """<lines style='total'> <row> <col> """ + _("Total Cost of %s %s") % (str(number), product_uom_name) + """: </col> <col/> <col f='yes'/> <col t='yes'>""" + rml_obj.formatLang(total_strd, digits=purchase_price_digits) + " " + (company_currency_symbol) + """</col> <col t='yes'>""" + rml_obj.formatLang(total, digits=purchase_price_digits) + " " + (company_currency_symbol) + """</col> </row></lines>'""" ) else: bom = bom_pool.browse(cr, uid, bom_id, context=context) factor = number * product.uom_id.factor / bom.product_uom.factor sub_boms = bom_pool._bom_explode(cr, uid, bom, product, factor / bom.product_qty, context=context) total = 0 total_strd = 0 parent_bom = { "product_qty": bom.product_qty, "name": bom.product_id.name, "product_uom": bom.product_uom.id, "product_id": bom.product_id.id, } xml_tmp = "" for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]: txt, sum, sum_strd = process_bom(sub_bom, company_currency.id) xml_tmp += txt total += sum total_strd += sum_strd xml += "<lines style='lines'>" + xml_tmp + "</lines>" xml += ( """<lines style='sub_total'> <row> <col> """ + _("Components Cost of %s %s") % (str(number), product_uom_name) + """: </col> <col/> <col t='yes'/> <col t='yes'>""" + rml_obj.formatLang(total_strd, digits=purchase_price_digits) + " " + (company_currency_symbol) + """</col> <col t='yes'></col> </row></lines>'""" ) total2 = 0 xml_tmp = "" for wrk in sub_boms and sub_boms[1]: txt, sum = process_workcenter(wrk) xml_tmp += txt total2 += sum if xml_tmp: xml += workcenter_header xml += "<lines style='lines'>" + xml_tmp + "</lines>" xml += ( """<lines style='sub_total'> <row> <col> """ + _("Work Cost of %s %s") % (str(number), product_uom_name) + """: </col> <col/> <col/> <col/> <col t='yes'>""" + rml_obj.formatLang(total2, digits=purchase_price_digits) + " " + (company_currency_symbol) + """</col> </row></lines>'""" ) xml += ( """<lines style='total'> <row> <col> """ + _("Total Cost of %s %s") % (str(number), product_uom_name) + """: </col> <col/> <col t='yes'/> <col t='yes'>""" + rml_obj.formatLang(total_strd + total2, digits=purchase_price_digits) + " " + (company_currency_symbol) + """</col> <col t='yes'></col> </row></lines>'""" ) xml = '<?xml version="1.0" ?><report>' + config_start + config_stop + xml + "</report>" return xml
def create_xml(self, cr, uid, ids, datas, context=None): number = (datas.get('form', False) and datas['form']['number']) or 1 registry = openerp.registry(cr.dbname) product_pool = registry.get('product.product') product_uom_pool = registry.get('product.uom') workcenter_pool = registry.get('mrp.workcenter') user_pool = registry.get('res.users') bom_pool = registry.get('mrp.bom') pricelist_pool = registry.get('product.pricelist') rml_obj=report_sxw.rml_parse(cr, uid, product_pool._name,context) rml_obj.localcontext.update({'lang':context.get('lang',False)}) company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id company_currency_symbol = company_currency.symbol or company_currency.name def process_bom(bom, currency_id, factor=1): xml = '<row>' sum = 0 sum_strd = 0 prod = product_pool.browse(cr, uid, bom['product_id']) prod_name = to_xml(bom['name']) prod_qtty = factor * bom['product_qty'] product_uom = product_uom_pool.browse(cr, uid, bom['product_uom'], context=context) product_uom_name = to_xml(product_uom.name) main_sp_price, main_sp_name , main_strd_price = '','','' sellers, sellers_price = '','' if prod.seller_id: main_sp_name = '- <b>'+ to_xml(prod.seller_id.name) +'</b>\r\n' pricelist = prod.seller_id.property_product_pricelist_purchase price = pricelist_pool.price_get(cr,uid,[pricelist.id], prod.id, number*prod_qtty or 1.0, prod.seller_id.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] main_sp_price = """<b>"""+rml_obj.formatLang(price)+' '+ (company_currency_symbol)+"""</b>\r\n""" sum += prod_qtty*price std_price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id) main_strd_price = str(std_price) + '\r\n' sum_strd = prod_qtty*std_price for seller_id in prod.seller_ids: if seller_id.name.id == prod.seller_id.id: continue sellers += '- <i>'+ to_xml(seller_id.name.name) +'</i>\r\n' pricelist = seller_id.name.property_product_pricelist_purchase price = pricelist_pool.price_get(cr,uid,[pricelist.id], prod.id, number*prod_qtty or 1.0, seller_id.name.id, { 'uom': prod.uom_po_id.id, 'date': time.strftime('%Y-%m-%d'), })[pricelist.id] sellers_price += """<i>"""+rml_obj.formatLang(price) +' '+ (company_currency_symbol) +"""</i>\r\n""" xml += """<col para='yes'> """+ prod_name +""" </col> <col para='yes'> """+ main_sp_name + sellers + """ </col> <col f='yes'>"""+ rml_obj.formatLang(prod_qtty) +' '+ product_uom_name +"""</col> <col f='yes'>"""+ rml_obj.formatLang(float(main_strd_price)) +' '+ (company_currency_symbol) +"""</col> <col f='yes'>""" + main_sp_price + sellers_price + """</col>'""" xml += '</row>' return xml, sum, sum_strd def process_workcenter(wrk): workcenter = workcenter_pool.browse(cr, uid, wrk['workcenter_id']) cost_cycle = wrk['cycle']*workcenter.costs_cycle cost_hour = wrk['hour']*workcenter.costs_hour total = cost_cycle + cost_hour xml = '<row>' xml += "<col para='yes'>" + to_xml(workcenter.name) + '</col>' xml += "<col/>" xml += """<col f='yes'>"""+rml_obj.formatLang(cost_cycle)+' '+ (company_currency_symbol) + """</col>""" xml += """<col f='yes'>"""+rml_obj.formatLang(cost_hour)+' '+ (company_currency_symbol) + """</col>""" xml += """<col f='yes'>"""+rml_obj.formatLang(cost_hour + cost_cycle)+' '+ (company_currency_symbol) + """</col>""" xml += '</row>' return xml, total xml = '' config_start = """ <config> <date>""" + to_xml(rml_obj.formatLang(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),date_time=True)) + """</date> <company>%s</company> <PageSize>210.00mm,297.00mm</PageSize> <PageWidth>595.27</PageWidth> <PageHeight>841.88</PageHeight> <tableSize>55.00mm,58.00mm,29.00mm,29.00mm,29.00mm</tableSize> """ % to_xml(user_pool.browse(cr, uid, uid).company_id.name) config_stop = """ <report-footer>Generated by Odoo</report-footer> </config> """ workcenter_header = """ <lines style='header'> <row> <col>%s</col> <col t='yes'/> <col t='yes'>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> </row> </lines> """ % (_('Work Center name'), _('Cycles Cost'), _('Hourly Cost'),_('Work Cost')) prod_header = """ <row> <col>%s</col> <col>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> <col t='yes'>%s</col> </row> """ % (_('Components'), _('Components suppliers'), _('Quantity'),_('Cost Price per Unit of Measure'), _('Supplier Price per Unit of Measure')) purchase_price_digits = rml_obj.get_digits(dp='Product Price') for product in product_pool.browse(cr, uid, ids, context=context): product_uom_name = to_xml(product.uom_id.name) bom_id = bom_pool._bom_find(cr, uid, product_id=product.id, context=context) title = "<title>%s</title>" %(_("Cost Structure")) title += "<title>%s</title>" % (to_xml(product.name)) xml += "<lines style='header'>" + title + prod_header + "</lines>" if not bom_id: total_strd = number * product.standard_price total = number * product_pool.price_get(cr, uid, [product.id], 'standard_price')[product.id] xml += """<lines style='lines'><row> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> <col para='yes'>-</col> </row></lines>""" xml += """<lines style='total'> <row> <col> """ + _('Total Cost of %s %s') % (str(number), product_uom_name) + """: </col> <col/> <col f='yes'/> <col t='yes'>"""+ rml_obj.formatLang(total_strd, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col> <col t='yes'>"""+ rml_obj.formatLang(total, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col> </row></lines>'""" else: bom = bom_pool.browse(cr, uid, bom_id, context=context) factor = number * product.uom_id.factor / bom.product_uom.factor sub_boms = bom_pool._bom_explode(cr, uid, bom, product, factor / bom.product_qty, context=context) total = 0 total_strd = 0 parent_bom = { 'product_qty': bom.product_qty, 'name': bom.product_id.name, 'product_uom': bom.product_uom.id, 'product_id': bom.product_id.id } xml_tmp = '' for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]: txt, sum, sum_strd = process_bom(sub_bom, company_currency.id) xml_tmp += txt total += sum total_strd += sum_strd xml += "<lines style='lines'>" + xml_tmp + '</lines>' xml += """<lines style='sub_total'> <row> <col> """ + _('Components Cost of %s %s') % (str(number), product_uom_name) + """: </col> <col/> <col t='yes'/> <col t='yes'>"""+ rml_obj.formatLang(total_strd, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col> <col t='yes'></col> </row></lines>'""" total2 = 0 xml_tmp = '' for wrk in (sub_boms and sub_boms[1]): txt, sum = process_workcenter(wrk) xml_tmp += txt total2 += sum if xml_tmp: xml += workcenter_header xml += "<lines style='lines'>" + xml_tmp + '</lines>' xml += """<lines style='sub_total'> <row> <col> """ + _('Work Cost of %s %s') % (str(number), product_uom_name) +""": </col> <col/> <col/> <col/> <col t='yes'>"""+ rml_obj.formatLang(total2, digits=purchase_price_digits) +' '+ (company_currency_symbol) +"""</col> </row></lines>'""" xml += """<lines style='total'> <row> <col> """ + _('Total Cost of %s %s') % (str(number), product_uom_name) + """: </col> <col/> <col t='yes'/> <col t='yes'>"""+ rml_obj.formatLang(total_strd+total2, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col> <col t='yes'></col> </row></lines>'""" xml = '<?xml version="1.0" ?><report>' + config_start + config_stop + xml + '</report>' return xml
def create_xml(self, cr, uid, ids, datas, context=None): obj_emp = pooler.get_pool(cr.dbname).get('hr.employee') if context is None: context = {} month = datetime(datas['form']['year'], datas['form']['month'], 1) emp_ids = datas['active_ids'] user_xml = ['<month>%s</month>' % _(month2name[month.month]), '<year>%s</year>' % month.year] if emp_ids: for emp in obj_emp.read(cr, uid, emp_ids, ['name']): stop, days_xml = False, [] total_wh = 0.0 user_repr = ''' <user> <name>%s</name> %%s </user> ''' % (ustr(toxml(emp['name']))) today, tomor = month, month + one_day while today.month == month.month: #### Work hour calculation sql = ''' select action, att.name from hr_employee as emp inner join hr_attendance as att on emp.id = att.employee_id where att.name between %s and %s and emp.id = %s order by att.name ''' cr.execute(sql, (today.strftime('%Y-%m-%d %H:%M:%S'), tomor.strftime('%Y-%m-%d %H:%M:%S'), emp['id'])) attendences = cr.dictfetchall() wh = 0.0 # Fake sign ins/outs at week ends, to take attendances across week ends into account if attendences and attendences[0]['action'] == 'sign_out': attendences.insert(0, {'name': today.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_in'}) if attendences and attendences[-1]['action'] == 'sign_in': attendences.append({'name': tomor.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_out'}) # sum up the attendances' durations ldt = None for att in attendences: dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') if ldt and att['action'] == 'sign_out': if dt.date() > ldt.date(): dt = ldt wh += (float((dt - ldt).seconds)/60/60) else: ldt = dt # Week xml representation total_wh += wh wh = hour2str(wh) today_xml = '<day num="%s"><wh>%s</wh></day>' % ((today - month).days+1, (wh)) dy=(today - month).days+1 days_xml.append(today_xml) today, tomor = tomor, tomor + one_day total_wh = hour2str(total_wh) today_xml = '<day num="Total"><wh>%s</wh></day>' % (total_wh) days_xml.append(today_xml) user_xml.append(user_repr % '\n'.join(days_xml)) rpt_obj = pooler.get_pool(cr.dbname).get('hr.employee') rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(pooler.get_pool(cr.dbname).get('res.users').browse(cr,uid,uid).company_id.name)) first_date = str(month) som = datetime.strptime(first_date, '%Y-%m-%d %H:%M:%S') eom = som + timedelta(int(dy)-1) day_diff=eom-som date_xml=[] cell=1 date_xml.append('<days>') if day_diff.days>=30: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] else: if day_diff.days>=(lengthmonth(som.year, som.month)-som.day): date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] else: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, eom.day+1)] cell=x-som.day+1 day_diff1=day_diff.days-cell+1 width_dict={} month_dict={} i=1 j=1 year=som.year month=som.month month_dict[j]=som.strftime('%B') width_dict[j]=cell while day_diff1>0: if month+i<=12: if day_diff1 > lengthmonth(year,i+month): # Not on 30 else you have problems when entering 01-01-2009 for example som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(year,i+month)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x day_diff1=day_diff1-x else: years=year+1 year=years month=0 i=1 if day_diff1>=30: som1=datetime.date(years,i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(years,i)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(years,i,1) i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] cell=cell+x width_dict[j]=x day_diff1=day_diff1-x date_xml += ['<dayy name="Total" cell="Total"/>'] date_xml.append('</days>') date_xml.append('<cols>3.5cm%s,1.2cm</cols>\n' % (',0.74cm' * (int(dy)))) xml = '''<?xml version="1.0" encoding="UTF-8" ?> <report> %s <title>%s</title> %s %s </report> ''' % (header_xml,_('Attendances by Month'),'\n'.join(user_xml),date_xml) return xml
def create_xml(self, cr, uid, ids, data, context): registry = openerp.registry(cr.dbname) obj_emp = registry['hr.employee'] depts=[] emp_id={} rpt_obj = registry['hr_attendance.record.report'] rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) cr.execute("SELECT name FROM res_company") res=cr.fetchone()[0] date_xml=[] date_today=time.strftime('%Y-%m-%d %H:%M:%S') date_xml +=['<res name="%s" today="%s" />' % (to_xml(res),date_today)] legend = {'Present':'green','Weekends':'lightgrey','Absent':'red','Leave':'violet','Public Holiday':'blue'} today=datetime.datetime.today() today_year = today.strftime('%Y-%m-%d %H:%M:%S')[0:4] #### Check for Filter in Wizard to get Start and end date ##### if data['form']['filter_by_date'] == True: first_date = datetime.datetime.strptime(data['form']['date_from'],'%Y-%m-%d') + datetime.timedelta() last_date = datetime.datetime.strptime(data['form']['date_to'],'%Y-%m-%d') + datetime.timedelta() else : month_selected = data['form']['monthly_status'] first_date = datetime.datetime(int(today_year),int(month_selected),1) number_of_days = lengthmonth( int(today_year), int(month_selected)) last_date = datetime.datetime(int(today_year),int(month_selected),number_of_days) day_diff=last_date-first_date name = '' if len(data['form'].get('emp_id', ())) == 1: name = obj_emp.read(cr, uid, data['form']['emp_id'][0], ['name'])['name'] date_xml.append('<from>%s</from>\n'% (str(rml_obj.formatLang(first_date.strftime("%Y-%m-%d"),date=True)))) date_xml.append('<to>%s</to>\n' %(str(rml_obj.formatLang(last_date.strftime("%Y-%m-%d"),date=True)))) date_xml.append('<name>%s</name>'%(name)) # date_xml=[] for l in range(0,len(legend)): date_xml += ['<legend row="%d" id="%d" name="%s" color="%s" />' % (l+1, l+1, legend.keys()[l], legend.values()[l] )] date_xml += ['<date month="%s" year="%d" />' % (ustr(first_date.strftime('%B')),first_date.year),'<days>'] cell=1 if day_diff.days>=31: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x-first_date.day+1) for x in range(first_date.day, day_diff.days +1)] else: #date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x-first_date.day+1) for x in range(first_date.day, last_date.day+1)] if day_diff.days>=(lengthmonth(first_date.year, first_date.month)-first_date.day): date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')),x-first_date.day+1) for x in range(first_date.day, lengthmonth(first_date.year, first_date.month)+1)] else: date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(first_date.replace(day=x).strftime('%a')), x-first_date.day+1) for x in range(first_date.day, last_date.day+1)] cell=x-first_date.day+1 day_diff1=day_diff.days-cell+1 width_dict={} month_dict={} i=1 j=1 year=first_date.year month=first_date.month month_dict[j]=first_date.strftime('%B') width_dict[j]=cell while day_diff1>0: if month + i <=12: # If month + i <=12 if day_diff1 > lengthmonth(year,i+month): # Not on 30 else you have problems when entering 01-01-2009 for example som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(year,i+month)+1)] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x else: som1=datetime.date(year,month+i,1) date_xml += ['<dayy number="%d" name="%s" cell="%d"/>' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, last_date.day +1 )] i=i+1 j=j+1 month_dict[j]=som1.strftime('%B') cell=cell+x width_dict[j]=x day_diff1=day_diff1-x date_xml.append('</days>') date_xml.append('<cols>3.5cm%s,1.0cm</cols>\n' % (',0.7cm' * (day_diff.days+1))) date_xml = ''.join(date_xml) st='<cols_months>3.5cm' for m in range(1,len(width_dict)+1): st+=',' + str(0.7 *width_dict[m])+'cm' st+=',1.0cm</cols_months>\n' months_xml =['<months number="%d" name="%s"/>' % (x, _(month_dict[x])) for x in range(1,len(month_dict)+1) ] months_xml.append(st) emp_xml='' row_id=1 if data['model'] == 'hr.employee': for items in obj_emp.read(cr, uid, data['form']['emp_id'], ['id', 'name']): emp_xml += emp_create_xml(self, cr, uid, 0, row_id, items['id'], items['name'], first_date, last_date) row_id = row_id +1 header_xml = ''' <header> <date>%s</date> <company>%s</company> </header> ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(registry['res.users'].browse(cr,uid,uid).company_id.name)) # Computing the xml xml='''<?xml version="1.0" encoding="UTF-8" ?> <report> %s %s %s %s </report> ''' % (header_xml,months_xml,date_xml, ustr(emp_xml)) return xml