[ADD] stock_ux: invariant battery for the stock test suites - #1012
Open
jcadhoc wants to merge 1 commit into
Open
[ADD] stock_ux: invariant battery for the stock test suites#1012jcadhoc wants to merge 1 commit into
jcadhoc wants to merge 1 commit into
Conversation
Add a battery of invariants that must hold after any stock operation, so a test verifies not only what its scenario went looking for, but also that nothing broke next to it. The battery lives in stock_ux because it is the root of the Adhoc stock dependency chain: the modules that declare it in depends inherit it without copying it, and a shared battery cannot be quietly relaxed the way per-module copies can. Invariants: - assert_sin_moves_extra: the picking gains no move nobody asked for. - assert_cantidad_no_supera_demanda: no quantity above the initial demand when the operation type blocks additionals. - assert_sin_disponible_negativo: no internal source location left with negative availability. - assert_lineas_con_descripcion: every operation line carries a description. - assert_estados_consistentes: a validated picking leaves every move done or cancelled, and none done at zero quantity. - assert_sin_pickings_contraflujo: the document generates no picking in the opposite direction to its own. Parametrized by the codes each consuming module declares, so a sale declares outgoing/internal and a purchase incoming/internal instead of hardcoding one flow. Each invariant is tested in both directions: that it stays quiet on a sane operation, and that it detects the defective one it exists to catch. Without the second direction there is no evidence the invariant looks at anything. Change note: se agrega la batería de invariantes de stock_ux con sus tests en los dos sentidos. No cambia comportamiento de producto: es infraestructura de testing que heredan los módulos que dependen de stock_ux.
Collaborator
There was a problem hiding this comment.
Pull request overview
Este PR agrega infraestructura de testing para stock_ux: una batería reusable de invariantes de stock (mixin) y una suite de tests que valida cada invariante en “verde” y “rojo”, para que las suites consumidoras puedan detectar estados inconsistentes luego de operaciones.
Cambios:
- Incorpora el mixin
StockUxInvariantscon invariantes aplicables a pickings y a conjuntos de pickings por documento. - Agrega
TestInvariantspara probar cada invariante en ambos sentidos (no molesta / detecta). - Suma un
StockUxCommonpara construir escenario controlado (tipos de operación propios, helpers) e integra los tests entests/__init__.py.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| stock_ux/tests/invariants.py | Define el mixin con invariantes y runners (assert_bateria, assert_bateria_documento). |
| stock_ux/tests/test_invariants.py | Suite de tests que valida las invariantes en “verde” y “rojo”. |
| stock_ux/tests/common.py | Base común de escenario y helpers para tests (picking types propios, creación de pickings/stock). |
| stock_ux/tests/init.py | Registra nuevos módulos de tests/helpers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+53
to
+55
| real = {} | ||
| for move in vivos: | ||
| real[move.product_id] = real.get(move.product_id, 0.0) + move.product_uom_qty |
Comment on lines
+168
to
+169
| if any(not move.origin_returned_move_id for move in picking.move_ids): | ||
| contraflujo |= picking |
Comment on lines
+195
to
+197
| self.assert_sin_pickings_contraflujo(pickings, codigos_esperados) | ||
| for picking in pickings: | ||
| self.assert_bateria(picking) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Qué hace
Agrega una batería de invariantes para las suites de tests de stock, en
stock_ux/tests/. No cambia comportamiento de producto: es infraestructura de testing.Una invariante es una propiedad que tiene que valer después de cualquier operación, no lo que un escenario puntual fue a buscar. El caso que lo motiva: un test que verifica que un número está bien no ve lo que quedó roto al lado — una línea de más, un estado intermedio, un movimiento que nadie pidió. Los bugs que llegan como incidentes casi nunca son "el número está mal", son "el número está bien, pero al lado quedó algo roto".
Por qué en
stock_uxEs la raíz de la cadena Adhoc de stock (depende solo de core). Los módulos que lo declaran en
dependsheredan la batería sin copiarla. Copias por módulo se pudren: alguien relaja una para que su test pase y nadie lo ve.Invariantes
assert_sin_moves_extraassert_cantidad_no_supera_demandaassert_sin_disponible_negativoassert_lineas_con_descripcionassert_estados_consistentesassert_sin_pickings_contraflujoLa última está parametrizada (
codigos_esperados): la forma se comparte, el conjunto lo declara cada módulo consumidor — una venta declara("outgoing", "internal"); una compra,("incoming", "internal"). Sin ese parámetro marcaría como bug toda recepción legítima en el flujo de compras.assert_bateriacorre la batería sobre un picking;assert_bateria_documentosobre el conjunto de pickings que generó un documento, que es el punto de entrada para los módulos cuyo documento genera más de un picking.Decisiones de diseño
Test plan
Base Odoo 19 limpia con
sale_stock_uxinstalado.Sin warnings de addons (runbot los trata como error).
Rojo demostrado. Neutralizando la condición de
assert_sin_pickings_contraflujo(if any(not move.origin_returned_move_id ...)→if False):Fallan exactamente los dos tests que dicen detectarla, y ninguno de los otros. Código restaurado y verde de nuevo.
Qué sigue
Las suites que consumen esta batería van en PRs aparte, por módulo. El primero es
sale_stock_ux, que además suma dos invariantes propias (las que leen campos que ese módulo define).Task: https://www.adhoc.inc/odoo/project.task/72661