Skip to Content
Menu
This question has been flagged

Hi.

I want to make a little change to the def write() function in res.partner.

My first problem is, that I don't find the function "write" in official Odoo10 module "account" in the partner.py file.

The second problem is, that I don't know how I can check if any field is changed. I need to check that and then when something changed I need to set the "state to draft". 


So for example:

@api.model
def write(self):
self.write({'state': 'draft'})
return True


Thank you


update:

I have this 2 functions:

@api.multi
def confirm_customer(self):
self.state = 'confirmed'
return True
@api.multi
def write(self, data):
res = super(Partner, self).write(data)
if self.state == 'confirmed':
self.state = 'draft'
return res

After I click my button "confirm_customer" it should go to state=confirmed. It works fine without the "def write" function.

But with the write function it doesn't work.

Now it didn't change the "confirm_customer" state to confirm. It stays all the time on draft.







Avatar
Discard

When you use self.a_field = 'some_value' write function is called. So when you call self.state = 'confirm' it will go to write. Write your functions accordingly

also in your write function don't use self.field = 'a_value' pass values by dictionary

Author

so I need to write something like this : vals (dict) vals{'foo': 1, 'bar': "Qux"}

Author

I mean, I have no idea how I can change a value without using the .write() method...

Author

any solution on that problem ?

Best Answer

Hello,

I think you cant use self.write in def write as it will create a recurring problem.

What you can do is to pass values as dictionary in write function

an example to see stage_id and changed stage_id of hr_recruitment

@api.multi
def write(self, data):
res = super(YourClassName, self).write(data)
print data['stage_id'], data['last_stage_id']
return res


Avatar
Discard
Author

Thank you Mohammed. I fixed my problem with this: data['state'] = 'draft'

Author

I have a new problem now, my other buttons doesn't work now. because it's going in the write method everytime...

sorry. i don't get your problem correctly. Can you explain it a little more

Author

I updated the question above , thank you

Related Posts Replies Views Activity
3
Feb 18
2890
0
Oct 24
130
8
Apr 23
15833
2
Dec 16
4826
0
Mar 16
3813