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

Error When Created second records

By
philip
on 9/25/14, 9:47 PM 922 views

Is there anyone can figure out what has to be done. When I created My first record,
everything is fine then created the second record I got error message below. and I don't know how to fix.
Is this a bug or something wrong with my module/code.

Thank you

python functions------

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time
from osv import osv, fields

class xyz_product(osv.Model):
    _name = "xyz.product"

            ## Beginning Selling Area
    def totalbegsellingarea(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzprod in self.browse(cr, uid, ids, context):
            if xyzprod.begsellingareaboxpcs=='12':
                res[xyzprod.id] = xyzprod.begsellingarea * 12
            if xyzprod.begsellingareaboxpcs=='1':
                res[xyzprod.id] = xyzprod.begsellingarea * 1
            return res
            ## Beginning Warehouse
    def totalbegwarehouse(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzprod in self.browse(cr, uid, ids, context):
            if xyzprod.begwarehousboxpcs=='12':
                res[xyzprod.id] = xyzprod.begwarehouse * 12
            if xyzprod.begwarehousboxpcs=='1':
                res[xyzprod.id] = xyzprod.begwarehouse * 1
            return res
            
            ## Ending Selling Area
    def totalendsellingarea(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzprod in self.browse(cr, uid, ids, context):
            if xyzprod.endsellingareaboxpcs=='12':
                res[xyzprod.id] = xyzprod.endsellingarea * 12
            if xyzprod.endsellingareaboxpcs=='1':
                res[xyzprod.id] = xyzprod.endsellingarea * 1
            return res
            ## Ending Warehouse
    def totalendwarehouse(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzprod in self.browse(cr, uid, ids, context):
            if xyzprod.endwarehousboxpcs=='12':
                res[xyzprod.id] = xyzprod.endwarehouse * 12
            if xyzprod.endwarehousboxpcs=='1':
                res[xyzprod.id] = xyzprod.endwarehouse * 1
            return res

    def get_daysales1(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales1 in self.browse(cr, uid, ids, context):
            res[daysales1.id] = daysales1.price * daysales1.offtake1
            return res

    def get_daysales2(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales2 in self.browse(cr, uid, ids, context):
            res[daysales2.id] = daysales2.price * daysales2.offtake2
            return res

    def get_daysales3(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales3 in self.browse(cr, uid, ids, context):
            res[daysales3.id] = daysales3.price * daysales3.offtake3
            return res

    def get_daysales4(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales4 in self.browse(cr, uid, ids, context):
            res[daysales4.id] = daysales4.price * daysales4.offtake4
            return res

    def get_daysales5(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales5 in self.browse(cr, uid, ids, context):
            res[daysales5.id] = daysales5.price * daysales5.offtake5
            return res
    
    def get_daysales6(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales6 in self.browse(cr, uid, ids, context):
            res[daysales6.id] = daysales6.price * daysales6.offtake6
            return res

    def get_daysales7(self, cr, uid, ids, name, arg, context):
        res = {}
        for daysales7 in self.browse(cr, uid, ids, context):
            res[daysales7.id] = daysales7.price * daysales7.offtake7
            return res

    def get_totaldelivery(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzdelivery in self.browse(cr, uid, ids, context):
            res[xyzdelivery.id] = xyzdelivery.delivery1 + xyzdelivery.delivery2 + xyzdelivery.delivery3 + xyzdelivery.delivery4 + xyzdelivery.delivery5 + xyzdelivery.delivery6 + xyzdelivery.delivery7
            return res

    def get_totalreturn(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzreturn in self.browse(cr, uid, ids, context):
            res[xyzreturn.id] = xyzreturn.return1 + xyzreturn.return2 + xyzreturn.return3 + xyzreturn.return4 + xyzreturn.return5 + xyzreturn.return6 + xyzreturn.return7
            return res

    def get_totalpullout(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzpullout in self.browse(cr, uid, ids, context):
            res[xyzpullout.id] = xyzpullout.pullout1 + xyzpullout.pullout2 + xyzpullout.pullout3 + xyzpullout.pullout4 + xyzpullout.pullout5 + xyzpullout.pullout6 + xyzpullout.pullout7
            return res

    def get_totalofftake(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzofftake in self.browse(cr, uid, ids, context):
            res[xyzofftake.id] = ((xyzofftake.begwarehouse + xyzofftake.begsellingarea) + xyzofftake.totaldelivery + xyzofftake.totalreturn - (xyzofftake.endwarehouse + xyzofftake.endsellingarea)) - xyzofftake.totalpullout
            return res

    def get_totalweeklysales(self, cr, uid, ids, name, arg, context):
        res = {}
        for totalweeklysales in self.browse(cr, uid, ids, context):
            res[totalweeklysales.id] = totalweeklysales.price * totalweeklysales.totalofftake
            return res

    _columns = {

.......

}

error in ubuntu version OpenERP7/odoo7---------------

Client Traceback (most recent call last):
 

     File "/home/philip/ws/openerp/web/addons/web/http.py", line 204, in dispatch
        response["result"] = method(self, **self.params)
      File "/home/philip/ws/openerp/web/addons/web/controllers/main.py", line 1051, in search_read
        return self.do_search_read(req, model, fields, offset, limit, domain, sort)
      File "/home/philip/ws/openerp/web/addons/web/controllers/main.py", line 1086, in do_search_read
        records = Model.read(ids, fields or False, req.context)
      File "/home/philip/ws/openerp/web/addons/web/session.py", line 42, in proxy
        result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
      File "/home/philip/ws/openerp/web/addons/web/session.py", line 30, in proxy_method
        result = self.session.send(self.service_name, method, *args)
      File "/home/philip/ws/openerp/web/addons/web/session.py", line 103, in send
        raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)


    Server Traceback (most recent call last):
      File "/home/philip/ws/openerp/web/addons/web/session.py", line 89, in send
        return openerp.netsvc.dispatch_rpc(service_name, method, args)
      File "/home/philip/ws/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
        result = ExportService.getService(service_name).dispatch(method, params)
      File "/home/philip/ws/openerp/server/openerp/service/web_services.py", line 626, in dispatch
        res = fn(db, uid, *params)
      File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
        return self.execute(db, uid, obj, method, *args, **kw or {})
      File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 132, in wrapper
        return f(self, dbname, *args, **kwargs)
      File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 199, in execute
        res = self.execute_cr(cr, uid, obj, method, *args, **kw)
      File "/home/philip/ws/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
        return getattr(object, method)(cr, uid, *args, **kw)
      File "/home/philip/ws/openerp/server/openerp/osv/orm.py", line 3674, in read
        result = self._read_flat(cr, user, select, fields, context, load)
      File "/home/philip/ws/openerp/server/openerp/osv/orm.py", line 3798, in _read_flat
        record[f] = res2[record['id']]
    KeyError: 2

error in Windows version OpenERP7/odoo7-----------------

Client Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\http.py", line 204, in dispatch
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\controllers\main.py", line 1051, in search_read
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\controllers\main.py", line 1086, in do_search_read
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\session.py", line 42, in proxy
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\session.py", line 30, in proxy_method
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\session.py", line 103, in send


Server Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\web\session.py", line 89, in send
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\netsvc.py", line 296, in dispatch_rpc
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\osv.py", line 190, in execute_kw
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\osv.py", line 132, in wrapper
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\osv.py", line 199, in execute
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\osv.py", line 187, in execute_cr
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\orm.py", line 3679, in read
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\orm.py", line 3803, in _read_flat
KeyError: 2

But if I remove the folowing line:

    def get_totaldelivery(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzdelivery in self.browse(cr, uid, ids, context):
            res[xyzdelivery.id] = xyzdelivery.delivery1 + xyzdelivery.delivery2 + xyzdelivery.delivery3 + xyzdelivery.delivery4 + xyzdelivery.delivery5 + xyzdelivery.delivery6 + xyzdelivery.delivery7
            return res

    def get_totalreturn(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzreturn in self.browse(cr, uid, ids, context):
            res[xyzreturn.id] = xyzreturn.return1 + xyzreturn.return2 + xyzreturn.return3 + xyzreturn.return4 + xyzreturn.return5 + xyzreturn.return6 + xyzreturn.return7
            return res

    def get_totalpullout(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzpullout in self.browse(cr, uid, ids, context):
            res[xyzpullout.id] = xyzpullout.pullout1 + xyzpullout.pullout2 + xyzpullout.pullout3 + xyzpullout.pullout4 + xyzpullout.pullout5 + xyzpullout.pullout6 + xyzpullout.pullout7
            return res

    def get_totalofftake(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzofftake in self.browse(cr, uid, ids, context):
            res[xyzofftake.id] = ((xyzofftake.begwarehouse + xyzofftake.begsellingarea) + xyzofftake.totaldelivery + xyzofftake.totalreturn - (xyzofftake.endwarehouse + xyzofftake.endsellingarea)) - xyzofftake.totalpullout
            return res

    def get_totalweeklysales(self, cr, uid, ids, name, arg, context):
        res = {}
        for totalweeklysales in self.browse(cr, uid, ids, context):
            res[totalweeklysales.id] = totalweeklysales.price * totalweeklysales.totalofftake
            return res

even if i only add like below, I got desame  above error.

is there someone who can create to compute the following field in the different way but same result

    def get_totaldelivery(self, cr, uid, ids, name, arg, context):
        res = {}
        for xyzdelivery in self.browse(cr, uid, ids, context):
            res[xyzdelivery.id] = xyzdelivery.delivery1 + xyzdelivery.delivery2 + xyzdelivery.delivery3 + xyzdelivery.delivery4 + xyzdelivery.delivery5 + xyzdelivery.delivery6 + xyzdelivery.delivery7
            return res

 

is there someone who can create to compute the following field in the different way of coding but same result in below code? ----def get_totaldelivery(self, cr, uid, ids, name, arg, context): --------res = {} --------for xyzdelivery in self.browse(cr, uid, ids, context): ------------res[xyzdelivery.id] = xyzdelivery.delivery1 + xyzdelivery.delivery2 + xyzdelivery.delivery3 + xyzdelivery.delivery4 + xyzdelivery.delivery5 + xyzdelivery.delivery6 + xyzdelivery.delivery7 ------------return res

philip
on 9/27/14, 6:53 AM

Hi all, my apologies to my last post, I found out that the error occurred when I add my functional field to my tree view, but in form view is working but I needto show in tree view
'totaldelivery': fields.function(get_totaldelivery, 'Total Delivery'), Thanks

philip
on 9/28/14, 2:20 AM

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: 9/25/14, 9:47 PM
Seen: 922 times
Last updated: 3/16/15, 8:10 AM