Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
10131 มุมมอง
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Just update the record using write method.

Example,

    def method_name(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': 'state_name'}, context=context)
        return True

อวตาร
ละทิ้ง
ผู้เขียน

thanks

thank you very much it did work

คำตอบที่ดีที่สุด

Hi,
In Odoo, you can change the state of a record (e.g., a model) when a button is clicked by using Python methods and XML views. Here's a step-by-step guide on how to achieve this:

Create a Button:
First, create a button in your Odoo model's XML view file. This button will trigger the action to change the state of the record. For example:

 


Then define a method that will change the state of record using write method

class YourModel(models.Model):
    _name = 'your.model'

    state = fields.Selection([
        ('draft', 'Draft'),
        ('approved', 'Approved'),
        ('rejected', 'Rejected'),
    ], default='draft', string='State')

    def action_change_state(self):
        # Update the state of the current record or a set of records
        self.write({'state': 'approved'})  # Change the state to 'approved'

Hope it helps



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 24
14285
2
มี.ค. 18
5094
0
ม.ค. 18
3221
2
ก.พ. 24
25662
3
ก.พ. 25
55572