تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
418 أدوات العرض

Hi everyone here,



How can I return an action window or wizard from def copy or def write method in odoo 10.



Thank you very much.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thank you very much for your effort to reply. I appreciated it.

الصورة الرمزية
إهمال
أفضل إجابة

Hii,

In Odoo 10 , def copy() and def write() are not designed to return an action (like opening a wizard or form view), because:

  • They're data model methods , not action methods.
  • They're typically called invisibly from backend logic or buttons , and the framework does not expect a return value from them.
So: Returning an action from write() or copy() is not directly possible.

BUT... There are workarounds depending on whyYou want to return an action:

Define a button method in your model

from odoo import models, api class MyModel (models.Model): _name = 'my.model' @api.multi def copy_and_open_wizard ( self ): # Step 1: Duplicate the record new_record = self.copy() # Step 2: Return a wizard action return { 'name' : 'Open Wizard' , 'type' : 'ir.actions.act_window' , 'res_model' : 'my.wizard.model' , 'view_mode' : 'form' , 'view_type' : 'form' , 'target' : 'new' , 'context' : { 'default_related_id' : new_record. id # pre-fill field in wizard } }

Add the button in your XML form view


<button name = "copy_and_open_wizard" type = "object" string = "Copy & Open Wizard" class = "btn-primary" />

Define a simple wizard model (optional)

from odoo import models, fields class MyWizard (models.TransientModel): _name = 'my.wizard.model' related_id = fields.Many2one( 'my.model' , string= 'Related Record' ) notes = fields.Text( 'Notes' )

i hope it is usefull

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
ديسمبر 24
1060
2
أكتوبر 24
1153
1
أغسطس 24
2305
2
يوليو 24
1535
1
يوليو 24
1114