From 466fadfc1e7d4a3ffe23ea247aee087dcb0f6f01 Mon Sep 17 00:00:00 2001 From: zainab8585 Date: Wed, 11 Sep 2024 13:13:28 +0200 Subject: [PATCH] [UPDATE] --- .../models/end_rental_contract.py | 57 ++++++++++++------- .../models/rent_payment.py | 6 +- .../models/rental_contract.py | 1 + .../views/end_rent_views.xml | 6 +- .../views/rent_payment_view.xml | 2 + 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/odex25_realstate/property_management/models/end_rental_contract.py b/odex25_realstate/property_management/models/end_rental_contract.py index 66ba4d6f7..cbdfbe80b 100644 --- a/odex25_realstate/property_management/models/end_rental_contract.py +++ b/odex25_realstate/property_management/models/end_rental_contract.py @@ -42,7 +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 + 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', @@ -55,19 +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, + 'account_id': end.contract_id.debit_account_id.id, })], - 'line_ids': [(0, 0, {'account_id': end.contract_id.accrued_account_id.id, 'debit': 0.0, 'credit': amount, + '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.debit_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})] + {'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): - self.contract_id.partner_id.property_account_receivable_id = end.contract_id.revenue_account_id.id + self.contract_id.partner_id.property_account_receivable_id = end.contract_id.debit_account_id.id invoice_vals = { 'ref': end.name, 'move_type': 'out_invoice', @@ -80,13 +80,15 @@ class EndOfRent(models.Model): 'name': end.name + ' - ' + str(end.date), 'price_unit': amount, 'quantity': 1.0, + 'account_id': end.contract_id.revenue_account_id.id, + })], - 'line_ids': [(0, 0, {'account_id': end.contract_id.debit_account_id.id, 'debit': 0.0, 'credit': amount, + '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.revenue_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})] + {'account_id': end.contract_id.debit_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})] } return invoice_vals @@ -107,10 +109,10 @@ class EndOfRent(models.Model): 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}) + 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: @@ -118,20 +120,20 @@ class EndOfRent(models.Model): 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}) + 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) - # 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}) + 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': @@ -161,6 +163,8 @@ class EndOfRent(models.Model): 'partner_id': rec.contract_id.partner_id.id, 'end_rent_id': rec.id, 'maintenance_type': 'end_contract', + 'hand_cost': rec.hand_cost, + 'total_amount': rec.hand_cost+rec.maintenance_cost, 'date': rec.date, 'state': 'draft', } maintenance_id = self.env['property.management.maintenance'].create(vals) @@ -272,6 +276,15 @@ class PropertyManagementMaintenance(models.Model): 'quantity': line.qty, 'price_unit': line.cost, })) + line_data.append((0, 0, { + 'name':_('Hand Cost') + maintenance.name + ' '+self.property_id.name+' ' +unit_name+' ' +maintenance.partner_id.name if maintenance.partner_id else \ + _('Hand Cost') + ' ' + maintenance.name +' '+self.property_id.name+' ' +unit_name+' ' + maintenance.vendor_id.name, + 'quantity': 1.0, + 'price_unit': self.hand_cost, + 'account_id': payment.contract_id.revenue_account_id.id, + 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, + 'tax_ids': [(6, 0, [payment.tax_id.id])] if payment.tax_id else False, # Assigning tax_id to tax_ids + })) invoice_vals = { 'ref': maintenance.name, 'move_type': 'in_invoice', @@ -293,9 +306,9 @@ class PropertyManagementMaintenance(models.Model): invoice_vals = rec._prepare_invoice_values(rec, abs(rec.total_amount)) if rec.end_rent_id and rec.end_rent_id.state != 'done': raise exceptions.ValidationError(_('Please confirm end of rent first ')) - if not rec.end_rent_id: - invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) - rec.invoice_id = invoice.id + # if not rec.end_rent_id: + invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) + rec.invoice_id = invoice.id for line in rec.end_line_ids: line_ids.append((0, 0, { 'product_id': line.product_id.id, diff --git a/odex25_realstate/property_management/models/rent_payment.py b/odex25_realstate/property_management/models/rent_payment.py index a74347f13..3d97ba8fe 100644 --- a/odex25_realstate/property_management/models/rent_payment.py +++ b/odex25_realstate/property_management/models/rent_payment.py @@ -113,7 +113,7 @@ class RentPayment(models.Model): if payment.amount>0.00: line_invoice.append((0, 0, { - 'name':'قيمة الإيجار ' + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), + 'name':_('Reant Amount ') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'quantity': 1.0, 'price_unit': self.amount, 'account_id': payment.contract_id.revenue_account_id.id, @@ -122,7 +122,7 @@ class RentPayment(models.Model): })) if payment.water_cost>0.00: line_invoice.append((0, 0, { - 'name': 'تكلفة المياه'+ ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), + 'name': _('Water Cost ')+ ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'price_unit':self.water_cost, 'quantity': 1.0, 'account_id': payment.contract_id.revenue_account_id.id, @@ -131,7 +131,7 @@ class RentPayment(models.Model): }),) if payment.service_cost>0.00: line_invoice.append((0, 0, { - 'name': 'قيمة الخدمات' + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), + 'name': _('Serviecs Cost') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'price_unit': self.service_cost, 'quantity': 1.0, 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, diff --git a/odex25_realstate/property_management/models/rental_contract.py b/odex25_realstate/property_management/models/rental_contract.py index cefd0cbf6..af2801dbd 100644 --- a/odex25_realstate/property_management/models/rental_contract.py +++ b/odex25_realstate/property_management/models/rental_contract.py @@ -351,6 +351,7 @@ class RentalContract(models.Model): full = True if self.property_id.state in ['reserve', 'rent']: raise exceptions.ValidationError(_("Property is already reserved or rented")) + # for units in self.property_id.unit_ids: if units.state in ['draft', 'available']: full = False diff --git a/odex25_realstate/property_management/views/end_rent_views.xml b/odex25_realstate/property_management/views/end_rent_views.xml index 1b14110ed..b412c6e81 100644 --- a/odex25_realstate/property_management/views/end_rent_views.xml +++ b/odex25_realstate/property_management/views/end_rent_views.xml @@ -66,9 +66,9 @@ readonly="1"/> - - - + + + diff --git a/odex25_realstate/property_management/views/rent_payment_view.xml b/odex25_realstate/property_management/views/rent_payment_view.xml index 75a7d64bf..380e45269 100644 --- a/odex25_realstate/property_management/views/rent_payment_view.xml +++ b/odex25_realstate/property_management/views/rent_payment_view.xml @@ -104,6 +104,8 @@ + +