0

I tried to pass a list to check in domain field in view side. But when I execute it displayed a error that telling the passing variable was defined

In python file

class generate_time_table_line(osv.osv_memory):
@api.onchange('lecturer_id')
def onchange_lecturer(self):
    if self.lecturer_id:
        global list_new
        list_new =[1]
        return list_new

in view file

<record id="view_gen_time_table_line_tree" model="ir.ui.view">
        <field name="name">gen.time.table.line.tree</field>
        <field name="model">gen.time.table.line</field>
        <field name="priority" eval="8" />
        <field name="arch" type="xml">
            <tree string="TimeTable Line" editable="top">
                <field name="day" />
                <field name="period_id" />
                <field name="lecturer_id"  />
                <field name="subject_id" domain="[('id','=',list_new)]"/>
            </tree>
        </field>
    </record>

error

Uncaught Error: NameError: name 'list_new' is not defined
PnX Brinky
  • 1
  • 1
  • 2

2 Answers2

0

First, to avoid the error, list_new should be a field name.

Second, in the domain you are comparing an id (integer?) with a list. Maybe you meant 'in' instead of '='

  • because of this error i created a list called list_new , out side of the function with few ids and check the domain.. its working perfectly.. But its displaying the error when i try to pass the list through the function. – PnX Brinky Jun 05 '15 at 04:01
0

A domain is a list of criteria, each criterion being a triple (either a list or a tuple) of (field_name, operator, value) where:

field_name (str) is a field name of the current model, or a relationship traversal through a Many2one using dot-notation e.g. 'street' or 'partner_id.country'

operator (str) is an operator used to compare the field_name with the value. Some valid operators are: =, !=. You can find all the available domain operators and their use cases here Available domain operator in openerp/odoo?

value is a variable type, must be comparable (through operator) to the named field.

So in your code,

If you put list_new on a domain in python file means, list_new should be a valid variable which produces a value or a valid field name. In the later, ORM will compute the value for you.

If you put list_new on a domain in xml file means, list_new should be a valid field_name.

I think the following may fit your need to generate dynamic domains:

Use a functional field to save the domain and use that field in view like

def _get_domain(self, cr, uid, ids, field_name, arg, context=None):
    record_id = ids[0] 
    # do some computations....
    return {record_id: YOUR DOMAIN} 

'list_new': fields.function(_get_domain, type='char', size=255, method=True, string="Domain"),

and in xml:

<field name="subject_id" domain="list_new" />

Another way is fields_view_get() function. But i would not recommend this.

Community
  • 1
  • 1
no coder
  • 2,290
  • 16
  • 18