Merge pull request #5792 from expsa/fix_test_note
[FIX] replacment action
This commit is contained in:
commit
32c6ab16e8
|
|
@ -1049,17 +1049,7 @@ class DonationsDetailsLines(models.Model):
|
|||
|
||||
def action_view_replacement_wizard(self):
|
||||
self.ensure_one()
|
||||
|
||||
# wizard = self.env['replacement.wiz'].create({
|
||||
# 'replacement_line_ids': [(0, 0, {
|
||||
# 'sponsorship_type': self.sponsorship_type,
|
||||
# 'from_benefit_id': self.benefit_id.id if self.sponsorship_type == 'person' else False,
|
||||
# 'from_benefit_ids': [(6, 0, self.benefit_ids.ids)] if self.sponsorship_type == 'group' else False
|
||||
# })]
|
||||
# })
|
||||
|
||||
wizard = self.env['replacement.wiz'].create({
|
||||
'old_family_id': self.family_id.id if self.family_id else False,
|
||||
'old_members_id': self.benefit_ids[0].id if self.benefit_ids else False,
|
||||
'record_type': self.record_type,
|
||||
'sponsorship_id': self.id,
|
||||
|
|
|
|||
|
|
@ -148,92 +148,6 @@ class ReplacementWiz(models.TransientModel):
|
|||
|
||||
rec.members_domain_ids = members if members else self.env['family.member'].sudo().browse()
|
||||
|
||||
|
||||
|
||||
@api.onchange('branch_id', 'family_category_ids', 'replacement_line_ids.members_domain_ids')
|
||||
def _onchange_filter_family_ids(self):
|
||||
active_id = self.env.context.get('active_id')
|
||||
if active_id:
|
||||
sponsorship_id = self.env['takaful.sponsorship'].browse(active_id)
|
||||
if sponsorship_id:
|
||||
current_sponsorship_benefits = list(set(
|
||||
sponsorship_id.donations_details_lines.mapped('benefit_id').ids +
|
||||
sponsorship_id.donations_details_lines.mapped('benefit_ids').ids +
|
||||
sponsorship_id.donations_details_lines_mechanism_ids.mapped('benefit_id').ids +
|
||||
sponsorship_id.donations_details_lines_mechanism_ids.mapped('benefit_ids').ids
|
||||
))
|
||||
|
||||
domain = ['|', ('state', '=', 'second_approve'), '&', ('state', '=', 'waiting_approve'),('action_type', '=', 'suspended')]
|
||||
if self.branch_id:
|
||||
domain.append(('branch_custom_id', '=', self.branch_id.id))
|
||||
if self.family_category_ids:
|
||||
domain.append(('benefit_category_id', '=', self.family_category_ids.ids))
|
||||
|
||||
|
||||
# return family which have at least one member of these
|
||||
member_domain = [('member_status', '=', 'benefit')]
|
||||
|
||||
all_lines = self.env['donations.details.lines'].sudo().search(
|
||||
['|', ('sponsorship_id', '!=', False), ('sponsorship_mechanism_id', '!=', False)])
|
||||
|
||||
running_sponsorships = all_lines.sudo().filtered(
|
||||
lambda line: line.sponsorship_id.state in ('confirmed', 'wait_pay', 'under_refund', 'under_replacement',
|
||||
'replacement_done') or line.sponsorship_mechanism_id.state in (
|
||||
'confirmed', 'wait_pay', 'under_refund', 'under_replacement', 'replacement_done')
|
||||
)
|
||||
|
||||
benefit_ids = running_sponsorships.mapped('benefit_id').ids + running_sponsorships.mapped('benefit_ids').ids
|
||||
|
||||
if self.gender:
|
||||
if self.gender == 'male':
|
||||
member_domain.append(('relationn.relation_type', 'in', ['son', 'other relation']))
|
||||
elif self.gender == 'female':
|
||||
member_domain.append(('relationn.relation_type', 'in',
|
||||
['daughter', 'mother', 'replacement_mother', 'other relation']))
|
||||
|
||||
if self.age_category_id:
|
||||
member_domain.append(('age', '<=', self.age_category_id.max_age))
|
||||
member_domain.append(('age', '>=', self.age_category_id.min_age))
|
||||
if self.education_status:
|
||||
member_domain.append(('education_status', '=', self.education_status))
|
||||
if self.education_level_id:
|
||||
member_domain.append(('education_levels', '=', self.education_level_id.id))
|
||||
if benefit_ids:
|
||||
member_domain.append(('id', 'not in', benefit_ids))
|
||||
if current_sponsorship_benefits:
|
||||
member_domain.append(('id', 'not in', current_sponsorship_benefits))
|
||||
|
||||
members = self.env['family.member'].sudo().search(member_domain)
|
||||
|
||||
if members:
|
||||
domain.append(('member_ids.id', 'in', members.ids))
|
||||
|
||||
return {'domain': {'family_ids': domain}}
|
||||
|
||||
@api.onchange('family_ids', 'branch_id')
|
||||
def _onchange_family_ids(self):
|
||||
if self.family_ids and not self.branch_id:
|
||||
raise ValidationError(
|
||||
_("Select Branch First !"))
|
||||
if self.family_ids and self.branch_id:
|
||||
for rec in self.family_ids:
|
||||
if rec.branch_custom_id.id != self.branch_id.id:
|
||||
raise ValidationError(
|
||||
_("The selected Families Doesn't belong to Selected Branch ."))
|
||||
|
||||
@api.onchange('gender', 'age_category_id', 'education_status', 'education_level_id', 'family_ids')
|
||||
def onchange_filters(self):
|
||||
for rec in self.replacement_line_ids:
|
||||
rec.compute_domain_ids()
|
||||
if rec.to_benefit_id and rec.to_benefit_id not in rec.members_domain_ids:
|
||||
rec.to_benefit_id = False
|
||||
|
||||
if rec.to_benefit_ids:
|
||||
invalid_ids = rec.to_benefit_ids.filtered(lambda b: b not in rec.members_domain_ids)
|
||||
if invalid_ids:
|
||||
rec.to_benefit_ids = [(5, 0, 0)]
|
||||
rec.compute_domain_ids()
|
||||
|
||||
def replacement_benefit_action(self):
|
||||
|
||||
self.ensure_one()
|
||||
|
|
@ -242,17 +156,8 @@ class ReplacementWiz(models.TransientModel):
|
|||
raise UserError(_("Please determine sponsorship."))
|
||||
|
||||
donation_line = self.sponsorship_id
|
||||
old_benefit = new_benefit = False
|
||||
|
||||
try:
|
||||
if self.record_type == "donation":
|
||||
donation_line.sudo().write({
|
||||
'family_id': self.new_family_id.id
|
||||
})
|
||||
old_benefit = self.old_family_id.name
|
||||
new_benefit = self.new_family_id.name
|
||||
|
||||
elif self.record_type == "sponsorship":
|
||||
if self.record_type == "sponsorship":
|
||||
state = donation_line.state
|
||||
if donation_line.state == 'replace':
|
||||
state = 'active'
|
||||
|
|
@ -287,42 +192,4 @@ class ReplacementWiz(models.TransientModel):
|
|||
})
|
||||
|
||||
except Exception as e:
|
||||
raise UserError(_("Error in replacement:\n%s") % str(e))
|
||||
|
||||
|
||||
# def replacement_action(self):
|
||||
# active_id = self.env.context.get('active_id')
|
||||
# if active_id:
|
||||
# sponsorship_id = self.env['takaful.sponsorship'].browse(active_id)
|
||||
# if sponsorship_id:
|
||||
# sponsorship_id.sudo().write({'state': 'under_replacement'})
|
||||
# replacement = self.env['replacement.process'].create({
|
||||
# 'user_id': self.env.user.id,
|
||||
# 'sponsorship_id': sponsorship_id.id,
|
||||
# 'branch_id': self.branch_id.id,
|
||||
# 'sponsor_donor_type': sponsorship_id.sponsor_donor_type or sponsorship_id.sponsor_or_donor_type,
|
||||
# 'registered_type': sponsorship_id.registered_type,
|
||||
# 'record_type': sponsorship_id.record_type,
|
||||
# 'sponsor_id': sponsorship_id.sponsor_id.id,
|
||||
# 'replacement_reason_id': self.replacement_reason_id.id,
|
||||
#
|
||||
# })
|
||||
# if self.replacement_line_ids:
|
||||
# for line in self.replacement_line_ids:
|
||||
# if len(line.from_benefit_ids) != len(line.to_benefit_ids):
|
||||
# raise ValidationError(
|
||||
# _("You must select the same number of beneficiaries in the from benefits group (%s) to the to benefits group (%s)" % (
|
||||
# ", ".join(line.from_benefit_ids.mapped('name')),
|
||||
# ", ".join(line.to_benefit_ids.mapped('name')))))
|
||||
# self.env['replacement.process.line'].create({
|
||||
# 'from_benefit_id': line.from_benefit_id.id,
|
||||
# 'to_benefit_id': line.to_benefit_id.id,
|
||||
# 'from_benefit_ids': [(6, 0, line.from_benefit_ids.ids)],
|
||||
# 'to_benefit_ids': [(6, 0, line.to_benefit_ids.ids)],
|
||||
# 'sponsorship_type': line.sponsorship_type,
|
||||
# 'members_domain_ids': [(6, 0, line.members_domain_ids.ids)],
|
||||
# 'process_id': replacement.id,
|
||||
#
|
||||
# })
|
||||
#
|
||||
# sponsorship_id.replacement_id = replacement.id
|
||||
raise UserError(_("Error in replacement:\n%s") % str(e))
|
||||
Loading…
Reference in New Issue