Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
7370 Vistas

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

Avatar
Descartar
Mejor respuesta


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

Avatar
Descartar
Mejor respuesta

Did you solve this? This is my problem now.

Avatar
Descartar
Mejor respuesta

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']


Avatar
Descartar
Autor

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

Autor

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?

Autor

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

Mejor respuesta

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')? 

Avatar
Descartar
Autor

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?

Autor

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?

Autor

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.

Autor

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.

Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
2
ago 24
1825
2
abr 24
3793
1
nov 23
13768
1
abr 23
2494
1
abr 16
7025