Merge pull request #1923 from expsa/tasks_2_12

Sponsor(task02)
This commit is contained in:
enagahh 2024-12-16 03:07:51 +02:00 committed by GitHub
commit 2a4e966ae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 116 additions and 26 deletions

View File

@ -60,24 +60,12 @@ class TakafulSponsorship(models.Model):
gifter_mobile = fields.Char(string="The Gifter Mobile")
gifter_message = fields.Text(string='Message To Gifter')
sponsorship_type = fields.Selection([
('person', 'Individual'),
('group', 'Group')],
string='Sponsorship Type',
tracking=True
)
sponsorship_type = fields.Selection([('person', 'Individual'),('group', 'Group')],string='Sponsorship Type',tracking=True)
code = fields.Char(string="Code",
copy=False,
readonly=True)
benefit_type = fields.Selection([
('orphan', 'Orphans'),
('widow', 'Widows')],
required=True,
string='Sponsorship Beneficiary Type',
tracking=True
)
benefit_type = fields.Selection([('orphan', 'Orphans'),('widow', 'Widows')],string='Sponsorship Beneficiary Type',tracking=True)
branch_custom_id = fields.Many2one('branch.settings', string="Branch")
sponsorship_creation_date = fields.Datetime(string="Sponsorship Creation Date", default=fields.Datetime.now)
sponsor_note = fields.Text(string='Sponsor Note')
@ -90,11 +78,7 @@ class TakafulSponsorship(models.Model):
registered_type = fields.Selection(string='Registered Type',selection=[('sponsor', 'Sponsor'),('member', 'Member')])
members_domain_ids = fields.Many2many(comodel_name='family.member', compute='_compute_domain_ids')
# This is if for one person, and not a group.
benefit_id = fields.Many2one(
'family.member',
string='Beneficiary Name',
ondelete='set null',domain = "[('id', 'in',members_domain_ids)]"
)
benefit_id = fields.Many2one('family.member',string='Beneficiary Name',ondelete='set null',domain = "[('id', 'in',members_domain_ids)]")
family_id = fields.Many2one(
'grant.benefit',
string='Family',
@ -255,10 +239,7 @@ class TakafulSponsorship(models.Model):
is_widow_orphan = fields.Boolean(
string='Widow with Her Orphans?', default=False)
payment_option = fields.Selection([
('month', 'Monthly'),
('once', 'For Once'),
], string='Payment Option', default='month')
payment_option = fields.Selection([('month', 'Monthly'),('once', 'For Once')], string='Payment Option', default='month')
payment_method = fields.Selection([
('cash', 'Cash'),
@ -1066,4 +1047,84 @@ class DonationsDetailsLines(models.Model):
donation_name = fields.Many2one('donations.items', string="Donation Name" , domain="[('donation_type','=',donation_type),('show_donation_item','=',True)]")
sponsorship_id = fields.Many2one('takaful.sponsorship', string="Sponsorship")
donation_amount = fields.Float(string='Donation Amount')
donation_mechanism = fields.Selection([('with_conditions', 'With Conditions'),('without_conditions', 'Without Conditions')],string='Donation Mechanism')
donation_mechanism = fields.Selection([('with_conditions', 'With Conditions'),('without_conditions', 'Without Conditions')],string='Donation Mechanism')
benefit_type = fields.Selection([('orphan', 'Orphans'),('widow', 'Widows'),('both', 'Both')],required=True,string='Sponsorship Beneficiary Type',tracking=True)
sponsorship_type = fields.Selection([('person', 'Individual'),('group', 'Group')],string='Sponsorship Type',tracking=True)
gender = fields.Selection(selection=[('male', 'Male'), ('female', 'Female')], string="Gender")
age_category_id = fields.Many2one('age.category', string='Age Category')
education_status = fields.Selection(string='Education Status',selection=[('educated', 'educated'), ('illiterate', 'illiterate'),('under_study_age', 'Under Study Age')])
education_level = fields.Many2one("education.level", string='Education Levels')
benefit_id = fields.Many2one('family.member',string='Beneficiary Name',ondelete='set null',domain = "[('id', 'in',members_domain_ids)]")
members_domain_ids = fields.Many2many(comodel_name='family.member', compute='_compute_domain_ids')
benefit_ids = fields.Many2many('family.member',string='Beneficiaries Names')
sponsorship_duration = fields.Selection([('temporary', 'Temporary'),('permanent', 'Permanent')],string='Sponsorship Duration',default='permanent',tracking=True)
start_date = fields.Date(string="Sponsorship Start Date", copy=False)
end_date = fields.Date(string="Sponsorship End Date")
payment_option = fields.Selection([('month', 'Monthly'),('once', 'For Once')], string='Payment Option', default='month')
@api.depends('gender', 'education_status', 'education_level', 'sponsorship_type', 'benefit_type', 'age_category_id')
def _compute_domain_ids(self):
# Create a domain
self.members_domain_ids = [(6, 0, [])]
if self.benefit_type == 'orphan' and self.sponsorship_type:
base_domain = \
[
('state', 'in', ['second_approve', 'temporarily_suspended', 'suspended_first_approve']),
('member_status', '=', 'benefit'),
'|',
('relationn.relation_type', '=', 'daughter'),
('relationn.relation_type', '=', 'son')
]
if self.gender:
if self.gender == 'female':
base_domain = [
('state', 'in', ('second_approve', 'temporarily_suspended', 'suspended_first_approve')),
('member_status', '=', 'benefit'), ('relationn.relation_type', '=', 'daughter')]
if self.gender == 'male':
base_domain = [
('state', 'in', ('second_approve', 'temporarily_suspended', 'suspended_first_approve')),
('member_status', '=', 'benefit'), ('relationn.relation_type', '=', 'son')]
if self.education_status:
base_domain.append(('education_status', '=', self.education_status))
if self.education_level:
base_domain.append(('education_levels', '=', self.education_level.id))
if self.age_category_id:
base_domain.append(('age', '<=', self.age_category_id.max_age))
base_domain.append(('age', '>=', self.age_category_id.min_age))
self.members_domain_ids = self.env['family.member'].sudo().search(base_domain)
domain = {'benefit_id': [('id', 'in', self.members_domain_ids.ids)]}
return {'domain': domain}
if self.benefit_type == 'widow' and self.sponsorship_type:
base_domain = [('state', 'in', ['second_approve', 'temporarily_suspended', 'suspended_first_approve']),
('member_status', '=', 'benefit'), '|', ('relationn.relation_type', '=', 'mother'),
('relationn.relation_type', '=', 'replacement_mother')]
if self.education_status:
base_domain.append(('education_status', '=', self.education_status))
if self.education_level:
base_domain.append(('education_levels', '=', self.education_level.id))
if self.age_category_id:
base_domain.append(('age', '<=', self.age_category_id.max_age))
base_domain.append(('age', '>=', self.age_category_id.min_age))
self.members_domain_ids = self.env['family.member'].sudo().search(base_domain)
domain = {'benefit_id': [('id', 'in', self.members_domain_ids.ids)]}
return {'domain': domain}
if self.benefit_type == 'both' and self.sponsorship_type:
base_domain = [('state', 'in', ['second_approve', 'temporarily_suspended', 'suspended_first_approve']),
('member_status', '=', 'benefit')]
if self.education_status:
base_domain.append(('education_status', '=', self.education_status))
if self.education_level:
base_domain.append(('education_levels', '=', self.education_level.id))
if self.age_category_id:
base_domain.append(('age', '<=', self.age_category_id.max_age))
base_domain.append(('age', '>=', self.age_category_id.min_age))
self.members_domain_ids = self.env['family.member'].sudo().search(base_domain)
domain = {'benefit_id': [('id', 'in', self.members_domain_ids.ids)]}
return {'domain': domain}
@api.onchange('donation_type')
def onchange_donation_type(self):
for rec in self:
if rec.donation_type == 'sponsorship':
rec.donation_mechanism = 'with_conditions'

View File

@ -196,13 +196,42 @@
<group>
<group>
<field name="donation_type"/>
<field name="donation_name"/>
<field name="sponsorship_duration" attrs="{'invisible': [('donation_type','!=','sponsorship')]}"/>
<field name="start_date" attrs="{'invisible': [('sponsorship_duration','=','permanent')]}"/>
<field name="end_date" attrs="{'invisible': [('sponsorship_duration','=','permanent')]}"/>
</group>
<group>
<field name="donation_name"/>
<field name="donation_mechanism" attrs="{'invisible':[('donation_type','=','waqf')],'readonly': [('donation_type','=','sponsorship')]}" force_save="1"/>
<field name="payment_option" attrs="{'invisible': [('donation_type','!=','sponsorship')]}"/>
<field name="donation_amount"/>
<field name="donation_mechanism" attrs="{'invisible': ['|',('donation_type','=','sponsorship'),('donation_type','=','waqf')]}"/>
</group>
</group>
<group>
<group>
<h3> Benefit Details</h3>
<field name="members_domain_ids" invisible="1"/>
<field name="benefit_type"/>
<field name="sponsorship_type"/>
<field name="gender"/>
<field name="age_category_id"/>
<field name="education_status"/>
<field name="education_level"/>
</group>
<group>
<br/>
<field name="benefit_id" attrs="{'invisible': [('sponsorship_type','!=','person')]}"/>
</group>
</group>
<group string="Orphans List" attrs="{'invisible': ['|', ('sponsorship_type', '!=', 'group'), ('benefit_type', '!=', 'orphan')]}">
<field name="benefit_ids" nolabel="1" domain="[('id', 'in', members_domain_ids)]"/>
</group>
<group string="Widows List" attrs="{'invisible': ['|', ('sponsorship_type', '!=', 'group'), ('benefit_type', '!=', 'widow')]}">
<field name="benefit_ids" nolabel="1" domain="[('id', 'in', members_domain_ids)]"/>
</group>
<group string="Orphans and Widows List" attrs="{'invisible': ['|', ('sponsorship_type', '!=', 'group'), ('benefit_type', '!=', 'both')]}">
<field name="benefit_ids" nolabel="1" domain="[('id', 'in', members_domain_ids)]"/>
</group>
</form>
<tree>
<field name="donation_type"/>