Update rent_payment.py

This commit is contained in:
zainab2097 2024-08-06 10:10:54 +03:00 committed by GitHub
parent 10f21f6fcc
commit c318d70bb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 26 deletions

View File

@ -82,22 +82,22 @@ class RentPayment(models.Model):
if payment.amount>0.00: if payment.amount>0.00:
print('go on....') print('go on....')
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name':'قيمة الإيجار '+'- '+ self.name + ' - ' + payment.code + ' - ' + str(payment.due_date), 'name':'قيمة الإيجار '+' - '+payment.contract_id.name+'- '+ self.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': payment.amount, 'price_unit': self.amount,
'quantity': 1.0, 'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id, 'account_id': payment.contract_id.accrued_account_id.id,
})) }))
if payment.water_cost>0.00: if payment.water_cost>0.00:
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name': 'تكلفة المياه'+' -'+payment.name + ' - ' + payment.code + ' - ' + str(payment.due_date), 'name': 'تكلفة المياه'+' -'+self.name + ' - '+payment.contract_id.name +' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': payment.water_cost, 'price_unit':self.water_cost,
'quantity': 1.0, 'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id, 'account_id': payment.contract_id.accrued_account_id.id,
}),) }),)
if payment.service_cost>0.00: if payment.service_cost>0.00:
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name':'قيمة الخدمات'+' - '+ payment.name + ' - ' + payment.code + ' - ' + str(payment.due_date), 'name':'قيمة الخدمات'+' - '+ self.name+' - '+payment.contract_id.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': payment.service_cost, 'price_unit': self.service_cost,
'quantity': 1.0, 'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id, 'account_id': payment.contract_id.accrued_account_id.id,
})) }))
@ -105,8 +105,8 @@ class RentPayment(models.Model):
print('if 0000000') print('if 0000000')
print(self.name) print(self.name)
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name':self.name + ' - ' + payment.code + ' - ' + str(payment.due_date), 'name':self.name + ' - ' +payment.contract_id.name + ' - '+payment.code + ' - ' + str(payment.due_date),
'price_unit': amount, 'price_unit':self.total_amount,
'quantity': 1.0, 'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id, 'account_id': payment.contract_id.accrued_account_id.id,
})) }))
@ -118,21 +118,8 @@ class RentPayment(models.Model):
'narration': payment.note, 'narration': payment.note,
'partner_id': payment.contract_id.partner_id.id or payment.contract_id.renter_id.id, 'partner_id': payment.contract_id.partner_id.id or payment.contract_id.renter_id.id,
'invoice_line_ids': line_invoice, 'invoice_line_ids': line_invoice,
'line_ids': [
(0, 0, {
'account_id': payment.contract_id.revenue_account_id.id,
'debit': 0.0,
'credit': amount,
'name': payment.contract_id.name + ' - ' + payment.contract_id.seq + ' - ' + str(payment.contract_id.date),
'quantity': 1
}),
(0, 0, {
'account_id': payment.contract_id.debit_account_id.id,
'debit': amount,
'credit': 0.0,
'quantity': 1
})
],
# 'tax_ids': [(6, 0, [payment.tax_id.id])], # 'tax_ids': [(6, 0, [payment.tax_id.id])],
} }
return invoice_vals return invoice_vals
@ -145,9 +132,9 @@ class RentPayment(models.Model):
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)
# Get the ID of the second line # Get the ID of the second line
line_id = invoice.invoice_line_ids[1].id # line_id = invoice.invoice_line_ids[1].id
commands = [(2, line_id, 0)] # commands = [(2, line_id, 0)]
invoice.write({'invoice_line_ids': commands}) # invoice.write({'invoice_line_ids': commands})
self.invoice_id = invoice.id self.invoice_id = invoice.id
self.write({'state': 'invoice'}) self.write({'state': 'invoice'})