コード例 #1
0
    def create_spare_pdf(self, components):
        recursion = True
        if self._name == 'report.plm_spare.pdf_one':
            recursion = False
        self.processed_objs = []

        component_type = self.env['product.product']
        bom_type = self.env['mrp.bom']
        user = self.env['res.users'].browse(self.env.uid)
        msg = getBottomMessage(user, self.env.context)
        main_book_collector = BookCollector(customTest=(True, msg))
        for component in components:
            self.processed_objs = []
            buf = self.get_first_page([component.id])
            main_book_collector.addPage((buf, ''))
            self.get_spare_parts_pdf_file(component, main_book_collector,
                                          component_type, bom_type, recursion)
        if main_book_collector is not None:
            pdf_string = BytesIO()
            main_book_collector.collector.write(pdf_string)
            out = pdf_string.getvalue()
            pdf_string.close()
            byte_string = b"data:application/pdf;base64," + base64.b64encode(
                out)
            return byte_string.decode('UTF-8')
        logging.warning('Unable to create PDF')
        return False, ''
コード例 #2
0
def commonInfos(env):
    docRepository = env['plm.document']._get_filestore()
    user = env['res.users'].browse(env.uid)
    msg = getBottomMessage(user, env.context)
    mainBookCollector = BookCollector(jumpFirst=False,
                                      customTest=(False, msg),
                                      bottomHeight=10)
    return docRepository, mainBookCollector