OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

  1. # License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
  2. import os
  3. from odoo import SUPERUSER_ID, api
  4. def post_init_hook(cr, registry):
  5. """
  6. Loaded after installing this module, and before the next module starts
  7. installing.
  8. Add XSD Validation Schema for a demo report if it's in the system.
  9. Demo data records are always created with `noupdate == True` and render of
  10. tag `report` doesn't support new `ir.actions.report` field `xsd_schema`.
  11. Thus it is impossible to define `xsd_schema` in the demo definition or add
  12. schema after that via xml update record. Therefore it possible to add value
  13. to `xsd_schema` field for demo record only via hook.
  14. Args:
  15. * cr(odoo.sql_db.Cursor) - database cursor.
  16. * registry(odoo.modules.registry.RegistryManager) - a mapping between
  17. model names and model classes.
  18. """
  19. with api.Environment.manage():
  20. env = api.Environment(cr, SUPERUSER_ID, {})
  21. report_domain = [
  22. ("report_name", "=", "report_xml.demo_report_xml_view") # report tech name
  23. ]
  24. demo_report = env["ir.actions.report"].search(report_domain, limit=1)
  25. if demo_report:
  26. dir_path = os.path.dirname(__file__)
  27. xsd_file_relative_path = "demo/demo_report.xsd"
  28. xsd_file_full_path = os.path.join(dir_path, xsd_file_relative_path)
  29. with open(xsd_file_full_path, "r") as xsd:
  30. # `xsd_schema` is binary fields with an attribute
  31. # `attachment=True` so XSD Schema will be added as attachment
  32. attach_vals = {
  33. "name": "Demo Report.xsd",
  34. "datas": xsd.read(),
  35. "res_model": "ir.actions.report",
  36. "res_id": demo_report.id,
  37. "res_field": "xsd_schema",
  38. "type": "binary",
  39. }
  40. env["ir.attachment"].create(attach_vals)