diff --git a/odex25_realstate/property_management/models/end_rental_contract.py b/odex25_realstate/property_management/models/end_rental_contract.py index 75e96ada9..543394134 100644 --- a/odex25_realstate/property_management/models/end_rental_contract.py +++ b/odex25_realstate/property_management/models/end_rental_contract.py @@ -58,11 +58,12 @@ class EndOfRent(models.Model): 'account_id': end.contract_id.debit_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.debit_account_id.id, 'debit': 0.0, 'credit': amount, 'name': end.name + ' - ' + str(end.date), 'quantity': 1}), (0, 0, - {'account_id': end.contract_id.accrued_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 @@ -82,13 +83,13 @@ class EndOfRent(models.Model): 'quantity': 1.0, 'account_id': end.contract_id.revenue_account_id.id, - })], - 'line_ids': [(0, 0, {'account_id':end.contract_id.revenue_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 @@ -96,8 +97,8 @@ class EndOfRent(models.Model): def get_remain_amount(self): for rec in self: rec.remain_amount = rec.insurance_amount - rec.total_amount - - def action_draft (self): + + def action_draft(self): self.write({'state': 'draft'}) def action_cancel(self): @@ -106,25 +107,19 @@ class EndOfRent(models.Model): def action_done(self): for rec in self: - if (rec.remain_amount > 0.0) or (rec.remain_amount > 0.0 and rec.maintenance): + 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) - print(invoice_vals,'iiiiiiiiiiii') - # print(invoice_vjjjals,'iiiiiiiiiiii') + invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) - print(invoice,'invoiceceee') - print(len(invoice.invoice_line_ids),'len(invoice.invoice_line_ids)') - print(invoice.invoice_line_ids,'len(invoice.jjjjjjjjjjjjinvoice_line_ids)') # 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 - print(rec.invoice_id,'invoice_idrerererer') - # print(rec.invohhhice_id,'invoice_idrerererer') rec.write({'state': 'done'}) - elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and not rec.maintenance: + elif (rec.insurance_amount == 0.0 or rec.remain_amount == 0.0) and not rec.maintenance: rec.write({'state': 'done'}) - elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and rec.maintenance: + 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) if len(invoice.invoice_line_ids) > 1: @@ -133,8 +128,8 @@ class EndOfRent(models.Model): 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): + + 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) if len(invoice.invoice_line_ids) > 1: @@ -171,7 +166,7 @@ class EndOfRent(models.Model): 'end_rent_id': rec.id, 'maintenance_type': 'end_contract', 'hand_cost': rec.hand_cost, - 'total_amount': rec.hand_cost+rec.maintenance_cost, + 'total_amount': rec.hand_cost + rec.maintenance_cost, 'date': rec.date, 'state': 'draft', } maintenance_id = self.env['property.management.maintenance'].create(vals) @@ -184,8 +179,8 @@ class EndOfRent(models.Model): if rec.end_line_ids: rec.maintenance_cost = sum([line.total for line in rec.end_line_ids]) rec.total_amount = rec.maintenance_cost + rec.hand_cost - - + + class EndRentLine(models.Model): _name = "end.rent.line" _description = "End Of Rent Line" @@ -240,7 +235,7 @@ class PropertyManagementMaintenance(models.Model): end_rent_id = fields.Many2one('end.of.rent', string="Rent End") contract_id = fields.Many2one('rental.contract', string="Contract") property_id = fields.Many2one('internal.property', string="Property") - partner_id = fields.Many2one('res.partner', string="Partner",domain=[('is_tenant', '=', True)]) + partner_id = fields.Many2one('res.partner', string="Partner", domain=[('is_tenant', '=', True)]) vendor_id = fields.Many2one('res.partner', string="Vendor") unit_ids = fields.Many2many('re.unit', string="Unit/Units") maintenance_cost = fields.Float(string="Maintenance Cost", compute="_get_total_amount", store=True) @@ -259,8 +254,7 @@ class PropertyManagementMaintenance(models.Model): request_id = fields.Many2one('sale.order', string="Request Item") def action_rest_draft(self): - rec.write({'state': 'draft'}) - + self.write({'state': 'draft'}) @api.onchange('renter_invoice') def rest_values(self): @@ -271,8 +265,8 @@ class PropertyManagementMaintenance(models.Model): # Check if unit_ids is not empty before accessing the first element unit_name = self.unit_ids[0].name if self.unit_ids else ' ' origin = _( - 'Maintenance Order') + ' ' + maintenance.name + ' '+self.property_id.name+' ' +unit_name+' ' +maintenance.partner_id.name if maintenance.partner_id else \ - _('Maintenance Order') + ' ' + maintenance.name +' '+self.property_id.name+' ' +unit_name+' ' + maintenance.vendor_id.name + 'Maintenance Order') + ' ' + maintenance.name + ' ' + self.property_id.name + ' ' + unit_name + ' ' + maintenance.partner_id.name if maintenance.partner_id else \ + _('Maintenance Order') + ' ' + maintenance.name + ' ' + self.property_id.name + ' ' + unit_name + ' ' + maintenance.vendor_id.name line_data = [] for line in maintenance.end_line_ids: line_data.append((0, 0, { @@ -284,13 +278,14 @@ class PropertyManagementMaintenance(models.Model): '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, + '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 + 'account_id': maintenance.contract_id.revenue_account_id.id, + 'analytic_account_id': maintenance.property_id.account_analy_id.id if maintenance.property_id.account_analy_id else False, + # 'tax_ids': [(6, 0, [maintenance.tax_id.id])] if maintenance.tax_id else False, # Assigning tax_id to tax_ids })) invoice_vals = { 'ref': maintenance.name, @@ -355,7 +350,7 @@ class PropertyManagementMaintenance(models.Model): rec.maintenance_cost = sum([line.total for line in rec.end_line_ids]) rec.total_amount = rec.maintenance_cost + rec.hand_cost - @api.depends('maintenance_cost', 'hand_cost', 'end_line_ids','end_line_ids.cost', 'end_line_ids.total') + @api.depends('maintenance_cost', 'hand_cost', 'end_line_ids', 'end_line_ids.cost', 'end_line_ids.total') def _get_total_amount(self): for rec in self: # تأكد من إعادة حساب maintenance_cost باستخدام المجموع الصحيح لجميع الأسطر