0

I have a class order_order:

class order_order(osv.osv):

    _inherit = "sale.order"

    _columns = {
        'order_completed_date' : fields.char('Order Completed Date'),
        .
        .
        .
    }

Based on this SO post I wrote the following initializer:

def __init__(self, **kwargs):
    super(order_order, self).__init__(**kwargs)
    self.order_completed_date = order_completed_date
    .
    .
    .

I am trying to create an object as:

order_order.__new__(order_completed_date=order_completed_date, ...)

But I am getting the following error:

TypeError: __new__() got an unexpected keyword argument 'order_completed_date'

EDIT: Getting the same error with:

order_order(order_completed_date=order_completed_date, ...)

EDIT2: Full error:

Traceback (most recent call last):
  File "/home/nish/repos/stage/openerp/web/addons/web/http.py", line 292, in dispatch
    r = method(self, **self.params)
  File "/home/nish/repos/stage/openerp/web/addons/web/controllers/spree_api.py", line 118, in some_html
    order_order(order_completed_date=order_completed_date, order_id=order_id, product_id=product_id, product_name=product_name, size=size, product_cost_cp=product_cost_cp, product_cost_sp=product_cost_sp, product_cost_mrp=product_cost_mrp, product_creation_date=product_creation_date, product_taxon=product_taxon, user_email=user_email, user_name=user_name, user_address=user_address, user_city=user_city, city_zip_code=city_zip_code, user_state=user_state, user_country=user_country)
TypeError: __new__() got an unexpected keyword argument 'user_address'

What am I doing wrong? How can I correct the error?

Community
  • 1
  • 1
nish
  • 6,952
  • 18
  • 74
  • 128

1 Answers1

2

__new__ is the type’s constructor, and you usually don’t want to use it like that ever. The normal way to create an object, that also includes calling its initializator is this:

order_order(order_completed_date=order_completed_date, ...)

So, just call the type; and the parameters of that call will be passed to the initializator.

poke
  • 369,085
  • 72
  • 557
  • 602
  • Do I need to make changes in the initializer of base class? – nish Nov 28 '14 at 12:46
  • 1
    Can you show the full error message? The *same* error is unlikely (since you are no longer calling `__new__` explicitely); but it’s possible that passing the keyword arguments to the base type. You should probably not pass the keyword arguments to the base’s `__init__`. – poke Nov 28 '14 at 12:47
  • Well, in the file `spree_api.py`, on line 119, you are still calling `order_order.__new__(…)` instead of just `order_order(…)`. – poke Nov 28 '14 at 13:02
  • Sorry, I copied the old traceback. PLease can you have a look again. Even without __new__, I am getting the same error – nish Nov 28 '14 at 13:05
  • Also tried `super(order_order, self).__init__()`. But same – nish Nov 28 '14 at 13:05
  • @nish Could you [join chat](http://chat.stackoverflow.com/rooms/6/python) so that we can discuss this in more detail? – poke Nov 28 '14 at 13:07