Skip to content

Commit

Permalink
REL #37 Add skill to manage antigüedad and 3/4
Browse files Browse the repository at this point in the history
  • Loading branch information
lukio committed Jul 26, 2024
1 parent 17c6ed1 commit b35e247
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
2 changes: 2 additions & 0 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
3 changes: 3 additions & 0 deletions message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
<record model="ir.message" id="msg_lot_delete_cancel">
<field name="text">Lot "%s" must be cancelled before deletion.</field>
</record>
<record model="ir.message" id="msg_start_activity_date_not_defined">
<field name="text">The start activity date is not defined.</field>
</record>
</data>
</tryton>
56 changes: 54 additions & 2 deletions partner.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions view/configuration_skill_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
<field name="skill_09"/>
<label name="skill_10"/>
<field name="skill_10"/>
<label name="skill_11"/>
<field name="skill_11"/>
<label name="skill_12"/>
<field name="skill_12"/>
</form>
3 changes: 3 additions & 0 deletions view/partner_skill_tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
<field name="skill_08"/>
<field name="skill_09"/>
<field name="skill_10"/>
<field name="skill_11"/>
<field name="skill_12"/>
<field name="recibo_without_seniority"/>
<field name="recibo_total"/>
</tree>

0 comments on commit b35e247

Please sign in to comment.