This question has been flagged
3 Replies
9066 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?.

Avatar
Discard
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)
Best Answer

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...

 

 

 

Avatar
Discard
Author

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.

Author

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, 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.

S I think Ivan is right...

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..

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)
Best Answer

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".

Avatar
Discard
Author

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

Best Answer

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.

Avatar
Discard