Integra: la factura solo a dirección

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jorem JuárezandClaude Fable 5 committed 2026-09-14 12:27:08 -06:00
commit 46b6255a8a
2 files changed
+58 -14

No files matched your search

@@ -578,12 +578,16 @@ class BeyondInventarioPantalla(models.AbstractModel):
movimientos = self.env['beyond.movimiento'].search(
dominio, order='fecha desc, id desc')
# El adjunto de un movimiento es la FACTURA de compra: el documento
# del costo. Viaja con el mismo pase que el costo (14-sep, segunda
# decisión del Director): al gerente ni se le consultan.
adjuntos = {}
for adj in self.env['ir.attachment'].search_read(
[('res_model', '=', 'beyond.movimiento'),
('res_id', 'in', movimientos.ids)], ['res_id', 'name']):
adjuntos.setdefault(adj['res_id'], []).append(
{'id': adj['id'], 'nombre': adj['name']})
if self._beyond_es_director():
for adj in self.env['ir.attachment'].search_read(
[('res_model', '=', 'beyond.movimiento'),
('res_id', 'in', movimientos.ids)], ['res_id', 'name']):
adjuntos.setdefault(adj['res_id'], []).append(
{'id': adj['id'], 'nombre': adj['name']})
etiquetas = dict(self.env['beyond.movimiento']._fields['tipo'].selection)
motivos = dict(self.env['beyond.movimiento']._fields['motivo'].selection)
@@ -693,8 +697,8 @@ class BeyondInventarioPantalla(models.AbstractModel):
] if datos['con_dinero'] else []) + [
{'etiqueta': _('Quién'), 'formato': 'texto'},
{'etiqueta': _('Detalle'), 'formato': 'texto'},
{'etiqueta': _('Factura'), 'formato': 'texto'},
],
] + ([{'etiqueta': _('Factura'), 'formato': 'texto'}]
if datos['con_dinero'] else []),
'filas': [
[f['fecha'], f['articulo'], f['movimiento'], f['cantidad'],
f['resultante']]
@@ -706,8 +710,9 @@ class BeyondInventarioPantalla(models.AbstractModel):
else '—'),
] if datos['con_dinero'] else []) + [
f['quien'], f['detalle'],
', '.join(a['nombre'] for a in f['adjuntos']) or '—',
] for f in filas_pdf],
] + ([', '.join(a['nombre'] for a in f['adjuntos']) or '—']
if datos['con_dinero'] else [])
for f in filas_pdf],
'total_filas': filas_total,
'grafica': None,
}],
@@ -755,12 +760,14 @@ class BeyondInventarioPantalla(models.AbstractModel):
dominio.append(('motivo', '=', motivo))
movimientos = self.env['beyond.movimiento'].search(dominio)
# La factura, solo a dirección: es el documento del costo (14-sep).
adjuntos = {}
for adj in self.env['ir.attachment'].search_read(
[('res_model', '=', 'beyond.movimiento'),
('res_id', 'in', movimientos.ids)], ['res_id', 'name']):
adjuntos.setdefault(adj['res_id'], []).append(
{'id': adj['id'], 'nombre': adj['name']})
if self._beyond_es_director():
for adj in self.env['ir.attachment'].search_read(
[('res_model', '=', 'beyond.movimiento'),
('res_id', 'in', movimientos.ids)], ['res_id', 'name']):
adjuntos.setdefault(adj['res_id'], []).append(
{'id': adj['id'], 'nombre': adj['name']})
etiquetas = dict(self.env['beyond.movimiento']._fields['tipo'].selection)
motivos = dict(self.env['beyond.movimiento']._fields['motivo'].selection)
filas = [{
@@ -470,6 +470,43 @@ class TestBeyondLibroSinDineroParaElGerente(BeyondBranchCase):
self.assertNotIn(vedado, celdas,
f'al gerente se le fue «{vedado}» en el archivo')
def test_la_factura_tampoco_le_viaja_al_gerente(self):
"""El adjunto de un movimiento es la FACTURA de compra: el documento
del costo, y viaja con su mismo pase (14-sep, segunda decisión). Al
gerente le llegan los renglones con la lista de adjuntos VACÍA — ni
los ids, que serían la mitad de la URL de descarga."""
Pantalla = self.env['beyond.inventario'].with_user(self.admin_general)
Pantalla.beyond_recibir(
[{'id': self.tinte.id, 'cantidad': 2, 'costo': 300.0}],
branch_id=self.branch_a.id, nota='ZZ con factura',
adjunto={'nombre': 'factura-gerente.pdf',
'datas': base64.b64encode(b'%PDF-1.4 zz').decode()})
libro = self._libro(self.admin_a)
self.assertTrue(all(f['adjuntos'] == [] for f in libro['filas']),
'al gerente le viajaron adjuntos en el libro')
historial = self.env['beyond.inventario'].with_user(
self.admin_a).beyond_historial(self.tinte.id, self.branch_a.id)
self.assertTrue(all(f['adjuntos'] == [] for f in historial['filas']),
'al gerente le viajaron adjuntos en el historial')
# A dirección le siguen llegando, que la factura es suya.
de_direccion = self._libro(self.admin_general)
nombres = [a['nombre'] for f in de_direccion['filas']
for a in f['adjuntos']]
self.assertIn('factura-gerente.pdf', nombres)
# Y su archivo tampoco la nombra: ni la columna ni el nombre.
archivo = self.env['beyond.inventario'].with_user(
self.admin_a).beyond_movimientos_descarga(
'xlsx', dict(self.filtros), self.branch_a.id)
celdas = [c.value for hoja in openpyxl.load_workbook(
io.BytesIO(base64.b64decode(archivo['contenido']))).worksheets
for fila in hoja.iter_rows() for c in fila]
self.assertNotIn('Factura', celdas)
self.assertNotIn('factura-gerente.pdf', celdas)
def test_el_historial_del_articulo_tampoco_le_dice_el_costo(self):
historial = self.env['beyond.inventario'].with_user(
self.admin_a).beyond_historial(self.tinte.id, self.branch_a.id)