0

these methods should update the res.partner name on form view, it opens a new window, showing partners name, and a button to update it.

Originally on v8 it looked like this:

class WizUpdatename(osv.osv_memory):
_name = 'wiz.updatename'
_description = "Wizard that changes the partner name"

def set_name(self, cr, uid, ids, context):
    """ Change value of the name field
    """
    data = self.pool.get('wiz.updatename').read(cr, uid, ids)[0]
    if not data['sure']:
        raise osv.except_osv(
            _("Error!"),
            _("Please confirm that you want to do this by checking the"
              " option"))

    partner_obj = self.pool.get('res.partner')
    name_partner = data['name']

    partner_obj.write(cr, uid, context['active_id'],
                      {'name': name_partner}, context=context)
    return {}

def _get_name(self, cr, uid, context=None):
    """ Get name field value
    """
    if context is None:
        context = {}
    partner_obj = self.pool.get('res.partner')
    partner = partner_obj.search(cr, uid,
                                 [('id', '=', context['active_id'])])
    partner_o = partner_obj.browse(cr, uid, partner[0])
    return partner_o and partner_o.name or False

_columns = {
    'name': fields.char(
        string='Name', size=256, required=True,
        default=lambda s: s._get_name()),
    'sure': fields.boolean('Are you sure?'),
}

WizUpdatename()

After mirgation, it now look like this:

class WizUpdatename(models.TransientModel):
_name = 'wiz.updatename'
_description = "Wizard that changes the partner name"

name = fields.Char(
    string='Name', size=256, required=True,
    default=lambda s: s._get_name())
sure =fields.Boolean(string='Are you sure?')

@api.multi
@api.depends('res.partner')
def set_name(self): #, cr, uid, ids, context
    """ Change value of the name field
    """
    data = self.env['wiz.updatename'].read()[0]
    if not data['sure']:
        raise UserError(
            _("Error!"),
            _("Please confirm that you want to do this by checking the"
              " option"))

    partner_obj = self.env['res.partner']
    name_partner = data['name']

    partner_obj.write(context['active_id'],
                      {'name': name_partner}) 
    return {}

@api.depends('res.partner')
def _get_name(self): #, cr, uid, context=None
    """ Get name field value
    """
    #if context is None:
        #context = {}
    #ctx = self._context.get()
    partner_obj = self.env['res.partner']
    partner = partner_obj.search([('id', '=', 'active')]) 
    partner_o = partner_obj.browse(partner[0]) 
    return partner_o and partner_o.name or False

But everytime I click on this, it throws:

Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 862, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 679, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 664, in call_kw_model
result = method(recs, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 1101, in default_get
defaults[name] = field.default(self)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_update_name.py", line 37, in <lambda>
default=lambda s: s._get_name())
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_update_name.py", line 67, in _get_name
partner = partner_obj.search([('id', '=', 'active')]) #cr, uid, context['active_id'] later added ctx before active_id, now, brackets removed let's see
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 1497, in search
res = self._search(args, offset=offset, limit=limit, order=order, count=count)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/base/res/res_partner.py", line 621, in _search
count=count, access_rights_uid=access_rights_uid)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 4203, in _search
self._cr.execute(query_str, where_clause_params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/sql_db.py", line 141, in wrapper
return f(self, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/sql_db.py", line 218, in execute
res = self._obj.execute(query, params)
DataError: invalid input syntax for integer: "active"
LINE 1: ...artner"."active" = true)  AND  "res_partner".id = 'active') ...

The error is on this line partner = partner_obj.search([('id', '=', 'active')]) now, originally active was active_id, because it should browse one record based on that, but on new Odoo v10, the field active_id no longer exists, there's an active one, but I think is used in some other way, obviously different from active_id.

I still can't find something equivalent for this field on v10 community.

Any ideas?

2 Answers 2

1

The depends decorators aren't necessary here. The new API search will already return a RecordSet, so there is no need to browse again. Or since you already have the ID in context, just use browse. I would migrate both methods like:

@api.multi
def set_name(self):
    """ Change value of the name field """
    self.ensure_one()
    if not self.sure:
        raise UserError(
            _("Error!"),
            _("Please confirm that you want to do this by checking the"
            " option"))

    partner_obj = self.env['res.partner']

    partner_obj.browse(self.env.context.get('active_id', 0).write(
        {'name': self.name})
    return {}

@api.model  # default methods don't work on records
def _get_name(self):
    """ Get name field value """
    partner = self.env['res.partner'].browse(
        self.env.context.get('active_id', 0))
    return partner.name if partner else False
Sign up to request clarification or add additional context in comments.

1 Comment

Man, really awesome, speechless, Thank You very much, I'm getting to a good point on this, and it will serve me for other modules as well, Thank You again
1

You can not search integer fields with the string.

You can get active ids from the context variable to search selected partners.

To get active_id use following code

self._context.get('active_ids')

**here is you method with correction **

@api.depends(your_field_name) 
def _get_name(self): 
    partner_obj = self.env['res.partner']
    partner = partner_obj.search([('id', '=',self._context.get('active_ids'))],limit=1)
    return partner and partner.name or False

This may help you.

4 Comments

Hi Jignesh, thank You again, it says 'ProgrammingError: can't adapt type 'res.partner' :( it's a weird error, your code is ok to me...
you have written res.partner in the @api.depend so
Hi, Thank You very much, same error, it says is here: return partner_o and partner_o.name or False , the field is 'name' and I've changed it, but error persists, I'm so sorry
I've chaged the code in answer. verify it with your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.