anthem


Nameanthem JSON
Version 0.14.0 PyPI version JSON
download
home_pagehttps://github.com/camptocamp/anthem
SummaryMake your Odoo scripts sing.
upload_time2023-12-27 13:12:49
maintainer
docs_urlNone
authorCamptocamp
requires_python
licenseLGPLv3+
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ========================================
Anthem: make your Odoo scripts sing 🐜🎵
========================================

.. image:: https://travis-ci.org/camptocamp/anthem.svg?branch=master
    :target: https://travis-ci.org/camptocamp/anthem

Anthem is a tool to help scripting Odoo instances for automated setup,
upgrades, testing and more.

It should be an alternative to the other tools like ``oerpscenario``.


Make your own songs
===================

Writing your songs is as easy as creating a Python Package. The
songs functions called by anthem must have a positional ``ctx``
argument.

``ctx`` is essentially the execution context - you can access ``ctx.env`` from
it, which is an Odoo environment instance that you should be pretty much familiar with.

::

  ## songs/install.py

  def setup_company(ctx):
      """ Setup company """
      company = ctx.env.ref('base.main_company')
      company.name = 'My Company'


  def main(ctx):
      setup_company(ctx)


Logs
====

A song can display some logs when executed with ``@anthem.log``,
``Context.log`` and ``Context.log_line``.

.. code:: python

  import anthem

  @anthem.log
  def setup_company(ctx):
      """ Setting up company """
      company = ctx.env.ref('base.main_company')
      with ctx.log('Changing name'):
          company.name = 'My Company'
          ctx.log_line('Name changed')
      with ctx.log('Loading a logo'):
          company.logo = b64encode(LOGO_CONTENT)
          ctx.log_line('Logo changed')


The decorator on the function will display the first line of the docstring.
Both the decorator and the context manager will show the timing of the
execution. The upper example gives:

.. code

  Setting up company...
      Changing name...
          Name changed
      Changing name: 0.0150s
      Loading a logo...
          Logo changed
      Loading a logo: 0.100s
  Setting up company: 0.300s


Execute your songs
==================

Use the command line ``anthem``. Provided your songs and ``openerp`` are in the
``PYTHONPATH``:

.. code

  anthem songs.install::main -c path/to/openerp.cfg

Anthem will execute the function ``main`` of the module ``songs.install`` with
a ``ctx`` initialized with an Odoo ``env``.

Instead of using ``-c`` for the command line, you can export the environment
variable ``OPENERP_SERVER`` with the path of the configuration file.

.. code

  export OPENERP_SERVER=path/to/openerp.cfg
  anthem songs.install::main

In order to have ``openerp`` in the ``PYTHONPATH``, you might install it as a
package with ``pip install -e`` or directly modify the ``PYTHONPATH``.

In order to have your ``songs`` in the ``PYTHONPATH``, the better is to make a
Python package out of them.

Testing
=======

Dependencies
------------

To run the tests, you must have Postgresql running, with accesses for your user
(or you will have to modify ``tests/config/odoo.cfg`` with your database
username and password).

Run the tests
-------------

To run ``anthem``'s tests, it is a good idea to do an *editable* install of it
in a virtualenv. You must also prepare the environment by installing odoo packages.

Odoo 9.0 (Python 2):

.. code

  $ git clone https://github.com/camptocamp/anthem.git
  Cloning into 'anthem'...
  $ cd anthem
  $ virtualenv -p python2 env-9.0
  $ source env-9.0/bin/activate
  $ pip install -e .
  $ pip install pytest invoke
  $ invoke tests.prepare-version 9.0
  $ OPENERP_SERVER=/tmp/test-anthem-config-9.0.cfg py.test -s tests

Odoo 10.0 (Python 2):

.. code

  $ git clone https://github.com/camptocamp/anthem.git
  Cloning into 'anthem'...
  $ cd anthem
  $ virtualenv -p python2 env-10.0
  $ source env-10.0/bin/activate
  $ pip install -e .
  $ pip install pytest invoke
  $ invoke tests.prepare-version 10.0
  $ OPENERP_SERVER=/tmp/test-anthem-config-10.0.cfg py.test -s tests

Odoo 11.0 (Python 3):

.. code

  $ git clone https://github.com/camptocamp/anthem.git
  Cloning into 'anthem'...
  $ cd anthem
  $ virtualenv -p python3 anthem-env-11.0
  $ source anthem-env-11.0/bin/activate
  $ pip install -e .
  $ pip install pytest invoke
  $ invoke tests.prepare-version 11.0
  $ OPENERP_SERVER=/tmp/test-anthem-config-11.0.cfg py.test -s tests

If need be, you can drop the test database with (adapt the version):

.. code

  $ invoke tests.dropdb 9.0

These steps will download the nightly release of Odoo install it as a package
then install a database, so tests can be run against it (and that's also why it
is important to use a virtualenv!)

