akretion / ooor

Odoo Ruby JSON client. Emulates ActiveRecord enough (as much as Mongoid; Implements ActiveModel) to make Rails development with an Odoo datastore straightforward
MIT License
199 stars 59 forks source link

Error when calling on_change method #173

Open augustosamame opened 7 years ago

augustosamame commented 7 years ago

Code from readme fails in Odoo v10 (Rails 4 or 5 and Ruby 2.3.1) with Ooor master branch:

so = SaleOrder.new
so.on_change('onchange_partner_id', :partner_id, 1, 1, false)

This fails with:

Ooor::TypeError:

********************************************
***********     OOOR Request     ***********
method: onchange_partner_id - args: [[], 1, false]
********************************************

********************************************
*********** OpenERP Server ERROR ***********
********************************************
Traceback (most recent call last):
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 638, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 675, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 331, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo-10.0/odoo/service/model.py", line 119, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 324, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 933, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 504, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-10.0/addons/web/controllers/main.py", line 862, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/odoo-10.0/addons/web/controllers/main.py", line 854, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo-10.0/odoo/api.py", line 681, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo-10.0/odoo/api.py", line 670, in call_kw_multi
    recs = self.with_context(context or {}).browse(ids)
  File "/opt/odoo/odoo-10.0/odoo/models.py", line 4856, in with_context
    context = dict(args[0] if args else self._context, **kwargs)
TypeError: 'int' object is not iterable

I am trying to figure out if v10 calls the on_change method any differently. When changing the partner in the sales form through the Odoo UI, I see the following calls in the server logs with log_level debug_rpc_answer:


2017-10-21 02:36:06,549 1704 DEBUG ooor_dev odoo.http.rpc.request: call_kw: sale.order onchange, [[],
 {u'amount_tax': 0,
  u'amount_total': 0,
  u'amount_untaxed': 0,
  u'client_order_ref': False,
  u'company_id': 1,
  u'confirmation_date': False,
  u'currency_id': False,
  u'date_order': u'2017-10-21 02:33:44',
  u'fiscal_position_id': False,
  u'id': False,
  u'invoice_count': 0,
  u'invoice_status': u'no',
  u'message_follower_ids': False,
  u'message_ids': False,
  u'name': u'New',
  u'note': False,
  u'order_line': [],
  u'origin': False,
  u'partner_id': 12,
  u'partner_invoice_id': False,
  u'partner_shipping_id': False,
  u'payment_term_id': False,
  u'pricelist_id': False,
  u'project_id': False,
  u'related_project_id': False,
  u'state': u'draft',
  u'team_id': 1,
  u'user_id': 1,
  u'validity_date': False},
 u'partner_id',
 {u'amount_tax': u'',
  u'amount_total': u'',
  u'amount_untaxed': u'',
  u'client_order_ref': u'',
  u'company_id': u'',
  u'confirmation_date': u'',
  u'currency_id': u'1',
  u'date_order': u'',
  u'fiscal_position_id': u'1',
  u'invoice_count': u'',
  u'invoice_status': u'',
  u'message_follower_ids': u'',
  u'message_ids': u'',
  u'name': u'',
  u'note': u'',
  u'order_line': u'1',
  u'order_line.analytic_tag_ids': u'',
  u'order_line.currency_id': u'',
  u'order_line.customer_lead': u'',
  u'order_line.discount': u'1',
  u'order_line.invoice_lines': u'1',
  u'order_line.invoice_status': u'1',
  u'order_line.layout_category_id': u'',
  u'order_line.name': u'',
  u'order_line.price_subtotal': u'',
  u'order_line.price_total': u'1',
  u'order_line.price_unit': u'1',
  u'order_line.procurement_ids': u'',
  u'order_line.product_id': u'1',
  u'order_line.product_uom': u'1',
  u'order_line.product_uom_qty': u'1',
  u'order_line.qty_delivered': u'1',
  u'order_line.qty_delivered_updateable': u'',
  u'order_line.qty_invoiced': u'1',
  u'order_line.qty_to_invoice': u'1',
  u'order_line.sequence': u'',
  u'order_line.state': u'1',
  u'order_line.tax_id': u'1',
  u'origin': u'',
  u'partner_id': u'1',
  u'partner_invoice_id': u'',
  u'partner_shipping_id': u'1',
  u'payment_term_id': u'',
  u'pricelist_id': u'1',
  u'project_id': u'1',
  u'related_project_id': u'',
  u'state': u'1',
  u'team_id': u'',
  u'user_id': u'',
  u'validity_date': u''},
 {u'hide_sale': True,
  u'lang': u'en_US',
  u'params': {u'_push_me': False,
              u'action': 243,
              u'id': 6,
              u'model': u'sale.order',
              u'view_type': u'form'},
  u'search_default_customer': 1,
  u'show_address': 1,
  u'tz': u'Europe/Brussels',
  u'uid': 1}]
