콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

I want to change currency even if i had some journal items already created. Odoo does not allows it so thats why i had to override the write method but unable to do so . I am using the same code which is in res.company .py file but when i comment that error message from my custom module it still raises the error coming from the real module. Kindly help me with it.

@api.multi
def write(self, values):
#restrict the closing of FY if there are still unposted entries
self._validate_fiscalyear_lock(values)

# Reflect the change on accounts
for company in self:
#forbid the change of currency_id if there are already some accounting entries existing
if 'currency_id' in values and values['currency_id'] != company.currency_id.id:
if self.env['account.move.line'].search([('company_id', '=', company.id)]):
raise UserError(_('You cannot change'))

return super(ResCompany, self).write(values)

 Above is that error code

아바타
취소
베스트 답변


Thanks for the quick reply:)  https://get-mxplayer.in

아바타
취소
베스트 답변

Did you solve this? This is my problem now.

아바타
취소
베스트 답변

Yes you will get the error of the real module because the res.company write method already overrided in account module so to override it, in your custom module __manifest__.py file you have to set depends on 'account':

'depends': ['account']


아바타
취소
작성자

Thanks for replying. I have already set depends like this but still custom module method is not getting the preference it must have.

작성자

I am able to inherit into it but when i remove the error code from custom module then it still raise that error from odoo's code. How to fix that?

What the error you are getting? could you please write your overrided method?

작성자

when we try to change currency this code runs from the write method and stop us from doing that

if 'currency_id' in values and values['currency_id'] != company.currency_id.id:

if self.env['account.move.line'].search([('company_id', '=', company.id)]):

raise UserError(_('You cannot change the currency of the company since some journal items already exist'))

but i dont want this error to pop. For that i copied all of the write method put it into a module and i remove these lines from the new write method but it is still popping this error.

To check if the inheritance is working or not , i changed the error message and it works but i dont want this error to pop at all. how should i do that? Thanks for being so kind

베스트 답변

First can you name the file res_company.py. Try to stick to the conventions. In your custom module\models do you have this res.company.py imported in the __init__.py file? If you have there the problem might be because your line is "from . import res.company", the interpreter will try to find the file res and import the variable company from it.

When you created your custom class for res.company model do you inherit it (_inherit = 'res.company')? 

아바타
취소
작성자

Thanks for replying sir! I have done it all and also adds that in depends module but still it is notworking the way it should. Can u help a bit more?

작성자

I am able to inherit into it but when i remove the error code from custom module then it still raise that error from odoo's code. Please help me with it

what is the error?

작성자

when we try to change currency this code runs from the write method and stop us from doing that

if 'currency_id' in values and values['currency_id'] != company.currency_id.id:

if self.env['account.move.line'].search([('company_id', '=', company.id)]):

raise UserError(_('You cannot change the currency of the company since some journal items already exist'))

but i dont want this error to pop. For that i copied all of the write method put it into a module and i remove these lines from the new write method but it is still popping this error.

작성자

to check if the inheritance is working or not , i changed the error message and it works but i dont want this error to pop at all. how should i do that? Thanks for being so kind

Do you have anything else in the custom module that works, so you can check that your custom module even works? Use logger to check if it calls your method. It's like it doesn't even take your modules code.

comment it out... or use logger so it won't raise the error but just write it to log. Maybe there is another constrain somewhere that checks this again.

작성자

i know that there is always an option to comment it out but you know it was just not satisfying thats why i was trying other way around and yes custom module is working i have tested that.

관련 게시물 답글 화면 활동
2
8월 24
1824
2
4월 24
3793
1
11월 23
13768
1
4월 23
2494
1
4월 16
7025