예제 #1
0
    def _draw_description_line(self, canvas, print_settings, initial_position,
                               font):
        """ Draw a line above the payment slip

        The line shows the invoice number and payment term.

        :param canvas: payment slip reportlab component to be drawn
        :type canvas: :py:class:`reportlab.pdfgen.canvas.Canvas`

        :param print_settings: layouts print setting
        :type print_settings: :py:class:`PaymentSlipSettings` or subclass

        :para initial_position: tuple of coordinate (x, y)
        :type initial_position: tuple

        :param font: font to use
        :type font: :py:class:`FontMeta`

        """
        x, y = initial_position
        # align with the address
        x += print_settings.bvr_add_horz * inch
        invoice = self.move_line_id.invoice_id
        date_maturity = self.move_line_id.date_maturity
        message = _('Payment slip related to invoice %s '
                    'due on the %s')
        rml_parser = report_sxw.rml_parse(self.env.cr,
                                          self.env.uid,
                                          'payment_slip',
                                          context=self.env.context)
        fmt_date = rml_parser.formatLang(date_maturity, date=True)
        canvas.setFont(font.name, font.size)
        canvas.drawString(x, y,
                          message % (invoice.number, fmt_date))
예제 #2
0
def formatLang(env, value, digits=None, grouping=True, monetary=False,
               dp=False, currency_obj=False):
    rml_parser = report_sxw.rml_parse(
        env.cr, env.uid, 'format_lang_wrapper', context=env.context)
    return rml_parser.formatLang(
        value, digits=digits, grouping=grouping, monetary=monetary, dp=dp,
        currency_obj=currency_obj)
 def _get_parser_context(self, model_instance, data):
     report_xml = self.ir_actions_report_xml_id
     context_instance = rml_parse(self.env.cr,
                                  self.env.uid,
                                  report_xml.name,
                                  context=self.env.context)
     context_instance.set_context(model_instance, data, model_instance.ids,
                                  report_xml.report_type)
     self._extend_parser_context(context_instance, report_xml)
     return context_instance.localcontext
예제 #4
0
 def render_html(self, docids, data=None):
     data = data if data is not None else {}
     report_obj = self.env['report']
     report = report_obj._get_report_from_name(
         'cicon_prod.cicon_steel_order_in_hand_template')
     rml = report_sxw.rml_parse(self._cr, self._uid,
                                'cicon_steel_order_in_hand_template')
     docargs = {
         'doc_ids': data.get('ids'),
         'doc_model': report.model,
         'docs': self.get_docs(data.get('ids')),
         'formatLang': rml.formatLang,
         'digit': self._context.get('digits', 0),
         'heading': self._context.get('report_heading', ''),
     }
     return report_obj.render(
         'cicon_prod.cicon_steel_order_in_hand_template', docargs)
예제 #5
0
 def render_html(self, docids, data=None):
     data = data if data is not None else {}
     report_obj = self.env['report']
     report = report_obj._get_report_from_name(
         'cicon_hr.employee_leave_report_weekly')
     _docs = self._get_emp_leave(data.get('ids', data.get('active_ids')))
     rml = report_sxw.rml_parse(self._cr, self._uid,
                                'employee_leave_report_weekly')
     docargs = {
         'doc_ids': data.get('ids', data.get('active_ids')),
         'doc_model': report.model,
         'docs': _docs,
         'formatLang': rml.formatLang,
         'fromDate': self._context.get('start_date'),
         'toDate': self._context.get('end_date')
     }
     return report_obj.render('cicon_hr.employee_leave_report_weekly',
                              docargs)
