Community mailing list archives

Update model from web controller Odoo v8

- 05/31/2016 14:23:01

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