from odoo import api, fields, models
from odoo.exceptions import UserError
# class ProductCardReport(models.AbstractModel):
# _name = 'report.product_category_list_report.product_category_report'
# _description = 'Product Category List'
#
# @api.model
# def _get_report_values(self, docids, data=None):
# print("you entered the function")
# docs = self.env['product.product'].browse(data['ids'])
# products = self.env['product.product'].browse(data['location_id'])
# return {
# 'doc_model': 'product.template',
# 'data': data,
# 'products': products,
# 'list': list,
# }
class ProductCategoryReport(models.TransientModel):
_name = 'category.inventory.report.wizard'
_description = "Category Wise Inventory Report"
date_from = fields.Datetime('From', required=True)
date_to = fields.Datetime('To', default=lambda self: fields.datetime.now(), required=True)
categ_ids = fields.Many2many('product.category', string="Category", required=True)
def action_report(self):
product_list = self.env['product.template'].search([])
categ_list_groupby_dict = {}
for categories in self.categ_ids:
filtered_product_list = list(filter(lambda x: x.categ_id == categories, product_list))
filtered_by_date = list(filter(lambda x: x.create_date >= self.date_from and 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.categ_id.name)
# temp_data.append(products.date_order)
temp_data.append(products.id)
temp_data.append(products.name)
temp_data.append(products.qty_available)
temp_data.append(products.uom_id.name)
temp_data.append(products.standard_price)
temp_data.append(products.standard_price * products.qty_available)
# temp_data.append(products.item_code)
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('category_inventory_report.action_category_inventory_report').report_action([], data=datas)
here the code i want to do division. i want to divide like this:
temp_data.append(products.standard_price * products.qty_available) / products.qty_available
and frtch data in report how can i do that please help.
products.qty_available