Help

0

Creating into model from controller (Odoo 13)

Avatar
@Ing

I want to add a new partner from website.


//.py

class Test(http.Controller):
@http.route('/create/partner', type="http", website=True, auth="public")
    def create_partner(self, **kw):
        request.env["res.partner"].sudo().create(kw)
        return request.render("my_project.first_page", {
        })

//.xml
<template id="create_page" name="Create">
    <t t-call="website.layout">
         <form role="form" action="/create/partner" method="POST">
             <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
                    <div class="form-group row form-field o_website_form_custom o_website_form_required_custom">
                        <div class="col-lg-3 col-md-4">
                            <label class="col-form-label" for="Name">Partner Name</label>
                        </div>
                        <div class="col-lg-4 col-md-8">
                            <input type="text" id="name" class="form-control o_website_form_input"
                                   placeholder="name..."
                                   required="required"/>
                        </div>
                          <div class="col-lg-4 col-md-8">
                               <button  type="submit" class="btn btn-primary te_theme_button">Add Partner</button>
                        </div>
                    </div>
         </form>
    </t>
</template>

But , I got this error message :  "res_partner_check_name"
Any help please ?

Thanks.


Avatar
Discard
1 Answer
0

Hi,

This error occurred because the name field in res.partner is empty.Make sure that there is a name attribute in the kw argument list.

Regards

Avatar
Discard