Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
15757 Zobrazení
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'
Avatar
Zrušit
Nejlepší odpověď

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'
}
Avatar
Zrušit

Cursor goes BRRRRRR, +1

Cursor goes BRRRRRR, +1

Nejlepší odpověď
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
Avatar
Zrušit

not working anymore on odoo 15

Related Posts Odpovědi Zobrazení Aktivita
4
čvc 25
4911
0
zář 24
1388
4
kvě 24
12753
1
dub 24
3363
0
lis 23
2063