summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-07-26 09:23:51 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-07-26 09:23:51 +0700
commitfff5507cf7c0f360a5c68068e77fa84b1d6340c5 (patch)
tree97383c687c7dcf320f84df69308e4e4463d54dde
parent213d4a2e63f393b08b49d9b0da1f30396f717c77 (diff)
(andri) fix
-rw-r--r--indoteknik_custom/models/down_payment.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/indoteknik_custom/models/down_payment.py b/indoteknik_custom/models/down_payment.py
index 81f2044f..0429c4d8 100644
--- a/indoteknik_custom/models/down_payment.py
+++ b/indoteknik_custom/models/down_payment.py
@@ -361,11 +361,61 @@ class DownPayment(models.Model):
rec.estimated_return_date = False
rec.days_remaining = 0
+ @api.onchange('applicant_name')
+ def _onchange_applicant_name(self):
+ if self.applicant_name:
+ self.account_name = self.applicant_name
+
+ @api.onchange('account_name')
+ def _onchange_account_name(self):
+ if self.account_name:
+ self.applicant_name = self.account_name
+
+ @api.onchange('user_id')
+ def _onchange_user_id_limit_check(self):
+ if not self.user_id:
+ return
+
+ pum_ids = self.search([
+ ('user_id', '=', self.user_id.id),
+ ('status', '!=', 'reject')
+ ])
+
+ active_pum_count = 0
+ for pum in pum_ids:
+ realization = self.env['realization.down.payment'].search([('pum_id', '=', pum.id)], limit=1)
+ if not realization or realization.done_status != 'done_not_realized':
+ active_pum_count += 1
+
+ if active_pum_count >= 2:
+ return {
+ 'warning': {
+ 'title': 'Batas Pengajuan Tercapai',
+ 'message': 'User ini sudah memiliki 2 PUM aktif. Tidak dapat mengajukan lagi sampai salah satu direalisasi.',
+ }
+ }
@api.model
def create(self, vals):
+ user = self.env.user
+
+ pum_ids = self.search([
+ ('user_id', '=', user.id),
+ ('status', '!=', 'reject')
+ ])
+
+ active_pum_count = 0
+ for pum in pum_ids:
+ realization = self.env['realization.down.payment'].search([('pum_id', '=', pum.id)], limit=1)
+ if not realization or realization.done_status != 'done_not_realized':
+ active_pum_count += 1
+
+ if active_pum_count >= 2:
+ raise UserError("Anda hanya dapat mengajukan maksimal 2 PUM aktif. Silakan realisasikan salah satunya terlebih dahulu.")
+
if not vals.get('number') or vals['number'] == 'New Draft':
vals['number'] = self.env['ir.sequence'].next_by_code('down.payment') or 'New Draft'
+
vals['status'] = 'pengajuan1'
return super(DownPayment, self).create(vals)