diff --git a/partner_contact_age_range/README.rst b/partner_contact_age_range/README.rst new file mode 100644 index 000000000..78fd53e8a --- /dev/null +++ b/partner_contact_age_range/README.rst @@ -0,0 +1,91 @@ +==================== +Contact's Age Range +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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: https://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/13.0/partner_contact_age_range + :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-13-0/partner-contact-13-0-partner_contact_age_range + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/116/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to set up age ranges to categorize partners. + +The age range is computed based on the partner's age. + +The cron job will auto compute age range. + +.. image:: ../static/description/age_range.png + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to Contact / Configuration / Age Ranges + +Configure your Age Ranges + +.. image:: ../static/description/configure_age_range.png + +Contacts will automatically compute age range based on age. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Druidoo + +Contributors +~~~~~~~~~~~~ + +* Druidoo + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_contact_age_range/__init__.py b/partner_contact_age_range/__init__.py new file mode 100644 index 000000000..31660d6a9 --- /dev/null +++ b/partner_contact_age_range/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/partner_contact_age_range/__manifest__.py b/partner_contact_age_range/__manifest__.py new file mode 100644 index 000000000..c8b3c2cc7 --- /dev/null +++ b/partner_contact_age_range/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019-2020: Druidoo () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Contact's Age Range", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "Druidoo, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/partner-contact", + "category": "Customer Relationship Management", + "summary": "Age Range for Contact's", + "depends": ["partner_contact_birthdate"], + "data": [ + "security/ir.model.access.csv", + "data/age_range_cron.xml", + "views/res_partner_view.xml", + "views/res_partner_age_range_view.xml", + ], + "installable": True, +} diff --git a/partner_contact_age_range/data/age_range_cron.xml b/partner_contact_age_range/data/age_range_cron.xml new file mode 100644 index 000000000..5376a6352 --- /dev/null +++ b/partner_contact_age_range/data/age_range_cron.xml @@ -0,0 +1,14 @@ + + + + Contact: Update Age Range + + code + model._cron_update_age_range_id() + + 1 + days + -1 + + + diff --git a/partner_contact_age_range/models/__init__.py b/partner_contact_age_range/models/__init__.py new file mode 100644 index 000000000..ecd9dc0f5 --- /dev/null +++ b/partner_contact_age_range/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_partner_age_range +from . import res_partner diff --git a/partner_contact_age_range/models/res_partner.py b/partner_contact_age_range/models/res_partner.py new file mode 100644 index 000000000..f4e625ae2 --- /dev/null +++ b/partner_contact_age_range/models/res_partner.py @@ -0,0 +1,42 @@ +# Copyright 2019-2020: Druidoo () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + age_range_id = fields.Many2one( + "res.partner.age.range", + "Age Range", + compute="_compute_age_range_id", + store=True, + ) + + @api.depends("age") + def _compute_age_range_id(self): + age_ranges = self.env["res.partner.age.range"].search([]) + for record in self: + if not record.age: + age_range = False + else: + age_range = ( + age_ranges.filtered( + lambda age_range: age_range.age_from + <= record.age + <= age_range.age_to + ) + or False + ) + if record.age_range_id != age_range: + record.age_range_id = age_range and age_range.id or age_range + + @api.model + def _cron_update_age_range_id(self): + """ + This method is called from a cron job. + It is used to update age range on contact + """ + partners = self.search([("birthdate_date", "!=", False)]) + partners._compute_age_range_id() diff --git a/partner_contact_age_range/models/res_partner_age_range.py b/partner_contact_age_range/models/res_partner_age_range.py new file mode 100644 index 000000000..2781c84a2 --- /dev/null +++ b/partner_contact_age_range/models/res_partner_age_range.py @@ -0,0 +1,48 @@ +# Copyright 2019-2020: Druidoo () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ResPartnerDateRange(models.Model): + _name = "res.partner.age.range" + _description = "Partner Age Range" + + def _default_age_from(self): + age_from = 0 + last_age_range = self.env["res.partner.age.range"].search( + [], order="age_to desc", limit=1 + ) + if last_age_range: + age_from = last_age_range.age_to + 1 + return age_from + + name = fields.Char(string="Name", required=True) + age_from = fields.Integer( + string="From", required=True, default=lambda self: self._default_age_from() + ) + age_to = fields.Integer(string="To", required=True) + + _sql_constraints = [("name_uniq", "unique (name)", "A name must be unique !")] + + @api.constrains("age_from", "age_to") + def _validate_range(self): + for rec in self: + if rec.age_from >= rec.age_to: + raise ValidationError( + _("%s is not a valid range (%s >= %s)") + % (rec.name, rec.age_from, rec.age_to) + ) + range_id = rec.search( + [ + ("age_from", "<=", rec.age_to), + ("age_to", ">=", rec.age_from), + ("id", "!=", rec.id), + ], + limit=1, + ) + if range_id: + raise ValidationError( + _("%s is overalapping with range %s") % (rec.name, range_id.name) + ) diff --git a/partner_contact_age_range/readme/CONTRIBUTORS.rst b/partner_contact_age_range/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..a550e6fcd --- /dev/null +++ b/partner_contact_age_range/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Druidoo () diff --git a/partner_contact_age_range/readme/DESCRIPTION.rst b/partner_contact_age_range/readme/DESCRIPTION.rst new file mode 100644 index 000000000..8c6116e6e --- /dev/null +++ b/partner_contact_age_range/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module allows to set up age ranges to categorize partners. + +The age range is computed based on the partner's age. + +The cron job will auto compute age range. + +.. image:: ../static/description/age_range.png diff --git a/partner_contact_age_range/readme/USAGE.rst b/partner_contact_age_range/readme/USAGE.rst new file mode 100644 index 000000000..66511f038 --- /dev/null +++ b/partner_contact_age_range/readme/USAGE.rst @@ -0,0 +1,7 @@ +Go to Contact / Configuration / Age Ranges + +Configure your Age Ranges + +.. image:: ../static/description/configure_age_range.png + +Contacts will automatically compute age range based on age. diff --git a/partner_contact_age_range/security/ir.model.access.csv b/partner_contact_age_range/security/ir.model.access.csv new file mode 100644 index 000000000..8f69cc251 --- /dev/null +++ b/partner_contact_age_range/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_res_partner_age_range_admin,access_res_partner_age_range_admin,model_res_partner_age_range,base.group_partner_manager,1,1,1,1 +access_res_partner_age_range_user,access_res_partner_age_range_user,model_res_partner_age_range,base.group_user,1,0,0,0 diff --git a/partner_contact_age_range/static/description/age_range.png b/partner_contact_age_range/static/description/age_range.png new file mode 100644 index 000000000..72b7fc214 Binary files /dev/null and b/partner_contact_age_range/static/description/age_range.png differ diff --git a/partner_contact_age_range/static/description/configure_age_range.png b/partner_contact_age_range/static/description/configure_age_range.png new file mode 100644 index 000000000..b6ca18d00 Binary files /dev/null and b/partner_contact_age_range/static/description/configure_age_range.png differ diff --git a/partner_contact_age_range/static/description/icon.png b/partner_contact_age_range/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_contact_age_range/static/description/icon.png differ diff --git a/partner_contact_age_range/static/description/index.html b/partner_contact_age_range/static/description/index.html new file mode 100644 index 000000000..9840087a3 --- /dev/null +++ b/partner_contact_age_range/static/description/index.html @@ -0,0 +1,438 @@ + + + + + + +Contact's Age Range + + + +
+

Contact's Age

+ + +

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

+

Adds Age Ranges

+

Adds and computes Age Range on contacts

+

Table of contents

+ +
+

Installation

+

To install this module, you need to:

+
    +
  • clone the branch 13.0 of the repository https://github.com/OCA/partner-contact
  • +
  • add the path to this repository in your configuration (addons-path)
  • +
  • update the module list
  • +
  • search for “Contact's Age Range” in your addons
  • +
  • install the module
  • +
+
+
+

Usage

+

User can create age ranges.

+

When age on concact set it will auto populate age range on contact.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Druidoo
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/partner_contact_age_range/tests/__init__.py b/partner_contact_age_range/tests/__init__.py new file mode 100644 index 000000000..3f91f8997 --- /dev/null +++ b/partner_contact_age_range/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2019-2020: Druidoo () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_res_partner_age_range diff --git a/partner_contact_age_range/tests/test_res_partner_age_range.py b/partner_contact_age_range/tests/test_res_partner_age_range.py new file mode 100644 index 000000000..0a670e843 --- /dev/null +++ b/partner_contact_age_range/tests/test_res_partner_age_range.py @@ -0,0 +1,16 @@ +# Copyright 2019-2020: Druidoo () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestRespartnerAgeRange(TransactionCase): + def test_overlap(self): + self.env["res.partner.age.range"].create( + {"name": "baby", "age_from": 0, "age_to": 2} + ) + with self.assertRaises(ValidationError): + self.env["res.partner.age.range"].create( + {"name": "Toddler", "age_from": 1, "age_to": 4} + ) diff --git a/partner_contact_age_range/views/res_partner_age_range_view.xml b/partner_contact_age_range/views/res_partner_age_range_view.xml new file mode 100644 index 000000000..bb6453867 --- /dev/null +++ b/partner_contact_age_range/views/res_partner_age_range_view.xml @@ -0,0 +1,47 @@ + + + + res.partner.age.range.tree + res.partner.age.range + + + + + + + + + + res.partner.age.range.form + res.partner.age.range + +
+ + + + + + + +
+
+
+ + Age Ranges + ir.actions.act_window + res.partner.age.range + [] + {} + + Manage the contact age range you want to have available in your system. + For eg: 0-10, 11-20 + + + +
diff --git a/partner_contact_age_range/views/res_partner_view.xml b/partner_contact_age_range/views/res_partner_view.xml new file mode 100644 index 000000000..dbd7aa133 --- /dev/null +++ b/partner_contact_age_range/views/res_partner_view.xml @@ -0,0 +1,16 @@ + + + + Age Field + res.partner + + + + + + + +