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

Filtering orders, purchases, invoices based on a product field

By
Mathieu Laflamme
on 7/27/15, 1:09 PM 713 views

I try to figure how I can show a restricted list of orders, purchases or invoice based on a field I added in the product model, stock_owner_id. He should see only records related to his allowed_stock_owner_ids.

Am I forced to copy stock_owner_id from product.template to sale.order.line to sale.order to apply my domain filter? Is there another way around?

Here are my models:

class User(models.Model): 
    _inherit = 'res.users'
    
    current_stock_owner_id = fields.Many2one('res.partner', string='Current Stock Owner')
    allowed_stock_owner_ids = fields.Many2many('res.partner', 'res_partner_users_rel', 
                                       string='Stock Owners',
                                       domain="[('stock_owner','=',True)]")

class ProductTemplate(models.Model): _inherit = 'product.template' stock_owner_id = fields.Many2one('res.partner', string='Stock Owner',     domain="[('stock_owner','=',True)]")

you may need to provide domain in a RETURN.... which returns a model ,say 'purchase.order' and define that domain based on your condition

Abdul wahid
on 7/28/15, 1:37 AM

Abdul, can you give an example?

Mathieu Laflamme
on 7/28/15, 1:41 AM

please check the question that i have asked "pass filtered purchase orders"...

Abdul wahid
on 7/28/15, 2:22 AM

That doesn't help me at all sorry. I don't see the link between your case and mine. My ultimate goal is to create record rules...

Mathieu Laflamme
on 7/28/15, 3:22 PM
0
Mathieu Laflamme
On 7/28/15, 6:02 PM

Got it! Here is the record rule I need :)

 <record id="isolate_stock_owners_sale_order_rule" model="ir.rule">
        <field name="name">Isolate Stock Owner Sale Order</field>
        <field name="model_id" ref="model_sale_order"/>
        <field eval="True" name="global"/>
        <field name="domain_force">[('order_line.product_tmpl_id.stock_owner_id', '=', user.allowed_stock_owner_ids.id)]</field>
    </record>

if u don't mind will u please explain,how record rule works??currently i am familiarised with only two types of records.ir.ui.view and action.

Abdul wahid
on 7/28/15, 11:28 PM

This allow us to define rules tu access records based on a domain filter. As you can see the domain filter allow dot notation on the left and right side. Check the documentation because when executed on the client side, domain filter doesn't allow dot notation on the left side if I'm not mistaken.

Mathieu Laflamme
on 7/28/15, 11:41 PM

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: 7/27/15, 1:09 PM
Seen: 713 times
Last updated: 7/28/15, 6:03 PM