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['product.template'].search([])
sale_date = self.env['sale.order.line'].search([])
categ_list_groupby_dict = {}
for categories in self.categ_ids:
filtered_product_list = list(filter(lambda x: x.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]:
if products.sales_count > 0:
sales = self.sudo().env['sale.order.line'].search([('product_template_id', '=', products.id)])
total_net_sale = 0
temp_data = []
temp_data.append(products.name)
temp_data.append(products.sales_count)
temp_data.append(products.uom_id.name)
for i in sales:
total_net_sale = total_net_sale + i.price_subtotal
temp_data.append(total_net_sale)
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 how can I select date range from sale.order.line instead of product.template I want to show data from sale.order.line model create date wise not poduct.template