예제 #6
0
 def render_html(self, docids, data=None):
     data = data if data is not None else {}
     report_obj = self.env['report']
     report = report_obj._get_report_from_name(
         'cicon_hr.employee_attendance_report_template')
     _docs = dict(employees=self.env['hr.employee'].search([(
         'id', 'in', self._context.get('employee_ids'))]))
     rml = report_sxw.rml_parse(self._cr, self._uid,
                                'employee_attendance_report_template')
     docargs = {
         'doc_ids': self._context.get('employee_ids', False),
         'doc_model': report.model,
         'docs': _docs,
         'formatLang': rml.formatLang,
         'get_employee_attendance': self._get_employee_attendance,
         'fromDate': self._context.get('start_date'),
         'toDate': self._context.get('end_date')
     }
     return report_obj.render(
         'cicon_hr.employee_attendance_report_template', docargs)
예제 #7
0
    def _get_currency_help_label(self, currency_id, payment_rate, payment_rate_currency_id):
        """
        This function builds a string to help the users to understand the behavior of the payment rate fields they can specify on the voucher.
        This string is only used to improve the usability in the voucher form view and has no other effect.

        :param currency_id: the voucher currency
        :type currency_id: integer
        :param payment_rate: the value of the payment_rate field of the voucher
        :type payment_rate: float
        :param payment_rate_currency_id: the value of the payment_rate_currency_id field of the voucher
        :type payment_rate_currency_id: integer
        :return: translated string giving a tip on what's the effect of the current payment rate specified
        :rtype: str
        """
        rml_parser = report_sxw.rml_parse(self._cr, self._uid, 'currency_help_label', self._context)
        currency_pool = self.env['res.currency'].browse(currency_id)
        currency_str = payment_rate_str = ' '
        if currency_id:
            currency_str = rml_parser.formatLang(1, currency_pool)
        if payment_rate_currency_id:
            payment_rate_str = rml_parser.formatLang(payment_rate, currency_obj=currency_pool.browse())
        currency_help_label = ('At the operation date, the exchange rate was\n%s = %s') % (
        currency_str, payment_rate_str)
        return currency_help_label
