[IMP] account_background_post: add tests#230
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds a new test module to validate creating, duplicating, and mass-posting customer invoices, aiming to cover the core flow relevant to account_background_post.
- Introduces a TransactionCase test that creates a draft invoice, duplicates it, and posts all invoices in bulk.
- Wires the test into the test suite via tests/init.py.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| account_background_post/tests/test_crear_duplicar_y_validar_facturas_masivas_cliente.py | New end-to-end test for creating, duplicating, and posting customer invoices. |
| account_background_post/tests/init.py | Registers the new test module. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| # Paso 1: Creación de la Factura Borrador (Simulación 00:07 - 00:15) | ||
| move_line_vals = [ | ||
| (0, 0, {"product_id": self.producto.id, "quantity": 1.0, "price_unit": 100.00, "name": "Línea de Servicio"}) |
There was a problem hiding this comment.
El test asume 0% de impuestos pero no lo garantiza; si el producto o la compañía tienen impuestos por defecto, los montos no serán 100.00 y la aserción fallará. Propongo establecer explícitamente impuestos vacíos en la línea: agregar 'tax_ids': [(6, 0, [])].
| (0, 0, {"product_id": self.producto.id, "quantity": 1.0, "price_unit": 100.00, "name": "Línea de Servicio"}) | |
| (0, 0, { | |
| "product_id": self.producto.id, | |
| "quantity": 1.0, | |
| "price_unit": 100.00, | |
| "name": "Línea de Servicio", | |
| "tax_ids": [(6, 0, [])], | |
| }) |
| self.assertTrue( | ||
| all(f.state == "posted" for f in facturas_a_validar), | ||
| "Todas las facturas deben haber pasado a estado Publicado/Validado ('posted').", | ||
| ) |
There was a problem hiding this comment.
La verificación de estado 'posted' se realiza dos veces (aquí y en 100-103). Es redundante; elimina una de las dos para evitar duplicación.
| { | ||
| "partner_id": self.cliente.id, | ||
| "move_type": "out_invoice", | ||
| "invoice_date": date.today(), |
There was a problem hiding this comment.
[nitpick] Para respetar el contexto/zonas horarias de Odoo en pruebas, use fields.Date.context_today(self) en lugar de date.today().
| # Usar un producto existente o crear uno con los valores por defecto necesarios | ||
| self.producto = self.env["product.product"].search([("type", "=", "service")], limit=1) | ||
| if not self.producto: | ||
| # Crear plantilla de producto primero | ||
| template = self.env["product.template"].create( | ||
| { | ||
| "name": "Servicio de Test", | ||
| "list_price": 100.00, | ||
| "type": "service", | ||
| } | ||
| ) | ||
| self.producto = template.product_variant_ids[0] |
There was a problem hiding this comment.
[nitpick] Buscar un producto existente puede introducir flakiness (p. ej., impuestos por defecto, cuentas o políticas diferentes). Para aislar el test, cree siempre un producto específico para la prueba con 'taxes_id': [(6, 0, [])] y demás campos requeridos.
| # Usar un producto existente o crear uno con los valores por defecto necesarios | |
| self.producto = self.env["product.product"].search([("type", "=", "service")], limit=1) | |
| if not self.producto: | |
| # Crear plantilla de producto primero | |
| template = self.env["product.template"].create( | |
| { | |
| "name": "Servicio de Test", | |
| "list_price": 100.00, | |
| "type": "service", | |
| } | |
| ) | |
| self.producto = template.product_variant_ids[0] | |
| # Siempre crear un producto específico para la prueba con taxes_id vacío y demás campos requeridos | |
| template = self.env["product.template"].create( | |
| { | |
| "name": "Servicio de Test", | |
| "list_price": 100.00, | |
| "type": "service", | |
| "taxes_id": [(6, 0, [])], | |
| } | |
| ) | |
| self.producto = template.product_variant_ids[0] |
| from odoo.tests.common import TransactionCase | ||
|
|
||
|
|
||
| class TestCrearDuplicarYValidarFacturasMasivasCliente(TransactionCase): |
There was a problem hiding this comment.
[nitpick] Considere usar SavepointCase en lugar de TransactionCase para acelerar las pruebas cuando no se necesitan commits ni verificar efectos de transacción.
| from odoo.tests.common import TransactionCase | |
| class TestCrearDuplicarYValidarFacturasMasivasCliente(TransactionCase): | |
| from odoo.tests.common import SavepointCase | |
| class TestCrearDuplicarYValidarFacturasMasivasCliente(SavepointCase): |
| factura_duplicada_1 = factura_base.copy() | ||
| factura_duplicada_2 = factura_base.copy() | ||
| factura_duplicada_3 = factura_base.copy() | ||
| facturas_duplicadas = factura_duplicada_1 + factura_duplicada_2 + factura_duplicada_3 |
There was a problem hiding this comment.
[nitpick] Para combinar recordsets en Odoo, el operador recomendado es '|' (unión) en lugar de '+', ya que '|' elimina duplicados y es más idiomático: facturas_duplicadas = factura_duplicada_1 | factura_duplicada_2 | factura_duplicada_3.
| facturas_duplicadas = factura_duplicada_1 + factura_duplicada_2 + factura_duplicada_3 | |
| facturas_duplicadas = factura_duplicada_1 | factura_duplicada_2 | factura_duplicada_3 |
| ) | ||
|
|
||
| # Paso 3: Validación Masiva (Simulación 00:33 - 00:40) | ||
| facturas_a_validar = factura_base + facturas_duplicadas |
There was a problem hiding this comment.
[nitpick] Mismo criterio que arriba: use la unión de recordsets con '|' para combinar: facturas_a_validar = factura_base | facturas_duplicadas.
| facturas_a_validar = factura_base + facturas_duplicadas | |
| facturas_a_validar = factura_base | facturas_duplicadas |

No description provided.