跳至內容
選單
此問題已被標幟
8 回覆
4209 瀏覽次數

in the past we had @api.constraint function that checks amount_total of purchase_order. If some condition was true it raised an ValidationError. This worked fine.


But now we need some other logic that only shows a Warning-Messagebox when Save-Button is clicked in purchase order (if some condition is true), but the Save-Logic still should go On. Raising a ValidationError stops this logic.


can this be achieved with @aoi.constraint? Any other ideas to make such logic?


頭像
捨棄

I doubt you can do this... not with the default Save/Create buttons.

最佳答案

No, there is no proper way to achieve it. 
once the odoo raise the error it will rollback cursor on dispatch and nothing will save.

so before raise the error if you explicitly commit the cursor using (self.env.cr.commit()) it will save the record. but the client still raise the warning  (view stay in edit mode because it receives warning instead of True/False value of write)

it's a hack I don't recommend it to use until it absolutely necessary.
move the logic from api.constrains to api.onchange seems a good alternative

頭像
捨棄
最佳答案

Hi Jack:

You can define an Automated Action for this. Activate developer mode and go to Settings > Technical > Automated Actions. Specify the details per our need. For the Action To Do, select Execute Python Code and you should be able to write code to raise a Warning which will popup a message but allow the user to proceed.


頭像
捨棄
作者

we just have "scheduled actions", but i do not find "Automated Actions". is this a enterperise feature?

I asked similar question, and the answer was that it does not give you the option to save. It will stop the process.

@Jack The "Automated Action Rules" module will need to be installed.

最佳答案

raise warning


import odoo.exceptions
raise Warning(_('msg'))

頭像
捨棄
作者

no if i use this within the @api.constraint it will stop saving the purchase.order.

i want a PopUp Message but still save the purchase.order

You raise a warning 
Not constraint 

On Tue, Nov 5, 2019, 7:53 PM Jack <lorenz.strouhal@mediatesystems.at> wrote:

no if i use this within the @api.constraint it will stop saving the purchase.order.

i want a PopUp Message but still save the purchase.order

Gesendet durch Odoo S.A. in benutzung Odoo.