Skip to Content
Menu
This question has been flagged
1086 Views

Here this report I want to show account\.move\.line\ quantity\ that\ means\ I\ want\ to\ show\ sum\ of\ the\ quantity\ of\ account.move.line but in my code the report are generating and when I post the invoice the quantity show 3x. Please help me.

here is the code:

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.Date('From', required=False)
date_to = fields.Date('To', default=lambda self: fields.datetime.now(), required=False)
categ_ids = fields.Many2many('product.category', string="Category", required=True)

def action_excel_report(self):
domain = []
date_from = self.date_from
if date_from:
domain += [('create_date', '>=', date_from)]
date_to = self.date_to
if date_to:
domain += [('create_date', '<=', date_to)]
print("Domain.......", domain)
sale_date = self.env['sale.order.line'].search_read(domain)

data = {
'sale_date': sale_date,
'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['account.move.line'].search([])
categ_list_groupby_dict = {}
date_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,
sale_date))

elif self.date_from:
filtered_by_date = list(filter(lambda x: x.create_date >= self.date_from,
sale_date))
elif self.date_to:
filtered_by_date = list(filter(lambda x: x.create_date <= self.date_to,
sale_date))
print(filtered_by_date)
categ_list_groupby_dict[categories.name] = filtered_product_list
final_dist = {}
for categories in categ_list_groupby_dict.keys():
product_data = []
for products in categ_list_groupby_dict[categories]:

sales = self.sudo().env['sale.order.line'].search([('product_template_id', '=', products.id)])
total_net_sale = 0
total_qty = 0
temp_data = []
product = ''

temp_data.append(products.name)
for j in filtered_by_date:
if j.product_id.name == products.name:
for i in sales:
total_qty = total_qty + i.qty_invoiced
total_net_sale = total_net_sale + j.price_subtotal
if total_qty > 0:
temp_data.append(total_qty)
temp_data.append(products.uom_id.name)
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)


# class SaleOrderLine(models.Model):
# _inherit = 'sale.order.line'
#
# sales_count = fields.Float('sales_count')
# create_date = fields.Date('Created on')
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'

# sales_count = fields.Float('sales_count')
create_date = fields.Date('Created on')


Avatar
Discard


sale.order.line model has qty_invoiced field. you should use this field for your calculation.

Author

how can I use qty_invoiced from sale.order.line in my code because i am using account.move.line