Update end_rental_contract.py
This commit is contained in:
parent
fbef0f4ce5
commit
d8513d782c
|
|
@ -41,33 +41,7 @@ class EndOfRent(models.Model):
|
||||||
note = fields.Text(string="Note")
|
note = fields.Text(string="Note")
|
||||||
invoice_id = fields.Many2one('account.move', string="Invoice")
|
invoice_id = fields.Many2one('account.move', string="Invoice")
|
||||||
|
|
||||||
def _prepare_out_refund_invoice_values(self, end, amount):
|
|
||||||
self.contract_id.partner_id.property_account_receivable_id = end.contract_id.accrued_account_id.id
|
|
||||||
invoice_vals = {
|
|
||||||
'ref': end.name,
|
|
||||||
'move_type': 'out_refund',
|
|
||||||
'invoice_origin': _('Insurance Refund') + ' ' + end.name + ' ' + end.contract_id.partner_id.name,
|
|
||||||
'invoice_user_id': end.user_id.id,
|
|
||||||
'invoice_date': end.date,
|
|
||||||
'narration': end.note,
|
|
||||||
'partner_id': end.contract_id.partner_id.id,
|
|
||||||
'invoice_line_ids': [(0, 0, {
|
|
||||||
'name': end.name + ' - ' + str(end.date),
|
|
||||||
'price_unit': amount,
|
|
||||||
'quantity': 1.0,
|
|
||||||
'account_id': end.contract_id.debit_account_id.id,
|
|
||||||
|
|
||||||
})],
|
|
||||||
# 'line_ids': [(0, 0, {'account_id':end.contract_id.debit_account_id.id, 'debit': 0.0, 'credit': amount,
|
|
||||||
# 'name': end.name + ' - ' + str(end.date),
|
|
||||||
# 'quantity': 1}),
|
|
||||||
# (0, 0,
|
|
||||||
# {'account_id': end.contract_id.accrued_account_id.id , 'debit': amount, 'credit': 0.0, 'quantity': 1})]
|
|
||||||
}
|
|
||||||
return invoice_vals
|
|
||||||
|
|
||||||
def _prepare_invoice_values(self, end, amount):
|
def _prepare_invoice_values(self, end, amount):
|
||||||
self.contract_id.partner_id.property_account_receivable_id = end.contract_id.debit_account_id.id
|
|
||||||
invoice_vals = {
|
invoice_vals = {
|
||||||
'ref': end.name,
|
'ref': end.name,
|
||||||
'move_type': 'out_invoice',
|
'move_type': 'out_invoice',
|
||||||
|
|
@ -80,18 +54,31 @@ class EndOfRent(models.Model):
|
||||||
'name': end.name + ' - ' + str(end.date),
|
'name': end.name + ' - ' + str(end.date),
|
||||||
'price_unit': amount,
|
'price_unit': amount,
|
||||||
'quantity': 1.0,
|
'quantity': 1.0,
|
||||||
'account_id': end.contract_id.revenue_account_id.id,
|
|
||||||
|
|
||||||
|
|
||||||
})],
|
})],
|
||||||
# 'line_ids': [(0, 0, {'account_id':end.contract_id.revenue_account_id.id, 'debit': 0.0, 'credit': amount,
|
|
||||||
# 'name': end.name + ' - ' + str(end.date),
|
|
||||||
# 'quantity': 1}),
|
|
||||||
# (0, 0,
|
|
||||||
# {'account_id': end.contract_id.debit_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})]
|
|
||||||
}
|
}
|
||||||
return invoice_vals
|
return invoice_vals
|
||||||
|
|
||||||
|
def _prepare_out_refund_invoice_values(self, end, amount):
|
||||||
|
invoice_vals = {
|
||||||
|
'ref': end.name,
|
||||||
|
'move_type': 'out_refund',
|
||||||
|
'invoice_origin': _('Insurance Refund') + ' ' + end.name + ' ' + end.contract_id.partner_id.name,
|
||||||
|
'invoice_user_id': end.user_id.id,
|
||||||
|
'invoice_date': end.date,
|
||||||
|
'narration': end.note,
|
||||||
|
'partner_id': end.contract_id.partner_id.id,
|
||||||
|
'invoice_line_ids': [(0, 0, {
|
||||||
|
'name': end.name + ' - ' + str(end.date),
|
||||||
|
'price_unit': amount,
|
||||||
|
'quantity': 1.0,
|
||||||
|
|
||||||
|
})],
|
||||||
|
}
|
||||||
|
return invoice_vals
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@api.depends('insurance_amount', 'total_amount')
|
@api.depends('insurance_amount', 'total_amount')
|
||||||
def get_remain_amount(self):
|
def get_remain_amount(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
|
@ -103,37 +90,21 @@ class EndOfRent(models.Model):
|
||||||
def action_cancel(self):
|
def action_cancel(self):
|
||||||
if self.state not in ['check', 'done']:
|
if self.state not in ['check', 'done']:
|
||||||
self.write({'state': 'cancel'})
|
self.write({'state': 'cancel'})
|
||||||
|
|
||||||
def action_done(self):
|
def action_done(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if (rec.remain_amount > 0.0) or (rec.remain_amount > 0.0 and rec.maintenance):
|
if rec.remain_amount > 0.0:
|
||||||
invoice_vals = rec._prepare_out_refund_invoice_values(rec, rec.remain_amount)
|
invoice_vals = rec._prepare_out_refund_invoice_values(rec, rec.remain_amount)
|
||||||
invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
||||||
# if len(invoice.invoice_line_ids) > 1:
|
|
||||||
# line_id = invoice.invoice_line_ids[1].id
|
|
||||||
# commands = [(2, line_id, 0)]
|
|
||||||
# invoice.write({'invoice_line_ids': commands})
|
|
||||||
rec.invoice_id = invoice.id
|
|
||||||
rec.write({'state': 'done'})
|
|
||||||
elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and not rec.maintenance:
|
|
||||||
rec.write({'state': 'done'})
|
|
||||||
elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and rec.maintenance:
|
|
||||||
invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount))
|
|
||||||
invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
|
||||||
# if len(invoice.invoice_line_ids) > 1:
|
|
||||||
# line_id = invoice.invoice_line_ids[1].id
|
|
||||||
# commands = [(2, line_id, 0)]
|
|
||||||
# invoice.write({'invoice_line_ids': commands})
|
|
||||||
rec.invoice_id = invoice.id
|
rec.invoice_id = invoice.id
|
||||||
rec.write({'state': 'done'})
|
rec.write({'state': 'done'})
|
||||||
|
|
||||||
elif (rec.remain_amount < 0.0) or (rec.remain_amount<0.0 and rec.maintenance):
|
elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and not rec.maintenance:
|
||||||
|
rec.write({'state': 'done'})
|
||||||
|
|
||||||
|
elif rec.remain_amount < 0.0:
|
||||||
invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount))
|
invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount))
|
||||||
invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
||||||
# if len(invoice.invoice_line_ids) > 1:
|
|
||||||
# line_id = invoice.invoice_line_ids[1].id
|
|
||||||
# commands = [(2, line_id, 0)]
|
|
||||||
# invoice.write({'invoice_line_ids': commands})
|
|
||||||
rec.invoice_id = invoice.id
|
rec.invoice_id = invoice.id
|
||||||
rec.write({'state': 'done'})
|
rec.write({'state': 'done'})
|
||||||
if rec.contract_state == 'before':
|
if rec.contract_state == 'before':
|
||||||
|
|
@ -146,6 +117,49 @@ class EndOfRent(models.Model):
|
||||||
unit.write({'state': 'available'})
|
unit.write({'state': 'available'})
|
||||||
rec.contract_id.write({'state': 'close'})
|
rec.contract_id.write({'state': 'close'})
|
||||||
|
|
||||||
|
|
||||||
|
# def action_done(self):
|
||||||
|
# for rec in self:
|
||||||
|
# if (rec.remain_amount > 0.0) or (rec.remain_amount > 0.0 and rec.maintenance):
|
||||||
|
# invoice_vals = rec._prepare_out_refund_invoice_values(rec, rec.remain_amount)
|
||||||
|
# invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
||||||
|
# if len(invoice.invoice_line_ids) > 1:
|
||||||
|
# line_id = invoice.invoice_line_ids[1].id
|
||||||
|
# commands = [(2, line_id, 0)]
|
||||||
|
# invoice.write({'invoice_line_ids': commands})
|
||||||
|
# rec.invoice_id = invoice.id
|
||||||
|
# rec.write({'state': 'done'})
|
||||||
|
# elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and not rec.maintenance:
|
||||||
|
# rec.write({'state': 'done'})
|
||||||
|
# elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and rec.maintenance:
|
||||||
|
# invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount))
|
||||||
|
# invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
||||||
|
# if len(invoice.invoice_line_ids) > 1:
|
||||||
|
# line_id = invoice.invoice_line_ids[1].id
|
||||||
|
# commands = [(2, line_id, 0)]
|
||||||
|
# invoice.write({'invoice_line_ids': commands})
|
||||||
|
# rec.invoice_id = invoice.id
|
||||||
|
# rec.write({'state': 'done'})
|
||||||
|
|
||||||
|
# elif (rec.remain_amount < 0.0) or (rec.remain_amount<0.0 and rec.maintenance):
|
||||||
|
# invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount))
|
||||||
|
# invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
|
||||||
|
# if len(invoice.invoice_line_ids) > 1:
|
||||||
|
# line_id = invoice.invoice_line_ids[1].id
|
||||||
|
# commands = [(2, line_id, 0)]
|
||||||
|
# invoice.write({'invoice_line_ids': commands})
|
||||||
|
# rec.invoice_id = invoice.id
|
||||||
|
# rec.write({'state': 'done'})
|
||||||
|
# if rec.contract_state == 'before':
|
||||||
|
# for rent_payment in rec.rent_payment_ids:
|
||||||
|
# if rent_payment.due_date > rec.date and rent_payment.state != 'paid':
|
||||||
|
# rent_payment.write({'state': 'cancel'})
|
||||||
|
# elif rent_payment.due_date < rec.date and rent_payment.state != 'paid':
|
||||||
|
# rent_payment.write({'state': 'cancel'})
|
||||||
|
# for unit in rec.contract_id.unit_ids:
|
||||||
|
# unit.write({'state': 'available'})
|
||||||
|
# rec.contract_id.write({'state': 'close'})
|
||||||
|
|
||||||
def action_check(self):
|
def action_check(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.contract_state == 'before':
|
if rec.contract_state == 'before':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue