Browse Source

[13.0][ADD] partner_iterative_archive

14.0
Andrea 4 years ago
committed by newtratip
parent
commit
d990e00906
  1. 30
      partner_iterative_archive/README.rst
  2. 3
      partner_iterative_archive/__init__.py
  3. 14
      partner_iterative_archive/__manifest__.py
  4. 3
      partner_iterative_archive/models/__init__.py
  5. 16
      partner_iterative_archive/models/res_partner.py
  6. 2
      partner_iterative_archive/readme/CONTRIBUTORS.rst
  7. 1
      partner_iterative_archive/readme/DESCRIPTION.rst
  8. 3
      partner_iterative_archive/tests/__init__.py
  9. 47
      partner_iterative_archive/tests/test_partner_iterative_archive.py

30
partner_iterative_archive/README.rst

@ -0,0 +1,30 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=========================
Partner Iterative Archive
=========================
This module automatically (un)archives contact partners when their parent is (un)archived.
Credits
=======
Contributors
------------
* Antonio Esposito <a.esposito@onestein.nl>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit http://odoo-community.org.

3
partner_iterative_archive/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models

14
partner_iterative_archive/__manifest__.py

@ -0,0 +1,14 @@
# Copyright 2019-2020 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Partner Iterative Archive",
"summary": "Archive all contacts when parent is archived",
"author": "Onestein, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"category": "Tools",
"version": "13.0.1.0.0",
"license": "AGPL-3",
"depends": ["base"],
"installable": True,
}

3
partner_iterative_archive/models/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import res_partner

16
partner_iterative_archive/models/res_partner.py

@ -0,0 +1,16 @@
# Copyright 2019-2020 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class ResPartner(models.Model):
_inherit = "res.partner"
def toggle_active(self):
res = super().toggle_active()
if self.env.context.get("skip_child_toggle_active"):
return res
for partner in self.filtered(lambda x: not x.active):
partner.child_ids.filtered(lambda x: x.active).toggle_active()
return res

2
partner_iterative_archive/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
* Antonio Esposito <a.esposito@onestein.nl>
* Andrea Stirpe <a.stirpe@onestein.nl>

1
partner_iterative_archive/readme/DESCRIPTION.rst

@ -0,0 +1 @@
This module automatically archives contacts when their parent is archived.

3
partner_iterative_archive/tests/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_partner_iterative_archive

47
partner_iterative_archive/tests/test_partner_iterative_archive.py

@ -0,0 +1,47 @@
# Copyright 2019-2020 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestBase(TransactionCase):
def setUp(self):
super().setUp()
Partner = self.env["res.partner"]
self.p1 = Partner.browse(Partner.name_create("Parent")[0])
self.c1 = Partner.create({"name": "Child 1", "parent_id": self.p1.id})
self.c11 = Partner.create({"name": "Grand-Child 1.1", "parent_id": self.c1.id})
self.c2 = Partner.create({"name": "Child 2", "parent_id": self.p1.id})
def test_01_archive_partners(self):
self.assertTrue(self.p1.active)
self.assertTrue(self.c1.active)
self.assertTrue(self.c11.active)
self.assertTrue(self.c2.active)
# archive the parent partner, skip the archive of contacts
self.p1.with_context(skip_child_toggle_active=True).toggle_active()
self.assertFalse(self.p1.active)
self.assertTrue(self.c1.active)
self.assertTrue(self.c11.active)
self.assertTrue(self.c2.active)
# unarchive the parent partner
self.p1.toggle_active()
self.assertTrue(self.c1.active)
self.assertTrue(self.c11.active)
self.assertTrue(self.c2.active)
# archive the parent partner, automatically archive contacts
self.p1.toggle_active()
self.assertFalse(self.p1.active)
self.assertFalse(self.c1.active)
self.assertFalse(self.c11.active)
self.assertFalse(self.c2.active)
# unarchive the parent partner
self.p1.toggle_active()
self.assertTrue(self.p1.active)
self.assertFalse(self.c1.active)
self.assertFalse(self.c11.active)
self.assertFalse(self.c2.active)
Loading…
Cancel
Save