Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
15557 มุมมอง
Hope you will be fine 
i am working on odoo from last 4 to 5 months 
when i use 'odoo.exception'  for raising an validationError as a popup for showing Warnings,odoo works fine and show the popup and after raising Error, it stop execution and when we press "OK"  it reruns the program. in this case everything works fine.
i want that when  I Raises the ValidationError after that i want to write some data into field how i can do that 

i have tried with "TRY EXCEPT FINALLY" block  For Example

i have Char type Field 
test = fields.Char()

@api.onchange('test')
def _change_value(self):
    try:
        self.test = 2
    except:
        raise ValidationError("Pop up")
    else:
        pass
    finally:
          self.test = 'gggg'
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi there,

Actually you need a custom behavior that shows warning message to user than make some data changes but when you raise errors 

cursor goes brrrrrrrr then rollback.. :D

So just create a wizard to show warning;

model:

class CustomPopup(models.TransientModel):
_name = 'module_name.cpup'
_description = 'Custom Popup'
_rec_name = 'title'

# ----------------------------------------
# Main Information
# ----------------------------------------
title = fields.Char(string='Title')
description = fields.Text(string='Description')

view:
<!--Custom Popup Form View -->
<record model="ir.ui.view" id="custom_popup_wizard_form">
<field name="name">module_name.custom_popup</field>
<field name="model">module_name.cpup</field>
<field name="arch" type="xml">
<form string="Popup" create="0">
<sheet>
<div class="oe_title">
<div class="o_notification_box mb0 alert alert-dismissible alert-info"
role="status">
<a class="close" data-dismiss="alert" href="#">x</a>
<i class="fa fa-info-circle fa-3x text-info float-left"
style="padding-right: 15px;" role="img" aria-label="Info"
title="Info"/>
<h4 class="alert-heading" role="status"> <field name="title"/></h4>

<hr/>
<p class="mb-0">

<strong>
<field name="description"/>
</strong>
</p>
</div>
</div>
</sheet>
</form>
</field>
</record>


Then create an instance from this wizard;
where u raise the error then make your database thinks after this;

created_popup = self.env['module_name.cpup'].create({'title':'WOW DUDE SLOW DOWN!','description':'Life goes on ..'})
return {
'name': _('Somethink Went Wrong'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'module_name.cpup',
'res_id': created_popup,
'target': 'new'
}
อวตาร
ละทิ้ง

Cursor goes BRRRRRR, +1

Cursor goes BRRRRRR, +1

คำตอบที่ดีที่สุด
Hello Mudassar Syed,


Execute the program after the pop-up(in your case it's validation) you need to use the "onchange" method and return the waning.
if you work with Validation or UserError then it is blocking your further code execution.

Example:
@api.onchange('your_field')
def onchange_your_field(self):
return {
'warning': {'title': ('Error'), 'message': ('Error message'),},
}
// Code Execute
Thanks...
For more information Contact us: -  https://kanakinfosystems.com/odoo-development-services
อวตาร
ละทิ้ง

not working anymore on odoo 15

Related Posts ตอบกลับ มุมมอง กิจกรรม
Validation Error แก้ไขแล้ว
4
ก.ค. 25
4500
0
ก.ย. 24
1219
4
พ.ค. 24
12356
1
เม.ย. 24
3051
0
พ.ย. 23
1860