#51 refactor: traer categorias anidadas en un solo request de productos

Issue #51: discriminacion y administracion de categorias de productos.

- product.read ahora solicita template.categories.name; se elimina la
  llamada separada model.product.category.read

- ProductTrytonService y CategoryTrytonService construyen el mapa
  {id_tryton: nombre} desde 'template.categories.' de los productos leídos
- import_from_external pasa de 3 llamadas RPC a 2
This commit is contained in:
2026-10-10 17:52:21 -05:00
parent 128ba215dd
commit 6e14dd9f36
5 changed files with 112 additions and 111 deletions

View File

@@ -30,19 +30,22 @@ class TestCategoryTrytonImport(TestCase):
{
"id": 1,
"name": "Producto 1",
"template.": {"id": 999, "categories": [6]},
"template.": {
"id": 999,
"categories": [6],
"categories.": [{"id": 6, "name": "Alimentos"}],
},
},
{
"id": 2,
"name": "Producto 2",
"template.": {"id": 999, "categories": [7]},
"template.": {
"id": 999,
"categories": [7],
"categories.": [{"id": 7, "name": "Verduras"}],
},
},
]
if args[0] == "model.product.category.read":
return [
{"id": 6, "name": "Alimentos"},
{"id": 7, "name": "Verduras"},
]
raise Exception(f"args no esperados: {args}")
mock_call.side_effect = fake_call
@@ -93,11 +96,15 @@ class TestCategoryTrytonImport(TestCase):
{
"id": 1,
"name": "Producto 1",
"template.": {"id": 999, "categories": [7]},
"template.": {
"id": 999,
"categories": [7],
"categories.": [
{"id": 7, "name": "Cereales y Granos"}
],
},
},
]
if args[0] == "model.product.category.read":
return [{"id": 7, "name": "Cereales y Granos"}]
raise Exception(f"args no esperados: {args}")
mock_call.side_effect = fake_call
@@ -135,11 +142,13 @@ class TestCategoryTrytonImport(TestCase):
{
"id": 1,
"name": "Producto 1",
"template.": {"id": 999, "categories": [6]},
"template.": {
"id": 999,
"categories": [6],
"categories.": [{"id": 6, "name": "Alimentos"}],
},
},
]
if args[0] == "model.product.category.read":
return [{"id": 6, "name": "Alimentos"}]
raise Exception(f"args no esperados: {args}")
mock_call.side_effect = fake_call
@@ -182,11 +191,13 @@ class TestCategoryTrytonImport(TestCase):
{
"id": 1,
"name": "Producto 1",
"template.": {"id": 999, "categories": [6]},
"template.": {
"id": 999,
"categories": [6],
"categories.": [{"id": 6, "name": None}],
},
},
]
if args[0] == "model.product.category.read":
return [{"id": 6, "name": None}]
raise Exception(f"args no esperados: {args}")
mock_call.side_effect = fake_call

View File

@@ -157,11 +157,13 @@ class ProductCategoryApiTest(TestCase):
{
"id": 1,
"name": "Producto 1",
"template.": {"id": 999, "categories": [6]},
"template.": {
"id": 999,
"categories": [6],
"categories.": [{"id": 6, "name": "Alimentos"}],
},
},
]
if args[0] == "model.product.category.read":
return [{"id": 6, "name": "Alimentos"}]
raise Exception(f"args no esperados: {args}")
mock_call.side_effect = fake_call

View File

@@ -56,6 +56,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -157,6 +158,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -226,6 +228,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -288,6 +291,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -354,6 +358,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -364,22 +369,17 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"list_price": Decimal("25000"),
"name": "Producto 1",
"default_uom.": {"id": 1, "rec_name": "Unit"},
"template.": {"id": 999, "categories": [5, 8]},
"template.": {
"id": 999,
"categories": [5, 8],
"categories.": [
{"id": 5, "name": "Abarrotes"},
{"id": 8, "name": "Bebidas"},
],
},
},
]
category_read = "model.product.category.read"
category_args = (
[5, 8],
["id", "name"],
{"company": 1},
)
if args == (category_read, category_args):
return [
{"id": 5, "name": "Abarrotes"},
{"id": 8, "name": "Bebidas"},
]
raise Exception(
f"Sorry, args non expected on this test: {args}"
)
@@ -445,6 +445,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -455,21 +456,14 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"list_price": Decimal("25000"),
"name": "Producto 1",
"default_uom.": {"id": 1, "rec_name": "Unit"},
"template.": {"id": 999, "categories": [7]},
"template.": {
"id": 999,
"categories": [7],
"categories.": [{"id": 7, "name": "Cereales"}],
},
},
]
category_read = "model.product.category.read"
category_args = (
[7],
["id", "name"],
{"company": 1},
)
if args == (category_read, category_args):
return [
{"id": 7, "name": "Cereales"},
]
raise Exception(
f"Sorry, args non expected on this test: {args}"
)
@@ -536,6 +530,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -546,21 +541,14 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"list_price": Decimal("25000"),
"name": "Producto 1",
"default_uom.": {"id": 1, "rec_name": "Unit"},
"template.": {"id": 999, "categories": [5]},
"template.": {
"id": 999,
"categories": [5],
"categories.": [{"id": 5, "name": "Abarrotes"}],
},
},
]
category_read = "model.product.category.read"
category_args = (
[5],
["id", "name"],
{"company": 1},
)
if args == (category_read, category_args):
return [
{"id": 5, "name": "Abarrotes"},
]
raise Exception(
f"Sorry, args non expected on this test: {args}"
)
@@ -627,6 +615,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -688,6 +677,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -698,21 +688,16 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"list_price": Decimal("4500"),
"name": "Papa",
"default_uom.": {"id": 2, "rec_name": "Kilogram"},
"template.": {"id": 999, "categories": [9]},
"template.": {
"id": 999,
"categories": [9],
"categories.": [
{"id": 9, "name": "Tubérculos"}
],
},
},
]
category_read = "model.product.category.read"
category_args = (
[9],
["id", "name"],
{"company": 1},
)
if args == (category_read, category_args):
return [
{"id": 9, "name": "Tubérculos"},
]
raise Exception(
f"Sorry, args non expected on this test: {args}"
)
@@ -786,6 +771,7 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"default_uom.rec_name",
"list_price",
"template.categories",
"template.categories.name",
],
{"company": 1},
)
@@ -796,21 +782,14 @@ class TestProductsFromTryton(TestCase, LoginMixin):
"list_price": Decimal("4500"),
"name": "Papa",
"default_uom.": {"id": 2, "rec_name": "Kilogram"},
"template.": {"id": 999, "categories": [8]},
"template.": {
"id": 999,
"categories": [8],
"categories.": [{"id": 8, "name": "Bebidas"}],
},
},
]
category_read = "model.product.category.read"
category_args = (
[8],
["id", "name"],
{"company": 1},
)
if args == (category_read, category_args):
return [
{"id": 8, "name": "Bebidas"},
]
raise Exception(
f"Sorry, args non expected on this test: {args}"
)