0

I have this controller in Odoo v8, which creates an url for a model in website:

@route('/contrato/editar/', type='http', auth='public',website=True)
def edit(self, **post_data):
    form = CuidumForm(request.httprequest.form)
    post = 'account.periodical_invoicing.agreement.id'
    if request.httprequest.method == 'POST' and form.validate():
        obj = request.env['account.periodical_invoicing.agreement'].browse( post.get(id))
        obj.write(post([
            (field_name, field.data)
            for field_name, field in form._fields.iteritems()
        ]))
        return request.render(
            'website_create_partner.success',
            {'name': form.name.data})
    return request.render(
        'website_create_partner.contrato_editar',
        {'form': form})

This is the xml view:

<template id="contrato_editar" name="Edicion">
<t t-call="website.layout">
    <div class="row">
        <div class="col-md-6 col-md-offset-2">
            <form role="form" action="/contrato/editar" method="POST">
                <t t-foreach="form" t-as="field">
                    <t t-call="website_create_partner.field_render_cuidum" />
                </t>
                <button type="submit" class="btn btn-primary mt8">Guardar</button>
            </form>
        </div>
    </div>
</t>
</template>

When I access this url via this button action:

    def action_test_contrato(self, cr, uid, ids, context=None):
    ''' Open the website page'''
    context = dict(context)
    return {
        'type': 'ir.actions.act_url',
        'name': "Resultados",
        'target': 'self',
        #'url': self.read(cr, uid, ids, ['public_url'], context=context)[0]['public_url'] + "/phantom"
        'context': context,
        'url': "/contrato/editar/"
    }

It throws me this traceback:

Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\openerp\addons\website\models\ir_http.py", line 199, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\openerp\addons\base\ir\ir_http.py", line 145, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\http.py", line 668, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\openerp\addons\base\ir\ir_http.py", line 171, in _dispatch
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\http.py", line 686, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\http.py", line 312, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\http.py", line 309, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\http.py", line 805, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\.\openerp\http.py", line 405, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20160507\server\openerp\addons\website_create_partner\controller\partners.py", line 48, in edit
 AttributeError: 'str' object has no attribute 'get'

Im tryng to make an UPDATE on a model, but is really confusing

Anybody has an idea about this?

The idea is to go to a form view of the account.periodical_invoicing.agreement from the action_test_contrato launch the web form, edit or fill fields from the model and then save.

I'm really stuck on this.

Please, does anybody knows how to solve this?

Thanks in advance!

NeoVe
  • 3,857
  • 8
  • 54
  • 134
  • 1
    In `def edit(self, **post_data):`, the variable `post` is a string (`'post = 'account.periodical_invoicing.agreement.id'` ). `get()` is a dictionary method, not a string method. – jDo May 31 '16 at 20:51
  • 1
    As a first pointer: In line 4 of your first section, you define 'post' as a string, then in line 6 you call 'post.get(id)' on that string, if that of any help? – ninehundred May 31 '16 at 20:51
  • Yeah, @ninehundred thank you, that was it, but, for instance, how could I define 'post' in this situation? Sorry for the noob question, I'm quite confused at this – NeoVe May 31 '16 at 20:57

0 Answers0