2017-10-21 02:36:06,549 1704 DEBUG ooor_dev odoo.api: call sale.order().onchange({u'origin': False, u'message_follower_ids': False, u'order_line': [], u'currency_id': False, u'team_id': 1, u'client_order_ref': False, u'date_order': u'2017-10-21 02:33:44', u'partner_id': 12, u'id': False, u'note': False, u'user_id': 1, u'invoice_status': u'no', u'company_id': 1, u'message_ids': False, u'amount_tax': 0, u'state': u'draft', u'pricelist_id': False, u'project_id': False, u'confirmation_date': False, u'validity_date': False, u'payment_term_id': False, u'partner_invoice_id': False, u'amount_untaxed': 0, u'fiscal_position_id': False, u'amount_total': 0, u'invoice_count': 0, u'name': u'New', u'partner_shipping_id': False, u'related_project_id': False}, u'partner_id', {u'origin': u'', u'message_follower_ids': u'', u'order_line.state': u'1', u'client_order_ref': u'', u'order_line': u'1', u'order_line.qty_to_invoice': u'1', u'company_id': u'', u'currency_id': u'1', u'team_id': u'', u'order_line.qty_invoiced': u'1', u'date_order': u'', u'partner_id': u'1', u'order_line.price_total': u'1', u'note': u'', u'amount_untaxed': u'', u'invoice_status': u'', u'order_line.invoice_status': u'1', u'message_ids': u'', u'amount_tax': u'', u'state': u'1', u'fiscal_position_id': u'1', u'pricelist_id': u'1', u'order_line.customer_lead': u'', u'project_id': u'1', u'order_line.qty_delivered_updateable': u'', u'order_line.product_uom': u'1', u'order_line.layout_category_id': u'', u'confirmation_date': u'', u'validity_date': u'', u'order_line.tax_id': u'1', u'order_line.qty_delivered': u'1', u'payment_term_id': u'', u'partner_invoice_id': u'', u'user_id': u'', u'order_line.price_unit': u'1', u'order_line.invoice_lines': u'1', u'amount_total': u'', u'order_line.procurement_ids': u'', u'invoice_count': u'', u'name': u'', u'partner_shipping_id': u'1', u'order_line.discount': u'1', u'order_line.product_id': u'1', u'order_line.name': u'', u'order_line.product_uom_qty': u'1', u'order_line.price_subtotal': u'', u'order_line.currency_id': u'', u'related_project_id': u'', u'order_line.analytic_tag_ids': u'', u'order_line.sequence': u''})
2017-10-21 02:36:06,611 1704 DEBUG ooor_dev odoo.http.rpc.response: call_kw: sale.order onchange: time:0.063s mem: 931028k -> 931028k (diff: 0k), {'value': {'currency_id': (162, u'PEN'),
           'partner_invoice_id': (12,
                                  u'Camptocamp\n93, Press Avenue\n73377 Le Bourget du Lac\nFrance'),
           'partner_shipping_id': (12,
                                   u'Camptocamp\n93, Press Avenue\n73377 Le Bourget du Lac\nFrance'),
           'payment_term_id': (4, u'End of Following Month'),
           'pricelist_id': (1, u'Public Pricelist (PEN)')}}
2017-10-21 02:36:06,612 1704 INFO ooor_dev werkzeug: 200.121.156.4 - - [21/Oct/2017 02:36:06] "POST /web/dataset/call_kw/sale.order/onchange HTTP/1.1" 200 -

However, I cannot figure out how to convert this into the proper on_change ooor call.

rvalyi commented 7 years ago

Hello @augustosamame that was for calling the old Odoo on_change system. But the new system now is different (and much better). I will have a look what is the best way to call it and tell you how do to it/update the documentation.