Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10561 Lượt xem

When i want to print a sale order, i have the error : AttributeError: 'NoneType' object has no attribute 'search'

i have created a custom module that overwrite the method create of a sale order, i think this is why i have this error, but i dont know why.. Any ideas ?

Ảnh đại diện
Huỷ bỏ

Hi,

Please post code of your new function

Câu trả lời hay nhất

Hi,

variable section_pool is defined only in your "if" section with :

section_pool = self.pool.get('sale.order.section') #recuperation de l'objet section

but not in the "else" section.

bye

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
    def create(self, cr, uid, vals, context=None):
    id = super(sale_order, self).create(cr, uid, vals, context) # creation du devis (et des lignes de commandes du devis)
    liste_numeros_section = [] # creation d'une liste vide qui contiendra tous les numeros de sections saisis dans la vue
    order_line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', '=', id), ('is_option', '=', False)], context=context) # recuperation de toutes les lignes du devis (qui ne sont pas des options)
    for i in self.pool.get('sale.order.line').browse(cr,uid,order_line_ids, context=context): # pour chaque ligne du devis
        if not(i.number_section in liste_numeros_section): # si nouveau numero de section, alors creation section + lien avec ligne de devis actuelle
            liste_numeros_section.append(i.number_section)
            dict_section = {
                                'order_id': id,
                                'order_line': [(4, i.id)], # lier ligne du devis actuelle a la section (creation d'une relation)
                                'number': i.number_section,
            }
            section_pool = self.pool.get('sale.order.section') #recuperation de l'objet section
            section_pool.create(cr,uid,dict_section, context=context)
        else: # si le numero de section existe deja, alors creation lien ligne du devis actuelle / section
            id_section = section_pool.search(cr,uid, [('number', '=', i.number_section), ('order_id' , '=', id)], context=context) #recupere section qui correspond a la ligne du devis
            dict_section = {
                                'order_line': [(4, i.id)], # lier ligne du devis actuelle a la section (creation d'une relation)
            }
            section_pool.write(cr,uid,id_section,dict_section, context=context) #mise a jour de la section (cad ajout lien avec ligne devis)
    return id
Ảnh đại diện
Huỷ bỏ

everything seems correct. remove this function and try print a sale order .if ok try to keep your code by print.

dont post ur query in answer post it as comment

Bài viết liên quan Trả lời Lượt xem Hoạt động
8
thg 7 24
16272
1
thg 3 15
3824
2
thg 3 15
5682
0
thg 3 15
8371
0
thg 12 23
5047