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

Domain restriction - Odoo 8

By
Alejandro Perez Cosio
on 4/7/15, 9:23 AM 941 views

Dear all,

I added a new many2one field "reference_id" to the sale.order.line model and it worked well, but now I would want to set a domain for that field.

This is the idea:

  • When I create a new sale_order and add some order_lines, there should not be any "reference" at the dropbox for the sale_order_line field, but we should be able to create a new one (lets call it "ref004" because I created others before).

  • With that line created, I would want to add a new order line and set that ref004 to the new line.

  • If I create a new sale order, I should see the reference_id field empty again.

My model "exe_reference" fields look like this:


class exe_reference(models.Model):
    _name = 'exe.reference'
sale_order_id = fields.Many2one('sale.order')
    sale_order_line_id = fields.Many2one('sale.order.line')
    name = fields.Char(string='Reference Name')
    date = fields.Date()
    establishment_id = fields.Many2one('res.partner')
    partner_id = fields.Many2one('res.partner', string='Partner')

class reference_sale(models.Model):
    _inherit = 'sale.order.line'
    reference_id = fields.Many2one('exe.reference', string="Reference", domain=[('sale_order_id','=',???)])


If I set a 1 instead '???' I get what I want (obviously, only if I'm at the SO001). How can I get the sale_order.id?

I would appreciate any help.

Best regards 

0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 4/16/15, 11:48 PM

You need to put quotes around the full domain so you can use variables in the domain declaration.

reference_id = fields.Many2one('exe.reference', string="Reference", domain="[('sale_order_id','=',order_id)]") 

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: 4/7/15, 9:23 AM
Seen: 941 times
Last updated: 4/16/15, 11:48 PM