Community mailing list archives


Re: Update model from web controller Odoo v8

- 05/31/2016 15:34:45
Hi Nhomar

Thank You very much, btw I noticed I forgot to change 'GET' to 'POST' in my xml template, I guess that was the reason for the page reloading.

But now it throws this error:

global name 'post' is not defined

I'm going to do more testing

On Tue, May 31, 2016 at 2:12 PM, Nhomar Hernandez <> wrote:
To test it.

Try to use "curl":

curl --data "name=kristian8&nombre=gago&n_seguridad_social=878787&fecha_nacimiento=24%2F05%2F2000&grado_discapacidad=878787http://localhost:8069/contrato/editar/


You will need a JS that put the POST for you in the form for you.

I strongly recomment use a controller for the form render and another one (json) to post your data in json format.

I hope this little note helps you, very good question BTW.

On Tue, May 31, 2016 at 1:27 PM, Kristian Koci <> wrote:

I have this button action on my form view in backend:

    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',
        'context': context,
        'url': "/contrato/editar/"

This is my controller for /contrato/editar/:

@route('/contrato/editar/', type='http', auth='public',website=True)
def edit(self, **post_data):
    form = CuidumForm(request.httprequest.form)
    form.partner_id.choices = [
        for partner in request.env['res.partner'].search([])
    if request.httprequest.method == 'POST' and form.validate():
        obj = request.env['account.periodical_invoicing.agreement'].browse( post.get(id))
        return request.render(
    return request.render(
        {'form': form})

The xml for this controller:

<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="GET">
                <t t-foreach="form" t-as="field">
                    <t t-call="website_create_partner.field_render_cuidum" />
                <button type="submit" class="btn btn-primary mt8">Guardar</button>

It is partially working as it is not creating a new record, but it also doesn't update anything, seems like it's not saving the update on the model.

Also, when I click on submit, it seems it isn't submitting the data, but just reloads the page with the form again, and shows this kind of url on browser:


These of course are sample fields, I don't get it

This is the form I'm using, it's based on WTForms:

class CuidumForm(Form):
    name = StringField(_('Nombre periodical'),
        [Required(_('Please enter a name for the invoicing'))])
    nombre = StringField(_('Nombre'),
        [Required(_('Please enter a name for the Partner'))])
    n_seguridad_social = StringField(_('N de Seguridad Social'))#, [
    fecha_nacimiento = DateField(_('Fecha de nacimiento'), format='%d/%m/%Y', validators=(validators.Optional(),) )
    grado_discapacidad = StringField(_('Grado de discapacidad'))

Please, any ideas on this?

Any help would be greatly appreciated.

Thanks in advance!

Kristian Koci
Linux User #582221

Post to:

Nhomar Hernandez
CEO Vauxoo.
Twitter: @nhomar
Odoo Gold Partner
Skype: nhomar00 (Envia mail previo no lo superviso siempre).
Móvil Venezuela:
+58 4144110269
Móvil México:
+52 1 4773933942

Post to:

Kristian Koci
Linux User #582221