Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
15746 Vizualizări
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'
Imagine profil
Abandonează
Cel mai bun răspuns

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'
}
Imagine profil
Abandonează

Cursor goes BRRRRRR, +1

Cursor goes BRRRRRR, +1

Cel mai bun răspuns
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
Imagine profil
Abandonează

not working anymore on odoo 15

Related Posts Răspunsuri Vizualizări Activitate
4
iul. 25
4901
0
sept. 24
1384
4
mai 24
12746
1
apr. 24
3360
0
nov. 23
2062