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

Hi all, I'm trying to change the value of a field from another class as you can see in the example below:


class A(models.Model):

status = fields.Boolean(default=False)


and my second class is TransientModel which is named wizard. I want to change the value of the field(status) with a button that is lined in my second class. I have to set my second class as a wizard for project necessity.

I have examined write and self.env functions but couldn't change the value for the field.

Thanks in advance.

الصورة الرمزية
إهمال

You can refer Lead lost in default odoo addons

in wizard:
def action_lost_reason_apply(self):
leads = self.env['crm.lead'].browse(self.env.context.get('active_ids'))
return leads.action_set_lost(lost_reason=self.lost_reason_id.id)

in class A
def action_set_lost(self, **additional_values):
if additional_values['lost_reason']:
self.write({'status':True})

أفضل إجابة

Hello KorayK,


You can write the below method in your second class (TransientModel) and pass this method to the button in XML of the second class

Find code in Comment.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

الصورة الرمزية
إهمال

def button_click(self):
if self._context.get('active_id', False):
record = self.env["Your model name"].browse(self._context.get('active_id'))
if record:
record.update({'status': True})

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
يوليو 25
244
2
يوليو 22
11328
1
سبتمبر 24
6925
2
أكتوبر 21
4122
1
سبتمبر 24
3705