Add Domain on sponsership
This commit is contained in:
parent
f97078a400
commit
e2e8b884dc
|
|
@ -55,7 +55,7 @@ class DonationsDetailsLines(models.Model):
|
|||
family_domain_ids = fields.Many2many('grant.benefit', compute='_compute_family_domain_ids')
|
||||
benefit_id = fields.Many2one('family.member', string='Beneficiary Name', ondelete='restrict', domain="[('id', 'in', members_domain_ids)]", tracking=True)
|
||||
family_id = fields.Many2one('grant.benefit', string='Family', ondelete='restrict', domain="[('id', 'in', family_domain_ids)]", tracking=True)
|
||||
benefit_ids = fields.Many2many('family.member', string='Beneficiaries Names', tracking=True, domain="[('id', 'in', members_domain_ids)]")
|
||||
benefit_ids = fields.Many2many('family.member', string='Beneficiaries Names', tracking=True, domain="[('id', 'in', members_domain_ids) , ('age' , '<' , ages)]")
|
||||
sponsorship_duration = fields.Selection([('temporary', 'Temporary'), ('permanent', 'Permanent')],
|
||||
string='Sponsorship Type', default="temporary")
|
||||
start_date = fields.Date(string="Sponsorship Start Date", copy=False, default=fields.Date.today())
|
||||
|
|
@ -98,6 +98,7 @@ class DonationsDetailsLines(models.Model):
|
|||
debit_payment_attachment_file_name = fields.Char('Debit Payment File Name', required=False)
|
||||
journal_id = fields.Many2one('account.journal', string="Journal",domain="[('type','=','bank')]",default=_default_journal_id)
|
||||
benefit_status = fields.Selection(related='benefit_id.member_status')
|
||||
ages = fields.Integer(compute='_compute_get_age_range' , store=True)
|
||||
# cheque_number = fields.Integer(string="Cheque Number")
|
||||
# cheque_due_date = fields.Date(string="Cheque Due Date")
|
||||
# cheque_file_attachment = fields.Binary(string='Cheque Attachment', attachment=True)
|
||||
|
|
@ -106,6 +107,38 @@ class DonationsDetailsLines(models.Model):
|
|||
# bank_transfer_attachment_file_name = fields.Char('Bank Transfer File Name', required=False)
|
||||
|
||||
|
||||
@api.depends('sponsorship_duration' , 'product_template_id' , 'payment_month_count' , 'direct_debit')
|
||||
def _compute_get_age_range(self):
|
||||
for rec in self:
|
||||
x = []
|
||||
records = self.env['donations.details.lines'].search(['|' , ('state', '=', 'replace') , ('state', '=', 'waiting')])
|
||||
print('records >>> ' , records)
|
||||
for i in records:
|
||||
x.append(self.compute_donation_value(records))
|
||||
lowest_value = min(x) if x else None
|
||||
rec.ages = lowest_value
|
||||
|
||||
def compute_donation_value(self , records):
|
||||
"""
|
||||
Loop through donation detail lines and return a number based on conditions:
|
||||
- If sponsorship_duration == 'permanent' → return 1
|
||||
- Else if not permanent and payment_month_count > 6 → return 1
|
||||
- Else if not permanent and payment_month_count < 6 and direct_debit == True → return 16
|
||||
- Else if not permanent and payment_month_count < 6 → return 18
|
||||
- Else → return 1
|
||||
"""
|
||||
for record in records:
|
||||
if record.sponsorship_duration == 'permanent':
|
||||
return 1
|
||||
elif record.sponsorship_duration != 'permanent' and record.payment_month_count > 6:
|
||||
return 1
|
||||
elif record.sponsorship_duration != 'permanent' and record.payment_month_count < 6 and record.direct_debit:
|
||||
return 16
|
||||
elif record.sponsorship_duration != 'permanent' and record.payment_month_count < 6:
|
||||
return 18
|
||||
else:
|
||||
return 1
|
||||
return 1
|
||||
@api.depends('extension_history_ids')
|
||||
def _compute_extension_count(self):
|
||||
for rec in self:
|
||||
|
|
@ -1074,4 +1107,4 @@ class DonationsDetailsLines(models.Model):
|
|||
'context': {
|
||||
'default_donation_detail_id': self.id,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@
|
|||
|
||||
<group>
|
||||
<group string="Donation Information">
|
||||
<field name="ages" />
|
||||
<field name="donation_type" invisible="1"/>
|
||||
<field name="donation_types"
|
||||
attrs="{'invisible': [('donation_type', '!=', 'donation')], 'readonly': [('parent_state', '!=', 'draft')]}" />
|
||||
|
|
@ -373,4 +374,4 @@
|
|||
<field name="context">{'create': False, 'delete': False, 'search_default_filter_replace': 1}</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -509,6 +509,7 @@
|
|||
</header>
|
||||
<group>
|
||||
<group>
|
||||
<field name="ages" />
|
||||
<field name="family_id"
|
||||
attrs="{'invisible': [('sponsorship_type','=','group'), ('parent.record_type','=','sponsorship')],
|
||||
'readonly': ['|', ('sponsorship_type', '!=', 'group'), ('parent.record_type','!=','donation')],
|
||||
|
|
@ -612,7 +613,7 @@
|
|||
<page string="Orphans and Widows List"
|
||||
attrs="{'invisible': ['|',('sponsorship_type', '!=', 'group'), ('hide_beneficiary_group', '=', True)]}">
|
||||
<!-- attrs="{'invisible': ['|', '|', '|', ('hide_beneficiary_group','=', True), ('parent.record_type','!=','sponsorship'), ('sponsorship_type', '!=', 'group'), ('benefit_type', '!=', 'both')]}">-->
|
||||
<field name="benefit_ids" nolabel="1" options="{'no_create': True}">
|
||||
<field name="benefit_ids" nolabel="1" options="{'no_create': True}">
|
||||
<tree editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="age"/>
|
||||
|
|
@ -818,4 +819,4 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
|
|
|||
Loading…
Reference in New Issue