Update rent_payment.py

This commit is contained in:
zainab2097 2024-08-07 13:03:55 +03:00 committed by GitHub
parent fe118e4da4
commit c91d10a2b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 0 deletions

View File

@ -182,6 +182,24 @@ class RentPayment(models.Model):
self.write(({'state': 'cancel'}))
elif self.state == 'due':
raise exceptions.ValidationError(_('Cannot Cancel This Payment Because it Due'))
def action_validate2(self):
for record in self:
if record.contract_id.state == 'confirm':
rent_payment = [line for line in record.contract_id.rent_payment_ids.filtered(
lambda payment: payment.due_date < record.due_date and
(not payment.invoice_id or
all(invoice.state == 'draft' for invoice in payment.invoice_id))
)]
# if len(rent_payment):
# raise exceptions.ValidationError(
# _("You must validate the previous rent payment and complete the process"))
if record.code == '/' or not record.code:
code = self.env['ir.sequence'].next_by_code('rent.payment') or '/'
record.write({'code': code})
record.write({"state": 'due'})
else:
raise exceptions.ValidationError(_("You Must Confirm Contract First"))
def action_validate(self):
for record in self: