Skip to content

Commit 7f770c2

Browse files
ajayjaviyanewtratip
authored andcommitted
[ADD] new module : partner_contact_age_range
1 parent fcb0b07 commit 7f770c2

19 files changed

+761
-0
lines changed

partner_contact_age_range/README.rst

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
====================
2+
Contact's Age Range
3+
====================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
17+
:target: https://github.com/OCA/partner-contact/tree/13.0/partner_contact_age_range
18+
:alt: OCA/partner-contact
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-partner_contact_age_range
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/116/13.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module allows to set up age ranges to categorize partners.
29+
30+
The age range is computed based on the partner's age.
31+
32+
The cron job will auto compute age range.
33+
34+
.. image:: ../static/description/age_range.png
35+
36+
**Table of contents**
37+
38+
.. contents::
39+
:local:
40+
41+
Usage
42+
=====
43+
44+
Go to Contact / Configuration / Age Ranges
45+
46+
Configure your Age Ranges
47+
48+
.. image:: ../static/description/configure_age_range.png
49+
50+
Contacts will automatically compute age range based on age.
51+
52+
53+
Bug Tracker
54+
===========
55+
56+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
57+
In case of trouble, please check there if your issue has already been reported.
58+
If you spotted it first, help us smashing it by providing a detailed and welcomed
59+
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20partner_contact_age_range%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
60+
61+
Do not contact contributors directly about support or help with technical issues.
62+
63+
Credits
64+
=======
65+
66+
Authors
67+
~~~~~~~
68+
69+
* Druidoo
70+
71+
Contributors
72+
~~~~~~~~~~~~
73+
74+
* Druidoo <https://www.druidoo.io>
75+
76+
Maintainers
77+
~~~~~~~~~~~
78+
79+
This module is maintained by the OCA.
80+
81+
.. image:: https://odoo-community.org/logo.png
82+
:alt: Odoo Community Association
83+
:target: https://odoo-community.org
84+
85+
OCA, or the Odoo Community Association, is a nonprofit organization whose
86+
mission is to support the collaborative development of Odoo features and
87+
promote its widespread use.
88+
89+
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/13.0/partner_contact_age_range>`_ project on GitHub.
90+
91+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

partner_contact_age_range/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import models
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Contact's Age Range",
6+
"version": "13.0.1.0.0",
7+
"license": "AGPL-3",
8+
"author": "Druidoo, Odoo Community Association (OCA)",
9+
"website": "https://github.com/OCA/partner-contact",
10+
"category": "Customer Relationship Management",
11+
"summary": "Age Range for Contact's",
12+
"depends": ["partner_contact_birthdate"],
13+
"data": [
14+
"security/ir.model.access.csv",
15+
"data/age_range_cron.xml",
16+
"views/res_partner_view.xml",
17+
"views/res_partner_age_range_view.xml",
18+
],
19+
"installable": True,
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="ir_cron_partner_age_range" model="ir.cron">
4+
<field name="name">Contact: Update Age Range</field>
5+
<field name="model_id" ref="model_res_partner" />
6+
<field name="state">code</field>
7+
<field name="code">model._cron_update_age_range_id()</field>
8+
<field name="user_id" ref="base.user_root" />
9+
<field name="interval_number">1</field>
10+
<field name="interval_type">days</field>
11+
<field name="numbercall">-1</field>
12+
<field name="doall" eval="False" />
13+
</record>
14+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import res_partner_age_range
4+
from . import res_partner
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class ResPartner(models.Model):
8+
_inherit = "res.partner"
9+
10+
age_range_id = fields.Many2one(
11+
"res.partner.age.range",
12+
"Age Range",
13+
compute="_compute_age_range_id",
14+
store=True,
15+
)
16+
17+
@api.depends("age")
18+
def _compute_age_range_id(self):
19+
age_ranges = self.env["res.partner.age.range"].search([])
20+
for record in self:
21+
if not record.age:
22+
age_range = False
23+
else:
24+
age_range = (
25+
age_ranges.filtered(
26+
lambda age_range: age_range.age_from
27+
<= record.age
28+
<= age_range.age_to
29+
)
30+
or False
31+
)
32+
if record.age_range_id != age_range:
33+
record.age_range_id = age_range and age_range.id or age_range
34+
35+
@api.model
36+
def _cron_update_age_range_id(self):
37+
"""
38+
This method is called from a cron job.
39+
It is used to update age range on contact
40+
"""
41+
partners = self.search([("birthdate_date", "!=", False)])
42+
partners._compute_age_range_id()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class ResPartnerDateRange(models.Model):
9+
_name = "res.partner.age.range"
10+
_description = "Partner Age Range"
11+
12+
def _default_age_from(self):
13+
age_from = 0
14+
last_age_range = self.env["res.partner.age.range"].search(
15+
[], order="age_to desc", limit=1
16+
)
17+
if last_age_range:
18+
age_from = last_age_range.age_to + 1
19+
return age_from
20+
21+
name = fields.Char(string="Name", required=True)
22+
age_from = fields.Integer(
23+
string="From", required=True, default=lambda self: self._default_age_from()
24+
)
25+
age_to = fields.Integer(string="To", required=True)
26+
27+
_sql_constraints = [("name_uniq", "unique (name)", "A name must be unique !")]
28+
29+
@api.constrains("age_from", "age_to")
30+
def _validate_range(self):
31+
for rec in self:
32+
if rec.age_from >= rec.age_to:
33+
raise ValidationError(
34+
_("%s is not a valid range (%s >= %s)")
35+
% (rec.name, rec.age_from, rec.age_to)
36+
)
37+
range_id = rec.search(
38+
[
39+
("age_from", "<=", rec.age_to),
40+
("age_to", ">=", rec.age_from),
41+
("id", "!=", rec.id),
42+
],
43+
limit=1,
44+
)
45+
if range_id:
46+
raise ValidationError(
47+
_("%s is overalapping with range %s") % (rec.name, range_id.name)
48+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Druidoo (<https://www.druidoo.io>)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This module allows to set up age ranges to categorize partners.
2+
3+
The age range is computed based on the partner's age.
4+
5+
The cron job will auto compute age range.
6+
7+
.. image:: ../static/description/age_range.png
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Go to Contact / Configuration / Age Ranges
2+
3+
Configure your Age Ranges
4+
5+
.. image:: ../static/description/configure_age_range.png
6+
7+
Contacts will automatically compute age range based on age.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
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
3+
access_res_partner_age_range_user,access_res_partner_age_range_user,model_res_partner_age_range,base.group_user,1,0,0,0
Loading
Loading
Loading

0 commit comments

Comments
 (0)