semvec/pypi-packages huggingface dataset:
odoo-utilities 0.2
Set of tools for Odoo ERP

OdooTools
=========

Set of tools for Odoo developpement

.. code:: python

    import OdooTools

Debug
-----

Debug utilities

.. code:: python

    from odoo.ONS import debug

-  **print\_func\_code**: print function code and its inheritance
   (considering loading order)

``python   print_func_code(env, model, function)``

-  env: odoo environnement
-  model: model \_name value, e.g. "sale.order"
-  function: function to analyse, e.g. "onchange\_partner\_id"

-  **printTraceBack**: print the call path up to this function call

``python   printTraceBack(printer)``

-  printer: display function, default is "print", we can use the logger
   from logging library

   .. code:: python

       printTraceBack(_logger.critical)

-  **get\_depends\_methods**: return a list of dict containing trigger
   keys and function object of all "api.depends" of a model

``python   for depends in get_onchange_methods(env, model):       print(x["keys"], x["function"])``

-  env: environnement odoo
-  model: model from which to extract depends methods, e.g. "sale.order"

-  **get\_onchange\_methods**: same as get\_depends\_methods but for
   "api.onchange"

-  **analyse\_depends**: call print\_func\_code on get\_depends\_methods
   result

``python   analyse_depends(env, model)``

-  **analyse\_onchange**: call print\_func\_code on
   get\_onchange\_methods result

``python   analyse_onchange(env, model)``

Records
-------

Tools to handle recordset

-  **groupby**: group recordset according to list of key (or key getter)

``python   groupby(records, attributes)``

-  records: recordset to group
-  attributes: list of grouping key, that can be either:

   -  an object attribute's name as string, e.g. ``"name"``
   -  a function taking a record and returning the key, e.g.
      ``lambda line: line.move_id.sale_line_id.order_id``

Example:

``python   lines = self.mapped("move_line_ids").filtered("result_package_id")   grouped = groupby(lines, [       "result_package_id",       "picking_id",       lambda line: line.move_id.sale_line_id.order_id,   ])   for package, package_data in grouped.items():      for picking_id, picking_id_data in package_data.items():         for sale_id, records in package_data.items():               print(records)``

Datetime
--------

Tools to handle date and datetime.

-  **client\_specific\_to\_utc**: There 's some cases where you need to
   convert a datetime for the write, for example a datetime built from
   the controller

``python   utc_date = client_specific_to_utc(env, mydate)``