Añadir actualización opcional de stock y datos de compra al importar facturas#46
Merged
Merged
Conversation
FacturaScripts Playground Preview
Try this PR in your browser This preview is generated automatically for the |
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/6d55aadf-bfa3-494f-bede-f0fdddccb666 Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/6d55aadf-bfa3-494f-bede-f0fdddccb666 Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add option to add invoice line items to inventory
Add optional stock and purchase-data updates to AiScan invoice imports
May 20, 2026
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/e4ff998d-1393-4064-927a-69c97e9bae17 Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/a683e196-b492-4dce-9aea-27ef5178811c Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/a683e196-b492-4dce-9aea-27ef5178811c Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/bac10e7a-0192-4197-94ef-60aad89474ef Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/ce77c561-522d-4fda-8668-aaa24200e2bf Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/1fd3b1f4-c7ef-4a30-9825-9b047f10bb3c Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/b64c2300-936d-417b-9253-22386c86e65b Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/b64c2300-936d-417b-9253-22386c86e65b Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/e4bfa2ad-0568-48d7-9228-61e1dd51345c Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/1be0b80e-9789-4c16-b6c4-7997cdca3b12 Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/be1e17e6-0eb8-4e49-91b6-528235b42c03 Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/be1e17e6-0eb8-4e49-91b6-528235b42c03 Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
…) for PHPUnit 13 Agent-Logs-Url: https://github.com/erseco/facturascripts-plugin-AiScan/sessions/68c975d9-7e1c-4701-a8db-7b9e9a0042fe Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Resolve conflicts in workflow.js and InvoiceMapper to combine the payment-method selector from #48 with the stock/purchase-data update flow. Force actualizastock=0 on built lines so the inventory updater is the single source of truth for stock changes, fixing the failing InvoiceMapperStockUpdateTest cases (disabled flag + invalid quantity) where setReceivedStatus was auto-incrementing stock.
…k on invalid quantity - Only call setReceivedStatus when updateStockPurchaseData is enabled so the FS core state-change loop does not auto-bump stock for invoices the user imported with the toggle off (test 1). - When the inventory updater skips a line for invalid quantity, force actualizastock back to 0 and save to reverse any stock added by the state transition before the updater ran (test 2). - Ensure the invalid-payment-method error always contains the offending codpago string, even when the plugin translation file is not loaded in the test environment (test 3).
…abled Reverting the earlier 'skip setReceivedStatus when disabled' shortcut broke success=true in the PHP-matrix CI (something in the slim test env needs the invoice advanced to a real state). Restore the original unconditional call to setReceivedStatus, and undo its stock side effects in the inventory updater by resetting actualizastock=0 on every line when updateStockPurchaseData is false.
The PHP-matrix CI is asserting false=true with no clue why. Attach the errors array to the assertion message so the next run tells us what's actually being returned.
CI's PHP-matrix environment installs a bare FacturaScripts where new Proveedor instances do not get default codpago/codserie, causing the downstream FacturaProveedor save to fail with NOT NULL constraint errors. Look up the first available FormaPago / Serie and assign them before saving the supplier so the invoice mapper has the values it needs to persist the invoice.
The PHP-matrix CI's bare FacturaScripts install does not seed any Serie, so even after we set codpago the FacturaProveedor save still fails on codserie. Create a minimal 'A' serie when none exist and assign it to the supplier so the downstream invoice save can proceed.
PHPUnit 9 uses an int-based getStatus() (0 = PASSED), while PHPUnit 13 exposes a status() object with isSuccess(). The CI matrix uses 9.6 and Docker uses 13.1, so check method_exists for each.
- InvoiceMapper: skip the stock/purchase-data updater when import mode is 'total'. Total mode aggregates lines by tax with no linked products, so running the updater only produced misleading 'no product' warnings. - PurchaseLineInventoryUpdater: load the Variante once per line instead of twice (the old hasLinkedProduct() re-queried it) and drop the unused helper. Behavior is covered by the existing matched/unmatched-product tests.
060d922 to
79357f2
Compare
This was referenced May 31, 2026
erseco
added a commit
that referenced
this pull request
May 31, 2026
…S.md (#54) - Document the live upload -> AI extraction -> review -> import flow (make up, port, login, provider selection, fixtures) so the merged features can be exercised against a real provider, mirroring the ScheduledMail recipe. - Add Test/e2e-smoke.php: a non-interactive helper that runs the extraction + map + import path over the fixtures and reports invoice/attachment/warnings. - Fix outdated CI matrix references (8.1-8.4 -> 8.1-8.5 after the 8.5 addition). - Exclude the dev-only smoke helper from PHPCS, like the other Test/ scripts. No functional defects were found end-to-end testing today's merged PRs (#27 keyboard nav, #29 image attachments, #46 stock/purchase data, #48 payment method, #41 localized warnings, #31 tax-inclusive receipts); this PR only adds the validation guide, the smoke helper and the doc fixes.
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.
Implementa la propuesta del #37: poder volcar al inventario las líneas de las facturas importadas con AiScan.
Qué hace
Añade una opción opcional (desactivada por defecto) en el paso de importación que, al activarse, hace dos cosas por cada línea de la factura de proveedor:
ProductoProveedor): precio de compra, descuentos, divisa, fecha de actualización y, si viene en la extracción, la referencia del proveedor.La opción se controla con una casilla en la pantalla de importación (individual y por lote), y la decisión se propaga al backend (
update_stock_purchase_data).Cómo funciona
En lugar de mover el stock manualmente, se apoya en el mecanismo nativo de FacturaScripts: cada línea se crea con
actualizastock = 0y, cuando la opción está activa, elPurchaseLineInventoryUpdatermarcaactualizastock = 1y guarda la línea, dejando que el core calcule el movimiento de stock (con su lógica de delta: revierte la contribución anterior y aplica la nueva). Si la opción está desactivada, se garantiza que ninguna línea mueva stock.Comportamiento por línea (con avisos claros, sin abortar la importación)
nostock) → no se genera movimiento, pero sí se actualizan los datos de compra (aviso).Los avisos generados se devuelven al frontend y se muestran con un badge por documento y un modal de detalle.
Cobertura
Tests de integración contra modelos reales de FacturaScripts que cubren: stock sumado al activar, sin cambios al desactivar, producto
nostock, producto sin coincidencia, precio inválido, cantidad inválida y varias líneas de forma independiente.Notas
Closes #37