Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
15738 Widoki
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'
Awatar
Odrzuć
Najlepsza odpowiedź

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'
}
Awatar
Odrzuć

Cursor goes BRRRRRR, +1

Cursor goes BRRRRRR, +1

Najlepsza odpowiedź
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
Awatar
Odrzuć

not working anymore on odoo 15

Powiązane posty Odpowiedzi Widoki Czynność
Validation Error Rozwiązane
4
lip 25
4899
0
wrz 24
1384
4
maj 24
12741
1
kwi 24
3357
0
lis 23
2059