This commit is contained in:
Abdurrahman Saber 2025-10-15 11:13:11 +03:00
parent ec0440e7f3
commit ca82901868
2 changed files with 59 additions and 58 deletions

View File

@ -165,70 +165,70 @@ class TakafulSponsorship(models.Model):
raise UserError(_('You cannot delete this record'))
return super(TakafulSponsorship, self).unlink()
@api.constrains('donations_details_lines')
def check_period_benefit(self):
for rec in self:
all_items = rec.donations_details_lines + rec.donations_details_lines_mechanism_ids
for item in all_items:
if not item.start_date or not item.end_date:
continue
# @api.constrains('donations_details_lines')
# def check_period_benefit(self):
# for rec in self:
# all_items = rec.donations_details_lines + rec.donations_details_lines_mechanism_ids
# for item in all_items:
# if not item.start_date or not item.end_date:
# continue
params = [item.donation_type, item.id,
item.end_date, item.start_date, # Overlapping case 1
item.end_date, item.start_date, # Overlapping case 2
item.start_date, item.end_date, # Overlapping case 3
item.start_date, item.end_date] # Inside the range
# params = [item.donation_type, item.id,
# item.end_date, item.start_date, # Overlapping case 1
# item.end_date, item.start_date, # Overlapping case 2
# item.start_date, item.end_date, # Overlapping case 3
# item.start_date, item.end_date] # Inside the range
condition = "donation_type = %s AND id != %s"
# condition = "donation_type = %s AND id != %s"
if item.donation_type == 'sponsorship' and item.benefit_id:
condition += " AND benefit_id = %s"
params.insert(2, item.benefit_id.id)
# if item.donation_type == 'sponsorship' and item.benefit_id:
# condition += " AND benefit_id = %s"
# params.insert(2, item.benefit_id.id)
if item.donation_type != 'sponsorship':
condition += " AND product_template_id = %s"
params.insert(2, item.product_template_id.id)
# if item.donation_type != 'sponsorship':
# condition += " AND product_template_id = %s"
# params.insert(2, item.product_template_id.id)
if item.donation_type != 'sponsorship' and item.benefit_id:
condition += " AND benefit_id = %s"
params.insert(2, item.benefit_id.id)
# if item.donation_type != 'sponsorship' and item.benefit_id:
# condition += " AND benefit_id = %s"
# params.insert(2, item.benefit_id.id)
query = f"""
SELECT id FROM donations_details_lines
WHERE {condition}
AND (
(end_date <= %s AND end_date >= %s) OR -- Overlapping case 1
(start_date <= %s AND start_date >= %s) OR -- Overlapping case 2
(start_date <= %s AND end_date >= %s) OR -- Overlapping case 3
(start_date >= %s AND end_date <= %s) -- Inside the range
)
LIMIT 1;
"""
# query = f"""
# SELECT id FROM donations_details_lines
# WHERE {condition}
# AND (
# (end_date <= %s AND end_date >= %s) OR -- Overlapping case 1
# (start_date <= %s AND start_date >= %s) OR -- Overlapping case 2
# (start_date <= %s AND end_date >= %s) OR -- Overlapping case 3
# (start_date >= %s AND end_date <= %s) -- Inside the range
# )
# LIMIT 1;
# """
self.env.cr.execute(query, tuple(params))
result = self.env.cr.fetchone()
# self.env.cr.execute(query, tuple(params))
# result = self.env.cr.fetchone()
if result:
if item.donation_type == 'sponsorship':
raise exceptions.ValidationError(
_('Sponsorship periods for the same beneficiary cannot overlap: '
'There is a sponsorship in period %s - %s for beneficiary %s that conflicts '
'with the current record. Please amend') % (
item.start_date, item.end_date, item.benefit_id.name)
)
# if result:
# if item.donation_type == 'sponsorship':
# raise exceptions.ValidationError(
# _('Sponsorship periods for the same beneficiary cannot overlap: '
# 'There is a sponsorship in period %s - %s for beneficiary %s that conflicts '
# 'with the current record. Please amend') % (
# item.start_date, item.end_date, item.benefit_id.name)
# )
elif item.donation_type != 'sponsorship' and item.benefit_id:
raise exceptions.ValidationError(
_('Sorry, there is a Donation Record in this Period %s - %s beneficiary %s') % (
item.start_date, item.end_date, item.benefit_id.name)
)
# elif item.donation_type != 'sponsorship' and item.benefit_id:
# raise exceptions.ValidationError(
# _('Sorry, there is a Donation Record in this Period %s - %s beneficiary %s') % (
# item.start_date, item.end_date, item.benefit_id.name)
# )
else:
raise exceptions.ValidationError(
_('Sorry, there is a Donation Record in this Period %s - %s') % (
item.start_date, item.end_date)
)
# else:
# raise exceptions.ValidationError(
# _('Sorry, there is a Donation Record in this Period %s - %s') % (
# item.start_date, item.end_date)
# )
def pay_all_sponsorships(self):
"""
@ -1719,7 +1719,7 @@ class TakafulSponsorship(models.Model):
def _compute_show_register_payment(self):
for rec in self:
rec.show_register_payment = len(((rec.donations_details_lines + rec.donations_details_lines_mechanism_ids).filtered(lambda l: l.state == 'draft')).payment_method_id) <= 1
rec.show_register_payment = len(((rec.donations_details_lines + rec.donations_details_lines_mechanism_ids).filtered(lambda l: l.state == 'draft' and l.payment_method != 'direct_debit')).payment_method_id) == 1
class AnotherSponsors(models.Model):
_name = "donate.for.another.person"

View File

@ -333,10 +333,7 @@
</group>
<group attrs="{'invisible': ['|', ('donation_mechanism','!=','with_conditions'), ('hide_beneficiary_group','=', True)]}">
<group string="Beneficiary Filters" attrs="{'invisible': [('sponsorship_type','=','group'), ('parent.record_type','=','donation')]}">
<field name="sponsorship_type"
attrs="{'invisible': [('donation_mechanism','!=','with_conditions')], 'required': [('hide_beneficiary_group','=', False), ('donation_mechanism','=','with_conditions')]}" />
<field name="benefit_type"
attrs="{'invisible': [('donation_mechanism','!=','with_conditions')], 'required': [('hide_beneficiary_group','=', False), ('donation_mechanism','=','with_conditions')]}" />
<field name="gender"
attrs="{'invisible': [('donation_mechanism','!=','with_conditions')]}" />
<field name="age_category_id"
@ -352,6 +349,10 @@
</group>
<group>
<field name="members_domain_ids" invisible="1" />
<field name="sponsorship_type"
attrs="{'invisible': [('donation_mechanism','!=','with_conditions')], 'required': [('hide_beneficiary_group','=', False), ('donation_mechanism','=','with_conditions')]}" />
<field name="benefit_type"
attrs="{'invisible': [('donation_mechanism','!=','with_conditions')], 'required': [('hide_beneficiary_group','=', False), ('donation_mechanism','=','with_conditions')]}" />
<field name="benefit_id"
attrs="{'invisible': ['|', ('sponsorship_type','!=','person'), ('donation_mechanism','!=','with_conditions')], 'required': [('members_domain_ids', '!=', []), ('sponsorship_type','=','person'), ('hide_beneficiary_group','=', False), ('donation_mechanism','=','with_conditions'), ('state', 'in', ['active', 'closed', 'extended'])]}"
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}" />