Merge pull request #1943 from expsa/tasks_2_12

Sponsor(task07)
This commit is contained in:
enagahh 2024-12-21 19:12:39 +02:00 committed by GitHub
commit 69284bfdbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 28 deletions

View File

@ -20,7 +20,7 @@ class PointsOfSaleCustom(models.Model):
name = fields.Char(string="Sequence/Point Name",readonly=True)
department_name = fields.Selection([('men', 'Men'),('women', 'Women')], string='Department Name')
branch_custom_id = fields.Many2one('branch.settings', string="Branch")
branch_custom_ids = fields.Many2many('branch.settings',relation='points_sale_branch_settings_rel',column1='points_sale_id', column2='branch_id',string="Branch")
journal_id = fields.Many2one('account.journal', string="Journal",domain="[('type','=','bank')]")
@api.model

View File

@ -131,7 +131,7 @@ class TakafulSponsorship(models.Model):
@api.depends('donations_details_lines')
def _get_total_sponsorship_amount(self):
for rec in self:
rec.total_sponsorship_amount = sum(line.donation_amount for line in rec.donations_details_lines)
rec.total_sponsorship_amount = sum(line.total_donation_amount for line in rec.donations_details_lines)
@api.onchange('donations_details_lines')
def onchange_donations_details_lines(self):
@ -252,7 +252,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')
payment_method = fields.Selection([
('cash', 'Cash'),
@ -1054,6 +1054,7 @@ class AnotherSponsors(models.Model):
sponsor_phone = fields.Char(string="Sponsor Phone")
sponsor_id_number = fields.Char(string="Sponsor ID Number")
sponsorship_id = fields.Many2one('takaful.sponsorship')
receive_messages = fields.Boolean(string='Receive messages?')
class DonationsDetailsLines(models.Model):
_name = "donations.details.lines"
@ -1073,12 +1074,35 @@ class DonationsDetailsLines(models.Model):
family_id = fields.Many2one('grant.benefit',string='Family',ondelete='set null',related="benefit_id.benefit_id")
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)
sponsorship_duration = fields.Selection([('temporary', 'Temporary'),('permanent', 'Permanent')],string='Sponsorship Type',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')
end_date = fields.Date(string="Sponsorship End Date",compute='_compute_end_date')
payment_option = fields.Selection([('month', 'Monthly'),('once', 'For Once')], string='Payment Option')
payment_month_count = fields.Integer(string='Payment Month Count')
fixed_value = fields.Boolean(string='Is Fixed Value?',related='donation_name.fixed_value')
benefits_count = fields.Integer(string='Benefits Count',compute='_get_benefits_count')
total_donation_amount = fields.Float(string='Total Donation Amount',compute='_get_total_donation_amount')
@api.depends('start_date', 'payment_month_count')
def _compute_end_date(self):
for record in self:
if record.start_date and record.payment_month_count:
record.end_date = record.start_date + relativedelta(months=record.payment_month_count)
else:
record.end_date = False
@api.depends('benefit_ids')
def _get_benefits_count(self):
for rec in self:
rec.benefits_count = len(rec.benefit_ids)
@api.depends('benefits_count','donation_amount')
def _get_total_donation_amount(self):
for rec in self:
if rec.sponsorship_type == 'group':
rec.total_donation_amount = rec.benefits_count * rec.donation_amount
else :
rec.total_donation_amount = rec.donation_amount
@api.depends('gender', 'education_status', 'education_level', 'sponsorship_type', 'benefit_type', 'age_category_id')
def _compute_domain_ids(self):
@ -1152,19 +1176,6 @@ class DonationsDetailsLines(models.Model):
for rec in self:
if rec.donation_type == 'sponsorship':
rec.donation_mechanism = 'with_conditions'
# if not rec.sponsorship_id:
# raise ValidationError(_("Sponsorship ID must be set for sponsorship donations."))
#
# # Search for an existing record
# record_exist = self.env["donations.details.lines"].search(
# [('donation_type', '=', 'sponsorship'),
# ('sponsorship_id', '=', rec.sponsorship_id.id)],
# limit=1
# )
#
# # Raise error if record already exists
# if record_exist:
# raise ValidationError(_("A donation with the same sponsorship ID already exists."))
class PaymentDetailsLines(models.Model):
_name = "payment.details.lines"
@ -1174,7 +1185,7 @@ class PaymentDetailsLines(models.Model):
donation_date = fields.Date(string='Donation Date',default=lambda self: fields.Date.today())
note = fields.Char(string='Note')
journal_id = fields.Many2one('account.journal', string="Journal")
points_of_sale = fields.Many2one('points.of.sale.custom', string="Point OF sale",domain="[('branch_custom_id','=',branch_custom_id)]")
points_of_sale = fields.Many2one('points.of.sale.custom', string="Point OF sale")
sponsorship_id = fields.Many2one('takaful.sponsorship')
bank_id = fields.Many2one('res.partner.bank',string="Sponsorship Bank")
charity_journal_id = fields.Many2one('account.journal', string="charity Bank",related = 'points_of_sale.journal_id')
@ -1202,6 +1213,14 @@ class PaymentDetailsLines(models.Model):
if len(self.sponsor_account_number) != 22:
raise ValidationError(_("The IBAN number must contain exactly 22 digits."))
@api.onchange('branch_custom_id')
def _onchange_branch_custom_id(self):
domain = []
for rec in self:
domain = [
('branch_custom_ids', 'in', [rec.branch_custom_id.id]) ]
return {'domain': {'points_of_sale': domain}}

View File

@ -56,7 +56,7 @@
<group>
<field name="name"/>
<field name="department_name"/>
<field name="branch_custom_id"/>
<field name="branch_custom_ids" widget="many2many_tags"/>
<field name="journal_id"/>
</group>
</group>
@ -71,7 +71,7 @@
<tree string="Points of sale custom">
<field name="name"/>
<field name="department_name"/>
<field name="branch_custom_id"/>
<field name="branch_custom_ids" widget="many2many_tags"/>
<field name="department_name"/>
<field name="journal_id"/>
</tree>

View File

@ -150,7 +150,7 @@
<!-- </div>-->
<!-- </group>-->
<group>
<field name="donate_for_another_person"/>
<field name="donate_for_another_person" widget="boolean_toggle"/>
</group>
<group string="Gifter Information" attrs="{'invisible': [('is_gift', '!=', 'yes')]}">
@ -179,6 +179,7 @@
<field name="sponsor_name"/>
<field name="sponsor_phone"/>
<field name="sponsor_id_number"/>
<field name="receive_messages" widget="boolean_toggle"/>
</tree>
</field>
</page>
@ -189,15 +190,18 @@
<group>
<field name="donation_type"/>
<field name="sponsorship_duration" attrs="{'invisible': [('donation_type','!=','sponsorship')]}"/>
<field name="start_date" attrs="{'invisible': ['|',('sponsorship_duration','!=','temporary'),('donation_type','!=','sponsorship')]}"/>
<field name="end_date" attrs="{'invisible': ['|',('sponsorship_duration','!=','temporary'),('donation_type','!=','sponsorship')]}"/>
<field name="payment_option" attrs="{'invisible': [('sponsorship_duration','!=','temporary')]}"/>
<field name="payment_month_count" attrs="{'invisible': [('payment_option','!=','month')]}"/>
<field name="start_date" attrs="{'invisible': [('payment_option', '!=', 'month')]}"/>
<field name="end_date" attrs="{'invisible': [('payment_option', '!=', 'month')]}"/>
</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_mechanism" attrs="{'invisible':[('donation_type','!=','donation')],'readonly': [('donation_type','=','sponsorship')]}" force_save="1"/>
<field name="fixed_value" invisible="1"/>
<field name="donation_amount" attrs="{'readonly':[('fixed_value','=',True)]}" force_save="1"/>
<field name="benefits_count" attrs="{'invisible':[('sponsorship_type','!=','group')]}"/>
<field name="total_donation_amount" attrs="{'invisible':[('sponsorship_type','!=','group')]}"/>
</group>
</group>
<group attrs="{'invisible': ['|',('donation_mechanism','!=','with_conditions'),('donation_type','=','waqf')]}">
@ -264,7 +268,7 @@
<field name="direct_debit_end_date" attrs="{'invisible': [('payment_method','!=','direct_debit')]}"/>
<field name="donation_date"/>
<field name="charity_journal_id" attrs="{'invisible': [('payment_method','!=','card'),('payment_method','!=','credit_card')]}"/>
<field name="donation_amount" attrs="{'invisible': [('payment_method','!=','bank_transfer'),('payment_method','!=','direct_debit')]}"/>
<field name="donation_amount" attrs="{'invisible': ['|',('payment_method','!=','bank_transfer'),('payment_method','!=','direct_debit')]}"/>
<field name="account_payment_method" attrs="{'invisible': [('payment_method','!=','card'),('payment_method','!=','credit_card')]}"/>
<field name="note"/>
<field name="payment_attachment" widget="many2many_attachment_preview" attrs="{'invisible': [('payment_method','!=','bank_transfer'),('payment_method','!=','direct_debit')]}"/>