Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
1483 มุมมอง

Hello,

I would like to have a form allowing me to edit the values of the objects in my model.


For example, I have a customized model name "enfant" (ie. children), and I'd like to be able to edit it and with a form on the user's website.


Currently I've managed to display the values present for each object using t-att-value="record.x_studio_name" for example. But I can't validate the form to save the new values.


The question is : how can i make a form in user website to edit a child ?



Here the code of the form for informations (sorry for the image format, i didn't succeed to copy/past code) :


อวตาร
ละทิ้ง
ผู้เขียน

For now, i have added this code arount the input :
<div class="col-sm">
<record model="x_liste_des_enfants" id="enfant.id">
<field name="x_name">
<input t-att-value="enfant.x_name" type="text" class="form-control s_website_form_input" name="x_name" placeholder="" data-fill-with="undefined"/>
</field>
</record>
<!-- <delete model="record" search="[('id','=',ref('module_name.record_id'))]"/> -->
</div>

ผู้เขียน คำตอบที่ดีที่สุด

I finally did it!


It feels more like a patch than anything else, but it'll do the job.

In the automation rules, I've added a “on registration” rule, for all my custom fields, with the following python code:

enfant = record.env.user.x_enfants.search([]).filtered(lambda e : e["x_name"] == record["x_name"]).filtered(lambda e : e["id"] != record['id'])
savedName = record["x_name"]
record["x_name"] = record["x_studio_parent"]

if enfant:
    enfant.write({
        "x_studio_age_mois" : record["x_studio_age_mois"],
        "x_studio_poids_kg" : record["x_studio_poids_kg"],
        "x_studio_taille_cm" : record["x_studio_taille_cm"],
        "x_studio_commande" : record["x_studio_commande"],
        "x_studio_parent" : enfant["x_studio_parent"],
        "x_studio_notes" : record["x_studio_notes"]})
else:
    record["x_name"] = savedName


In this code, we retrieve the "enfant" we're interested in with a filter. Then we edit its content with the record data.


The savedName thing is to avoid creating a new object with the x_name currently being parsed, which would belong to the current user. The “else” case is to continue managing the creation of an object in the normal way .

The only problem is that it creates objects to be destroyed afterwards that belong to the OdooBot user, so I think another automation rule to clean this up will do the trick.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Have you seen https://www.odoo.com/forum/help-1/creating-a-website-form-for-a-new-model-240246 ?

อวตาร
ละทิ้ง
ผู้เขียน

Yes but that's not working. I'm not looking to customize a form, i try to change the form to let customer edit value by himself, from the website.
For now, i'm trying to do it by adding automated actions in the create form.

คำตอบที่ดีที่สุด

Thank you for sharing

อวตาร
ละทิ้ง
ผู้เขียน

That's not working at all. I've just shared more informations...

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 25
9747
3
มี.ค. 24
5404
0
ธ.ค. 23
1204
Website form field conditions แก้ไขแล้ว
1
ม.ค. 21
3429
1
ส.ค. 15
3789