Skip to content

Commit

Permalink
Merge PR #1021 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Mar 3, 2021
2 parents 55b071c + dff3343 commit a2dbd98
Show file tree
Hide file tree
Showing 16 changed files with 781 additions and 0 deletions.
81 changes: 81 additions & 0 deletions partner_address_version/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
=======================
Partner Address Version
=======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/12.0/partner_address_version
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-partner_address_version
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/134/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to manage versions for partner addresses.

A list of fields are defined for versioning. These are immutable once set, and force the user to create a new partner
if they want to change one of these fields.

This forces historical consistency. For example, the moment you confirm a
sale order, you might want to lock the address of that sale order instead of having it
change everytime that partner is modified (see e.g sale_partner_version).

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_address_version%0Aversion:%2012.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
~~~~~~~

* Akretion

Contributors
~~~~~~~~~~~~

* Benoît Guillot <benoit.guillot@akretion.com>
* Kevin Khao <kevin.khao@akretion.com>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/12.0/partner_address_version>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions partner_address_version/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2018 Akretion - Benoît Guillot
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import wizards
14 changes: 14 additions & 0 deletions partner_address_version/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2018 Akretion - Benoît Guillot
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Partner Address Version",
"version": "14.0.1.0.0",
"author": "Akretion, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"category": "CRM",
"license": "AGPL-3",
"installable": True,
"depends": [
"base",
],
}
38 changes: 38 additions & 0 deletions partner_address_version/i18n/partner_address_version.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_address_version
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: partner_address_version
#: model:ir.model.fields,field_description:partner_address_version.field_res_partner_date_version
#: model:ir.model.fields,field_description:partner_address_version.field_res_users_date_version
msgid "Date version"
msgstr ""

#. module: partner_address_version
#: model:ir.model,name:partner_address_version.model_res_partner
msgid "Partner"
msgstr ""

#. module: partner_address_version
#: model:ir.model.fields,field_description:partner_address_version.field_res_partner_version_hash
#: model:ir.model.fields,field_description:partner_address_version.field_res_users_version_hash
msgid "Version hash"
msgstr ""

#. module: partner_address_version
#: code:addons/partner_address_version/models/res_partner.py:63
#, python-format
msgid "You can't modify a versioned field %s on the versioned partner %s."
msgstr ""

4 changes: 4 additions & 0 deletions partner_address_version/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2018 Akretion - Benoît Guillot
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import res_partner
113 changes: 113 additions & 0 deletions partner_address_version/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright 2018 Akretion - Benoît Guillot
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import hashlib
from collections import OrderedDict

from odoo import _, exceptions, fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

version_hash = fields.Char(readonly=True, copy=False)
date_version = fields.Datetime(string="Date version", readonly=True)

def get_version_fields(self):
# deprecated uses _version_fields instead
return self._version_fields()

def _version_fields(self):
return [
"name",
"street",
"street2",
"zip",
"city",
"country_id",
"parent_id",
]

def get_version_hash(self):
# deprecated uses _version_hash instead
return self._version_hash()

def _version_hash(self):
version_fields = self._version_fields()
version = OrderedDict()
for field in version_fields:
if field == "parent_id":
parent_id = self.parent_id.id if self.parent_id else self.id
version[field] = parent_id
elif self[field]:
version[field] = self[field]
version_hash = hashlib.md5(str(version).encode("utf-8")).hexdigest()
return version_hash

def _version_impacted_tables(self):
"""
:return:
- list of tables to update in case of address versioning
"""
return []

def _version_exclude_keys(self):
"""
:return:
- dict:
key = table name
value = list of columns to ignore in case of address
versioning
"""
return {}

def _version_need(self):
"""
This method is supposed to be overriden to determine when
an address versioning is needed or not
:return: True if versioning is required else False
"""
return False

def _version_apply(self):
self.ensure_one()
if self._version_need():
# the address is used, create a new version and
# update related tables
version_p = self._version_create()
partner_wizard = self.env[
"base.partner.merge.automatic.wizard"
].with_context(address_version=True)
partner_wizard._update_foreign_keys(self, version_p)
return False

def write(self, vals):
version_fields = self._version_fields()
has_written_versioned_fields = any((f in version_fields) for f in vals.keys())
for partner in self:
if (
not partner.version_hash
and not vals.get("version_hash", False)
and has_written_versioned_fields
):
partner._version_apply()

if partner.version_hash and has_written_versioned_fields:
raise exceptions.UserError(
_(
"You can't modify a versioned field %s on the "
"versioned partner %s."
)
% (version_fields, partner.name)
)
return super(ResPartner, self).write(vals)

def _version_create(self):
version_hash = self._version_hash()
default = {
"active": False,
"version_hash": version_hash,
"parent_id": self.parent_id.id if self.parent_id else self.id,
"date_version": fields.Datetime.now(),
}
return self.copy(default=default)
3 changes: 3 additions & 0 deletions partner_address_version/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Benoît Guillot <benoit.guillot@akretion.com>
* Kevin Khao <kevin.khao@akretion.com>
* Cédric Pigeon
8 changes: 8 additions & 0 deletions partner_address_version/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This module allows you to manage versions for partner addresses.

A list of fields are defined for versioning. These are immutable once set, and force the user to create a new partner
if they want to change one of these fields.

This forces historical consistency. For example, the moment you confirm a
sale order, you might want to lock the address of that sale order instead of having it
change everytime that partner is modified (see e.g sale_partner_version).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a2dbd98

Please sign in to comment.