Skip to content

Commit

Permalink
[IMP] base_import_pdf_by_template_account: Define data in test (do no…
Browse files Browse the repository at this point in the history
…t use demo data)

TT50003
  • Loading branch information
victoralmau committed Dec 3, 2024
1 parent 35420ab commit b89a01f
Showing 1 changed file with 214 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,223 @@ class TestBaseImportPdfByTemplateAccount(BaseCommon):
def setUpClass(cls):
super().setUpClass()
cls.env.user.groups_id += cls.env.ref("analytic.group_analytic_accounting")
generic_product = cls.env.ref(
"base_import_pdf_by_template_account.generic_product"
# Demo data is not consistent, let's set our own template here
# We define a different auto_detect_pattern in the existing demo template
# to prevent it from being used.
cls.env.ref("base_import_pdf_by_template_account.invoice_tecnativa").write(
{"auto_detect_pattern": "custom-pattern"}
)
cls.partner_tecnativa = cls.env.ref(
"base_import_pdf_by_template_account.partner_tecnativa"
generic_product = cls.env["product.product"].create(
{
"name": "Test product",
"default_code": "GENERIC",
}
)
cls.env.ref(
"base_import_pdf_by_template_account.invoice_tecnativa_line_product_id"
).write({"default_value": f"product.product,{generic_product.id}"})
cls.analytic_account = cls.env.ref(
"base_import_pdf_by_template_account.analytic_account_tecnativa"
plan = cls.env["account.analytic.plan"].create({"name": "Test plan"})
cls.analytic_account = cls.env["account.analytic.account"].create(
{
"name": "Test account",
"plan_id": plan.id,
}
)
cls.partner_tecnativa = cls.env["res.partner"].create({"name": "Tecnativa"})
cls.env["product.product"].create(
{
"name": "Test Rotulador",
"default_code": "ROTULADOR",
"seller_ids": [
(
0,
0,
{
"partner_id": cls.partner_tecnativa.id,
"product_code": "CONS_0001",
},
),
],
}
)
cls.env["product.product"].create(
{
"name": "Test Boligrafo",
"default_code": "BOLIGRAFO",
"seller_ids": [
(
0,
0,
{
"partner_id": cls.partner_tecnativa.id,
"product_code": "CONS_0002",
},
),
],
}
)
cls.env["product.product"].create(
{
"name": "Test Leds",
"default_code": "LEDS",
"seller_ids": [
(
0,
0,
{
"partner_id": cls.partner_tecnativa.id,
"product_code": "FURN_0003",
},
),
],
}
)
cls.env["product.product"].create(
{
"name": "Test Plastificadora",
"default_code": "PLASTIFICADORA",
"seller_ids": [
(
0,
0,
{
"partner_id": cls.partner_tecnativa.id,
"product_code": "E-COM10",
},
),
],
}
)
cls.env["product.product"].create(
{
"name": "Test Laminas",
"default_code": "LAMINAS",
"seller_ids": [
(
0,
0,
{
"partner_id": cls.partner_tecnativa.id,
"product_code": "FURN_8621",
},
),
],
}
)
cls.env["product.product"].create(
{
"name": "Test Trituradora",
"default_code": "TRITURADORA",
"seller_ids": [
(
0,
0,
{
"partner_id": cls.partner_tecnativa.id,
"product_code": "FURN_7023",
},
),
],
}
)
# pylint: disable=W1401
cls.env["base.import.pdf.template"].create(
{
"name": "Invoices Tecnativa",
"model_id": cls.env.ref("account.model_account_move").id,
"child_field_id": cls.env.ref(
"account.field_account_move__invoice_line_ids"
).id,
"auto_detect_pattern": "(B 8 7 5 3 0 4 3 2)",
"header_items": "Producto,Cantidad,Precio,AnalyticDistribution",
"line_ids": [
(
0,
0,
{
"related_model": "header",
"field_id": cls.env.ref(
"account.field_account_move__partner_id"
).id,
"value_type": "fixed",
"fixed_value": f"res.partner,{cls.partner_tecnativa.id}",
},
),
(
0,
0,
{
"related_model": "header",
"field_id": cls.env.ref(
"account.field_account_move__move_type"
).id,
"value_type": "fixed",
"fixed_value_selection": cls.env.ref(
"account.selection__account_invoice_report__move_type__in_invoice"
).id,
},
),
(
0,
0,
{
"related_model": "lines",
"field_id": cls.env.ref(
"account.field_account_move_line__product_id"
).id,
"column": 0,
"pattern": "\[([A-Z\d]+[_|-][A-Z\d]+)\]",
"value_type": "variable",
"search_field_id": cls.env.ref(
"product.field_product_product__seller_ids"
).id,
"search_subfield_id": cls.env.ref(
"product.field_product_supplierinfo__product_code"
).id,
"default_value": f"product.product,{generic_product.id}",
},
),
(
0,
0,
{
"related_model": "lines",
"field_id": cls.env.ref(
"account.field_account_move_line__quantity"
).id,
"column": 1,
"pattern": "\[[A-Z\d]+[_|-][A-Z\d]+\] [a-zA-Záí]* ([0-9]{1,3})", # noqa: E501
"value_type": "variable",
},
),
(
0,
0,
{
"related_model": "lines",
"field_id": cls.env.ref(
"account.field_account_move_line__price_unit"
).id,
"column": 2,
"pattern": "\[[A-Z\d]+[_|-][A-Z\d]+\] [a-zA-Záí]* [0-9]{1,3} ([0-9]{1,3}.[0-9]{2})", # noqa: E501
"value_type": "variable",
"log_distinct_value": True,
},
),
(
0,
0,
{
"related_model": "lines",
"field_id": cls.env.ref(
"account.field_account_move_line__analytic_distribution"
).id,
"column": 3,
"value_type": "fixed",
"fixed_value_text": '{"%s": 100.0}'
% (cls.analytic_account.id),
},
),
],
}
)
cls.env.ref(
"base_import_pdf_by_template_account.invoice_tecnativa_analytic_distribution"
).write({"fixed_value_text": '{"%s": 100.0}' % (cls.analytic_account.id)})
cls.journal = cls.env["account.journal"].search(
[("type", "=", "purchase"), ("company_id", "=", cls.env.company.id)],
limit=1,
Expand Down

0 comments on commit b89a01f

Please sign in to comment.