commit
d276d68ba0
|
|
@ -19,7 +19,7 @@ class AccountMove(models.Model):
|
|||
def action_view_esterdad_id(self):
|
||||
self.ensure_one() # Ensure the method is called on a single record
|
||||
action = self.env.ref('odex_takaful.view_esterdad_wizard_tree').read()[0]
|
||||
action['domain'] = [('id', '=', self.cancel_record_id.id)]
|
||||
action['domain'] = [('id', '=', self.esterdad_id.id)]
|
||||
action['context'] = {
|
||||
'create': False
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ class DonationsDetailsLines(models.Model):
|
|||
members_domain_ids = fields.Many2many('family.member', compute='_compute_members_domain_ids')
|
||||
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, compute='_compute_family_id', store=True)
|
||||
benefit_ids = fields.Many2many('family.member', string='Beneficiaries Names', tracking=True, domain="[('id', 'in', members_domain_ids) , ('age' , '<' , ages)]")
|
||||
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) ]")
|
||||
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())
|
||||
|
|
@ -67,7 +67,7 @@ class DonationsDetailsLines(models.Model):
|
|||
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')
|
||||
total_months_amount = fields.Float(string='Total Months Amount', compute='_get_total_months_amount')
|
||||
currency_id = fields.Many2one('res.currency', string='Currency',
|
||||
currency_id = fields.Many2one('res.currency', string='Currency',
|
||||
default=lambda self: self.env.company.currency_id, readonly=True)
|
||||
sponsorships_computed = fields.Boolean(copy=False, readonly=True)
|
||||
direct_debit = fields.Boolean(string='Direct Debit')
|
||||
|
|
@ -79,7 +79,7 @@ class DonationsDetailsLines(models.Model):
|
|||
sponsor_phone = fields.Char(related='sponsor_id.mobile')
|
||||
branch_custom_id = fields.Many2one('branch.settings', compute='_compute_branch_custom_id')
|
||||
record_type = fields.Selection([('sponsorship', 'Sponsorship'),('donation', 'Donation')], compute='_compute_record_type', store=True, readonly=True)
|
||||
state = fields.Selection([('draft', 'Draft'),('confirmed', 'Confirmed'),('waiting', 'Waiting'), ('active', 'Active'),('closed', 'Closed'),('extended', 'Extended'),('replace', 'To Replace'), ('paid', 'Paid')], string='State', default='draft')
|
||||
state = fields.Selection([('draft', 'Draft'),('confirmed', 'Confirmed'),('waiting', 'Waiting'), ('active', 'Active'),('closed', 'Closed'),('extended', 'Extended'),('replace', 'To Replace'), ('paid', 'Paid'),('cancel', 'Canceled')], string='State', default='draft')
|
||||
sponsorship_scheduling_line_ids = fields.One2many('sponsorship.scheduling.line', 'donation_detail_linked_id')
|
||||
extension_history_ids = fields.One2many('donation.extension.history', 'donation_detail_id',
|
||||
string='Extension History')
|
||||
|
|
@ -148,10 +148,11 @@ class DonationsDetailsLines(models.Model):
|
|||
store=False
|
||||
)
|
||||
|
||||
@api.depends()
|
||||
@api.depends('sponsorship_mechanism_id.create_uid')
|
||||
def _compute_can_edit_benefit(self):
|
||||
for rec in self:
|
||||
user = self.env.user
|
||||
print('User , >>>> ' , user )
|
||||
is_manager = (
|
||||
user.has_group('odex_takaful.sponsorship_system_manager_group') or
|
||||
user.has_group('odex_takaful.branch_manager_group'))
|
||||
|
|
@ -159,7 +160,6 @@ class DonationsDetailsLines(models.Model):
|
|||
@api.depends('sponsorship_duration', 'payment_month_count', 'direct_debit')
|
||||
def _compute_age_category(self):
|
||||
for rec in self:
|
||||
print( rec.sponsorship_duration , ' ' ,rec.direct_debit , ' ' , rec.payment_month_count)
|
||||
if rec.sponsorship_duration == 'permanent':
|
||||
rec.age_category = 'all'
|
||||
elif rec.sponsorship_duration != 'permanent' :
|
||||
|
|
@ -271,7 +271,7 @@ class DonationsDetailsLines(models.Model):
|
|||
def _compute_branch_custom_id(self):
|
||||
for rec in self:
|
||||
rec.branch_custom_id = rec.sponsorship_id.branch_custom_id or rec.sponsorship_mechanism_id.branch_custom_id
|
||||
|
||||
|
||||
@api.depends('direct_debit', 'end_date')
|
||||
def _compute_show_extend_button(self):
|
||||
today = fields.Date.today()
|
||||
|
|
@ -738,11 +738,12 @@ class DonationsDetailsLines(models.Model):
|
|||
domain = []
|
||||
if rec.record_type == 'sponsorship':
|
||||
domain = [
|
||||
'|',
|
||||
'|',
|
||||
('state', '=', 'second_approve'),
|
||||
'&',
|
||||
'&','&',
|
||||
('state', 'in', ('waiting_approve', 'first_approve')),
|
||||
('action_type', '=', 'suspended')]
|
||||
('action_type', '=', 'suspended'),
|
||||
('age', '<', rec.ages)]
|
||||
|
||||
domain = expression.AND([domain, [
|
||||
('member_status', '=', 'benefit'),
|
||||
|
|
@ -754,18 +755,18 @@ class DonationsDetailsLines(models.Model):
|
|||
domain = expression.AND([domain, [
|
||||
('benefit_id.code', '=', rec.benefit_family_code)
|
||||
]])
|
||||
|
||||
|
||||
if rec.age_category_id:
|
||||
domain = expression.AND([domain, [
|
||||
('age', '<=', rec.age_category_id.max_age),
|
||||
('age', '>=', rec.age_category_id.min_age)
|
||||
]])
|
||||
|
||||
|
||||
if rec.education_level:
|
||||
domain = expression.AND([domain, [
|
||||
('education_levels', '=', rec.education_level.id)
|
||||
]])
|
||||
|
||||
|
||||
if rec.education_status:
|
||||
domain = expression.AND([domain, [
|
||||
('education_status', '=', rec.education_status)
|
||||
|
|
@ -796,7 +797,7 @@ class DonationsDetailsLines(models.Model):
|
|||
domain = expression.AND([domain, [
|
||||
('relationn.relation_type', '=', 'son')
|
||||
]])
|
||||
|
||||
|
||||
if rec.benefit_id_number:
|
||||
domain = expression.AND([domain, [
|
||||
('member_id_number', '=', rec.benefit_id_number)
|
||||
|
|
@ -852,6 +853,7 @@ class DonationsDetailsLines(models.Model):
|
|||
|
||||
if record_type == 'donation':
|
||||
domain.append(('donation_category', '=', 'donation'))
|
||||
domain.append(('donation_category', '=', 'endowment'))
|
||||
|
||||
elif record_type == 'sponsorship':
|
||||
domain.append(('donation_category', '=', 'sponsorship'))
|
||||
|
|
@ -862,6 +864,7 @@ class DonationsDetailsLines(models.Model):
|
|||
'product_template_id': domain}
|
||||
}
|
||||
|
||||
|
||||
@api.onchange('donation_type')
|
||||
def onchange_donation_type(self):
|
||||
for rec in self:
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ class DonationExtensionHistory(models.Model):
|
|||
string='New Direct Debit',
|
||||
readonly=True
|
||||
)
|
||||
|
||||
state = fields.Selection([ ('active', 'Active'),('cancel', 'Canceled')], string='State', default='active')
|
||||
canceled = fields.Boolean()
|
||||
@api.depends('donation_detail_id', 'extension_date')
|
||||
def _compute_extension_ref(self):
|
||||
for rec in self:
|
||||
|
|
|
|||
|
|
@ -309,6 +309,18 @@ class ResPartner(models.Model):
|
|||
if self.kafel_id:
|
||||
self.kafel_id.login = vals['mobile']
|
||||
|
||||
if 'mobile' in vals and self.mobile != False:
|
||||
kafeel = self.env['res.users'].with_user(2).create({
|
||||
'name' : vals['name'],
|
||||
'branch_custom_id':vals['branch_custom_id'],
|
||||
'sel_groups_1_9_10' : 9,
|
||||
'partner_id' : self.id,
|
||||
'login' : vals['mobile'],
|
||||
'otp_mobile_phone' : vals['mobile'],
|
||||
'otp_enabled' : True,
|
||||
})
|
||||
self.kafel_id = kafeel
|
||||
|
||||
res = super(ResPartner, self).write(vals)
|
||||
return res
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,12 @@ class TakafulSponsorship(models.Model):
|
|||
pay_date = fields.Datetime()
|
||||
cancel_record_id = fields.Many2one('esterdad.wizard', string="Cancel Record")
|
||||
record_url = fields.Char(string="Record URL", readonly=True)
|
||||
is_canceled_refund = fields.Boolean()
|
||||
|
||||
@api.depends('is_canceled_refund')
|
||||
def cancel_refund_tamded(self):
|
||||
for rec in self:
|
||||
print('Hi')
|
||||
|
||||
def action_quotation_send(self):
|
||||
self.ensure_one()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,12 @@
|
|||
<field name="model">donation.extension.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<form create="0" edit="0" delete="0">
|
||||
<header>
|
||||
<field name="state" widget="statusbar"
|
||||
statusbar_visible="active,cancel" />
|
||||
</header>
|
||||
<sheet>
|
||||
<widget name="web_ribbon" title="Canceld" bg_color="bg-danger" attrs="{'invisible': [('state', '!=', 'cancel')]}"/>
|
||||
<group>
|
||||
<group>
|
||||
<field name="extension_ref"/>
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@
|
|||
<!-- string="Replacement Processes" class="oe_stat_button" icon="fa-users">-->
|
||||
<!-- </button>-->
|
||||
</div>
|
||||
<widget name="web_ribbon" title="Canceld" bg_color="bg-danger" attrs="{'invisible': [('state', '!=', 'canceled')]}"/>
|
||||
<widget name="web_ribbon" title="Canceld" bg_color="bg-danger"
|
||||
attrs="{'invisible': [('state', '!=', 'canceled')]}"/>
|
||||
<!-- Code badge hidden for now -->
|
||||
<!-- <div style="position: absolute; top: 70px; right: 15px; z-index: 100;" attrs="{'invisible': [('code', '=', False)]}">
|
||||
<span class="badge badge-info" style="font-size: 14px; padding: 6px 12px;">
|
||||
|
|
@ -526,7 +527,9 @@
|
|||
</header>
|
||||
<group>
|
||||
<group>
|
||||
<field name="ages" invisible="1"/>
|
||||
<field name="ages" invisible="0"/>
|
||||
<field name="members_domain_ids" invisible="0"/>
|
||||
|
||||
<field name="waiting_date" invisible="1" widget="date"/>
|
||||
<field name="family_id"
|
||||
attrs="{'invisible': [('sponsorship_type','=','group'), ('parent.record_type','=','sponsorship')],
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from odoo import models, fields, api, _
|
|||
from odoo.exceptions import UserError, ValidationError, Warning
|
||||
import logging
|
||||
from odoo import SUPERUSER_ID
|
||||
from datetime import datetime, date
|
||||
from datetime import datetime, date, timedelta
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -27,8 +27,73 @@ class EsterdadWizard(models.Model):
|
|||
sponsor_name = fields.Char()
|
||||
mobile = fields.Char()
|
||||
id_num = fields.Char()
|
||||
payment_ids = fields.Many2many('account.payment')
|
||||
payment_ids = fields.Many2many(
|
||||
'account.payment',
|
||||
'esterdad_wizard_payment_rel',
|
||||
'wizard_id',
|
||||
'payment_id',
|
||||
string="Payments",
|
||||
domain="[('id', 'in', allowed_payment_ids)]",
|
||||
)
|
||||
allowed_payment_ids = fields.Many2many(
|
||||
'account.payment',
|
||||
'esterdad_wizard_allowed_payment_rel',
|
||||
'wizard_id',
|
||||
'payment_id',
|
||||
string="Allowed Payments",
|
||||
)
|
||||
confirmed = fields.Boolean()
|
||||
|
||||
@api.onchange('sponsor_id')
|
||||
def _onchange_sponsor_id_set_payment_domain(self):
|
||||
"""Limit available payments to same partner within restriction_period days."""
|
||||
for rec in self:
|
||||
domain = []
|
||||
partner = False
|
||||
invoice_names = []
|
||||
|
||||
if rec.sponsor_id:
|
||||
# Assuming sponsor_id.sponsor_id is the related partner on the sponsorship
|
||||
partner = getattr(rec.sponsor_id, 'sponsor_id', False) or getattr(rec.sponsor_id, 'partner_id', False)
|
||||
|
||||
# Get all invoices from journal_entry_ids where move_type is 'out_invoice'
|
||||
invoices = rec.sponsor_id.journal_entry_ids.filtered(lambda inv: inv.move_type == 'out_invoice')
|
||||
# Get all invoice names (numbers) in a list
|
||||
invoice_names = invoices.mapped('name')
|
||||
|
||||
if partner:
|
||||
# Get restriction period (in days) from config parameters
|
||||
sudo_conf = self.env['ir.config_parameter'].sudo()
|
||||
restriction_period = sudo_conf.get_param('odex_takaful.restriction_period')
|
||||
|
||||
try:
|
||||
restriction_period = int(restriction_period or 0)
|
||||
except (TypeError, ValueError):
|
||||
restriction_period = 0
|
||||
|
||||
if restriction_period and restriction_period > 0:
|
||||
limit_date = date.today() - timedelta(days=restriction_period)
|
||||
domain = [
|
||||
('partner_id', '=', partner.id),
|
||||
('date', '>=', limit_date),
|
||||
]
|
||||
else:
|
||||
# If no restriction configured, just filter by partner
|
||||
domain = [('partner_id', '=', partner.id)]
|
||||
|
||||
# Add filter for ref field to match invoice names if we have any
|
||||
if invoice_names:
|
||||
domain.append(('ref', 'in', invoice_names))
|
||||
|
||||
# If we have a domain, fetch the matching payments and store them
|
||||
# in the helper field, then use their IDs as the domain.
|
||||
if domain:
|
||||
payments = self.env['account.payment'].search(domain)
|
||||
rec.allowed_payment_ids = payments
|
||||
return {'domain': {'payment_ids': [('id', 'in', payments.ids)]}}
|
||||
else:
|
||||
rec.allowed_payment_ids = False
|
||||
return {'domain': {'payment_ids': []}}
|
||||
def action_confirm_refund(self):
|
||||
for rec in self:
|
||||
user = rec.sponsor_id.sponsor_id.kafel_id
|
||||
|
|
@ -41,6 +106,7 @@ class EsterdadWizard(models.Model):
|
|||
rec.sponsor_id.write({
|
||||
'cancel_record_id': rec.id
|
||||
})
|
||||
context['default_payment_ids'] = [(6, 0, rec.payment_ids.ids)]
|
||||
view = self.env.ref('odex_takaful.view_otp_wizard_form')
|
||||
return {
|
||||
'name': _('OTP Confirmation'),
|
||||
|
|
@ -73,6 +139,10 @@ class OTPWizard(models.TransientModel):
|
|||
otp_code = fields.Integer()
|
||||
esterdad_id = fields.Many2one('esterdad.wizard')
|
||||
user_id = fields.Many2one('res.users')
|
||||
payment_ids = fields.Many2many(
|
||||
'account.payment',
|
||||
string="Payments"
|
||||
)
|
||||
|
||||
def action_confirm_otp(self):
|
||||
for rec in self:
|
||||
|
|
@ -80,24 +150,71 @@ class OTPWizard(models.TransientModel):
|
|||
sponsor_ship = rec.esterdad_id.sponsor_id
|
||||
rec.esterdad_id.cancel_date = date.today()
|
||||
if sponsor_ship:
|
||||
credit = self.env['account.move.reversal'].with_company(self.env.user.company_id.id).create({
|
||||
'refund_method': 'refund',
|
||||
'date': date.today(),
|
||||
'date_mode': 'custom',
|
||||
'move_ids': sponsor_ship.journal_entry_ids.ids,
|
||||
# Get ref values from selected payments
|
||||
payment_refs = rec.payment_ids.mapped('ref')
|
||||
# Filter out empty/False refs
|
||||
payment_refs = [ref for ref in payment_refs if ref]
|
||||
|
||||
})
|
||||
x = credit.reverse_moves()
|
||||
sponsor_ship.state = 'canceled'
|
||||
if not payment_refs:
|
||||
raise UserError("لا توجد مراجع في الدفعات المحددة")
|
||||
|
||||
# Search for invoices in account.move matching payment refs
|
||||
invoices = self.env['account.move'].search([
|
||||
('name', 'in', payment_refs),
|
||||
])
|
||||
if not invoices:
|
||||
raise UserError("لا توجد فواتير مطابقة للمراجع المحددة")
|
||||
for invoice in invoices:
|
||||
credit = self.env['account.move.reversal'].with_company(self.env.user.company_id.id).create({
|
||||
'refund_method': 'refund',
|
||||
'date': date.today(),
|
||||
'date_mode': 'custom',
|
||||
'move_ids': [invoice.id],
|
||||
})
|
||||
x = credit.reverse_moves()
|
||||
sponsor_ship.state = 'canceled'
|
||||
domain_ids = x.get('res_id')
|
||||
if domain_ids:
|
||||
last_id = domain_ids
|
||||
sponsor_ship.write({
|
||||
'journal_entry_ids': [(4, last_id)]
|
||||
})
|
||||
credit_note = self.env['account.move'].search([('id', '=', last_id)])
|
||||
credit_note.action_post()
|
||||
credit_note.esterdad_id = rec.esterdad_id
|
||||
rec.esterdad_id.confirmed = True
|
||||
rec.esterdad_id.sponsor_id.is_canceled_refund = True
|
||||
|
||||
# Get all donation lines from donations_details_lines and donations_details_lines_mechanism_ids
|
||||
all_donation_lines = sponsor_ship.donations_details_lines | sponsor_ship.donations_details_lines_mechanism_ids
|
||||
|
||||
# Set state to 'cancel' for all donation lines
|
||||
if all_donation_lines:
|
||||
all_donation_lines.write({'state': 'cancel'})
|
||||
|
||||
# Process extension history for each donation line
|
||||
for donation_line in all_donation_lines:
|
||||
# Get extension_history_ids for this donation line
|
||||
extension_histories = donation_line.extension_history_ids
|
||||
|
||||
if extension_histories:
|
||||
# Set state to 'cancel' for all extension histories
|
||||
extension_histories.write({'state': 'cancel'})
|
||||
total_extension_months = 0
|
||||
current_payment_month_count = 0
|
||||
new_payment_month_count = 0
|
||||
# Sum all extension_months
|
||||
total_extension_months = sum(extension_histories.mapped('extension_months'))
|
||||
|
||||
# Subtract the sum from payment_month_count
|
||||
if total_extension_months > 0:
|
||||
current_payment_month_count = donation_line.payment_month_count or 0
|
||||
new_payment_month_count = current_payment_month_count - total_extension_months
|
||||
# Ensure it doesn't go below 0
|
||||
donation_line.write({
|
||||
'payment_month_count': max(0, new_payment_month_count)
|
||||
})
|
||||
|
||||
domain_ids = x.get('domain')[0][2]
|
||||
last_id = domain_ids[-1]
|
||||
sponsor_ship.write({
|
||||
'journal_entry_ids': [(4, last_id)]
|
||||
})
|
||||
credit_note = self.env['account.move'].search([('id' , '=' , last_id)])
|
||||
credit_note.action_post()
|
||||
rec.esterdad_id.confirmed = True
|
||||
|
||||
else:
|
||||
raise UserError("الرقم المدخل خاطئ")
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
<field name="another_reason"/>
|
||||
<field name="reason" attrs="{'invisible': [('another_reason', '=', False)],
|
||||
'required': [('another_reason', '=', True)]}"/>
|
||||
<field name="sponsor_id" />
|
||||
<field name="allowed_payment_ids" widget="many2many_tags" />
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="بيانات المتبرع">
|
||||
|
|
|
|||
Loading…
Reference in New Issue