When calling ``pytest``, you have to define the ``OPENERP_SERVER`` environment
variable with the configuration file for the Odoo database that will be used
for the tests.

Lyrics
======

Lyrics are predefined snippets written for the most commonly used cases, like:

* `Loading data`_: read (load) a data file (CSV format is supported at the moment)
* `Provide XMLIDs for records`_
* `Upserting a record`_: essentially search for the record and update it with
  given values, or create it in case it isn't there yet
* `Uninstalling a module(s)`_
* `Updating module configuration`_: pre-defining a set of settings for a particular
  module (or set of modules)

.. _loading-data:

Loading data
------------

There's an ability to supply data in a handy CSV format - Anthem is just able to
parse and load those. ``load_csv`` method is meant to be the main entrypoint for
doing so:

+--------------------+----------------------------------------------------------+
| Param              | Description                                              |
+====================+==========================================================+
| ``ctx``            | Anthem context instance                                  |
+--------------------+----------------------------------------------------------+
| ``model``          | Odoo model name or model klass from ``ctx.env``          |
+--------------------+----------------------------------------------------------+
| ``path``           | absolute or relative path to CSV file.                   |
|                    | If a relative path is given you must provide a value for |
|                    | ``ODOO_DATA_PATH`` in your environment                   |
|                    | or set ``--odoo-data-path`` option.                      |
+--------------------+----------------------------------------------------------+
| ``header``         | whitelist of CSV columns to load                         |
+--------------------+----------------------------------------------------------+
| ``header_exclude`` | blacklist of CSV columns to ignore                       |
+--------------------+----------------------------------------------------------+
| ``fmtparams``      | keyword params for ``csv_unireader``                     |
+--------------------+----------------------------------------------------------+

CSV format is similar to that of an Odoo export format, namely:
* it should contain a set of field names in a header
* each consecutive row defines a set of values to use to create records on a given model

Records
-------

This section is dedicated to methods that operate on records.

Provide XMLIDs for records
^^^^^^^^^^^^^^^^^^^^^^^^^^

This is as simple as calling ``anthem.records.add_xmlid`` with a record as a
first parameter and a desired XMLID as a second.

E.g., you have a very special ``res.partner`` record ``foo``:

.. code:: python

  from anthem.records import add_xmlid

  [...]
  @anthem.log
  def add_xmlid_to_foo(ctx):
      """Make Jhony Foo great again."""
      foo = ctx.env['res.partner'].create({
          'name': 'Jhony',
          'lastname': 'Foo',
      })
      add_xmlid(foo, '__setup__.res_partner_foo_jhony')

From now on, Jhony could be referred to as
``ctx.env.ref('__setup__.res_partner_foo_jhony')``.

Upserting a record
^^^^^^^^^^^^^^^^^^

**"Upsert"** is a commonly used term that basically stands for UPDATE or INSERT.
Anthem features a facility that is capable of executing that kind of operations
on Odoo databases. There is a method called ``anthem.records.create_or_update``
that relies on the model, a set of values and a record XMLID.

If your goal is to create the record in the first place as well as provide an
XMLID, as was shown in a previous section, ``create_or_update`` does just what
you need.

Example
+++++++

.. code:: python

  from anthem.records import create_or_update

  [...]
  @anthem.log
  def create_partner_foo(ctx):
      """Ensure that Jhony Foo is known to our Company."""
      create_or_update(
          ctx,
          model='res.partner',
          xmlid='__setup__.res_partner_foo_jhony',
          values={
              'name': 'Jhony',
              'lastname': 'Foo',
          }
      )


Upon calling, it would:

* Try to fetch the record by a given XMLID
* If the record was found:
   * Update it with the given values (call ``record.update(values)`` on it)
* Otherwise:
   * Create a record with given values (call ``model.create(values)``)
   * Provide an XMLID to it (using ``anthem.records.add_xmlid``)
* In any case: return that record back

Modules
-------

This section is dedicated to methods that operate on modules.

Uninstalling a module(s)
^^^^^^^^^^^^^^^^^^^^^^^^

Sometimes you just need some particular module to be gone from your instance(s)
and you'd like it done programmatically, without having to reach for each
instance, search for it and hit the **"Uninstall"** button. Anthem can do the
job for you: you can simply call an ``anthem.lyrics.modules.uninstall`` with a
list of module names that you won't use anymore.

Example (given that there are modules ``foo`` and ``bar`` that you want gone):
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. code:: python

  from anthem.lyrics.modules import uninstall

  [...]
  @anthem.log
  def uninstall_foo(ctx):
      """Get rid of legacy `foo` and `bar`."""
      uninstall(ctx, ['foo', 'bar'])

