Skip to content

[FIX] stock_currency_valuation: Fix on posting moves with different company_id#872

Closed
feg-adhoc wants to merge 1 commit intoingadhoc:16.0from
adhoc-dev:16.0-h-110422-feg
Closed

[FIX] stock_currency_valuation: Fix on posting moves with different company_id#872
feg-adhoc wants to merge 1 commit intoingadhoc:16.0from
adhoc-dev:16.0-h-110422-feg

Conversation

@feg-adhoc
Copy link
Contributor

Copilot AI review requested due to automatic review settings February 10, 2026 18:45
@roboadhoc
Copy link
Collaborator

Pull request status dashboard

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _post para 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,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
force_input_acount=income_currency_exchange_account_id,
force_input_account=income_currency_exchange_account_id,

Copilot uses AI. Check for mistakes.
force_input_acount=income_currency_exchange_account_id,
default_bypass_currency_valuation=True)
)._post(soft=soft)

Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines 7 to +20
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
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +12 to +19
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)

Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
@maq-adhoc
Copy link
Contributor

@roboadhoc r+ nobumped

@roboadhoc
Copy link
Collaborator

@maq-adhoc unknown command 'nobumped'.

For your own safety I've ignored everything in your entire comment.

Currently available commands:

command
help displays this help
r(eview)+ approves the PR, if it's a forwardport also approves all non-detached parents
r(eview)=<number> only approves the specified parents
fw=no does not forward-port this PR
fw=default forward-ports this PR normally
fw=skipci does not wait for a forward-port's statuses to succeed before creating the next one
fw=skipmerge does not wait for the source to be merged before creating forward ports
up to <branch> only ports this PR forward to the specified branch (included)
merge integrate the PR with a simple merge commit, using the PR description as message
rebase-merge rebases the PR on top of the target branch the integrates with a merge commit, using the PR description as message
rebase-ff rebases the PR on top of the target branch, then fast-forwards
squash squashes the PR as a single commit on the target branch, using the PR description as message
delegate+ grants approval rights to the PR author
delegate=<...> grants approval rights on this PR to the specified github users
nice only stages the PR if there's room in the batch after default PRs
default stages the PR normally
priority tries to stage this PR first, then adds default PRs if the staging has room
alone stages this PR only with other PRs of the same priority
cancel=staging automatically cancels the current staging when this PR becomes ready
override=<...> marks overridable statuses as successful
check fetches or refreshes PR metadata, resets mergebot state

Note: this help text is dynamic and will change with the state of the PR.

@rov-adhoc
Copy link

@roboadhoc r+ nobump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments