Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
7246 Lượt xem

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,

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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,

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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)

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 22
2197
3
thg 9 25
273
3
thg 8 25
381
4
thg 8 25
1517
Block sale. Đã xử lý
3
thg 8 25
540