Пример #1
0
 def _get_xls(self):
     html = self.env['report'].get_html(self,
                                        'purchase_rfq_xls.report_template',
                                        data={
                                            'ids': self.ids,
                                            'form': {}
                                        })
     # convert html to xls
     xls = get_xls(html)
     # create attachment
     return self.env['ir.attachment'].create({
         'name':
         'RFQ_' + str(self.name) + '.xls',
         'datas':
         base64.b64encode(xls),
         'datas_fname':
         'RFQ_' + str(self.name) + '.xls',
         'type':
         'binary',
         'res_model':
         'purchase.order',
         'res_id':
         self.ids[0],
         'user_id':
         self._uid,
     })
Пример #2
0
 def _create_report(self, wiz_id, context=None):
     if context is None:
         context = {}
     context.update({
         'xls_report': True,
         'active_model': 'res.partner',
         'active_ids': [self.partner_id.id],
         'active_id': self.partner_id.id,
     })
     data = wiz_id.with_context(context).print_report()
     context.update({
         'active_model': 'account.aging.wizard',
         'active_ids': [wiz_id.id],
         'active_id': wiz_id.id,
     })
     result = openerp.report.render_report(self.cr,
                                           self.uid, [wiz_id.id],
                                           context.get('report_name', ''),
                                           data.get('data', {}),
                                           context=context)[0]
     report = get_xls(result)
     attach = self.attachment_obj.create({
         'name':
         'xls_aging_supplier',
         'datas_fname':
         'xls_aging_supplier.xls',
         'datas':
         base64.encodestring(report),
         'res_model':
         'account.aging.wizard',
         'res_id':
         wiz_id.id
     })
     self._check_file_xls(attach, context=context)
 def _generate_report_product(self):
     wiz_id = self.product_price_obj.create({
         'price_list': self.price_list_id,
         'qty1': 1,
         'qty2': 5,
         'qty3': 10,
         'qty4': 0,
         'qty5': 0,
         'report_format': 'xls',
     })
     context = {
         'xls_report': True,
         'active_model': 'product.product',
         'active_ids': [self.product.id],
         'active_id': self.product.id,
     }
     data = wiz_id.with_context(context).print_report()
     result = openerp.report.render_report(
         self.cr, self.uid, [wiz_id.id],
         'product.report_pricelist', data.get('data', {}),
         context=context)[0]
     report = get_xls(result)
     attach = self.attachment_obj.create({
         'name': 'xls_product_price_list',
         'datas_fname': 'xls_product_price_list.xls',
         'datas': base64.encodestring(report),
         'res_model': 'product.price_list',
         'res_id': wiz_id.id})
     self._check_file_xls(attach)
Пример #4
0
 def test_get_xls_en_us(self):
     xls_stream = get_xls(self.html_snippet % self.value_en_us)
     fileno, fname = tempfile.mkstemp('.xls', 'controller.xls')
     with open(fname, "wb") as fobj:
         fobj.write(xls_stream)
     os.close(fileno)
     book = xlrd.open_workbook(fname)
     sh = book.sheet_by_index(0)
     self.assertEquals(sh.cell(0, 0).value, 'Vauxoo', 'Should be Vauxoo')
     self.assertEquals(sh.cell(3, 2).value, self.result, 'Wrong Value')
Пример #5
0
    def test_basic_report(self):
        wzd_brw = self.create_ifrs_wizard()
        datas = wzd_brw.print_report()
        data = datas['data']
        res = self.ifrs_brw.get_report_data(
            data['wizard_id'],
            fiscalyear=data['fiscalyear'],
            exchange_date=data['exchange_date'],
            currency_wizard=data['currency_wizard'],
            target_move=data['target_move'],
            two=True,
        )

        # NOTE: Require `active_model` in order to work with UnitTest
        datas['context'].update({
            'active_model': 'ifrs.ifrs',
        })
        result = openerp.report.render_report(self.cr,
                                              self.uid, [wzd_brw.id],
                                              datas['report_name'],
                                              datas['data'],
                                              context=datas['context'])
        get_xls(result[0])

        for val in res:
            seq = val['sequence']
            if seq == 90:
                # TODO: code for number of customer is quite weak until further
                # development is done test for them will be skipped
                continue
            self.assertEquals(
                round(val['amount'], 2), RESULT[seq],
                'There is something wrong. Sequence %(seq)s!!!' %
                dict(seq=seq))
            self.assertEquals(
                val['name'], LABEL[seq],
                'There is something wrong. Sequence %(seq)s!!!' %
                dict(seq=seq))

        return True
Пример #6
0
 def _generate_report_product(self):
     wiz_id = self.product_price_obj.create({
         'price_list':
         self.price_list_id,
         'qty1':
         1,
         'qty2':
         5,
         'qty3':
         10,
         'qty4':
         0,
         'qty5':
         0,
         'report_format':
         'xls',
         'products_with_price':
         self.products_with_price,
     })
     context = {
         'xls_report': True,
         'active_model': 'product.product',
         'active_ids': [self.product.id],
         'active_id': self.product.id,
     }
     data = wiz_id.with_context(context).print_report()
     result = openerp.report.render_report(self.cr,
                                           self.uid, [wiz_id.id],
                                           'product.report_pricelist',
                                           data.get('data', {}),
                                           context=context)[0]
     report = get_xls(result)
     attach = self.attachment_obj.create({
         'name':
         'xls_product_price_list',
         'datas_fname':
         'xls_product_price_list.xls',
         'datas':
         base64.encodestring(report),
         'res_model':
         'product.price_list',
         'res_id':
         wiz_id.id
     })
     self._check_file_xls(attach)
Пример #7
0
    def _generate_afr(self, account_id):
        wiz_id = self.wiz_rep_obj.create({
            'company_id': self.company_id,
            'inf_type': 'BS',
            'columns': 'four',
            'currency_id': self.currency_id,
            'report_format': 'xls',
            'display_account': 'bal_mov',
            'fiscalyear_id': self.fiscalyear_id,
            'display_account_level': 0,
            'target_move': 'posted',
            'account_list': [(4, account_id, 0)]
        })

        context = {
            'xls_report': True,
            'active_model': 'wizard.report',
            'active_ids': [wiz_id.id],
            'active_id': wiz_id.id,
        }
        data = wiz_id.with_context(context).print_report()
        result = openerp.report.render_report(self.cr,
                                              self.uid, [wiz_id.id],
                                              'afr.1cols',
                                              data.get('data', {}),
                                              context=context)[0]
        report = get_xls(result)
        attach = self.attachment_obj.create({
            'name':
            'xls_afr',
            'datas_fname':
            'xls_afr.xls',
            'datas':
            base64.encodestring(report),
            'res_model':
            'wizard.report',
            'res_id':
            wiz_id.id
        })
        self._check_file_xls(attach)