تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1622 أدوات العرض

Can I create Custom report with Partner level in V17? I want to know how much amount of sales generated by which sales rep to each partner level. 

Sales need to be grouped by product, partner level and sales rep. 

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

I'm functional consultant, don't have knowledge in coding... Is it possible from studio ? or any front end changes ?


Thanks for your time.

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

You can try this code


from odoo import api, models


class CustomSalesReport(models.AbstractModel):

    _name = 'report.custom_module.report_custom_sales'


    @api.model

    def get_report_data(self, product_id, partner_level):

        # Fetch sales data based on product, partner level, etc.

        sales_data = self.env['sale.order'].search([

            ('product_id', '=', product_id),

            ('partner_id.partner_level', '=', partner_level),

        ])

        report_lines = []

        for sale_order in sales_data:

            sales_amount = sum(line.price_subtotal for line in sale_order.order_line)

            report_line = {

                'product_id': sale_order.product_id.name,

                'partner_id': sale_order.partner_id.name,

                'sales_rep_id': sale_order.user_id.name,

                'partner_level': sale_order.partner_id.partner_level,

                'sales_amount': sales_amount,

            }

            report_lines.append(report_line)

       

        return report_lines

Xml code:


for menu
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem id="menu_custom_sales_report" name="Custom Sales Report" action="action_custom_sales_report"/>
</odoo>



For templates :


<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_custom_sales_report">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="line">
                <div class="report-line">
<span><t t-esc="http://line.product_id.name" target="_blank">line.product_id.name"/></span>
<span><t t-esc="http://line.partner_id.name" target="_blank">line.partner_id.name"/></span>
<span><t t-esc="http://line.sales_rep_id.name" target="_blank">line.sales_rep_id.name"/></span>
<span><t t-esc="line.partner_level"/></span>
<span><t t-esc="line.sales_amount"/></span>
                </div>
            </t>
        </t>
    </template>
</odoo>

for Report :

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="action_custom_sales_report" model="ir.actions.report">
        <field name="name">Custom Sales Report</field>
<field name="model">custom_module.report_custom_sales</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">custom_module.report_custom_sales_report</field>
<field name="report_file">custom_module.report_custom_sales_report</field>
<field name="report_template" ref="custom_module.report_custom_sales_report"/>
    </record>
</odoo>



Hope it helps

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
أغسطس 23
1524
2
يناير 20
7647
1
أغسطس 19
3045
0
مارس 15
3841
0
مارس 15
3221