import io
import base64

from odoo import api, fields, models,_
try:
    from odoo.tools.misc import xlsxwriter
except ImportError:
    import xlsxwriter


class ManufactureWizard(models.TransientModel):
    _name = 'manufacture.wizard'

    bom_ids = fields.Many2many(comodel_name="mrp.bom",
                               string="Bills Of Materials", )
    excel_sheet = fields.Binary('Download Report')
    excel_sheet_name = fields.Char(string='Name', size=64)

    def export_to_excel(self):
        row = 2
        col = 1
        report_name = 'Manufacture Report'
        output = io.BytesIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True, 'align': 'center',
                                    'border': 2})
        for obj in self.bom_ids:
            sheet.merge_range(f"B{row+1}:G{row+1}",
                              'Bill of Material :%s' %obj.display_name, bold)
            row = row+2
            sheet.merge_range(row, col, row, 2, "Components",)
            sheet.write(row, col+2, "On Hand",)
            sheet.merge_range(f"E{row+1}:F{row+1}", "To Consume",)
            sheet.write(row, col+5, "FP",)
            sheet.write(row, col+6, "Surplus",)
            minimum_fp = 0
            for line in obj.bom_line_ids:
                row = row+1
                sheet.merge_range(row, col,row,2,line.product_id.name,)
                sheet.write(row,col+2, line.product_id.qty_available,)
                sheet.merge_range(f"E{row+1}:F{row+1}", line.to_consume,)
                sheet.write(row, col+5, line.fp)
                minimum_fp = min(obj.bom_line_ids.mapped('fp'))
                sheet.write(row, col+6, line.fp-minimum_fp)
            row += 1
            sheet.merge_range(f"B{row+1}:F{row+1}", "Qty can be manufactured")
            sheet.write(row, col+5, minimum_fp)
            row += 5
        self.excel_sheet_name = 'Manufacture Report'
        workbook.close()
        output.seek(0)
        self.excel_sheet = base64.encodestring(output.read())
        self.excel_sheet_name = str(self.excel_sheet_name) + '.xlsx'
        return {
            'type': 'ir.actions.act_url',
            'name': 'Manufacture Report',
            'url': '/web/content/manufacture.wizard/%s/excel_sheet/Report Mfc.xlsx?download=true' % (self.id),
            'target': 'self'
        }





6f10bb60bb3e900230d47ff97dbe2ed994e63e52
<mask token>


class ManufactureWizard(models.TransientModel):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

<mask token>


class ManufactureWizard(models.TransientModel):
    _name = 'manufacture.wizard'
    bom_ids = fields.Many2many(comodel_name='mrp.bom', string=
        'Bills Of Materials')
    excel_sheet = fields.Binary('Download Report')
    excel_sheet_name = fields.Char(string='Name', size=64)

    def export_to_excel(self):
        row = 2
        col = 1
        report_name = 'Manufacture Report'
        output = io.BytesIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True, 'align': 'center',
            'border': 2})
        for obj in self.bom_ids:
            sheet.merge_range(f'B{row + 1}:G{row + 1}', 
                'Bill of Material :%s' % obj.display_name, bold)
            row = row + 2
            sheet.merge_range(row, col, row, 2, 'Components')
            sheet.write(row, col + 2, 'On Hand')
            sheet.merge_range(f'E{row + 1}:F{row + 1}', 'To Consume')
            sheet.write(row, col + 5, 'FP')
            sheet.write(row, col + 6, 'Surplus')
            minimum_fp = 0
            for line in obj.bom_line_ids:
                row = row + 1
                sheet.merge_range(row, col, row, 2, line.product_id.name)
                sheet.write(row, col + 2, line.product_id.qty_available)
                sheet.merge_range(f'E{row + 1}:F{row + 1}', line.to_consume)
                sheet.write(row, col + 5, line.fp)
                minimum_fp = min(obj.bom_line_ids.mapped('fp'))
                sheet.write(row, col + 6, line.fp - minimum_fp)
            row += 1
            sheet.merge_range(f'B{row + 1}:F{row + 1}',
                'Qty can be manufactured')
            sheet.write(row, col + 5, minimum_fp)
            row += 5
        self.excel_sheet_name = 'Manufacture Report'
        workbook.close()
        output.seek(0)
        self.excel_sheet = base64.encodestring(output.read())
        self.excel_sheet_name = str(self.excel_sheet_name) + '.xlsx'
        return {'type': 'ir.actions.act_url', 'name': 'Manufacture Report',
            'url': 
            '/web/content/manufacture.wizard/%s/excel_sheet/Report Mfc.xlsx?download=true'
             % self.id, 'target': 'self'}

<mask token>
try:
    from odoo.tools.misc import xlsxwriter
except ImportError:
    import xlsxwriter


