diff --git a/odex25_realstate/property_management/models/rental_contract.py b/odex25_realstate/property_management/models/rental_contract.py
index af2801dbd..bad15c483 100644
--- a/odex25_realstate/property_management/models/rental_contract.py
+++ b/odex25_realstate/property_management/models/rental_contract.py
@@ -5,6 +5,7 @@ import calendar
import logging
from datetime import datetime
+from datetime import date
from dateutil.relativedelta import relativedelta
from odoo.tools import exception_to_unicode
from odoo import models, fields, api, exceptions, tools, _
@@ -67,6 +68,17 @@ class RentalContract(models.Model):
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = "id desc"
+
+ @api.depends('date_to', 'state')
+ def _compute_is_today_end_date(self):
+ for record in self:
+ record.is_today_end_date = False
+ if record.date_to and isinstance(record.date_to, date):
+ record.is_today_end_date = record.date_to <= date.today()
+ if record.state == 'renewed':
+ record.is_today_end_date = False
+
+
@api.onchange('rent_method')
def onchange_rent_method(self):
"""
@@ -91,8 +103,10 @@ class RentalContract(models.Model):
else:
if not self.property_id:
self.property_id = False
+
active = fields.Boolean(default=True)
+ is_today_end_date = fields.Boolean(string="Is Today End Date", compute="_compute_is_today_end_date",)
name = fields.Char(string="Name")
date = fields.Date(string="Contract Date")
seq = fields.Char(string="Sequence", default="/", index=True)
@@ -349,7 +363,7 @@ class RentalContract(models.Model):
def action_review(self):
full = True
- if self.property_id.state in ['reserve', 'rent']:
+ if self.property_id.state in ['reserve', 'rent'] and self.property_id.contract_counts>1:
raise exceptions.ValidationError(_("Property is already reserved or rented"))
#
for units in self.property_id.unit_ids:
diff --git a/odex25_realstate/property_management/views/end_rent_views.xml b/odex25_realstate/property_management/views/end_rent_views.xml
index b412c6e81..f06a08926 100644
--- a/odex25_realstate/property_management/views/end_rent_views.xml
+++ b/odex25_realstate/property_management/views/end_rent_views.xml
@@ -170,7 +170,7 @@
diff --git a/odex25_realstate/property_management/views/rental_contract_views.xml b/odex25_realstate/property_management/views/rental_contract_views.xml
index 9b70a56e9..74d273e45 100644
--- a/odex25_realstate/property_management/views/rental_contract_views.xml
+++ b/odex25_realstate/property_management/views/rental_contract_views.xml
@@ -60,8 +60,11 @@
+
+
+
@@ -308,6 +311,8 @@
+
+
diff --git a/odex25_realstate/real_estate/models/internal_property.py b/odex25_realstate/real_estate/models/internal_property.py
index ff6c7217d..d95281299 100644
--- a/odex25_realstate/real_estate/models/internal_property.py
+++ b/odex25_realstate/real_estate/models/internal_property.py
@@ -30,6 +30,29 @@ class Property(models.Model):
('residential', 'Residential'),
('non_residential', 'Non-Residential'),
], string="Property Suitability for Residence")
+ contract_counts = fields.Integer(string='Contracts', compute='count_contracts_number')
+ def count_contracts_number(self):
+ contract_count = self.env['rental.contract'].search([('property_id', '=', self.id)])
+ self.contract_counts = len(contract_count)
+
+ def get_contract(self):
+ contract_id = self.env['rental.contract'].search(
+ [('property_id', '=', self.id)])
+ form_id = self.env.ref('property_management.rental_contract_form_view').id
+ list_id = self.env.ref('property_management.rental_contract_list_view').id
+ domain = [('id', 'in', contract_id.ids)]
+ return {
+ 'name': _('Rental Contract'),
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'rental.contract',
+ 'views': [(list_id, 'tree'), (form_id, 'form')],
+ 'type': 'ir.actions.act_window',
+ 'target': 'current',
+ 'domain': domain,
+ }
+
+
# @api.model
# def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
@@ -44,7 +67,29 @@ class Property(models.Model):
# res['arch'] = etree.tostring(doc, encoding='unicode')
# return res
-
+ @api.onchange('floors_count')
+ def _onchange_no_of_floor(self):
+ if self.floors_count>0:
+ # Clear existing lines
+ self.floor_ids = [(5, 0, 0)]
+ # Create floor records based on the number of floors
+ floors = []
+ for i in range(1, self.floors_count + 1):
+
+ floor_name = _('Floor') + ' ' + str(i) # Construct the floor name
+
+ # Search for the role with the given floor name
+ role_record = self.env['property.role'].search([('name', '=', floor_name)], limit=1)
+
+ if not role_record:
+ # If not found, create a new role with the corresponding name
+ role_record = self.env['property.role'].create({
+ 'name': floor_name,
+ })
+ # Append the record to One2many field
+ floors.append((0, 0, {'role_id': role_record.id}))
+ self.floor_ids = floors
+
def _compute_maintenance_count(self):
for record in self:
record.maintenance_count = self.env['property.management.maintenance'].search_count([
diff --git a/odex25_realstate/real_estate/views/internal_property_views.xml b/odex25_realstate/real_estate/views/internal_property_views.xml
index 0296f5dca..f9e997c2a 100644
--- a/odex25_realstate/real_estate/views/internal_property_views.xml
+++ b/odex25_realstate/real_estate/views/internal_property_views.xml
@@ -39,6 +39,11 @@
icon="fa-wrench">
+
@@ -53,38 +58,38 @@
placeholder="Property Name"/>
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
+
-
+
-
-
+
+
-
-
-
+
+
+
@@ -160,7 +165,7 @@
-
+
-
+
-
+
-
-
+
+
-
+
@@ -231,20 +236,20 @@
attrs="{'readonly':[('state','!=','draft'),('unlock','=',True)]}"/>
-
-
-
+
+
+
-
+
-
-
+
+
@@ -255,9 +260,9 @@
-
-
-
+
+
+
@@ -266,14 +271,14 @@
-
+
-
+
@@ -284,18 +289,18 @@
-
-
+
+
-
-
-
+
+
-
-
-
+
+
+
diff --git a/odex25_realstate/real_estate/views/real_estate_menu.xml b/odex25_realstate/real_estate/views/real_estate_menu.xml
index 0da7a3e3c..0e9f4e0ba 100644
--- a/odex25_realstate/real_estate/views/real_estate_menu.xml
+++ b/odex25_realstate/real_estate/views/real_estate_menu.xml
@@ -1,15 +1,46 @@
-
-
+
+
+ role_view_form
+ property.role
+
+
+
+
+
+ role_view_tree
+ property.role
+
+
+
+
+
+
+
+ role.action.view
+ property.role
+ tree,form
+
+
+
+
+ parent="real_estate_main_menu" sequence="4"/>
+ parent="real_estate_main_menu" sequence="4"/>
+
+