[FIX] stock_currency_valuation: Fix on posting moves with different company_id#872
[FIX] stock_currency_valuation: Fix on posting moves with different company_id#872feg-adhoc wants to merge 1 commit intoingadhoc:16.0from
Conversation
There was a problem hiding this comment.
Pull request overview
Este PR corrige un bug en el módulo stock_currency_valuation que ocurría al intentar publicar movimientos contables (_post) que pertenecían a diferentes compañías. El problema original era que el método aplicaba el contexto con la cuenta de intercambio de moneda de self.company_id, asumiendo que todos los movimientos pertenecían a la misma compañía.
Changes:
- Refactorización del método
_postpara agrupar movimientos por compañía y procesarlos individualmente con el contexto correcto - Eliminación de imports no utilizados (
collections.defaultdict,fields,float_compare,float_is_zero) - Mejora en el manejo de escenarios multi-compañía aplicando el contexto específico de cada compañía a sus movimientos correspondientes
| # Llamar al super con el contexto específico de cada compañía | ||
| posted_moves |= super(AccountMove, moves.with_context( | ||
| bypass_update_product_price=True, | ||
| force_input_acount=income_currency_exchange_account_id, |
There was a problem hiding this comment.
Hay un error de ortografía en el nombre del parámetro del contexto: 'force_input_acount' debería ser 'force_input_account' (falta la 'c' en 'account').
| force_input_acount=income_currency_exchange_account_id, | |
| force_input_account=income_currency_exchange_account_id, |
| force_input_acount=income_currency_exchange_account_id, | ||
| default_bypass_currency_valuation=True) | ||
| )._post(soft=soft) | ||
|
|
There was a problem hiding this comment.
Espacios en blanco al final de la línea. Aunque esto no afecta la funcionalidad, es una convención de estilo limpio eliminar los espacios finales innecesarios.
| def _post(self, soft=True): | ||
| income_currency_exchange_account_id = self.company_id.income_currency_exchange_account_id.id | ||
| return super(AccountMove, self.with_context( | ||
| bypass_update_product_price=True, | ||
| force_input_acount=income_currency_exchange_account_id, | ||
| default_bypass_currency_valuation=True) | ||
| )._post(soft=soft) | ||
| # Agrupar los movimientos por compañía y procesar cada grupo con su contexto | ||
| posted_moves = self.env['account.move'] | ||
| for company in self.mapped('company_id'): | ||
| moves = self.filtered(lambda m: m.company_id == company) | ||
| income_currency_exchange_account_id = company.income_currency_exchange_account_id.id | ||
| # Llamar al super con el contexto específico de cada compañía | ||
| posted_moves |= super(AccountMove, moves.with_context( | ||
| bypass_update_product_price=True, | ||
| force_input_acount=income_currency_exchange_account_id, | ||
| default_bypass_currency_valuation=True) | ||
| )._post(soft=soft) | ||
|
|
||
| return posted_moves |
There was a problem hiding this comment.
Se ha modificado el comportamiento de un método del modelo (cambio en la lógica de _post) pero no se ha incrementado la versión en manifest.py. Según las convenciones del proyecto, cuando hay cambios estructurales o de lógica en modelos, se debe incrementar la versión (actualmente en 16.0.2.3.0).
| income_currency_exchange_account_id = company.income_currency_exchange_account_id.id | ||
| # Llamar al super con el contexto específico de cada compañía | ||
| posted_moves |= super(AccountMove, moves.with_context( | ||
| bypass_update_product_price=True, | ||
| force_input_acount=income_currency_exchange_account_id, | ||
| default_bypass_currency_valuation=True) | ||
| )._post(soft=soft) | ||
|
|
There was a problem hiding this comment.
Riesgo potencial: acceder a .id en company.income_currency_exchange_account_id.id puede fallar si income_currency_exchange_account_id no está configurado (es False). Aunque en Odoo los campos Many2one vacíos retornan False y no un recordset vacío, y False.id lanzaría AttributeError, sería más seguro usar company.income_currency_exchange_account_id.id if company.income_currency_exchange_account_id else False o simplemente pasar el objeto completo al contexto y dejar que Odoo maneje la conversión.
| income_currency_exchange_account_id = company.income_currency_exchange_account_id.id | |
| # Llamar al super con el contexto específico de cada compañía | |
| posted_moves |= super(AccountMove, moves.with_context( | |
| bypass_update_product_price=True, | |
| force_input_acount=income_currency_exchange_account_id, | |
| default_bypass_currency_valuation=True) | |
| )._post(soft=soft) | |
| account = company.income_currency_exchange_account_id | |
| income_currency_exchange_account_id = account.id if account else False | |
| # Llamar al super con el contexto específico de cada compañía | |
| posted_moves |= super(AccountMove, moves.with_context( | |
| bypass_update_product_price=True, | |
| force_input_acount=income_currency_exchange_account_id, | |
| default_bypass_currency_valuation=True) | |
| )._post(soft=soft) |
|
@roboadhoc r+ nobumped |
|
@maq-adhoc unknown command 'nobumped'. For your own safety I've ignored everything in your entire comment. Currently available commands:
Note: this help text is dynamic and will change with the state of the PR. |
|
@roboadhoc r+ nobump |
…ompany_id closes #872 Signed-off-by: rov-adhoc <[email protected]>

…