Updating translations on module(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In a similar fashion, sometimes you need to update translations on a set of
modules - ``anthem.lyrics.modules.update_translations`` is there for you :wink:

Example is similar to the previous case - just call the different method instead.

Updating module configuration
=============================

By using this feature, you're able to preconfigure your module setup via Anthem
song: you'll just need a straight idea what needs to be done, an instance of a
configuration settings model for your module (model name will do as well) and a
mapping (in a form of Python dictionary) of technical configuration names with
desired values.

Here's a brief example of ``sale`` module configuration:

.. code:: python

  from anthem.lyrics import settings

  [...]
  @anthem.log
  def define_sale_settings(ctx):
      """Configure `sale` module."""
      model = ctx.env['sale.config.settings']
      # it's okay to use 'sale.config.settings' as a string though
      model = 'sale.config.settings'
      settings(ctx, model, {
          'default_invoice_policy': 'delivery',
          ...: ...,
          'et': 'cetera',
      })

Be advised: settings onchange are not triggered by this function.

Usage within Marabunta
======================

Anthem and `Marabunta <https://github.com/camptocamp/marabunta>`_ are powerful
when combined: you can call a set of songs inside Marabunta's migration steps
using following syntax:

.. code:: yaml

  ...
  - version: 10.0.1.0.0
    operations:
      pre:
        - anthem songs.upgrade.your_pre_song::main
      post:
        - anthem songs.upgrade.your_post_song::main

By using this approach, you possess the power of full-pledged Odoo
``Environment`` instance initialized on a live database while performing a
regular upgrade powered by Marabunta.

Let's say that you have to enable multicompany with inter-company transactions
on a migration to next version, lets say, 10.0.1.1.0. In this case, you'll need
a song to back this up on a Python side first:

.. code:: python

   # songs.upgrade.upgrade_10_0_1_1_0.py
   from anthem.lyrics import settings

   [...]
   @anthem.log
   def enable_multicompany(ctx):
       """Set up multicompany."""
       settings(ctx, 'base.config.settings', {
           # enable multicompany as it is
           'group_light_multi_company': True,
           # enable inter-company transactions
           'module_inter_company_rules': True,
       })

    [...]
    @anthem.log
    def main(ctx):
        enable_multicompany(ctx)

And then you'll need to call it on a migration step:

.. code:: yaml

  ...
  - version: 10.0.1.1.0
    operations:
      post:
        - anthem songs.upgrade.upgrade_10_0_1_1_0::main

Boom! Enjoy your new multicompany settings.

That's all, folks!
==================

Thanks for reading. Happy hacking and enjoy your songwriting skills!


.. :changelog:

Release History
===============

Unreleased
----------

**Features**

**Bugfixes**

**Improvements**

**Documentation**

**Build**

0.14.0 (2023-05-16)
-------------------

**Bugfixes**

- Fix Update_translation function and update black version 22.3.0
- Pin version of Setuptools < 58
- Fix environment initialization for Odoo 15
- Fix `add_xmlid` for Odoo 15

**Improvements**

- Enable Travis-CI tests for Odoo 14 and Odoo 15
- Add: nuke_translations to allow to remove already existing translations

0.13.0 (2019-08-29)
-------------------

**Features**

- BREAKING: Change default `overwrite` value for
   ``lyrics.modules.update_translations`` to False

- Support odoo saas versions

**Bugfixes**

- Make ``lyrics.modules.update_translations`` Odoo >= 11.0 compatible

0.12.2 (2019-06-21)
-------------------

**Improvements**

- Add 'tracking_disable=True' as default context to load CSVs
  (avoid creating 'mail.message' records and speed up the import process)

**Build**

- Packaging: build universal wheels

0.12.1 (2018-11-09)
-------------------

**Documentation**

- Improve API docs

**Build**

- The lib is now automaticaly published to Pypi by Travis when a tag is added

0.12.0 (2018-03-19)
-------------------

**Features**

- Add a new option ``--odoo-data-path`` or env. variable ``ODOO_DATA_PATH``.
- The ``lyrics.loaders.load_csv`` method now accepts a relative path appended to the
  new option "odoo data path". Absolute paths are still allowed.

**Bugfixes**

- ``lyrics.loaders.update_translations`` is now deprecated as it was a duplicate from
  ``lyrics.modules.update_translations``

0.11.0 (2017-12-22)
-------------------

**Features**

 - Make it Python 3 and Odoo 11 compatible

**Build**

 - Switch to unicodecsv instead of custom code to handle that
 - Fix the flapping tests setup. Removed tox which was provoking that for some reason.
 - Add a lint check in build


0.10.0 (2017-09-19)
-------------------

**Bugfixes**

* Disable Odoo's xmlrpc port

**Build**

- Add 'build-release.sh' script with commands to build and upload the dist files

0.9.0 (2017-08-21)
------------------

**Features**

- New lyrics: modules.update_translations to update translations from po files
- Lyrics 'uninstall' has been moved from uninstaller.uninstall to modules.uninstall,
  previous path is still working for backward compatibility
- New lyrics context manager 'records.switch_company'


0.8.0 (2017-07-24)
------------------

**Features**

- New lyrics: Define settings like being in the interface
- Add CSV Loading columns control (columns whitelist and blacklist)

**Bugfixes**

- Fix error when loading CSV with no rows


0.7.0 (2017-04-28)
------------------

**Improvements**

- Split CSV loaders in functions to be able to get rows from a CSV or to load
  rows, enabling to modify the rows before loading them for instance
- create_or_update lyrics accepts now a model so we can change its env (user,
  context, ...)
- New lyrics to uninstall module


0.6.0 (2017-01-18)
------------------

**Features**

- CSV loaders can be used with a model in order to pass a context

**Bugfixes**

- Fix tests by installing eggs from odoo/requirements.txt


0.5.0 (2016-10-12)
------------------

**Features**

- Support Odoo 10
- Allow to specify the encoding of an imported file, default is utf8

**Bugfixes**

- 'records.add_xmlid' lyrics do no longer fail when it already exists


0.4.0 (2016-08-19)
------------------

**Features**

- New lyrics: CSV loaders from path or stream
- New ``ctx.log_line`` to print a line respecting the current indentation

**Improvements**

- Add tests for the existing lyrics

**Build**

- Finally green builds!


0.3.0 (2016-07-26)
------------------

**Features**

- Add --quiet mode

**Fixes**

- Encode the logged strings to the default encoding or utf8
- Allow to use Ctrl-c to stop anthem.
- Set openerp's loglevel to ERROR, its logs clutter anthem's own outputs

0.2.0 (2016-07-22)
------------------

**Features**

* Ability to log descriptions and timings in songs with the
  context manager ``Context.log`` and the decorator ``anthem.log``.

  ::

    from anthem import log

    @log
    def setup_company(ctx):
        """ Setup company """
        # do stuff
        with ctx.log('other stuff'):
            # do other stuff

    @log
    def load_data(ctx):
        """ Load data """
        # load

    @log
    def main(ctx):
        setup_company(ctx)
        load_data(ctx)

  If we run anthem on ``main``, we will get:

  ::

    running... main
       running... Setup company
          running... other stuff
          other stuff: 0.850s
       Setup company: 1.100s
       running... Load data
       Load data: 2.900s
    main: 4.000s

0.1.3 (2016-07-07)
------------------

**Fixes**

- Correct lyric to create or update a record

0.1.2 (2016-07-07)
------------------

- Add a lyric to create a xmlid
- Add a lyric to create or update a record

0.1.1 (2016-06-23)
------------------

- Fixed crash on non-editable install.

0.1.0 (2016-06-23)
------------------

Initial release.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/camptocamp/anthem",
    "name": "anthem",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Camptocamp",
    "author_email": "info@camptocamp.com",
    "download_url": "https://files.pythonhosted.org/packages/33/e8/c7d6bf359bfaf144d59d3f531ca042465e3419db3740c471ccfbb7f7018b/anthem-0.14.0.tar.gz",
    "platform": null,
    "description": "========================================\nAnthem: make your Odoo scripts sing \ud83d\udc1c\ud83c\udfb5\n========================================\n\n.. image:: https://travis-ci.org/camptocamp/anthem.svg?branch=master\n    :target: https://travis-ci.org/camptocamp/anthem\n\nAnthem is a tool to help scripting Odoo instances for automated setup,\nupgrades, testing and more.\n\nIt should be an alternative to the other tools like ``oerpscenario``.\n\n\nMake your own songs\n===================\n\nWriting your songs is as easy as creating a Python Package. The\nsongs functions called by anthem must have a positional ``ctx``\nargument.\n\n``ctx`` is essentially the execution context - you can access ``ctx.env`` from\nit, which is an Odoo environment instance that you should be pretty much familiar with.\n\n::\n\n  ## songs/install.py\n\n  def setup_company(ctx):\n      \"\"\" Setup company \"\"\"\n      company = ctx.env.ref('base.main_company')\n      company.name = 'My Company'\n\n\n  def main(ctx):\n      setup_company(ctx)\n\n\nLogs\n====\n\nA song can display some logs when executed with ``@anthem.log``,\n``Context.log`` and ``Context.log_line``.\n\n.. code:: python\n\n  import anthem\n\n  @anthem.log\n  def setup_company(ctx):\n      \"\"\" Setting up company \"\"\"\n      company = ctx.env.ref('base.main_company')\n      with ctx.log('Changing name'):\n          company.name = 'My Company'\n          ctx.log_line('Name changed')\n      with ctx.log('Loading a logo'):\n          company.logo = b64encode(LOGO_CONTENT)\n          ctx.log_line('Logo changed')\n\n\nThe decorator on the function will display the first line of the docstring.\nBoth the decorator and the context manager will show the timing of the\nexecution. The upper example gives:\n\n.. code\n\n  Setting up company...\n      Changing name...\n          Name changed\n      Changing name: 0.0150s\n      Loading a logo...\n          Logo changed\n      Loading a logo: 0.100s\n  Setting up company: 0.300s\n\n\nExecute your songs\n==================\n\nUse the command line ``anthem``. Provided your songs and ``openerp`` are in the\n``PYTHONPATH``:\n\n.. code\n\n  anthem songs.install::main -c path/to/openerp.cfg\n\nAnthem will execute the function ``main`` of the module ``songs.install`` with\na ``ctx`` initialized with an Odoo ``env``.\n\nInstead of using ``-c`` for the command line, you can export the environment\nvariable ``OPENERP_SERVER`` with the path of the configuration file.\n\n.. code\n\n  export OPENERP_SERVER=path/to/openerp.cfg\n  anthem songs.install::main\n\nIn order to have ``openerp`` in the ``PYTHONPATH``, you might install it as a\npackage with ``pip install -e`` or directly modify the ``PYTHONPATH``.\n\nIn order to have your ``songs`` in the ``PYTHONPATH``, the better is to make a\nPython package out of them.\n\nTesting\n=======\n\nDependencies\n------------\n\nTo run the tests, you must have Postgresql running, with accesses for your user\n(or you will have to modify ``tests/config/odoo.cfg`` with your database\nusername and password).\n\nRun the tests\n-------------\n\nTo run ``anthem``'s tests, it is a good idea to do an *editable* install of it\nin a virtualenv. You must also prepare the environment by installing odoo packages.\n\nOdoo 9.0 (Python 2):\n\n.. code\n\n  $ git clone https://github.com/camptocamp/anthem.git\n  Cloning into 'anthem'...\n  $ cd anthem\n  $ virtualenv -p python2 env-9.0\n  $ source env-9.0/bin/activate\n  $ pip install -e .\n  $ pip install pytest invoke\n  $ invoke tests.prepare-version 9.0\n  $ OPENERP_SERVER=/tmp/test-anthem-config-9.0.cfg py.test -s tests\n\nOdoo 10.0 (Python 2):\n\n.. code\n\n  $ git clone https://github.com/camptocamp/anthem.git\n  Cloning into 'anthem'...\n  $ cd anthem\n  $ virtualenv -p python2 env-10.0\n  $ source env-10.0/bin/activate\n  $ pip install -e .\n  $ pip install pytest invoke\n  $ invoke tests.prepare-version 10.0\n  $ OPENERP_SERVER=/tmp/test-anthem-config-10.0.cfg py.test -s tests\n\nOdoo 11.0 (Python 3):\n\n.. code\n\n  $ git clone https://github.com/camptocamp/anthem.git\n  Cloning into 'anthem'...\n  $ cd anthem\n  $ virtualenv -p python3 anthem-env-11.0\n  $ source anthem-env-11.0/bin/activate\n  $ pip install -e .\n  $ pip install pytest invoke\n  $ invoke tests.prepare-version 11.0\n  $ OPENERP_SERVER=/tmp/test-anthem-config-11.0.cfg py.test -s tests\n\nIf need be, you can drop the test database with (adapt the version):\n\n.. code\n\n  $ invoke tests.dropdb 9.0\n\nThese steps will download the nightly release of Odoo install it as a package\nthen install a database, so tests can be run against it (and that's also why it\nis important to use a virtualenv!)\n\nWhen calling ``pytest``, you have to define the ``OPENERP_SERVER`` environment\nvariable with the configuration file for the Odoo database that will be used\nfor the tests.\n\nLyrics\n======\n\nLyrics are predefined snippets written for the most commonly used cases, like:\n\n* `Loading data`_: read (load) a data file (CSV format is supported at the moment)\n* `Provide XMLIDs for records`_\n* `Upserting a record`_: essentially search for the record and update it with\n  given values, or create it in case it isn't there yet\n* `Uninstalling a module(s)`_\n* `Updating module configuration`_: pre-defining a set of settings for a particular\n  module (or set of modules)\n\n.. _loading-data:\n\nLoading data\n------------\n\nThere's an ability to supply data in a handy CSV format - Anthem is just able to\nparse and load those. ``load_csv`` method is meant to be the main entrypoint for\ndoing so:\n\n+--------------------+----------------------------------------------------------+\n| Param              | Description                                              |\n+====================+==========================================================+\n| ``ctx``            | Anthem context instance                                  |\n+--------------------+----------------------------------------------------------+\n| ``model``          | Odoo model name or model klass from ``ctx.env``          |\n+--------------------+----------------------------------------------------------+\n| ``path``           | absolute or relative path to CSV file.                   |\n|                    | If a relative path is given you must provide a value for |\n|                    | ``ODOO_DATA_PATH`` in your environment                   |\n|                    | or set ``--odoo-data-path`` option.                      |\n+--------------------+----------------------------------------------------------+\n| ``header``         | whitelist of CSV columns to load                         |\n+--------------------+----------------------------------------------------------+\n| ``header_exclude`` | blacklist of CSV columns to ignore                       |\n+--------------------+----------------------------------------------------------+\n| ``fmtparams``      | keyword params for ``csv_unireader``                     |\n+--------------------+----------------------------------------------------------+\n\nCSV format is similar to that of an Odoo export format, namely:\n* it should contain a set of field names in a header\n* each consecutive row defines a set of values to use to create records on a given model\n\nRecords\n-------\n\nThis section is dedicated to methods that operate on records.\n\nProvide XMLIDs for records\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThis is as simple as calling ``anthem.records.add_xmlid`` with a record as a\nfirst parameter and a desired XMLID as a second.\n\nE.g., you have a very special ``res.partner`` record ``foo``:\n\n.. code:: python\n\n  from anthem.records import add_xmlid\n\n  [...]\n  @anthem.log\n  def add_xmlid_to_foo(ctx):\n      \"\"\"Make Jhony Foo great again.\"\"\"\n      foo = ctx.env['res.partner'].create({\n          'name': 'Jhony',\n          'lastname': 'Foo',\n      })\n      add_xmlid(foo, '__setup__.res_partner_foo_jhony')\n\nFrom now on, Jhony could be referred to as\n``ctx.env.ref('__setup__.res_partner_foo_jhony')``.\n\nUpserting a record\n^^^^^^^^^^^^^^^^^^\n\n**\"Upsert\"** is a commonly used term that basically stands for UPDATE or INSERT.\nAnthem features a facility that is capable of executing that kind of operations\non Odoo databases. There is a method called ``anthem.records.create_or_update``\nthat relies on the model, a set of values and a record XMLID.\n\nIf your goal is to create the record in the first place as well as provide an\nXMLID, as was shown in a previous section, ``create_or_update`` does just what\nyou need.\n\nExample\n+++++++\n\n.. code:: python\n\n  from anthem.records import create_or_update\n\n  [...]\n  @anthem.log\n  def create_partner_foo(ctx):\n      \"\"\"Ensure that Jhony Foo is known to our Company.\"\"\"\n      create_or_update(\n          ctx,\n          model='res.partner',\n          xmlid='__setup__.res_partner_foo_jhony',\n          values={\n              'name': 'Jhony',\n              'lastname': 'Foo',\n          }\n      )\n\n\nUpon calling, it would:\n\n* Try to fetch the record by a given XMLID\n* If the record was found:\n   * Update it with the given values (call ``record.update(values)`` on it)\n* Otherwise:\n   * Create a record with given values (call ``model.create(values)``)\n   * Provide an XMLID to it (using ``anthem.records.add_xmlid``)\n* In any case: return that record back\n\nModules\n-------\n\nThis section is dedicated to methods that operate on modules.\n\nUninstalling a module(s)\n^^^^^^^^^^^^^^^^^^^^^^^^\n\nSometimes you just need some particular module to be gone from your instance(s)\nand you'd like it done programmatically, without having to reach for each\ninstance, search for it and hit the **\"Uninstall\"** button. Anthem can do the\njob for you: you can simply call an ``anthem.lyrics.modules.uninstall`` with a\nlist of module names that you won't use anymore.\n\nExample (given that there are modules ``foo`` and ``bar`` that you want gone):\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n.. code:: python\n\n  from anthem.lyrics.modules import uninstall\n\n  [...]\n  @anthem.log\n  def uninstall_foo(ctx):\n      \"\"\"Get rid of legacy `foo` and `bar`.\"\"\"\n      uninstall(ctx, ['foo', 'bar'])\n\nUpdating translations on module(s)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIn a similar fashion, sometimes you need to update translations on a set of\nmodules - ``anthem.lyrics.modules.update_translations`` is there for you :wink:\n\nExample is similar to the previous case - just call the different method instead.\n\nUpdating module configuration\n=============================\n\nBy using this feature, you're able to preconfigure your module setup via Anthem\nsong: you'll just need a straight idea what needs to be done, an instance of a\nconfiguration settings model for your module (model name will do as well) and a\nmapping (in a form of Python dictionary) of technical configuration names with\ndesired values.\n\nHere's a brief example of ``sale`` module configuration:\n\n.. code:: python\n\n  from anthem.lyrics import settings\n\n  [...]\n  @anthem.log\n  def define_sale_settings(ctx):\n      \"\"\"Configure `sale` module.\"\"\"\n      model = ctx.env['sale.config.settings']\n      # it's okay to use 'sale.config.settings' as a string though\n      model = 'sale.config.settings'\n      settings(ctx, model, {\n          'default_invoice_policy': 'delivery',\n          ...: ...,\n          'et': 'cetera',\n      })\n\nBe advised: settings onchange are not triggered by this function.\n\nUsage within Marabunta\n======================\n\nAnthem and `Marabunta <https://github.com/camptocamp/marabunta>`_ are powerful\nwhen combined: you can call a set of songs inside Marabunta's migration steps\nusing following syntax:\n\n.. code:: yaml\n\n  ...\n  - version: 10.0.1.0.0\n    operations:\n      pre:\n        - anthem songs.upgrade.your_pre_song::main\n      post:\n        - anthem songs.upgrade.your_post_song::main\n\nBy using this approach, you possess the power of full-pledged Odoo\n``Environment`` instance initialized on a live database while performing a\nregular upgrade powered by Marabunta.\n\nLet's say that you have to enable multicompany with inter-company transactions\non a migration to next version, lets say, 10.0.1.1.0. In this case, you'll need\na song to back this up on a Python side first:\n\n.. code:: python\n\n   # songs.upgrade.upgrade_10_0_1_1_0.py\n   from anthem.lyrics import settings\n\n   [...]\n   @anthem.log\n   def enable_multicompany(ctx):\n       \"\"\"Set up multicompany.\"\"\"\n       settings(ctx, 'base.config.settings', {\n           # enable multicompany as it is\n           'group_light_multi_company': True,\n           # enable inter-company transactions\n           'module_inter_company_rules': True,\n       })\n\n    [...]\n    @anthem.log\n    def main(ctx):\n        enable_multicompany(ctx)\n\nAnd then you'll need to call it on a migration step:\n\n.. code:: yaml\n\n  ...\n  - version: 10.0.1.1.0\n    operations:\n      post:\n        - anthem songs.upgrade.upgrade_10_0_1_1_0::main\n\nBoom! Enjoy your new multicompany settings.\n\nThat's all, folks!\n==================\n\nThanks for reading. Happy hacking and enjoy your songwriting skills!\n\n\n.. :changelog:\n\nRelease History\n===============\n\nUnreleased\n----------\n\n**Features**\n\n**Bugfixes**\n\n**Improvements**\n\n**Documentation**\n\n**Build**\n\n0.14.0 (2023-05-16)\n-------------------\n\n**Bugfixes**\n\n- Fix Update_translation function and update black version 22.3.0\n- Pin version of Setuptools < 58\n- Fix environment initialization for Odoo 15\n- Fix `add_xmlid` for Odoo 15\n\n**Improvements**\n\n- Enable Travis-CI tests for Odoo 14 and Odoo 15\n- Add: nuke_translations to allow to remove already existing translations\n\n0.13.0 (2019-08-29)\n-------------------\n\n**Features**\n\n- BREAKING: Change default `overwrite` value for\n   ``lyrics.modules.update_translations`` to False\n\n- Support odoo saas versions\n\n**Bugfixes**\n\n- Make ``lyrics.modules.update_translations`` Odoo >= 11.0 compatible\n\n0.12.2 (2019-06-21)\n-------------------\n\n**Improvements**\n\n- Add 'tracking_disable=True' as default context to load CSVs\n  (avoid creating 'mail.message' records and speed up the import process)\n\n**Build**\n\n- Packaging: build universal wheels\n\n0.12.1 (2018-11-09)\n-------------------\n\n**Documentation**\n\n- Improve API docs\n\n**Build**\n\n- The lib is now automaticaly published to Pypi by Travis when a tag is added\n\n0.12.0 (2018-03-19)\n-------------------\n\n**Features**\n\n- Add a new option ``--odoo-data-path`` or env. variable ``ODOO_DATA_PATH``.\n- The ``lyrics.loaders.load_csv`` method now accepts a relative path appended to the\n  new option \"odoo data path\". Absolute paths are still allowed.\n\n**Bugfixes**\n\n- ``lyrics.loaders.update_translations`` is now deprecated as it was a duplicate from\n  ``lyrics.modules.update_translations``\n\n0.11.0 (2017-12-22)\n-------------------\n\n**Features**\n\n - Make it Python 3 and Odoo 11 compatible\n\n**Build**\n\n - Switch to unicodecsv instead of custom code to handle that\n - Fix the flapping tests setup. Removed tox which was provoking that for some reason.\n - Add a lint check in build\n\n\n0.10.0 (2017-09-19)\n-------------------\n\n**Bugfixes**\n\n* Disable Odoo's xmlrpc port\n\n**Build**\n\n- Add 'build-release.sh' script with commands to build and upload the dist files\n\n0.9.0 (2017-08-21)\n------------------\n\n**Features**\n\n- New lyrics: modules.update_translations to update translations from po files\n- Lyrics 'uninstall' has been moved from uninstaller.uninstall to modules.uninstall,\n  previous path is still working for backward compatibility\n- New lyrics context manager 'records.switch_company'\n\n\n0.8.0 (2017-07-24)\n------------------\n\n**Features**\n\n- New lyrics: Define settings like being in the interface\n- Add CSV Loading columns control (columns whitelist and blacklist)\n\n**Bugfixes**\n\n- Fix error when loading CSV with no rows\n\n\n0.7.0 (2017-04-28)\n------------------\n\n**Improvements**\n\n- Split CSV loaders in functions to be able to get rows from a CSV or to load\n  rows, enabling to modify the rows before loading them for instance\n- create_or_update lyrics accepts now a model so we can change its env (user,\n  context, ...)\n- New lyrics to uninstall module\n\n\n0.6.0 (2017-01-18)\n------------------\n\n**Features**\n\n- CSV loaders can be used with a model in order to pass a context\n\n**Bugfixes**\n\n- Fix tests by installing eggs from odoo/requirements.txt\n\n\n0.5.0 (2016-10-12)\n------------------\n\n**Features**\n\n- Support Odoo 10\n- Allow to specify the encoding of an imported file, default is utf8\n\n**Bugfixes**\n\n- 'records.add_xmlid' lyrics do no longer fail when it already exists\n\n\n0.4.0 (2016-08-19)\n------------------\n\n**Features**\n\n- New lyrics: CSV loaders from path or stream\n- New ``ctx.log_line`` to print a line respecting the current indentation\n\n**Improvements**\n\n- Add tests for the existing lyrics\n\n**Build**\n\n- Finally green builds!\n\n\n0.3.0 (2016-07-26)\n------------------\n\n**Features**\n\n- Add --quiet mode\n\n**Fixes**\n\n- Encode the logged strings to the default encoding or utf8\n- Allow to use Ctrl-c to stop anthem.\n- Set openerp's loglevel to ERROR, its logs clutter anthem's own outputs\n\n0.2.0 (2016-07-22)\n------------------\n\n**Features**\n\n* Ability to log descriptions and timings in songs with the\n  context manager ``Context.log`` and the decorator ``anthem.log``.\n\n  ::\n\n    from anthem import log\n\n    @log\n    def setup_company(ctx):\n        \"\"\" Setup company \"\"\"\n        # do stuff\n        with ctx.log('other stuff'):\n            # do other stuff\n\n    @log\n    def load_data(ctx):\n        \"\"\" Load data \"\"\"\n        # load\n\n    @log\n    def main(ctx):\n        setup_company(ctx)\n        load_data(ctx)\n\n  If we run anthem on ``main``, we will get:\n\n  ::\n\n    running... main\n       running... Setup company\n          running... other stuff\n          other stuff: 0.850s\n       Setup company: 1.100s\n       running... Load data\n       Load data: 2.900s\n    main: 4.000s\n\n0.1.3 (2016-07-07)\n------------------\n\n**Fixes**\n\n- Correct lyric to create or update a record\n\n0.1.2 (2016-07-07)\n------------------\n\n- Add a lyric to create a xmlid\n- Add a lyric to create or update a record\n\n0.1.1 (2016-06-23)\n------------------\n\n- Fixed crash on non-editable install.\n\n0.1.0 (2016-06-23)\n------------------\n\nInitial release.\n",
    "bugtrack_url": null,
    "license": "LGPLv3+",
    "summary": "Make your Odoo scripts sing.",
    "version": "0.14.0",
    "project_urls": {
        "Homepage": "https://github.com/camptocamp/anthem"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90643b6686cd0133028ab2280636afe1b2a5af37924e17274a9781946b0886ce",
                "md5": "2a90536445d84ff93158efaf5384f023",
                "sha256": "3acc3b8af66ec15840fabb7821080ad2663dc4fc03a96b12e70c30a28a27be85"
            },
            "downloads": -1,
            "filename": "anthem-0.14.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a90536445d84ff93158efaf5384f023",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 19887,
            "upload_time": "2023-12-27T13:12:47",
            "upload_time_iso_8601": "2023-12-27T13:12:47.686851Z",
            "url": "https://files.pythonhosted.org/packages/90/64/3b6686cd0133028ab2280636afe1b2a5af37924e17274a9781946b0886ce/anthem-0.14.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33e8c7d6bf359bfaf144d59d3f531ca042465e3419db3740c471ccfbb7f7018b",
                "md5": "729a4fc179704e7155f7a619f697176f",
                "sha256": "a04d4e7e68dacc7f2915c3fadb842907964b7e19dda1d4fcab77528fdc65fed4"
            },
            "downloads": -1,
            "filename": "anthem-0.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "729a4fc179704e7155f7a619f697176f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29474,
            "upload_time": "2023-12-27T13:12:49",
            "upload_time_iso_8601": "2023-12-27T13:12:49.319471Z",
            "url": "https://files.pythonhosted.org/packages/33/e8/c7d6bf359bfaf144d59d3f531ca042465e3419db3740c471ccfbb7f7018b/anthem-0.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-27 13:12:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "camptocamp",
    "github_project": "anthem",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "anthem"
}
        
Elapsed time: 0.16036s