Skip to Content
Menu
This question has been flagged
1 Reply
8013 Views

I have a cutom module that should create a new sale_order based on the values of my module.
Sale order is intended to be generated by the following code:

    @api.one
    def create_sale_order(self):
    vals = {
        'name': self.name,
        'state': 'invoice_exept',
        'date_order': self.date_order,
        'date_create': self.date_order,
        'date_confirm': self.date_confirm,
        'user_id': self.user_id,
        'partner_id': self.partner_id,
        'order_policy': 'manual'
    }

    res = self.env['sale.order'].create(vals)
    return res

 

I'm getting the following error:

 

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 525, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 562, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 302, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 299, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 791, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 395, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 953, in call_button
    action = self._call_kw(model, method, args, {})
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 941, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 393, in old_api
    result = new_api(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 397, in new_api
    result = [method(rec, *args, **kwargs) for rec in self]
  File "/usr/lib/python2.7/dist-packages/openerp/addons/my_addon/myaddon.py", line 193, in action_test
    res = self.env['sale.order'].create(vals)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 462, in new_api
    result = method(self._model, cr, uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/sale/sale.py", line 355, in create
    defaults = self.onchange_partner_id(cr, uid, [], vals['partner_id'], context=context)['value']
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/sale/sale.py", line 331, in onchange_partner_id
    addr = self.pool.get('res.partner').address_get(cr, uid, [part.id], ['delivery', 'invoice', 'contact'])
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/res/res_partner.py", line 750, in address_get
    if record.type in adr_pref and not result.get(record.type):
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 775, in __get__
    self.determine_value(record)
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 868, in determine_value
    record._prefetch_field(self)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 3178, in _prefetch_field
    result = records.read(list(fnames), load='_classic_write')
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 3123, in read
    self._read_from_database(stored)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 3235, in _read_from_database
    cr.execute(query, [tuple(sub_ids)] + rule_params)
  File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
  File "/usr/lib/python2.7/dist-packages/psycopg2/extensions.py", line 129, in getquoted
    pobjs = [adapt(o) for o in self._seq]
ProgrammingError: can't adapt type 'res.partner'

I know that not all the field values are transferred from my module, but the key problem is that sale_order cannot connect with res.partner
Any ideas how to fix it?

Avatar
Discard

Hi Sam
I'm asking to know steps about how to input your code into the odoo. beacuse I want to use the data from custom module to create a order sale

Best Answer

Hello Sam

Try self.user_id.id and self.partner_id.id

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 16
5967
2
Nov 24
473
4
Feb 24
10154
1
Jan 24
369
0
May 23
831