예제 #8
0
파일: ps_list.py 프로젝트: Choumy/odoo
    def _create_table(self, uid, ids, fields, fields_order, results, context, title=''):
        pageSize=[297.0, 210.0]

        new_doc = etree.Element("report")
        config = etree.SubElement(new_doc, 'config')

        def _append_node(name, text):
            n = etree.SubElement(config, name)
            n.text = text

        #_append_node('date', time.strftime('%d/%m/%Y'))
        _append_node('date', time.strftime(str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))))
        _append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize))
        _append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,))
        _append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,))
        _append_node('report-header', title)

        env = odoo.api.Environment(self.cr, uid, {})
        Users = env['res.users']
        _append_node('company', Users.browse(uid).company_id.name)
        rml_obj = report_sxw.rml_parse(self.cr, uid, Users._name, context)
        _append_node('header-date', str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")))
        l = []
        t = 0
        strmax = (pageSize[0]-40) * 2.8346
        temp = []
        tsum = []
        for i in range(0, len(fields_order)):
            temp.append(0)
            tsum.append(0)
        ince = -1
        for f in fields_order:
            s = 0
            ince += 1
            if fields[f]['type'] in ('date','time','datetime','float','integer'):
                s = 60
                strmax -= s
                if fields[f]['type'] in ('float','integer'):
                    temp[ince] = 1
            else:
                t += fields[f].get('size', 80) / 28 + 1

            l.append(s)
        for pos in range(len(l)):
            if not l[pos]:
                s = fields[fields_order[pos]].get('size', 80) / 28 + 1
                l[pos] = strmax * s / t

        _append_node('tableSize', ','.join(map(str,l)) )

        header = etree.SubElement(new_doc, 'header')
        for f in fields_order:
            field = etree.SubElement(header, 'field')
            field.text = tools.ustr(fields[f]['string'] or '')

        lines = etree.SubElement(new_doc, 'lines')
        for line in results:
            node_line = etree.SubElement(lines, 'row')
            count = -1
            for f in fields_order:
                float_flag = 0
                count += 1
                if fields[f]['type']=='many2one' and line[f]:
                    if not line.get('__group'):
                        line[f] = line[f][1]
                if fields[f]['type']=='selection' and line[f]:
                    for key, value in fields[f]['selection']:
                        if key == line[f]:
                            line[f] = value
                            break
                if fields[f]['type'] in ('one2many','many2many') and line[f]:
                    line[f] = '( '+tools.ustr(len(line[f])) + ' )'
                if fields[f]['type'] == 'float' and line[f]:
                    precision=(('digits' in fields[f]) and fields[f]['digits'][1]) or 2
                    prec ='%.' + str(precision) +'f'
                    line[f]=prec%(line[f])
                    float_flag = 1

                if fields[f]['type'] == 'date' and line[f]:
                    new_d1 = line[f]
                    if not line.get('__group'):
                        format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))
                        d1 = datetime.strptime(line[f],'%Y-%m-%d')
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if fields[f]['type'] == 'time' and line[f]:
                    new_d1 = line[f]
                    if not line.get('__group'):
                        format = str(locale.nl_langinfo(locale.T_FMT))
                        d1 = datetime.strptime(line[f], '%H:%M:%S')
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if fields[f]['type'] == 'datetime' and line[f]:
                    new_d1 = line[f]
                    if not line.get('__group'):
                        format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))+' '+str(locale.nl_langinfo(locale.T_FMT))
                        d1 = datetime.strptime(line[f], '%Y-%m-%d %H:%M:%S')
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1


                if line.get('__group'):
                    col = etree.SubElement(node_line, 'col', para='group', tree='no')
                else:
                    col = etree.SubElement(node_line, 'col', para='yes', tree='no')

                # Prevent empty labels in groups
                if f == line.get('__grouped_by') and line.get('__group') and not line[f] and not float_flag and not temp[count]:
                    col.text = line[f] = 'Undefined'
                    col.set('tree', 'undefined')

                if line[f] is not None:
                    col.text = tools.ustr(line[f] or '')
                    if float_flag:
                        col.set('tree','float')
                    if line.get('__no_leaf') and temp[count] == 1 and f != 'id' and not line['__context']['group_by']:
                        tsum[count] = float(tsum[count]) + float(line[f])
                    if not line.get('__group') and f != 'id' and temp[count] == 1:
                        tsum[count] = float(tsum[count])  + float(line[f])
                else:
                    col.text = '/'

        node_line = etree.SubElement(lines, 'row')
        for f in range(0, len(fields_order)):
            col = etree.SubElement(node_line, 'col', para='group', tree='no')
            col.set('tree', 'float')
            if tsum[f] is not None:
                if tsum[f] != 0.0:
                    digits = fields[fields_order[f]].get('digits', (16, 2))
                    prec = '%%.%sf' % (digits[1], )
                    total = prec % (tsum[f], )
                    txt = str(total or '')
                else:
                    txt = str(tsum[f] or '')
            else:
                txt = '/'
            if f == 0:
                txt ='Total'
                col.set('tree','no')
            col.text = tools.ustr(txt or '')

        transform = etree.XSLT(
            etree.parse(os.path.join(tools.config['root_path'],
                                     'addons/base/report/custom_new.xsl')))
        rml = etree.tostring(transform(new_doc))
        self.obj = render.rml(rml, title=self.title)
        self.obj.render()
        return True
