From b35e24752d1f5f5f5d0802030e22f5d93ea14a1b Mon Sep 17 00:00:00 2001 From: Luciano Rossi Date: Fri, 26 Jul 2024 02:36:30 -0300 Subject: [PATCH] =?UTF-8?q?REL=20#37=20Add=20skill=20to=20manage=20antig?= =?UTF-8?q?=C3=BCedad=20and=203/4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configuration.py | 2 ++ message.xml | 3 ++ partner.py | 56 +++++++++++++++++++++++++++++-- view/configuration_skill_form.xml | 4 +++ view/partner_skill_tree.xml | 3 ++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/configuration.py b/configuration.py index a19b5d1..6aa6395 100644 --- a/configuration.py +++ b/configuration.py @@ -161,3 +161,5 @@ class ConfigurationSkill(ModelSingleton, ModelSQL, ModelView): skill_08 = fields.Numeric('Skill 8 %', digits=(16, 2)) skill_09 = fields.Numeric('Skill 9 %', digits=(16, 2)) skill_10 = fields.Numeric('Skill 10 %', digits=(16, 2)) + skill_11 = fields.Numeric('Skill 11 %', digits=(16, 2)) + skill_12 = fields.Numeric('Skill 12 %', digits=(16, 2)) diff --git a/message.xml b/message.xml index f586735..bf73996 100644 --- a/message.xml +++ b/message.xml @@ -19,5 +19,8 @@ Lot "%s" must be cancelled before deletion. + + The start activity date is not defined. + diff --git a/partner.py b/partner.py index 0173611..89cbde5 100644 --- a/partner.py +++ b/partner.py @@ -1,6 +1,8 @@ # This file is part of the cooperative_ar module for Tryton. # The COPYRIGHT file at the top level of this repository contains # the full copyright notices and license terms. +from datetime import datetime +from dateutil import relativedelta from decimal import Decimal from trytond.model import ModelView, ModelSQL, fields @@ -75,6 +77,11 @@ class Partner(ModelSQL, ModelView): skill_08 = fields.Boolean('Skill 8') skill_09 = fields.Boolean('Skill 9') skill_10 = fields.Boolean('Skill 10') + skill_11 = fields.Boolean('Skill 11') + skill_12 = fields.Boolean('Skill 12') + recibo_without_seniority = fields.Function(fields.Numeric( + 'Amount without seniority', digits=(16, 2)), + 'on_change_with_recibo_without_seniority') recibo_total = fields.Function(fields.Numeric( 'Total Amount', digits=(16, 2)), 'on_change_with_recibo_total') @@ -149,10 +156,23 @@ def create(cls, vlist): raise UserError(gettext('cooperative_ar.msg_unique_file')) return super().create(vlist) + @classmethod + def get_start_activity_date(cls): + 'get_start_activity_date' + pool = Pool() + Company = pool.get('company.company') + company_id = Transaction().context.get('company') + if company_id: + company = Company(company_id) + if company.party.start_activity_date: + return company.party.start_activity_date + + raise UserError(gettext('cooperative_ar.msg_start_activity_date_not_defined')) + @fields.depends('recibo_base', 'skill_01', 'skill_02', 'skill_03', 'skill_04', 'skill_05', 'skill_06', 'skill_07', 'skill_08', - 'skill_09', 'skill_10') - def on_change_with_recibo_total(self, name=None): + 'skill_09', 'skill_10', 'skill_11', 'skill_12', 'incorporation_date') + def on_change_with_recibo_without_seniority(self, name=None): pool = Pool() ConfigurationSkill = pool.get('cooperative_ar.configuration.skill') @@ -194,5 +214,37 @@ def on_change_with_recibo_total(self, name=None): if self.skill_10 and configuration.skill_10: amount += (recibo_base * configuration.skill_10 / Decimal(100)).quantize(quantize) + # 3/4 + if self.skill_12 and configuration.skill_12: + amount -= (recibo_base * configuration.skill_12 / + Decimal(100)).quantize(quantize) + + return amount + + @fields.depends('recibo_base', 'skill_01', 'skill_02', 'skill_03', + 'skill_04', 'skill_05', 'skill_06', 'skill_07', 'skill_08', + 'skill_09', 'skill_10', 'skill_11', 'skill_12', 'incorporation_date') + def on_change_with_recibo_total(self, name=None): + pool = Pool() + ConfigurationSkill = pool.get('cooperative_ar.configuration.skill') + Date = pool.get('ir.date) + + recibo_base = self.recibo_base + if not recibo_base: + return Decimal(0) + + start_date = self.incorporation_date + end_date = Date.today() + # Get the relativedelta between two dates + delta = relativedelta.relativedelta(end_date, start_date) + + configuration = ConfigurationSkill(1) + amount = self.on_change_with_recibo_without_seniority(name) + quantize = Decimal(10) ** -Decimal(2) + + # antiguedad + if self.skill_11 and configuration.skill_11: + amount += (recibo_base * configuration.skill_11 * delta.years / + Decimal(100)).quantize(quantize) return amount diff --git a/view/configuration_skill_form.xml b/view/configuration_skill_form.xml index 8bd6cf2..4d19816 100644 --- a/view/configuration_skill_form.xml +++ b/view/configuration_skill_form.xml @@ -20,4 +20,8 @@