Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
7534 Переглядів

I have this code for name_get but I am getting the error: 

in name_get TypeError: descriptor 'format' requires a 'str' object but received a 'bool'

I think I am not doing the name_get function right. Can you please help?

This is the code:   

========================================================================

def name_get(self, cursor, uid, ids, context=None):
        res = []
        for nget in self.browse(cursor, uid, ids):
            name = [str.format(nget.name), str.format(nget.batch_course_name), str.format(nget.batch_teacher),                     str.format(nget.batch_start_date), str.format(nget.batch_start_time), str.format(nget.batch_end_time)]
            res.append((nget.id, ", ".join(name)))
        return res

 

_name = 'intrac.batches'
    _columns = {
        'name': fields.char('Batch Number', readonly=True),
        'batch_course_name': fields.many2one('intrac.courses', 'Course', required=True),
        'batch_course_category': fields.char('Course Category', required=True),
        'batch_start_date': fields.date('Start Date', required=True),
        'batch_end_date': fields.date('End Date', required=True),
        'batch_duration': fields.integer('Batch Duration (Hours)', required=True),
        'batch_hours_per_day': fields.integer('Hours Per Day', required=True),
        'batch_teacher': fields.many2one('intrac.teachers', 'Teacher', required=True),
        'batch_start_time': fields.selection([('07:00 AM','07:00 AM'),('08:45 PM','08:45 PM')], 'Start Time', required=True),
        'batch_end_time': fields.selection([('07:00 AM','07:00 AM'),('07:15 AM','07:15 AM')], 'End Time', required=True),
        'batch_classroom': fields.many2one('intrac.classrooms', 'Classroom', required=True),
        'classroom_capacity': fields.integer('Classroom Capacity', required=True),
        'batch_registrations': fields.one2many('intrac.batches.registrations', 'batch_number', 'Registrations'),
        'batch_att_sheets': fields.one2many('intrac.att.sheet', 'batch_number', 'Daily Attendance Sheets'),
        'batch_attendance' : fields.one2many('intrac.attend', 'batch_number', 'Batch Attendance'),
        'batch_notes': fields.one2many('intrac.batches.notes', 'batch_number', 'Notes'),

    }

Аватар
Відмінити
Найкраща відповідь

Most of the fields which you are using in name_get are many2one fields.

So first you should check whether the many2one field does have value, if yes then append it in list like this.

for nget in self.browse(cursor, uid, ids):
    name = []
    if nget.batch_course_name:
        name.append(nget.batch_course_name.name)
    #if nget.your_other_fields:
        #name.append(nget.your_other_fields)

Аватар
Відмінити
Найкраща відповідь

The error is caused by incorrect use of format function.  You may want to check https://docs.python.org/2/library/functions.html#format.

Аватар
Відмінити