Can <condPageBreak height = '? Cm '> dynamically change?

I have <blockTable>one that changes size depending on user input.
I want to continue drawing on the next page if there is not enough space to draw a block on the same page.

<condPageBreak height='1in'/>
<blocklTable ...>
    ...

How can I change blockTable heightto go to the next page if there is not enough space on the current page?

+4
source share
2 answers

There is no way to do this from a tag condPageBreak.

But you can expand the PDF parser, get the code RMLand calculate the height blockTable, and then save the changes until called:

super(report_sxw_extended, self).create_single_pdf(cr, uid, ids, data, report_xml)

<condPageBreak height="?"/> <blockTable ...> RML-, lxml.etree, node height, blockTable node.

etree.XML(report_rml_content).xpath('//condPageBreak[@height="?"]').

:

class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
        })


class report_sxw_inherited(report_sxw.report_sxw):
    def __init__(self, name, table, rml=False, parser=report_sxw.rml_parse, header='external', store=False):
        #Extend __init__ function to save table reference for further use.
        self.table = table
        super(report_sxw_inherited, self).__init__(name, table, rml, parser, header, store)


    def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None):
        #To rewrite rml code you should inherit this.

        #Get invoice object to check if the field will be removed or not.
        invoice  = pooler.get_pool(cr.dbname).get(self.table).browse(cr, uid, ids[-1], context)

        expected = 0

        row_height = #row height in cm.

        minimum = #number of rows which will always be printed.

        height = 0

        #Parse RML code.
        rml = etree.XML(report_xml.report_rml_content)

        #Search for `condPageBreak` with name = `?`.
        for node in rml.xpath('//condPageBreak[@height="?"]'):
            for tr in node.getnext():
                for td in tr:
                    for para in td:
                        #Use regex to get text between "[[]]". 
                        if para.text:
                            clean = re.findall('(?:\[\[)(.*)(?:\]\])', para.text)
                            if clean:

                                #get attribute name from "object.attribute_name".
                                attr = re.findall('(?:\.)(.*)(?:or\s)', clean[0])

                                #Get tag name from "removeParentNode('tag_name')".
                                tag = re.findall('(?:removeParentNode\([\'\"])(.*)(?:[\'\"])', clean[0])

                                if tag:
                                    #Use buildin "getattr" function to get invoice attribute.
                                    attr = getattr(invoice, attr[0])

                                    # if attr!=0 "0 or removeParentNode('tag_name')" the node will not be removed.
                                    if attr and tag[0] == 'tr':
                                        expected += row_height

            height = minimum + expected
            #Set condPageBreak height to "height"
            node.set('height', "%fcm" % height)

        report_xml.report_rml_content = etree.tostring(rml)
        return super(report_sxw_inherited, self).create_single_pdf(cr, uid, ids, data, report_xml, context)

report_sxw.report_sxw = report_sxw_inherited
report_sxw.report_sxw(
    'report.account.invoice',
    'account.invoice',
    'addons/account/report/account_print_invoice.rml',
    parser=account_invoice
)
+3

. . , .

RML.

<condPageBreak/> - "CONDitional Page Break". , , RML.

. , , , , , <condPageBreak/>

<condPageBreak/> -

:

<condPageBreak height="1in"/>
<condPageBreak height="72"/>

: RML

:

<blockTable>

:

<condPageBreak height="1in"/>
    <blockTable style="Table4">
    .
    .
    .
    </blockTable>
+2

Source: https://habr.com/ru/post/1622079/


All Articles