Merge pull request #529 from expsa/test1

Update rent_payment.py
This commit is contained in:
zainab2097 2024-08-05 15:10:10 +03:00 committed by GitHub
commit 10f21f6fcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 38 additions and 11 deletions

View File

@ -29,7 +29,7 @@ class RentPayment(models.Model):
user_id = fields.Many2one('res.users', string="Responsible")
company_id = fields.Many2one('res.company', string="Company")
due_date = fields.Date(string="Due Date")
paid_date = fields.Date(string="Paid Date")
paid_date = fields.Date(string="Paid Date",related='invoice_id.payment_id.date')
payment_method = fields.Selection([('check', 'Bank Check'),
('cash', 'Cash'),
('transfer', 'Transfer')], string="Payment Method", default='transfer')
@ -57,7 +57,7 @@ class RentPayment(models.Model):
for rec in self:
if rec.invoice_id.payment_state in ['paid', 'in_payment']:
rec.write({'state': 'paid'})
payment_obj = self.env['account.payment'].search([('ref','=',rec.invoice_id.name)],limit=1)
rec.paid_date=payment_obj.date
return res
@ -78,19 +78,46 @@ class RentPayment(models.Model):
def _prepare_invoice_values(self, payment, amount):
self.renter_id.property_account_receivable_id = payment.contract_id.debit_account_id.id
line_invoice=[]
if payment.amount>0.00:
print('go on....')
line_invoice.append((0, 0, {
'name':'قيمة الإيجار '+'- '+ self.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': payment.amount,
'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id,
}))
if payment.water_cost>0.00:
line_invoice.append((0, 0, {
'name': 'تكلفة المياه'+' -'+payment.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': payment.water_cost,
'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id,
}),)
if payment.service_cost>0.00:
line_invoice.append((0, 0, {
'name':'قيمة الخدمات'+' - '+ payment.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': payment.service_cost,
'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id,
}))
if payment.amount==0.00 and payment.service_cost==0.00 and payment.water_cost==0.00:
print('if 0000000')
print(self.name)
line_invoice.append((0, 0, {
'name':self.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': amount,
'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id,
}))
invoice_vals = {
'ref': payment.name,
'move_type': 'out_invoice',
'invoice_origin': payment.code,
'invoice_user_id': payment.user_id.id,
'narration': payment.note,
'partner_id': payment.contract_id.partner_id.id,
'invoice_line_ids': [(0, 0, {
'name': payment.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
'price_unit': amount,
'quantity': 1.0,
'account_id': payment.contract_id.accrued_account_id.id,
})],
'partner_id': payment.contract_id.partner_id.id or payment.contract_id.renter_id.id,
'invoice_line_ids': line_invoice,
'line_ids': [
(0, 0, {
'account_id': payment.contract_id.revenue_account_id.id,
@ -117,11 +144,11 @@ class RentPayment(models.Model):
invoice_vals = self._prepare_invoice_values(self, self.total_amount)
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
commands = [(2, line_id, 0)]
invoice.write({'invoice_line_ids': commands})
self.invoice_id = invoice.id
self.write({'state': 'invoice'})