Metadata-Version: 2.1
Name: odoo-addon-import_metadata
Version: 20.0.1.0.1
Requires-Dist: odoo==20.0.*
Summary: Import the creation and last update user and date of records
Home-page: https://github.com/GetFluvo/addons
License: LGPL-3
Author: Fluvo
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 20.0
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Description-Content-Type: text/x-rst

===============
Import Metadata
===============

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:33f96c7b7fcf7f561dcc92eee6f576c5f58803fd482ca3267edcaf66c08c7556
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
    :target: https://odoo-community.org/page/development-status
    :alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
    :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
    :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-GetFluvo%2Faddons-lightgray.png?logo=github
    :target: https://github.com/GetFluvo/addons/tree/20.0/import_metadata
    :alt: GetFluvo/addons

|badge1| |badge2| |badge3|

Import the original creation and last update user and date of records,
the ``create_uid``, ``create_date``, ``write_uid`` and ``write_date``
fields.

Odoo always sets these fields itself, and drops any value given for
them. When data is migrated from another system, the original author and
dates are lost. With this module, an administrator can keep them by
importing with the ``write_metadata`` key in the context.

**Table of contents**

.. contents::
   :local:

Use Cases / Context
===================

Migrations often have to keep who created a record and when: the date a
customer was created, the author of a note, the history of a document.
Odoo does not allow setting these fields, even through an import.

Usage
=====

Import with ``write_metadata`` in the context, as a user of the
*Administration / Settings* group, and add any of the ``create_uid``,
``create_date``, ``write_uid`` and ``write_date`` columns. For example
with ``load()`` through JSON-RPC or XML-RPC:

.. code:: python

   models.execute_kw(
       db, uid, password, "res.partner", "load",
       [["name", "create_uid", "create_date"],
        [["Azure Interior", "Marc Demo", "2016-01-02 03:04:05"]]],
       {"context": {"write_metadata": True, "tz": "UTC"}},
   )

The user columns accept what any many2one column of an import accepts:

- ``create_uid``: the name of the user
- ``create_uid/id``: the XML ID of the user
- ``create_uid/.id``: the database id of the user

The dates are in the ``YYYY-MM-DD HH:MM:SS`` format. Like any date of an
import, ``load()`` reads them in the timezone of the context, or else of
the importing user, and stores them in UTC. Pass ``"tz": "UTC"`` in the
context to import UTC dates unchanged. Empty cells keep the value Odoo
sets.

The context key also works for ``create()`` and ``write()`` called
directly, with user ids or records and datetimes or strings.

Without the context key, or for other users, the columns are ignored as
without this module, and the import does not fail.

Odoo posts a *created* message in the chatter of every new record, with
the date of the import and the importing user as author. For historical
data, suppress it with one of these context keys of Odoo, next to
``write_metadata``:

- ``"mail_create_nolog": True``: no *created* message.
- ``"tracking_disable": True``: no *created* message, no tracking of
  field changes, and no automatic followers.

Known issues / Roadmap
======================

- ``write_uid`` and ``write_date`` are set again by any later write to
  the record, including writes done by Odoo itself later in the same
  transaction, for instance a recomputation of a stored field. Import
  them last, or in a separate import of the same records.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/GetFluvo/addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/GetFluvo/addons/issues/new?body=module:%20import_metadata%0Aversion:%2020.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Fluvo

Contributors
------------

- bosd

Other credits
-------------

Based on the idea and the ``write_metadata`` context key of the
``import_metadata`` module of
`easier_import <https://github.com/tfrancoi/easier_import>`__ by
Thibault Francois. This is a new implementation.

Maintainers
-----------

This module is part of the `GetFluvo/addons <https://github.com/GetFluvo/addons/tree/20.0/import_metadata>`_ project on GitHub.

You are welcome to contribute.
