From 7989057ebddf2e2e1f391d24ab563f8c743e761f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Sun, 29 Dec 2024 01:33:15 +0000 Subject: [PATCH] WIP --- l10n_br_fiscal/tests/tools.py | 48 ++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/l10n_br_fiscal/tests/tools.py b/l10n_br_fiscal/tests/tools.py index 421e832e6446..3192b66d1d79 100644 --- a/l10n_br_fiscal/tests/tools.py +++ b/l10n_br_fiscal/tests/tools.py @@ -5,11 +5,35 @@ def load_fiscal_fixture_files(env): - load_fixture_files( # FIXME create fake records - env, "base", file_names=["data/res_partner_demo.xml"], mode="init" - ) - # TODO base.res_partner_1 + # the following data is a minimal set of fixtures for the demo partners + # of the base module when it's installed without demo data. + partner_fixtures = { + "res_partner_1": {}, + "res_partner_2": {}, + "res_partner_3": {}, + "res_partner_4": {}, + "res_partner_10": {}, + "res_partner_12": {}, + "res_partner_18": {}, + } + for key, partner_data in partner_fixtures.items(): + if not env.ref(f"base.{key}", raise_if_not_found=False): + if not partner_data.get("name"): + partner_data["name"] = f"fixture_{key}" + + rec = env["res.partner"].create(partner_data) + env["ir.model.data"].create( + { + "name": key, + "res_id": rec.id, + "noupdate": True, + "module": "base", + "model": "res.partner", + } + ) + # the following data is a minimal set of fixtures for the demo products + # of the product module when it's installed without demo data. product_fixtures = { "product_product_1": {}, "product_product_2": {}, @@ -45,13 +69,7 @@ def load_fiscal_fixture_files(env): } idref = {} for key, product_data in product_fixtures.items(): - if not env["ir.model.data"].search( - [ - ("model", "=", "product.product"), - ("name", "=", key), - ("module", "=", "product"), - ] - ): + if not env.ref(f"product.{key}", raise_if_not_found=False): if not product_data.get("name"): product_data["name"] = f"fixture_{key}" prod = env["product.product"].create(product_data) @@ -65,12 +83,7 @@ def load_fiscal_fixture_files(env): } ) idref[f"product.{key}"] = prod.id - if not env["ir.model.data"].search( - [ - ("model", "=", "product.template"), - ("res_id", "=", prod.product_tmpl_id.id), - ] - ): + if not env.ref(f"product.{key}_product_template", raise_if_not_found=False): env["ir.model.data"].create( { "name": f"{key}_product_template", @@ -103,5 +116,4 @@ def load_fiscal_fixture_files(env): "fiscal_document_demo.xml", ], idref=idref, - mode="init", )