Update end_rental_contract
This commit is contained in:
parent
8de38dcb64
commit
8c6d5b0f34
|
|
@ -42,6 +42,7 @@ class EndOfRent(models.Model):
|
|||
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.debit_account_id.id
|
||||
invoice_vals = {
|
||||
'ref': end.name,
|
||||
'move_type': 'out_refund',
|
||||
|
|
@ -54,12 +55,19 @@ class EndOfRent(models.Model):
|
|||
'name': end.name + ' - ' + str(end.date),
|
||||
'price_unit': amount,
|
||||
'quantity': 1.0,
|
||||
'account_id': end.contract_id.accrued_account_id.id,
|
||||
|
||||
})],
|
||||
'line_ids': [(0, 0, {'account_id': end.contract_id.accrued_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
|
||||
|
||||
def _prepare_invoice_values(self, end, amount):
|
||||
self.contract_id.partner_id.property_account_receivable_id = end.contract_id.revenue_account_id.id
|
||||
invoice_vals = {
|
||||
'ref': end.name,
|
||||
'move_type': 'out_invoice',
|
||||
|
|
@ -74,6 +82,11 @@ class EndOfRent(models.Model):
|
|||
'quantity': 1.0,
|
||||
|
||||
})],
|
||||
'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.revenue_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})]
|
||||
}
|
||||
return invoice_vals
|
||||
|
||||
|
|
@ -91,16 +104,34 @@ class EndOfRent(models.Model):
|
|||
|
||||
def action_done(self):
|
||||
for rec in self:
|
||||
if rec.remain_amount > 0.0:
|
||||
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)
|
||||
# Get the ID of the second line
|
||||
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:
|
||||
elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and !rec.maintenance:
|
||||
rec.write({'state': 'done'})
|
||||
elif rec.remain_amount < 0.0:
|
||||
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)
|
||||
# Get the ID of the second line
|
||||
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)
|
||||
# Get the ID of the second line
|
||||
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':
|
||||
|
|
|
|||
Loading…
Reference in New Issue