from odoo import api, models
import datetime
class CategoryReportXls(models.AbstractModel):
_name = 'report.product_category_list_report.product_category_report_xls'
_inherit = 'report.report_xlsx.abstract'
def generate_xlsx_report(self, workbook, data, products):
domain = []
if data.get('date_from'):
domain.append(('create_date', '>=', data.get('date_from')))
if data.get('date_to'):
domain.append(('create_date', '<=', data.get('date_to')))
if data.get('categ_ids'):
domain.append(('categ_id', 'in', data.get('categ_ids')))
report_name = 'Lot Wise Inventory Report'
sheet = workbook.add_worksheet(report_name)
bold = workbook.add_format({'bold': True})
title = workbook.add_format({'bold': True, 'align': 'center', 'font_size': 20})
sheet.merge_range('A1:I1', 'Lot Wise Inventory Report', title)
date_style = workbook.add_format({'num_format': 'dd-mm-yyyy'})
sub_heading = workbook.add_format(
{'align': 'center', 'bold': True})
txt = workbook.add_format({'align': 'left'})
num = workbook.add_format({'align': 'right'})
head = workbook.add_format({'align': 'center', 'bold': True})
sheet.merge_range('C2:F2', 'Company Name' + ':' + self.env.user.company_id.name, head)
products = self.env['product.template'].search(domain)
col = 0
row = 3
sheet.write(row, col, 'Category', sub_heading)
row = 3
col = 1
sheet.set_column(0, 5, 15)
sheet.set_column(2, 2, 40)
sheet.set_column(7, 7, 15)
sheet.set_column(8, 8, 15)
sheet.write(row, col, 'Sl No.', sub_heading)
sheet.write(row, col + 1, 'Product', sub_heading)
sheet.write(row, col + 2, 'Date', sub_heading)
sheet.write(row, col + 3, 'Lot No.', sub_heading)
sheet.write(row, col + 4, 'Qty', sub_heading)
sheet.write(row, col + 5, 'Unit', sub_heading)
sheet.write(row, col + 6, 'Unit Cost', sub_heading)
sheet.write(row, col + 7, 'Stock Value', sub_heading)
row += 2
total_subtotal = 0
for product in products:
if product.categ_id:
sheet.merge_range(f"A{row}:F{row}", product.categ_id.name)
for rec in product:
lot_ids = self.env['stock.production.lot'].search([('product_id', '=', rec.name)])
sheet.write(row, col, rec.serial_number, num)
sheet.write(row, col + 1, rec.name, txt)
sheet.write(row, col + 2, rec.create_date, date_style)
for row in lot_ids:
lot_ids = lot_ids + row.name + '\n'
sheet.write(row, col + 3, lot_ids, num)
sheet.write(row, col + 4, rec.qty_available, num)
sheet.write(row, col + 5, rec.uom_id.name, txt)
sheet.write(row, col + 6, rec.standard_price, num)
sheet.write(row, col + 7, rec.qty_available * rec.standard_price, num)
total_subtotal = total_subtotal + rec.qty_available * rec.standard_price
row += 1
if product.categ_id:
row += 1
sheet.write(row, col + 6, 'Grand Total', bold)
sheet.write(row, col + 7, '{:,.2f}'.format(total_subtotal), bold)
# sheet.write(row, col + 7, '{:,.2f}'.format(total_subtotal), bold)
# for products in data['product_list']:
# # lot_id = self.sudo().env['stock.production.lot'].search([('product_id', '=', products.id)])
# row += 1
# sheet.write(row, col, products['id'])
# sheet.write(row, col + 1, products['name'])
# sheet.write(row, col + 2, products['create_date'])
# # sheet.write(row, col + 3, products.lot_id)
# sheet.write(row, col + 4, products['qty_available'])
# sheet.write_row(row, col + 5, products['uom_id'])
# sheet.write(row, col + 6, products['standard_price'])
# sheet.write(row, col + 7, products['qty_available'] * products['standard_price'])
# sheet.write(row, col + 1, products.name, bold)
# sheet.write(row, col + 2, products.create_date, bold)
# sheet.write(row, col + 4, products.qty_available, bold)
# sheet.write(row, col + 5, products.uom_id.name, bold)
# sheet.write(row, col + 6, products.standard_price, bold)
# sheet.write(row, col + 6, 'Unit Cost', bold)
# sheet.write(row, col + 7, 'Stock Value', bold)
When I generate xlsx report then this error show
TypeError: Mixing apples and oranges:' '(1,6).concat(10777)