콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
15733 화면
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

관련 게시물 답글 화면 활동
Validation Error 해결 완료
4
7월 25
4896
0
9월 24
1382
4
5월 24
12738
1
4월 24
3356
0
11월 23
2059