Skip to Content
Menu
This question has been flagged
1 Reply
2034 Views

I'm using odoo 13 and I need to generate a sales report by supplier or vendor. In details, I have a product on my inventory and I have purchased this product from multiple vendors. After that, this product has been sold using POS or Sale Order. Now, I need to keep track the product sold from which vendor. In this scenario, how can I will achieve this? 

Avatar
Discard
Best Answer

Hello Fahimul Islam,
Hope you are doing well.

I have create excel report the code below.

Please find code in comment.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

class ProductTrackingWizard(models.TransientModel):
_name = 'product.tracking.wizard'
_description = 'Product Tracking'

start_date = fields.Date(default=lambda self: fields.Date.context_today(self))
end_date = fields.Date(default=lambda self: fields.Date.context_today(self))

def generate_product_report(self):
fp = io.BytesIO()
workbook = xlsxwriter.Workbook(fp)
worksheet = workbook.add_worksheet()
row = 0
colm = 0
worksheet.write(row, colm, "Date", bold)
colm += 1
worksheet.write(row, colm, "Product", bold)
colm += 1
worksheet.write(row, colm, "Customer", bold)
colm += 1
worksheet.write(row, colm, "Vendor", bold)
colm = 1
row = 1
orders = self.env['sale.order'].search([('state', '=', 'sale'),
('date_order', '>=', self.start_date),
('date_order', '<=', self.end_date)])
for order_line in orders.order_line:
worksheet.write(row, colm, order_line.order_id.date_order or '')
colm += 1
worksheet.write(row, colm, order_line.product_id.name or '')
colm += 1
worksheet.write(row, colm, order_line.order_id.partner_id.name or '')
colm += 1
purchase_line = self.env['purchase.order.line'].search([('product_id', '=', order_line.product_id.id)])
for purchase in purchase_line:
worksheet.write(row, colm, purchase.order_id.partner_id.name or '')
colm += 1
colm = 3
row += 1
colm = 0
row += 1
workbook.close()
fp.seek(0)

Related Posts Replies Views Activity
0
Jun 24
385
1
May 24
722
7
Oct 24
12538
0
Nov 24
54
0
Mar 24
267