예제 #9
0
파일: ps_list.py 프로젝트: evils1990/newca
    def _create_table(self,
                      uid,
                      ids,
                      fields,
                      fields_order,
                      results,
                      context,
                      title=''):
        pageSize = [297.0, 210.0]

        new_doc = etree.Element("report")
        config = etree.SubElement(new_doc, 'config')

        def _append_node(name, text):
            n = etree.SubElement(config, name)
            n.text = text

        #_append_node('date', time.strftime('%d/%m/%Y'))
        _append_node(
            'date',
            time.strftime(
                str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))))
        _append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize))
        _append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346, ))
        _append_node('PageHeight', '%.2f' % (pageSize[1] * 2.8346, ))
        _append_node('report-header', title)

        env = odoo.api.Environment(self.cr, uid, {})
        Users = env['res.users']
        _append_node('company', Users.browse(uid).company_id.name)
        rml_obj = report_sxw.rml_parse(self.cr, uid, Users._name, context)
        _append_node(
            'header-date',
            str(rml_obj.formatLang(time.strftime("%Y-%m-%d"), date=True)) +
            ' ' + str(time.strftime("%H:%M")))
        l = []
        t = 0
        strmax = (pageSize[0] - 40) * 2.8346
        temp = []
        tsum = []
        for i in range(0, len(fields_order)):
            temp.append(0)
            tsum.append(0)
        ince = -1
        for f in fields_order:
            s = 0
            ince += 1
            if fields[f]['type'] in ('date', 'time', 'datetime', 'float',
                                     'integer'):
                s = 60
                strmax -= s
                if fields[f]['type'] in ('float', 'integer'):
                    temp[ince] = 1
            else:
                t += fields[f].get('size', 80) / 28 + 1

            l.append(s)
        for pos in range(len(l)):
            if not l[pos]:
                s = fields[fields_order[pos]].get('size', 80) / 28 + 1
                l[pos] = strmax * s / t

        _append_node('tableSize', ','.join(map(str, l)))

        header = etree.SubElement(new_doc, 'header')
        for f in fields_order:
            field = etree.SubElement(header, 'field')
            field.text = tools.ustr(fields[f]['string'] or '')

        lines = etree.SubElement(new_doc, 'lines')
        for line in results:
            node_line = etree.SubElement(lines, 'row')
            count = -1
            for f in fields_order:
                float_flag = 0
                count += 1
                if fields[f]['type'] == 'many2one' and line[f]:
                    if not line.get('__group'):
                        line[f] = line[f][1]
                if fields[f]['type'] == 'selection' and line[f]:
                    for key, value in fields[f]['selection']:
                        if key == line[f]:
                            line[f] = value
                            break
                if fields[f]['type'] in ('one2many', 'many2many') and line[f]:
                    line[f] = '( ' + tools.ustr(len(line[f])) + ' )'
                if fields[f]['type'] == 'float' and line[f]:
                    precision = (('digits' in fields[f])
                                 and fields[f]['digits'][1]) or 2
                    prec = '%.' + str(precision) + 'f'
                    line[f] = prec % (line[f])
                    float_flag = 1

                if fields[f]['type'] == 'date' and line[f]:
                    new_d1 = line[f]
                    if not line.get('__group'):
                        format = str(
                            locale.nl_langinfo(locale.D_FMT).replace(
                                '%y', '%Y'))
                        d1 = datetime.strptime(line[f], '%Y-%m-%d')
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if fields[f]['type'] == 'time' and line[f]:
                    new_d1 = line[f]
                    if not line.get('__group'):
                        format = str(locale.nl_langinfo(locale.T_FMT))
                        d1 = datetime.strptime(line[f], '%H:%M:%S')
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if fields[f]['type'] == 'datetime' and line[f]:
                    new_d1 = line[f]
                    if not line.get('__group'):
                        format = str(
                            locale.nl_langinfo(locale.D_FMT).replace(
                                '%y', '%Y')) + ' ' + str(
                                    locale.nl_langinfo(locale.T_FMT))
                        d1 = datetime.strptime(line[f], '%Y-%m-%d %H:%M:%S')
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if line.get('__group'):
                    col = etree.SubElement(node_line,
                                           'col',
                                           para='group',
                                           tree='no')
                else:
                    col = etree.SubElement(node_line,
                                           'col',
                                           para='yes',
                                           tree='no')

                # Prevent empty labels in groups
                if f == line.get('__grouped_by') and line.get(
                        '__group'
                ) and not line[f] and not float_flag and not temp[count]:
                    col.text = line[f] = 'Undefined'
                    col.set('tree', 'undefined')

                if line[f] is not None:
                    col.text = tools.ustr(line[f] or '')
                    if float_flag:
                        col.set('tree', 'float')
                    if line.get('__no_leaf') and temp[
                            count] == 1 and f != 'id' and not line[
                                '__context']['group_by']:
                        tsum[count] = float(tsum[count]) + float(line[f])
                    if not line.get(
                            '__group') and f != 'id' and temp[count] == 1:
                        tsum[count] = float(tsum[count]) + float(line[f])
                else:
                    col.text = '/'

        node_line = etree.SubElement(lines, 'row')
        for f in range(0, len(fields_order)):
            col = etree.SubElement(node_line, 'col', para='group', tree='no')
            col.set('tree', 'float')
            if tsum[f] is not None:
                if tsum[f] != 0.0:
                    digits = fields[fields_order[f]].get('digits', (16, 2))
                    prec = '%%.%sf' % (digits[1], )
                    total = prec % (tsum[f], )
                    txt = str(total or '')
                else:
                    txt = str(tsum[f] or '')
            else:
                txt = '/'
            if f == 0:
                txt = 'Total'
                col.set('tree', 'no')
            col.text = tools.ustr(txt or '')

        transform = etree.XSLT(
            etree.parse(
                os.path.join(tools.config['root_path'],
                             'addons/base/report/custom_new.xsl')))
        rml = etree.tostring(transform(new_doc))
        self.obj = render.rml(rml, title=self.title)
        self.obj.render()
        return True
