Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6592ce9
docs(Core4): README espejo — rol operador + frontera cliente
danielitoCode Sep 1, 2026
b28861d
docs(Core4): checklist espejo AT — ítems operador y frontera
danielitoCode Sep 1, 2026
e4539fd
docs(Core4): STATUS vivo AT — abierto
danielitoCode Sep 1, 2026
7663ec2
docs(roadmap): registrar Core4 abierto (espejo finanzas de ventas)
danielitoCode Sep 1, 2026
ee03c6a
B0 Checked
Danielito1996 Sep 1, 2026
cb42007
feat(Core4/B1): SaleFinanceWrite/Line con unitCostSnapshot (paridad p…
danielitoCode Sep 1, 2026
2ba1030
feat(Core4/B1): repo operador persiste lines_json cuando hay líneas
danielitoCode Sep 1, 2026
f9912ae
docs(Core4): B0 cerrado AT; B1 tipos/repo lines_json hechos
danielitoCode Sep 1, 2026
19e71aa
docs(Core4): STATUS AT — B0/B1 tipos listos
danielitoCode Sep 1, 2026
350e56d
feat(Core4 B3): operator finance escribe lines + unitCostSnapshot (pa…
danielitoCode Sep 1, 2026
12f8c77
test(Core4 B3): assert operator finance lines + unitCostSnapshot
danielitoCode Sep 1, 2026
352d83d
test(Core4): tipado Triple cost nullable para FakeStockRepo
danielitoCode Sep 1, 2026
3fc535d
docs(Core4): marcar B3 código + unit tests; smoke dispositivo pendiente
danielitoCode Sep 1, 2026
5ab15cd
docs(Core4): STATUS AT — B3 código cerrado; B4 siguiente
danielitoCode Sep 1, 2026
5ca570a
feat(web): add unified catalog search filters and currency
danielitoCode Sep 1, 2026
775d36b
feat(web): integrate unified catalog search bar
danielitoCode Sep 1, 2026
96d01c5
feat(web): wire unified catalog filters into product screen
danielitoCode Sep 1, 2026
9d34136
fix(web): harden unified catalog filter inputs
danielitoCode Sep 1, 2026
517cb69
ci: incluir Core4 en CI Android Operador
danielitoCode Sep 1, 2026
93cc1a3
fix(web): filter catalog by effective sale price
danielitoCode Sep 1, 2026
b496d29
ci: incluir Core4 en CI Android Cliente
danielitoCode Sep 1, 2026
6b657e4
ci: incluir Core4 en CI Web
danielitoCode Sep 1, 2026
2c110a4
ci: incluir Core4 en CI MCP
danielitoCode Sep 1, 2026
be7b9d8
ci: incluir Core3 y Core4 en coverage Android cliente
danielitoCode Sep 1, 2026
9e74c48
fix(catalog): panel de filtros fixed para evitar recorte por overflow…
danielitoCode Sep 1, 2026
22a1a5e
fix(product): detalle de producto fixed al viewport para no desplazar…
danielitoCode Sep 1, 2026
628daa3
fix(catalog): texto del segmento Categoría refleja filtros activos
danielitoCode Sep 2, 2026
5dd90a3
ux(catalog): filtros de categoría instantáneos + aplicar solo rango d…
danielitoCode Sep 2, 2026
aaf5609
test(scan): B4 espejo — createIdempotent no recalcula ni duplica con …
danielitoCode Sep 2, 2026
b1eb065
fix(scan): CI compileDebugUnitTestKotlin — FakeStockRepo sin clash JV…
danielitoCode Sep 2, 2026
a845f8e
docs(Core4): espejo B5 — paridad panel/operador + checklist
danielitoCode Sep 2, 2026
3e267a4
docs(Core4): B6 — PR #28 abierto, frontera MCP/web documentada
danielitoCode Sep 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/android-tests-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ on:
- master
- develop
- Core2
- Core3
- Core4
pull_request:
branches:
- main
- master
- develop
- Core2
- Core3
- Core4
workflow_dispatch:

permissions:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ci-android-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Android Cliente

on:
push:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "app/**"
- "shared-*/**"
Expand All @@ -16,7 +16,7 @@ on:
- "gradle.properties"
- ".github/workflows/ci-android-client.yml"
pull_request:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "app/**"
- "shared-*/**"
Expand All @@ -32,7 +32,6 @@ on:

concurrency:
group: ci-android-client-${{ github.ref }}
# false: pushes rápidos ya no cancelan el job a mitad (mensaje «operación cancelada»)
cancel-in-progress: false

permissions:
Expand Down Expand Up @@ -65,7 +64,6 @@ jobs:
- name: Placeholder local.properties
run: |
echo "sdk.dir=$ANDROID_HOME" > local.properties
# Agent keys opcionales (vacías en CI; BuildConfig las inyecta como "")
echo "MISTRAL_API_KEY=" >> local.properties
echo "MISTRAL_AGENT_ID=" >> local.properties
echo "MISTRAL_MODEL_ID=mistral-medium-latest" >> local.properties
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-android-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Android Operador

on:
push:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "alejotallerscan/**"
- "shared-*/**"
Expand All @@ -16,7 +16,7 @@ on:
- "gradle.properties"
- ".github/workflows/ci-android-operator.yml"
pull_request:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "alejotallerscan/**"
- "shared-*/**"
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ci-mcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ name: CI MCP

on:
push:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "mcp/**"
- ".github/workflows/ci-mcp.yml"
- ".github/workflows/ci-gate.yml"
pull_request:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "mcp/**"
- ".github/workflows/ci-mcp.yml"
Expand Down Expand Up @@ -79,5 +79,3 @@ jobs:
MCP_SMOKE_URL: https://alejotaller-mcp.daniel-imbert96.workers.dev
MCP_SMOKE_TIMEOUT_MS: "20000"
run: node scripts/smoke-health.mjs
# If deploy lags behind master, this can fail until wrangler deploy runs.
# workflow_dispatch allows re-run after deploy.
6 changes: 2 additions & 4 deletions .github/workflows/ci-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: CI Web

on:
push:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "web/**"
- ".github/workflows/ci-web.yml"
pull_request:
branches: [master, main, Core2, Core3]
branches: [master, main, Core2, Core3, Core4]
paths:
- "web/**"
- ".github/workflows/ci-web.yml"
Expand Down Expand Up @@ -39,8 +39,6 @@ jobs:
cache: npm
cache-dependency-path: web/package-lock.json

# npm ci requires package-lock in sync with package.json.
# Use npm install if lock is stale (still installs deterministic-enough for CI).
- name: Install dependencies
run: |
if npm ci; then
Expand Down
25 changes: 25 additions & 0 deletions .roadmap/Core4/CORE4_UNIFIED_CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Core 4 — Checklist (AlejoTaller)

**Última actualización:** 2026-09-02
**Rama:** `Core4`
**PR:** https://github.com/danielitoCode/AlejoTaller/pull/28
**Canónico:** [dash checklist](https://github.com/danielitoCode/dash_alejo_taller/blob/Core4/.roadmap/Core4/CORE4_UNIFIED_CHECKLIST.md)

## B0–B5

- [x] Baseline, contrato, write operador, B4 no-reescritura, paridad docs

## B6

- [x] MCP prohíbe `sale_finance_event` (SCOPE/DATA_CONTRACT)
- [x] Web sin create finance
- [x] Unit operador: DELETED sin finance; createIdempotent B4
- [ ] Smoke device (opcional)
- [ ] CI verde PR #28
- [ ] Merge coordinado con dash PR #21

## Registro

| Fecha | Nota |
|---|---|
| 2026-09-02 | B6: PR #28 abierto |
17 changes: 17 additions & 0 deletions .roadmap/Core4/MVP_CORE4_STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# MVP Core 4 — Estado vivo (AlejoTaller)

**Última actualización:** 2026-09-02
**Rama:** `Core4`
**PR:** https://github.com/danielitoCode/AlejoTaller/pull/28
**Core 4:** B0–B5 hecho; B6 código/frontera OK — CI + merge pendientes

| Bloque | Estado |
|--------|--------|
| B0–B5 | **Cerrado** |
| B6 frontera (MCP/web sin write finance) | **Documentado** |
| B6 smoke device | Opcional |
| B6 CI + merge | **Pendiente** PR #28 |

### Acción

Esperar CI verde en PR #28 y coordinar merge con dash PR #21.
21 changes: 21 additions & 0 deletions .roadmap/Core4/PARITY_PANEL_OPERATOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Core 4 — Paridad panel (dash) vs operador (AlejoTaller scan)

**Fecha:** 2026-09-02 · rama `Core4`
**Canónico completo:** [dash PARITY](https://github.com/danielitoCode/dash_alejo_taller/blob/Core4/.roadmap/Core4/PARITY_PANEL_OPERATOR.md)

## Escritura operador

| Campo Appwrite | Origen AT |
|----------------|-----------|
| `sale_id` | `SaleFinanceWrite.saleId` |
| `revenue` | `sale.amount` |
| `cogs` | Σ `unitCostSnapshot × qty` |
| `margin` | `revenue − cogs` |
| `user_id` | operador actual |
| `at` | ISO now |
| `currency` | `sale.currency.name` |
| `lines_json` | JSON camelCase (`productId`, `unitCostSnapshot`, …) |

`createIdempotent`: si ya hay doc por `sale_id`, devolver existente (B4).

Cliente web / MCP: **sin** write a finance.
42 changes: 42 additions & 0 deletions .roadmap/Core4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Core 4 — Finanzas de Ventas (AlejoTaller)

**Estado:** abierto · rama `Core4`
**Dependencia:** Core 2 cerrado · Core 3 (espejo / costos en panel)
**Canónico de orden / política:** [dash_alejo_taller/.roadmap/Core4](https://github.com/danielitoCode/dash_alejo_taller/tree/Core4/.roadmap/Core4)

## Rol de este monorepo

Core 4 es **paridad financiera** al confirmar ventas. El contrato lo define el panel; aquí se implementa el **write del operador** y se protege la frontera B2C.

| Superficie | Qué hacer en Core 4 |
|------------|---------------------|
| **alejotallerscan (operador)** | Al VERIFIED: `sale_finance_event` con **snapshot por línea** (mismo contrato que el panel); idempotente por `sale_id` |
| **web / app (cliente)** | **Nada** de write finance; solo crea `UNVERIFIED` |
| **mcp** | Sin tools que escriban `sale_finance_event` |
| **docs / policies** | Espejo de checklist y notas de paridad |

## Qué ya resolvió Core 2 (no repetir desde cero)

- Operador: `salida_venta` + `sale_finance_event` agregado (revenue / cogs / margin) al confirm
- COGS = Σ `last_unit_cost × qty` leído en el momento del confirm
- Idempotencia básica por `sale_id`
- DELETED sin finance

## Objetivo de este espejo

1. Alinear el write del operador al contrato Core 4 (líneas + `unit_cost_snapshot`)
2. Garantizar que un reintento o un cambio posterior de `last_unit_cost` **no** duplique ni reescriba el evento
3. Mantener cliente/MCP sin capacidad de crear ingresos

## Documentos

| Doc | Rol |
|------|-----|
| [CORE4_UNIFIED_CHECKLIST.md](./CORE4_UNIFIED_CHECKLIST.md) | Ítems **AT** del orden B0–B6 |
| [MVP_CORE4_STATUS.md](./MVP_CORE4_STATUS.md) | Estado vivo de este monorepo |

## Criterio de merge a `master`

- Código operador + frontera + docs alineados al checklist AT.
- Coordinar con el PR de `dash_alejo_taller` `Core4` → `master`.
- No merge a producción hasta CI verde en ambos.
2 changes: 2 additions & 0 deletions .roadmap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ Estructura por núcleo de entrega:
| [`Core1/`](./Core1/) | Auth visitante, Sale UNVERIFIED + soft-hold, Warehouse, operador confirm/reject, QA | **Cerrado** (2026-08-12) |
| [`Core2/`](./Core2/) | `salida_venta` + finance al VERIFIED (operador); factura/movements/COGS/reservas en **dash** | **Cerrado** (2026-08-24) |
| [`Core3/`](./Core3/) | Compras y abastecimiento (espejo; UI en dash) | **Listo para merge** · rama `Core3` |
| [`Core4/`](./Core4/) | Finanzas de ventas — paridad operador (snapshot COGS / líneas) + frontera cliente | **Abierto** · rama `Core4` |

**Cómo usar**
- Marca checkboxes `[x]` cuando verifiques.
- Core 1 y Core 2 cerrados a nivel ecosistema.
- **Core 3:** release mínimo del panel (B3.1) listo; este monorepo solo docs/frontera — PR `Core3` → `master`.
- **Core 4:** trabajo en `Core4`; canónico de política/checklist en dash; aquí B3 operador + frontera.

**Políticas de producto:** [`.policies/`](../.policies/)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.elitec.alejotallerscan.feature.finance.data.repository

import android.util.Log
import com.elitec.alejotallerscan.BuildConfig
import com.elitec.alejotallerscan.feature.finance.domain.entity.SaleFinanceLineWrite
import com.elitec.alejotallerscan.feature.finance.domain.entity.SaleFinanceRecord
import com.elitec.alejotallerscan.feature.finance.domain.entity.SaleFinanceWrite
import com.elitec.alejotallerscan.feature.finance.domain.repository.OperatorSaleFinanceRepository
import io.appwrite.ID
import io.appwrite.Query
import io.appwrite.services.Databases
import org.json.JSONArray
import org.json.JSONObject

class AppwriteOperatorSaleFinanceRepository(
private val databases: Databases
Expand All @@ -34,7 +37,8 @@ class AppwriteOperatorSaleFinanceRepository(
saleId = (data["sale_id"] as? String).orEmpty(),
revenue = (data["revenue"] as? Number)?.toDouble() ?: 0.0,
cogs = (data["cogs"] as? Number)?.toDouble() ?: 0.0,
margin = (data["margin"] as? Number)?.toDouble() ?: 0.0
margin = (data["margin"] as? Number)?.toDouble() ?: 0.0,
lines = parseLinesJson(data["lines_json"] as? String)
)
}

Expand All @@ -55,6 +59,9 @@ class AppwriteOperatorSaleFinanceRepository(
"at" to event.atIso
)
event.currency?.takeIf { it.isNotBlank() }?.let { data["currency"] = it }
if (event.lines.isNotEmpty()) {
data["lines_json"] = serializeLines(event.lines)
}

val doc = databases.createDocument(
databaseId = BuildConfig.APPWRITE_DATABASE_ID,
Expand All @@ -65,17 +72,72 @@ class AppwriteOperatorSaleFinanceRepository(
Log.i(
TAG,
"event=operator_finance_created id=${doc.id} saleId=${event.saleId} " +
"revenue=${event.revenue} cogs=${event.cogs} margin=${event.margin}"
"revenue=${event.revenue} cogs=${event.cogs} margin=${event.margin} lines=${event.lines.size}"
)
return SaleFinanceRecord(
id = doc.id,
saleId = event.saleId,
revenue = event.revenue,
cogs = event.cogs,
margin = event.margin
margin = event.margin,
lines = event.lines
)
}

private fun serializeLines(lines: List<SaleFinanceLineWrite>): String {
val arr = JSONArray()
for (l in lines) {
arr.put(
JSONObject()
.put("productId", l.productId)
.put("quantity", l.quantity)
.put("unitPrice", l.unitPrice)
.put("unitCostSnapshot", l.unitCostSnapshot)
.put("lineRevenue", l.lineRevenue)
.put("lineCogs", l.lineCogs)
.put("lineMargin", l.lineMargin)
)
}
return arr.toString()
}

private fun parseLinesJson(raw: String?): List<SaleFinanceLineWrite> {
if (raw.isNullOrBlank()) return emptyList()
return runCatching {
val arr = JSONArray(raw)
buildList {
for (i in 0 until arr.length()) {
val o = arr.optJSONObject(i) ?: continue
val productId = o.optString("productId").ifBlank {
o.optString("product_id")
}
if (productId.isBlank()) continue
val quantity = o.optInt("quantity", 0)
if (quantity <= 0) continue
val unitPrice = o.optDouble("unitPrice", o.optDouble("unit_price", 0.0))
val unitCostSnapshot = o.optDouble(
"unitCostSnapshot",
o.optDouble("unit_cost_snapshot", 0.0)
)
val lineRevenue = o.optDouble("lineRevenue", unitPrice * quantity)
val lineCogs = o.optDouble("lineCogs", unitCostSnapshot * quantity)
val lineMargin = o.optDouble("lineMargin", lineRevenue - lineCogs)
add(
SaleFinanceLineWrite(
productId = productId,
quantity = quantity,
unitPrice = unitPrice,
unitCostSnapshot = unitCostSnapshot,
lineRevenue = lineRevenue,
lineCogs = lineCogs,
lineMargin = lineMargin
)
)
}
}
}.getOrDefault(emptyList())
}

companion object {
private const val TAG = "OperatorFinanceRepo"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package com.elitec.alejotallerscan.feature.finance.domain.entity

/**
* Línea de sale_finance_event (Core 4).
* unitCostSnapshot = last_unit_cost congelado al confirm.
* Paridad con dash SaleFinanceLine / lines_json.
*/
data class SaleFinanceLineWrite(
val productId: String,
val quantity: Int,
val unitPrice: Double,
val unitCostSnapshot: Double,
val lineRevenue: Double,
val lineCogs: Double,
val lineMargin: Double
)

/**
* Evento financiero al VERIFIED. UNVERIFIED / DELETED no generan documento.
* COGS = sum(last_unit_cost × qty). margin = revenue − cogs.
* COGS = sum(unitCostSnapshot × qty). margin = revenue − cogs.
* Core 4: [lines] se serializa a lines_json en Appwrite (Opción A).
*/
data class SaleFinanceWrite(
val saleId: String,
Expand All @@ -11,13 +27,15 @@ data class SaleFinanceWrite(
val margin: Double,
val userId: String,
val atIso: String,
val currency: String?
val currency: String?,
val lines: List<SaleFinanceLineWrite> = emptyList()
)

data class SaleFinanceRecord(
val id: String,
val saleId: String,
val revenue: Double,
val cogs: Double,
val margin: Double
val margin: Double,
val lines: List<SaleFinanceLineWrite> = emptyList()
)
Loading
Loading