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

How can i filter sales orders and sales order lines based on products in sales orders ?

By
samba
on 12/27/14, 2:40 PM 1,846 views

Two uers  u1, u2 are create products in to openerp. The user1 created two products p11, p12 and user2 created two products p21,p22. The customers come to openerp website and make sales orders. Let us take two sales orders, SO1,SO2. SO1 has sale order line p11, and SO2 has sale order line p22. When the u1 loged into system, u1 should see the sales order SO1 but not SO2 (because SO1 contains the product p11 created by u1). When the u2 loged into system, u2 should see the sales order SO2 but not SO1 (because SO2 contains the product p22 created by u2).

To filter the sales orders, i am using the concept user groups. I have written a two domains in rules of  "sales manager" group.  1.  object="sale.order.line"  domain= [('product_id.create_uid','=',user.id)]  2. object='sale.order' domain=[('order_line[0].product_id.create_uid','=',user.id)] . But it's not working. Can any one help me please?.

Thank you Deep, You are right, me also have the same doubt, but i did not think about order total. I thought it's enough if we hide sales order line from  the user. but you have given an excelent point to us. Can you tell us, how to restrict the user from editing the sales order line which contains the product not created by that user. It's good if we are not shown to user in delivery order screen. Any way I will discus this issue with my team again to redesign. To filter the products i am using the rule object="product.product" domain= [('create_uid','=',user.id)] . It's working fine.
Thank you Deep.

On Mon, Dec 29, 2014 at 3:18 PM, deep <deepa4lok-yahoo-com@mail.odoo.com> wrote:

A new answer for How can i filter sales orders and sales order lines based on products in sales orders ? has been posted. Click here to access the post.

--
deep



--
--

Thanks and Regards,

Sambasiva rao,

Cell: +91.9676622023

Skype: samba.guduru2(skype)
samba
on 12/29/14, 5:09 AM
4

Hardikgiri Goswami

--Hardikgiri Goswami--
1123
| 2 1 5
Rajkot, India
--Hardikgiri Goswami--

OpenERP/Odoo Customization/Integration Expert / Python Programmer

Skype ID : hardikgiri.goswami

Hardikgiri Goswami
On 12/29/14, 2:16 AM

I think you have added qoutes in the user.id, This domain should be like. 

1. object="sale.order.line"  domain= [('product_id.create_uid','=',user.id)] 

2. object='sale.order' domain=[('order_line.product_id.create_uid','=',user.id)] .

Hope you can see the differance.

This could be the only reason of "it's not working".

Thank you Goswami, I have removed those single quotes, but it's not working.

samba
on 12/29/14, 5:13 AM
1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 12/29/14, 4:48 AM

Hi, your requirement is bit tricky...

As per your criteria, try this syntax

2. object='sale.order' domain=[('order_line[0].product_id.create_uid','=',user.id)] . [since it is one2many, you cannot browse the field directly right] However, Not sure whether the above syntax will work, but if it works then in this case you will be checking with First Order_lines' product and user...

And coming to your requirement, Let me add an another scenario....

Customer creates order [SO3] ... and SO3 has two order lines say p11 (user1), p22(user2).
Now in this case, how should your domain work?
If am not wrong, SO3 should be shown to both users,
however user1 will see SO3 with one line (i.e.) p11,
and user2 will see SO3 with one line (i.e.)  p22,

Consider you have acheived the same, I will say logically it is incorrect w.r.t to monetary terms,
suppose say line1 amount is 1000 and line2 amount is 2000, then Order total will be 3000 ..
then user1 will see SO3 with p11, but with 3000 as order total
and user2 will see SO3 with p22, but with 3000 as order total
Note: order total is shown as 3000 for both users, which is quite misleading...

So I suggest, filtering the records wont be a wise solution... however, you can let the user to see the other line(other users' lines) but you can control the record from editing...
I hope you are getting my point... and for locking lines from editing, I can suggest you a better idea for the same...

 

 

 

Thank you Deep, You are right, me also have the same doubt, but i did not think about order total. I thought it's enough if we hide sales order line from the user. but you have given an excelent point to us. Can you tell us, how to restrict the user from editing the sales order line which contains the product not created by that user. It's good if we are not shown to user in delivery order screen. Any way I will discus this issue with my team again to redesign. To filter the products i am using the rule object="product.product" domain= [('create_uid','=',user.id)] . It's working fine. Thank you Deep.

samba
on 12/29/14, 5:11 AM

Deep, The first one object="sale.order.line" domain=[('product_id.create_uid','=',user.id)] should work right. Can you help me why it's not working.

samba
on 12/29/14, 6:03 AM

@samba, no [('product_id.create_uid','=',user.id)] wouldn't work as during the evaluation of domain, product_id is not passed as an object but as a database ID (integer). You need to create a related field to capture the product_id's create_uid as sale.order.line's field, then use that in the domain.

Ivan
on 12/29/14, 7:39 AM

S I think Ivan is right...

deep
on 1/3/15, 2:55 AM

If you have decided to lock the record, then create a dynamic functional field(which returns boolean), in that you evaluate, based on user whether the record should be allowed to edit or not, or whatever criteria you want to do..

deep
on 1/3/15, 2:57 AM
Thank you Deep, I am not coding this thing. Just i am creating group.

On Sat, Jan 3, 2015 at 1:27 PM, deep <deepa4lok-yahoo-com@mail.odoo.com> wrote:

If you have decided to lock the record, then create a dynamic functional field(which returns boolean), in that you evaluate, based on user whether the record should be allowed to edit or not, or whatever criteria you want to do..

--
deep
Sent by Odoo S.A. using Odoo about Forum Post False



--
--

Thanks and Regards,

Sambasiva rao,

Skype: samba.guduru2(skype)
samba
on 1/7/15, 6:52 AM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/8/15, 7:19 AM

As I've mentioned you cannot use dot notation to access the fields of many2one fields in a domain, you need to create a related field.  e.g. 'product_creator': fields.related('product_id', 'create_uid, type='many2one', store=True, .....), then use this field in domain.  The store need to be True to enable this field to be used in domain.

As for the domain for sale.order, you may need to decide if the sale.order has multiple line with different products created by different user, what will be the behaviour.  Your current approach is to use the creator of the product of the first line.  You need to create a function field to return a value that you can use in domain.  Implement fnct_search as well for this function as you may not want it to be stored as it may be too dynamic.

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

1 follower(s)

Stats

Asked: 12/27/14, 2:40 PM
Seen: 1846 times
Last updated: 3/16/15, 8:10 AM