跳至内容
菜单
此问题已终结

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.







形象
丢弃

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

编写者

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

编写者

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

编写者

any solution on that problem ?

最佳答案

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


形象
丢弃
编写者

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

编写者

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

编写者

I updated the question above , thank you

相关帖文 回复 查看 活动
3
2月 18
3998
0
10月 24
1010
8
4月 23
18395
2
12月 16
6123
0
3月 16
4854