Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

is there anything like salesman.sales.amount() function

By
Mohamed Hagag
on 4/3/13, 4:56 PM 2,250 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,

3

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/4/13, 2:20 AM

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

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.

Mohamed Hagag
on 4/4/13, 9:40 AM

Can you post the error list?

Sudhir Arya (SA)
on 4/4/13, 9:42 AM
0
Ernest
On 1/15/16, 11:50 AM

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


0
Mohamed Hagag
On 4/4/13, 9:52 AM

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)

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.

Mohamed Hagag
on 4/4/13, 9:54 AM
0
Mohamed Hagag
On 4/4/13, 9:17 AM

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,

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/3/13, 4:56 PM
Seen: 2250 times
Last updated: 1/15/16, 11:50 AM