Update rent_payment.py

This commit is contained in:
zainab2097 2024-08-05 14:26:19 +03:00 committed by GitHub
parent 5b16ac9922
commit e820ddd90d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 30 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",related='invoice_id.payment_id.date')
paid_date = fields.Date(string="Paid 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,36 +78,19 @@ 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 amount>=0.00:
line_invoice.append((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,
}))
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,
}))
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 or payment.contract_id.renter_id.id,
invoice_line_ids : line_invoice,
'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,
})],
'line_ids': [
(0, 0, {
'account_id': payment.contract_id.revenue_account_id.id,
@ -134,11 +117,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'})
@ -181,8 +164,7 @@ class RentPayment(models.Model):
for rec in self:
rec.untaxed_amount = rec.amount + rec.water_cost + rec.service_cost
@api.depends('amount', 'water_cost', '')
@api.depends('amount', 'water_cost', 'service_cost')
def get_total_amount(self):
for rec in self:
rec.total_amount = rec.amount + rec.water_cost + rec.service_cost