Skip to content

Commit

Permalink
Merge pull request #670 from CompassionCH/devel
Browse files Browse the repository at this point in the history
Add sponsorship line + hr attendance fixes
  • Loading branch information
ecino authored May 8, 2018
2 parents 1efd83a + 1e0f162 commit b6e9c41
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 13 deletions.
3 changes: 0 additions & 3 deletions child_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@
'data/icp.involvement.csv',
'data/icp.church.ministry.csv',
'data/icp.program.csv',
'data/global_partner.xml',
'data/gmc_action.xml',
'data/demand_planning_cron.xml',
'data/connect.month.csv',
'data/icp.church.facility.csv',
'data/icp.church.utility.csv',
'data/icp.cognitive.activity.csv',
Expand Down
4 changes: 2 additions & 2 deletions contract_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# /_/
# in Jesus' name
#
# Copyright (C) 2014-2017 Compassion CH (http://www.compassion.ch)
# Copyright (C) 2014-2018 Compassion CH (http://www.compassion.ch)
# @author: David Coninckx, Emanuel Cino
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -30,7 +30,7 @@
# pylint: disable=C8101
{
'name': 'Compassion Contracts',
'version': '10.0.2.0.0',
'version': '10.0.2.1.0',
'category': 'Other',
'author': 'Compassion CH',
'license': 'AGPL-3',
Expand Down
73 changes: 73 additions & 0 deletions contract_compassion/migrations/10.0.2.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2018 Compassion CH (http://www.compassion.ch)
# Releasing children from poverty in Jesus' name
# @author: Emanuel Cino <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################

from openupgradelib import openupgrade


@openupgrade.migrate(use_env=True)
def migrate(env, version):
if not version:
return

# Correct SUB - parent relations
broken_subs = env['recurring.contract'].search([
('parent_id', '!=', False),
('child_id', '!=', False),
('parent_id.sub_sponsorship_id', '=', False)
])
for sub in broken_subs:
sub.parent_id.sub_sponsorship_id = sub
broken_subs = env['recurring.contract'].search([
('sub_sponsorship_id', '!=', False),
('child_id', '!=', False),
('sub_sponsorship_id.parent_id', '=', False)
])
for sub in broken_subs:
sub.sub_sponsorship_id.parent_id = sub

# Remove subs that are invalid
invalid_subs = env['recurring.contract'].search([
('parent_id', '!=', False),
'|',
'&', ('child_id', '=', False), ('state', '!=', 'draft'),
('parent_id.state', 'not in', ('terminated', 'cancelled'))
])
invalid_subs.with_context(allow_removing_sub=True).write({
'parent_id': False})

# Set sponsorship_line_id
new_sponsorships = env['recurring.contract'].search([
('child_id', '!=', False),
('activation_date', '!=', False),
('parent_id', '=', False),
], order='activation_date asc')
line_id = 1
for sponsorship in new_sponsorships:
sponsorship.sponsorship_line_id = line_id
sub_sponsorship = sponsorship.sub_sponsorship_id
while sub_sponsorship:
sub_sponsorship.sponsorship_line_id = line_id
sub_sponsorship = sub_sponsorship.sub_sponsorship_id
line_id += 1

# Find missed sponsorships (with parent not in sponsorship line)
new_sponsorships = env['recurring.contract'].search([
('child_id', '!=', False),
('activation_date', '!=', False),
('parent_id.sponsorship_line_id', '=', False)
], order='activation_date asc')
for sponsorship in new_sponsorships:
sponsorship.sponsorship_line_id = line_id
sub_sponsorship = sponsorship.sub_sponsorship_id
while sub_sponsorship:
sub_sponsorship.sponsorship_line_id = line_id
sub_sponsorship = sub_sponsorship.sub_sponsorship_id
line_id += 1
24 changes: 21 additions & 3 deletions contract_compassion/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class RecurringContract(models.Model):
group_freq = fields.Char(
string='Payment frequency', compute='_compute_frequency',
readonly=True)
sponsorship_line_id = fields.Integer(
help='Identifies the active sponsorship line of a sponsor.'
'When sponsorship is ended but a SUB is made, the SUB will have'
'the same line id. Only new sponsorships will have new ids.'
)

_sql_constraints = [('parent_id_unique',
'UNIQUE(parent_id)',
Expand Down Expand Up @@ -210,12 +215,15 @@ def create(self, vals):

new_sponsorship = super(RecurringContract, self).create(vals)

# Set the sub_sponsorship_id in the current parent_id
# Set the sub_sponsorship_id in the current parent_id and take
# sponsorship line id
if 'parent_id' in vals and vals['parent_id']:
sponsorship = self.env['recurring.contract'].\
browse(vals['parent_id'])

sponsorship.sub_sponsorship_id = new_sponsorship
new_sponsorship.sponsorship_line_id =\
sponsorship.sponsorship_line_id

return new_sponsorship

Expand All @@ -233,7 +241,9 @@ def write(self, vals):
# Set the sub_sponsorship_id in the current parent_id
if 'parent_id' in vals:
for sponsorship in self.filtered('parent_id'):
sponsorship.parent_id.sub_sponsorship_id = sponsorship
parent = sponsorship.parent_id
parent.sub_sponsorship_id = sponsorship
sponsorship.sponsorship_line_id = parent.sponsorship_line_id

if 'group_id' in vals or 'partner_id' in vals:
self._on_group_id_changed()
Expand Down Expand Up @@ -309,11 +319,19 @@ def contract_active(self):
'activation_date': fields.Date.today()
})
self.write({'state': 'active'})
last_line_id = self.search(
[('sponsorship_line_id', '!=', False)],
order='sponsorship_line_id desc',
limit=1
).sponsorship_line_id

# Write payment term in partner property
# Write payment term in partner property and sponsorship line id
for contract in self:
contract.partner_id.customer_payment_mode_id = \
contract.payment_mode_id
if contract.child_id and not contract.sponsorship_line_id:
last_line_id += 1
contract.sponsorship_line_id = last_line_id
return True

@api.multi
Expand Down
5 changes: 3 additions & 2 deletions contract_compassion/views/contract_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
options="{'create': false, 'm2o_dialog': false}"/>
<field name="group_id" domain="[('partner_id', '=', partner_id)]"
context="{'default_partner_id': partner_id}"/>
<field name="parent_id" domain="[('partner_id', '=', partner_id), ('child_id', '!=', child_id), ('sub_sponsorship_id', '=', False)]"/>
<field name="sub_sponsorship_id" states="terminated"/>
<field name="parent_id" domain="[('partner_id', '=', partner_id), ('child_id', '!=', child_id), ('sub_sponsorship_id', '=', False), ('sponsorship_line_id', '!=', False)]"
context="{'default_type':'S'}"/>
<field name="sub_sponsorship_id" states="terminated" context="{'default_type':'S'}"/>
</group>
<group>
<field name="start_date" string="Creation date"/>
Expand Down
2 changes: 1 addition & 1 deletion hr_attendance_calendar/models/hr_change_day_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ def _compute_hours(self):
@api.depends('employee_id', 'date1', 'date2', 'forced')
def _compute_name(self):
for h in self:
h.name = '{}, {}/{}, {} changed'\
h.name = u'{}, {}/{}, {} changed'\
.format(h.employee_id.display_name, h.date1, h.date2,
self.env['hr.employee'].convert_hour_to_time(h.forced))
2 changes: 1 addition & 1 deletion hr_attendance_calendar/models/hr_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def find_attendance_days(self):
('date', '<=', rd.date_to)
])
# Add leave in attendance day
att_day.leave_ids |= rd
att_day.write({'leave_ids': [(4, rd.id)]})
att_days |= att_day
return att_days

Expand Down
2 changes: 1 addition & 1 deletion sponsorship_compassion/views/sponsorship_contract_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<!-- Replace filter domain of parent_id field to take correspondant -->
<field name="parent_id" position="attributes">
<attribute name="domain" position="replace">
<attribute name="domain">[('correspondent_id', '=', correspondent_id), ('child_id', '!=', child_id), ('sub_sponsorship_id', '=', False)]</attribute>
<attribute name="domain">[('correspondent_id', '=', correspondent_id), ('child_id', '!=', child_id), ('sub_sponsorship_id', '=', False), ('sponsorship_line_id', '!=', False)]</attribute>
</attribute>
<attribute name="attrs">{'invisible': [('type', 'not in', ['S', 'SC'])]}</attribute>
</field>
Expand Down

0 comments on commit b6e9c41

Please sign in to comment.