You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.9 KiB
95 lines
2.9 KiB
# -*- coding: utf-8 -*-
|
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
from odoo import fields, models, api
|
|
|
|
STATUS = [
|
|
("minor", "Minor"),
|
|
("major", "Major"),
|
|
]
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
_inherit = "res.partner"
|
|
|
|
age = fields.Integer(store=True)
|
|
majority_date = fields.Date(
|
|
string="Majority date",
|
|
compute="_get_majority",
|
|
compute_sudo=True,
|
|
store=True,
|
|
)
|
|
majority_years = fields.Integer(
|
|
string="Majority years",
|
|
compute="_get_majority",
|
|
compute_sudo=True,
|
|
store=True,
|
|
)
|
|
is_major = fields.Boolean(
|
|
string="Is major",
|
|
compute="_get_majority",
|
|
compute_sudo=True,
|
|
)
|
|
legal_status = fields.Selection(
|
|
selection=STATUS,
|
|
string="Legal status",
|
|
compute="_get_legal_status",
|
|
)
|
|
emancipation_date = fields.Date(
|
|
string="Emancipation",
|
|
readonly=True,
|
|
)
|
|
is_emancipated = fields.Boolean(
|
|
string="Is emancipated",
|
|
compute="_get_majority",
|
|
compute_sudo=True,
|
|
store=True,
|
|
)
|
|
|
|
@api.depends(
|
|
"nationality_id",
|
|
"nationality_id.majority_age",
|
|
"birthdate_date",
|
|
"emancipation_date",
|
|
)
|
|
def _get_majority(self):
|
|
for partner in self:
|
|
country_age = (
|
|
partner.nationality_id.majority_age if partner.nationality_id else False
|
|
)
|
|
birth = partner.birthdate_date
|
|
emancipation = partner.emancipation_date
|
|
major = False
|
|
today = fields.Date.today()
|
|
if emancipation:
|
|
major = emancipation <= today
|
|
partner.is_emancipated = True
|
|
partner.majority_date = emancipation
|
|
partner.is_major = major
|
|
partner.majority_years = (
|
|
relativedelta(today, emancipation).years
|
|
if major
|
|
else relativedelta(emancipation, today).years
|
|
)
|
|
elif country_age and birth:
|
|
majority = birth + relativedelta(years=country_age)
|
|
major = majority <= today
|
|
partner.is_emancipated = False
|
|
partner.majority_date = majority
|
|
partner.is_major = major
|
|
partner.majority_years = (
|
|
relativedelta(today, majority).years
|
|
if major
|
|
else relativedelta(majority, today).years
|
|
)
|
|
else:
|
|
partner.is_emancipated = False
|
|
partner.majority_date = False
|
|
partner.is_major = False
|
|
partner.majority_years = 0
|
|
|
|
@api.depends("is_major")
|
|
def _get_legal_status(self):
|
|
for partner in self:
|
|
partner.legal_status = "major" if partner.is_major else "minor"
|