-
Notifications
You must be signed in to change notification settings - Fork 72
[REF] stock_ux: move exchange move logic from sale_stock to stock_ux #853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # For copyright and license notices, see __manifest__.py file in module root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from odoo import _, api, models | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from odoo.exceptions import UserError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class StockReturnPicking(models.TransientModel): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _inherit = "stock.return.picking" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @api.model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def default_get(self, fields): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Get sale order for lines.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Get sale order for lines.""" | |
| """Set to_refund to True by default for all product return move lines.""" |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El uso de assert en código de producción no es apropiado. Las assertions se eliminan cuando Python se ejecuta en modo optimizado (-O). Si necesitas validar que line[0] == 0, debes usar una validación explícita con una excepción adecuada, o mejor aún, simplemente procesar las líneas sin asumir su estructura. Considera reemplazarlo por una validación condicional o removerlo si no es estrictamente necesario.
| try: | |
| for line in result["product_return_moves"]: | |
| assert line[0] == 0 | |
| # en realidad no nos importa si hay linea de venta o no ya que | |
| # también lo usamos en compras y queremos que en todo caso este | |
| line[2]["to_refund"] = True | |
| except KeyError: | |
| pass | |
| for line in result.get("product_return_moves", []): | |
| if ( | |
| isinstance(line, (list, tuple)) | |
| and len(line) > 2 | |
| and line[0] == 0 | |
| and isinstance(line[2], dict) | |
| ): | |
| # en realidad no nos importa si hay linea de venta o no ya que | |
| # también lo usamos en compras y queremos que en todo caso este | |
| line[2]["to_refund"] = True |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
| try: | |
| for line in result["product_return_moves"]: | |
| assert line[0] == 0 | |
| # en realidad no nos importa si hay linea de venta o no ya que | |
| # también lo usamos en compras y queremos que en todo caso este | |
| line[2]["to_refund"] = True | |
| except KeyError: | |
| pass | |
| if "product_return_moves" in result: | |
| for line in result["product_return_moves"]: | |
| assert line[0] == 0 | |
| # en realidad no nos importa si hay linea de venta o no ya que | |
| # también lo usamos en compras y queremos que en todo caso este | |
| line[2]["to_refund"] = True |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El método _prepare_picking_default_values_based_on intenta asignar is_exchange_move al diccionario de valores del picking, pero el campo is_exchange_move no existe en el modelo stock.picking. Solo está definido en stock.move (línea 34 de stock_move.py). Esto causará que el valor se ignore silenciosamente o genere un error al intentar crear/escribir el picking. Debes agregar el campo is_exchange_move también al modelo stock.picking si es necesario marcarlo a nivel de transferencia, o remover esta asignación si solo se necesita a nivel de movimiento.
| vals = super()._prepare_picking_default_values_based_on(picking) | |
| if self.env.context.get("is_exchange_move"): | |
| vals["is_exchange_move"] = True | |
| return vals | |
| return super()._prepare_picking_default_values_based_on(picking) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <record id="view_stock_return_picking_form" model="ir.ui.view"> | ||
| <field name="name">Improve refunds wizard</field> | ||
| <field name="inherit_id" ref="stock.view_stock_return_picking_form"/> | ||
| <field name="model">stock.return.picking</field> | ||
| <field name="arch" type="xml"> | ||
| <field name="product_return_moves" position="before"> | ||
| <div class="alert alert-info" role="alert" style="margin-bottom:0px;"> | ||
| <b>Importante</b>: si está haciendo un movimiento inverso relacionado a un Pedido de Venta o de Compra, entonces debe prestar atención al campo <b>"Para Abonar (actualizar OC/OV)"</b>, donde, si: | ||
| <ul> | ||
| <li> | ||
| <b>Está marcado</b>: entonces <b>se va</b> a actualizar la OC/OV considerando que los productos devueltos no se van a volver a entregar, y por ende, permitiendo hacer una nota de crédito si los items ya fueron facturados, o tener en cuenta esta devolución al hacer la factura. | ||
| </li> | ||
| <li> | ||
| <b>No está marcado</b>: entonces <b>no se va</b> a actualizar la OC/OV. Esto es común, por ejemplo, si se devuelve mercadería defectuosa y se pretende hacer una nueva entrega de la misma. | ||
| </li> | ||
| </ul> | ||
| Si la devolución no está ligada a una OC/OV entonces este campo no repercute en nada. | ||
| </div> | ||
| </field> | ||
| <field name="to_refund" position="attributes"> | ||
| <!-- porque lo queremos usar tmb en oc y esto lo hace no marcable --> | ||
| <attribute name="attrs"></attribute> | ||
| <!-- always show the button --> | ||
| <attribute name="groups"></attribute> | ||
| <!-- porque la traducción no se actualiza --> | ||
| <attribute name="string">Para Abonar (actualizar OC/OV)</attribute> | ||
| </field> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se está agregando el campo almacenado
is_exchange_moveal modelostock.move(cambio estructural). Debes agregar un script de migración enmigrations/19.0.2.0.0/para asegurar que el campo se inicialice correctamente en registros existentes. Aunque el campo es booleano y PostgreSQL lo inicializará a False por defecto, es recomendable documentar esto explícitamente mediante un script post-migración que registre la operación en logs para futuras referencias.