from odoo import api, fields, models
from odoo.exceptions import UserError
class ProductCategoryReport(models.TransientModel):
_name = 'item.sales.wizard'
_description = "Print Item Wise Sales Report"
date_from = fields.Datetime('From', required=False)
date_to = fields.Datetime('To', default=lambda self: fields.datetime.now(), required=False)
categ_ids = fields.Many2many('product.category', string="Category", required=True)
def action_excel_report(self):
data = {
'date_from': self.date_from,
'date_to': self.date_to,
'categ_ids': self.categ_ids.ids
}
return self.env.ref('item_wise_sales_report.action_item_sales_report_xlsx').report_action(self,
data=data)
def action_report(self):
product_list = self.env['sale.order.line'].search([], order='product_id,create_date asc')
categ_list_groupby_dict = {}
for categories in self.categ_ids:
filtered_product_list = list(filter(lambda x: x.product_id.categ_id == categories, product_list))
if self.date_from and self.date_to:
filtered_by_date = list(
filter(lambda x: x.create_date >= self.date_from and x.create_date <= self.date_to,
filtered_product_list))
elif self.date_from:
filtered_by_date = list(filter(lambda x: x.create_date >= self.date_from,
filtered_product_list))
elif self.date_to:
filtered_by_date = list(filter(lambda x: x.create_date <= self.date_to,
filtered_product_list))
categ_list_groupby_dict[categories.name] = filtered_by_date
final_dist = {}
for categories in categ_list_groupby_dict.keys():
product_data = []
for products in categ_list_groupby_dict[categories]:
temp_data = []
temp_data.append(products.product_template_id.name)
temp_data.append(products.qty_invoiced)
temp_data.append(products.product_uom.name)
temp_data.append(products.price_subtotal)
product_data.append(temp_data)
final_dist[categories] = product_data
datas = {
'ids': self,
'model': 'product.category.wizard',
'form': final_dist,
'date_from': self.date_from,
'date_to': self.date_to,
}
return self.env.ref('item_wise_sales_report.action_item_sales_report').report_action([], data=datas)
Here sale order line how can i merge same product. here this report same product, quantity and price_subtotal are showing many time. But I want to show same product only one time How can I do that. Please help me.
Have you tried using set() instead of list() ?
No brother
Nothing change same result are shown