class ManufactureWizard(models.TransientModel):
    _name = 'manufacture.wizard'
    bom_ids = fields.Many2many(comodel_name='mrp.bom', string=
        'Bills Of Materials')
    excel_sheet = fields.Binary('Download Report')
    excel_sheet_name = fields.Char(string='Name', size=64)

    def export_to_excel(self):
        row = 2
        col = 1
        report_name = 'Manufacture Report'
        output = io.BytesIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True, 'align': 'center',
            'border': 2})
        for obj in self.bom_ids:
            sheet.merge_range(f'B{row + 1}:G{row + 1}', 
                'Bill of Material :%s' % obj.display_name, bold)
            row = row + 2
            sheet.merge_range(row, col, row, 2, 'Components')
            sheet.write(row, col + 2, 'On Hand')
            sheet.merge_range(f'E{row + 1}:F{row + 1}', 'To Consume')
            sheet.write(row, col + 5, 'FP')
            sheet.write(row, col + 6, 'Surplus')
            minimum_fp = 0
            for line in obj.bom_line_ids:
                row = row + 1
                sheet.merge_range(row, col, row, 2, line.product_id.name)
                sheet.write(row, col + 2, line.product_id.qty_available)
                sheet.merge_range(f'E{row + 1}:F{row + 1}', line.to_consume)
                sheet.write(row, col + 5, line.fp)
                minimum_fp = min(obj.bom_line_ids.mapped('fp'))
                sheet.write(row, col + 6, line.fp - minimum_fp)
            row += 1
            sheet.merge_range(f'B{row + 1}:F{row + 1}',
                'Qty can be manufactured')
            sheet.write(row, col + 5, minimum_fp)
            row += 5
        self.excel_sheet_name = 'Manufacture Report'
        workbook.close()
        output.seek(0)
        self.excel_sheet = base64.encodestring(output.read())
        self.excel_sheet_name = str(self.excel_sheet_name) + '.xlsx'
        return {'type': 'ir.actions.act_url', 'name': 'Manufacture Report',
            'url': 
            '/web/content/manufacture.wizard/%s/excel_sheet/Report Mfc.xlsx?download=true'
             % self.id, 'target': 'self'}

import io
import base64
from odoo import api, fields, models, _
try:
    from odoo.tools.misc import xlsxwriter
except ImportError:
    import xlsxwriter


class ManufactureWizard(models.TransientModel):
    _name = 'manufacture.wizard'
    bom_ids = fields.Many2many(comodel_name='mrp.bom', string=
        'Bills Of Materials')
    excel_sheet = fields.Binary('Download Report')
    excel_sheet_name = fields.Char(string='Name', size=64)

    def export_to_excel(self):
        row = 2
        col = 1
        report_name = 'Manufacture Report'
        output = io.BytesIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True, 'align': 'center',
            'border': 2})
        for obj in self.bom_ids:
            sheet.merge_range(f'B{row + 1}:G{row + 1}', 
                'Bill of Material :%s' % obj.display_name, bold)
            row = row + 2
            sheet.merge_range(row, col, row, 2, 'Components')
            sheet.write(row, col + 2, 'On Hand')
            sheet.merge_range(f'E{row + 1}:F{row + 1}', 'To Consume')
            sheet.write(row, col + 5, 'FP')
            sheet.write(row, col + 6, 'Surplus')
            minimum_fp = 0
            for line in obj.bom_line_ids:
                row = row + 1
                sheet.merge_range(row, col, row, 2, line.product_id.name)
                sheet.write(row, col + 2, line.product_id.qty_available)
                sheet.merge_range(f'E{row + 1}:F{row + 1}', line.to_consume)
                sheet.write(row, col + 5, line.fp)
                minimum_fp = min(obj.bom_line_ids.mapped('fp'))
                sheet.write(row, col + 6, line.fp - minimum_fp)
            row += 1
            sheet.merge_range(f'B{row + 1}:F{row + 1}',
                'Qty can be manufactured')
            sheet.write(row, col + 5, minimum_fp)
            row += 5
        self.excel_sheet_name = 'Manufacture Report'
        workbook.close()
        output.seek(0)
        self.excel_sheet = base64.encodestring(output.read())
        self.excel_sheet_name = str(self.excel_sheet_name) + '.xlsx'
        return {'type': 'ir.actions.act_url', 'name': 'Manufacture Report',
            'url': 
            '/web/content/manufacture.wizard/%s/excel_sheet/Report Mfc.xlsx?download=true'
             % self.id, 'target': 'self'}

import io
import base64

from odoo import api, fields, models,_
try:
    from odoo.tools.misc import xlsxwriter
except ImportError:
    import xlsxwriter


class ManufactureWizard(models.TransientModel):
    _name = 'manufacture.wizard'

    bom_ids = fields.Many2many(comodel_name="mrp.bom",
                               string="Bills Of Materials", )
    excel_sheet = fields.Binary('Download Report')
    excel_sheet_name = fields.Char(string='Name', size=64)

    def export_to_excel(self):
        row = 2
        col = 1
        report_name = 'Manufacture Report'
        output = io.BytesIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True, 'align': 'center',
                                    'border': 2})
        for obj in self.bom_ids:
            sheet.merge_range(f"B{row+1}:G{row+1}",
                              'Bill of Material :%s' %obj.display_name, bold)
            row = row+2
            sheet.merge_range(row, col, row, 2, "Components",)
            sheet.write(row, col+2, "On Hand",)
            sheet.merge_range(f"E{row+1}:F{row+1}", "To Consume",)
            sheet.write(row, col+5, "FP",)
            sheet.write(row, col+6, "Surplus",)
            minimum_fp = 0
            for line in obj.bom_line_ids:
                row = row+1
                sheet.merge_range(row, col,row,2,line.product_id.name,)
                sheet.write(row,col+2, line.product_id.qty_available,)
                sheet.merge_range(f"E{row+1}:F{row+1}", line.to_consume,)
                sheet.write(row, col+5, line.fp)
                minimum_fp = min(obj.bom_line_ids.mapped('fp'))
                sheet.write(row, col+6, line.fp-minimum_fp)
            row += 1
            sheet.merge_range(f"B{row+1}:F{row+1}", "Qty can be manufactured")
            sheet.write(row, col+5, minimum_fp)
            row += 5
        self.excel_sheet_name = 'Manufacture Report'
        workbook.close()
        output.seek(0)
        self.excel_sheet = base64.encodestring(output.read())
        self.excel_sheet_name = str(self.excel_sheet_name) + '.xlsx'
        return {
            'type': 'ir.actions.act_url',
            'name': 'Manufacture Report',
            'url': '/web/content/manufacture.wizard/%s/excel_sheet/Report Mfc.xlsx?download=true' % (self.id),
            'target': 'self'
        }




