Skip to Content
Menu
This question has been flagged
7 Replies
6125 Views

Ok I would like to know how can i get the amount of sales by salesman in python code.

I believe it's easy to be done, but i can't find the right function in sales_order or invoice classes.

I know it may need a composite query to the DB but i can't find object, class or function index for the system - specially new versions like 6.1 or 7.0 .

Regards,

Avatar
Discard
Best Answer

You can first search all sales orders done by particular salesman. After that you will have all sales orders of particular salesman. Then browse them all.

Try this code:

total_sale_amount = 0.0
sale_order_ids = sale_order_obj.search(cr, uid, [('user_id', '=', your_sales_man_id)], context=context)
for sale_order in sale_order_obj.browse(cr, uid, sale_order_ids, context=context):
    total_sale_amount += sale_order.amount_total
print "total_sale_amount::  ", total_sale_amount
return total_sale_amount
Avatar
Discard
Author

I tried it on 6.1 in the a salary rule to calculate commissions and replaced your_sales_man_id with employess as it's a predefined variable in salary rules but i got python code error.

Best Answer

I am currently having similar problems. I want to configure salary rule of 20% of sales per month. I am using odoo version 8.0.13. I will be glad if your question is answered.

Thanks


Avatar
Discard
Author Best Answer

Thanks @Sudhir looks ok - but when i use it as a salary rule to calculate commissions I get

Error Wrong python code defined for salary rule Comm10 (COMM10)

This how i define it:

# Available variables:
#----------------------
# payslip: object containing the payslips
# employee: hr.employee object
# contract: hr.contract object
# rules: object containing the rules code (previously computed)
# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category).
# worked_days: object containing the computed worked days.
# inputs: object containing the computed inputs.

# Note: returned value have to be set in the variable 'result'

total_sale_amount = 0.0
sale_order_ids = sale_order_obj.search(cr, uid, [('user_id', '='employee')], context=context)
for sale_order in sale_order_obj.browse(cr, uid, sale_order_ids, context=context):
    total_sale_amount += sale_order.amount_total

result = total_sale_amount * 0.10

BTW I tried it on OERP 6.1 .

Regards,

Avatar
Discard
Author Best Answer

Here's the COMM10 salary rule defined as python code and always true:

# Available variables:
#----------------------
# payslip: object containing the payslips
# employee: hr.employee object
# contract: hr.contract object
# rules: object containing the rules code (previously computed)
# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category).
# worked_days: object containing the computed worked days.
# inputs: object containing the computed inputs.

# Note: returned value have to be set in the variable 'result'
total_sale_amount = 0.0
sale_order_ids = sale_order_obj.search(cr, uid, [('user_id', '=', employee)], context=context)
for sale_order in sale_order_obj.browse(cr, uid, sale_order_ids, context=context):
    total_sale_amount += sale_order.amount_total
print "total_sale_amount::  ", total_sale_amount
return total_sale_amount

result =  total_sale_amount * 0.10

and this is the error reported:

ERROR ? openerp.netsvc: Error Wrong python code defined for salary rule Comm10 (COMM10)

Avatar
Discard
Author

I'm not sure if the employee variable predefined in the salary rules is the user_id or other thing - like employee_id which I think different from user_id.

Related Posts Replies Views Activity
0
Jan 22
1360
1
Dec 24
31
1
Dec 24
84
0
Nov 24
53
0
Nov 24
68