Merge pull request #5222 from expsa/takaful_notes

[IMP] odex_takaful: reset invoice to draft and reuse it
This commit is contained in:
abdurrahman-saber 2025-11-05 11:06:18 +02:00 committed by GitHub
commit 850716c2be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 11 deletions

View File

@ -17,12 +17,13 @@ class AccountMove(models.Model):
@api.depends('state')
def _compute_takaful_sponsorship_id(self):
for move in self:
if not move.takaful_sponsorship_id:
if not move.takaful_sponsorship_id and move.move_type == 'entry':
partials = move.line_ids.matched_debit_ids | move.line_ids.matched_credit_ids
takaful_sponsorship_ids = (partials.debit_move_id.move_id.takaful_sponsorship_id | partials.credit_move_id.move_id.takaful_sponsorship_id)
move.takaful_sponsorship_id = takaful_sponsorship_ids[-1] if takaful_sponsorship_ids else False
else:
move.takaful_sponsorship_id = move.takaful_sponsorship_id
def action_move_line_create(self):
'''
Confirm the vouchers given in ids and create the journal entries for each of them

View File

@ -1245,22 +1245,29 @@ class TakafulSponsorship(models.Model):
Invoice = self.env["account.move"].sudo()
invoice_values = {
'takaful_sponsorship_id': self.id,
'name': self.env['ir.sequence'].next_by_code('account.move.accrsp'),
'move_type': 'out_invoice',
'journal_id': int(kafala_journal_id),
'date': fields.Date.today(),
'partner_id': partner_id.id,
'invoice_origin': self.code,
'invoice_line_ids': [(0, 0, {
}
invoice_line_vals = [(0, 0, {
'product_id': line.product_id.id,
'price_unit': line.total_donation_amount,
'quantity': 1,
'name': _("Sponsorship Entitlement Number %s") % line.sequence_no,
'analytic_account_id': line.sponsorship_id.branch_custom_id.branch.analytic_account_id.id,
}) for line in all_donation_lines],
# 'branch_id': TODO there is no res.branch in takaful.sponsorship model
}
invoice_id = Invoice.create(invoice_values)
}) for line in all_donation_lines]
current_invoice = self.journal_entry_ids.filtered(lambda r: r.move_type == 'out_invoice' and r.state == 'draft')
if current_invoice:
invoice_values['invoice_line_ids'] = [(5, 0, 0)] + invoice_line_vals
current_invoice.write(invoice_values)
invoice_id = current_invoice
else:
invoice_values.update({'invoice_line_ids': invoice_line_vals, 'name': self.env['ir.sequence'].next_by_code('account.move.accrsp')})
invoice_id = Invoice.create(invoice_values)
for line in invoice_id.invoice_line_ids:
line.account_id = line._get_computed_account()
taxes = line._get_computed_taxes()
@ -1284,7 +1291,6 @@ class TakafulSponsorship(models.Model):
#self.action_send_whatsapp()
def action_send_whatsapp(self):
config = self.env['ir.config_parameter'].sudo()
account_sid = config.get_param('odex_takaful.twilio_account_sid')
@ -1661,6 +1667,8 @@ class TakafulSponsorship(models.Model):
'dont_redirect_to_payments': True,
'sponsorship_line_ids': sponsorship_line_ids.ids,
'sponsorship_payment': True,
'sponsorship_id': self.id,
'sponsorship_payment_skip_compute_amount': True,
'default_sponsorship_payment': True,
'force_sponsorship_line_partner_id': self.sponsor_id.id,
},
@ -1680,7 +1688,6 @@ class TakafulSponsorship(models.Model):
raise ValidationError(_("You can only reset to draft a confirmed sponsorship."))
move_ids = rec.journal_entry_ids.filtered(lambda l: l.move_type == 'out_invoice')
move_ids.button_draft()
move_ids.button_cancel()
self.write({'state': 'draft'})
class AnotherSponsors(models.Model):

View File

@ -137,9 +137,12 @@ class AccountRegisterPayment(models.TransientModel):
'kafala_status': 'have_kafala',
})
line.sponsorship_mechanism_id.sponsor_id.sudo().is_sponsor_portal = True
payment_vals = {
'takaful_sponsorship_id': self.env.context.get('sponsorship_id'),
}
if self.env.context.get('is_direct_debit'):
payments.write({'direct_debit': True})
payment_vals['direct_debit'] = True
payments.write(payment_vals)
if self.transaction_file_attachment:
self.env['ir.attachment'].sudo().create({