예제 #10
0
    def _create_table(self, uid, ids, fields, fields_order, results, context, title=""):
        pageSize = [297.0, 210.0]

        new_doc = etree.Element("report")
        config = etree.SubElement(new_doc, "config")

        def _append_node(name, text):
            n = etree.SubElement(config, name)
            n.text = text

        # _append_node('date', time.strftime('%d/%m/%Y'))
        _append_node("date", time.strftime(str(locale.nl_langinfo(locale.D_FMT).replace("%y", "%Y"))))
        _append_node("PageSize", "%.2fmm,%.2fmm" % tuple(pageSize))
        _append_node("PageWidth", "%.2f" % (pageSize[0] * 2.8346,))
        _append_node("PageHeight", "%.2f" % (pageSize[1] * 2.8346,))
        _append_node("report-header", title)

        env = odoo.api.Environment(self.cr, uid, {})
        Users = env["res.users"]
        _append_node("company", Users.browse(uid).company_id.name)
        rml_obj = report_sxw.rml_parse(self.cr, uid, Users._name, context)
        _append_node(
            "header-date",
            str(rml_obj.formatLang(time.strftime("%Y-%m-%d"), date=True)) + " " + str(time.strftime("%H:%M")),
        )
        l = []
        t = 0
        strmax = (pageSize[0] - 40) * 2.8346
        temp = []
        tsum = []
        for i in range(0, len(fields_order)):
            temp.append(0)
            tsum.append(0)
        ince = -1
        for f in fields_order:
            s = 0
            ince += 1
            if fields[f]["type"] in ("date", "time", "datetime", "float", "integer"):
                s = 60
                strmax -= s
                if fields[f]["type"] in ("float", "integer"):
                    temp[ince] = 1
            else:
                t += fields[f].get("size", 80) / 28 + 1

            l.append(s)
        for pos in range(len(l)):
            if not l[pos]:
                s = fields[fields_order[pos]].get("size", 80) / 28 + 1
                l[pos] = strmax * s / t

        _append_node("tableSize", ",".join(map(str, l)))

        header = etree.SubElement(new_doc, "header")
        for f in fields_order:
            field = etree.SubElement(header, "field")
            field.text = tools.ustr(fields[f]["string"] or "")

        lines = etree.SubElement(new_doc, "lines")
        for line in results:
            node_line = etree.SubElement(lines, "row")
            count = -1
            for f in fields_order:
                float_flag = 0
                count += 1
                if fields[f]["type"] == "many2one" and line[f]:
                    if not line.get("__group"):
                        line[f] = line[f][1]
                if fields[f]["type"] == "selection" and line[f]:
                    for key, value in fields[f]["selection"]:
                        if key == line[f]:
                            line[f] = value
                            break
                if fields[f]["type"] in ("one2many", "many2many") and line[f]:
                    line[f] = "( " + tools.ustr(len(line[f])) + " )"
                if fields[f]["type"] == "float" and line[f]:
                    precision = (("digits" in fields[f]) and fields[f]["digits"][1]) or 2
                    prec = "%." + str(precision) + "f"
                    line[f] = prec % (line[f])
                    float_flag = 1

                if fields[f]["type"] == "date" and line[f]:
                    new_d1 = line[f]
                    if not line.get("__group"):
                        format = str(locale.nl_langinfo(locale.D_FMT).replace("%y", "%Y"))
                        d1 = datetime.strptime(line[f], "%Y-%m-%d")
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if fields[f]["type"] == "time" and line[f]:
                    new_d1 = line[f]
                    if not line.get("__group"):
                        format = str(locale.nl_langinfo(locale.T_FMT))
                        d1 = datetime.strptime(line[f], "%H:%M:%S")
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if fields[f]["type"] == "datetime" and line[f]:
                    new_d1 = line[f]
                    if not line.get("__group"):
                        format = (
                            str(locale.nl_langinfo(locale.D_FMT).replace("%y", "%Y"))
                            + " "
                            + str(locale.nl_langinfo(locale.T_FMT))
                        )
                        d1 = datetime.strptime(line[f], "%Y-%m-%d %H:%M:%S")
                        new_d1 = d1.strftime(format)
                    line[f] = new_d1

                if line.get("__group"):
                    col = etree.SubElement(node_line, "col", para="group", tree="no")
                else:
                    col = etree.SubElement(node_line, "col", para="yes", tree="no")

                # Prevent empty labels in groups
                if (
                    f == line.get("__grouped_by")
                    and line.get("__group")
                    and not line[f]
                    and not float_flag
                    and not temp[count]
                ):
                    col.text = line[f] = "Undefined"
                    col.set("tree", "undefined")

                if line[f] is not None:
                    col.text = tools.ustr(line[f] or "")
                    if float_flag:
                        col.set("tree", "float")
                    if line.get("__no_leaf") and temp[count] == 1 and f != "id" and not line["__context"]["group_by"]:
                        tsum[count] = float(tsum[count]) + float(line[f])
                    if not line.get("__group") and f != "id" and temp[count] == 1:
                        tsum[count] = float(tsum[count]) + float(line[f])
                else:
                    col.text = "/"

        node_line = etree.SubElement(lines, "row")
        for f in range(0, len(fields_order)):
            col = etree.SubElement(node_line, "col", para="group", tree="no")
            col.set("tree", "float")
            if tsum[f] is not None:
                if tsum[f] != 0.0:
                    digits = fields[fields_order[f]].get("digits", (16, 2))
                    prec = "%%.%sf" % (digits[1],)
                    total = prec % (tsum[f],)
                    txt = str(total or "")
                else:
                    txt = str(tsum[f] or "")
            else:
                txt = "/"
            if f == 0:
                txt = "Total"
                col.set("tree", "no")
            col.text = tools.ustr(txt or "")

        transform = etree.XSLT(
            etree.parse(os.path.join(tools.config["root_path"], "addons/base/report/custom_new.xsl"))
        )
        rml = etree.tostring(transform(new_doc))
        self.obj = render.rml(rml, title=self.title)
        self.obj.render()
        return True