diff --git a/estate/__manifest__.py b/estate/__manifest__.py index d7cfa57d4c5..678edd0c243 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -1,11 +1,18 @@ { "name": "Estate", # The name that will appear in the App list - "version": "16.0.0", # Version + "version": "18.0.1.0.49", # Version "application": True, # This line says the module is an App, and not a module "depends": ["base"], # dependencies - "data": [ - + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', ], + "installable": True, 'license': 'LGPL-3', } diff --git a/estate/models.py b/estate/models.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..a9459ed5906 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import res_users \ No newline at end of file diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..435a8e0a92b --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,123 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + _order = "id desc" + + _sql_constraints = [ + ('check_expected_price', 'CHECK(expected_price > 0)', 'Expected price must be strictly positive'), + ('check_selling_price', 'CHECK(selling_price >= 0)', 'Selling price must be positive'), + ] + + # Basic Information + name = fields.Char(required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date(copy=False, default=lambda self: fields.Date.add(fields.Date.today(), months=2)) + active = fields.Boolean(default=True) + state = fields.Selection( + selection=[ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], default='new') + property_type_id = fields.Many2one("estate.property.type", string="Property Type") + # Pricing + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + best_price = fields.Float(compute='_compute_best_price', string='Best Offer') + + # Property Details + bedrooms = fields.Integer(default=2) + living_area = fields.Integer() + facades = fields.Integer() + total_area = fields.Integer(compute='_compute_total_area', string='Total Area') + + # Features + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection( + selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West'), + ] + ) + + # People + salesperson_id = fields.Many2one('res.users', string='Salesperson', default=lambda self: self.env.user) + buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False) + + # Tags + tag_ids = fields.Many2many('estate.property.tag', string='Tags') + + # Offers + offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers') + + # Computed Methods + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends('offer_ids.price') + def _compute_best_price(self): + for record in self: + prices = record.offer_ids.mapped('price') + record.best_price = max(prices) if prices else 0.0 + + # Onchange Methods + @api.onchange('garden') + def _onchange_garden(self): + if self.garden: + self.garden_area = 10 + self.garden_orientation = 'north' + else: + self.garden_area = 0 + self.garden_orientation = False + + # Button Action Methods (Public - no underscore prefix) + def action_cancel(self): + for record in self: + if record.state == 'sold': + raise UserError("Cannot cancel a sold property") + record.state = 'cancelled' + return True + + def action_sold(self): + for record in self: + if record.state == 'cancelled': + raise UserError("Cannot sell a cancelled property") + record.state = 'sold' + return True + + # Python Constraints + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + # Skip validation if selling price is zero (not yet sold) + if float_is_zero(record.selling_price, precision_digits=2): + continue + + # Calculate 90% of expected price + min_selling_price = record.expected_price * 0.9 + + # Compare selling price with minimum allowed (90% of expected) + if float_compare(record.selling_price, min_selling_price, precision_digits=2) < 0: + raise ValidationError( + f"Selling price ({record.selling_price:.2f}) cannot be lower than 90% of expected price ({min_selling_price:.2f})" + ) + + # CRUD Method Overrides + @api.ondelete(at_uninstall=False) + def _check_property_deletion(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError(f"Cannot delete property '{record.name}' because it is in '{record.state}' state. Only 'New' or 'Cancelled' properties can be deleted.") \ No newline at end of file diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..1325b5da28e --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,97 @@ +from odoo import models, fields, api +from datetime import timedelta +from odoo.exceptions import UserError + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Real Estate Property Offer" + _order = "price desc" + + _sql_constraints = [ + ('check_offer_price', 'CHECK(price > 0)', 'Offer price must be strictly positive'), + ] + + # Basic Information + price = fields.Float() + status = fields.Selection( + selection=[ + ('accepted', 'Accepted'), + ('refused', 'Refused'), + ], copy=False) + validity = fields.Integer(default=7, string='Validity (days)') + date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline', string='Deadline') + + # Relationships + partner_id = fields.Many2one('res.partner', string='Partner', required=True) + property_id = fields.Many2one('estate.property', string='Property', required=True) + property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id', string='Property Type', store=True) + + # Computed Methods + @api.depends('create_date', 'validity') + def _compute_date_deadline(self): + for record in self: + # Use create_date if available, otherwise use today as fallback + base_date = record.create_date.date() if record.create_date else fields.Date.today() + record.date_deadline = base_date + timedelta(days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + if record.date_deadline and record.create_date: + # Calculate validity based on deadline and create_date + base_date = record.create_date.date() + delta = record.date_deadline - base_date + record.validity = delta.days + elif record.date_deadline: + # If no create_date, use today as fallback + today = fields.Date.today() + delta = record.date_deadline - today + record.validity = delta.days + + # Button Action Methods (Public - no underscore prefix) + def action_accept(self): + for record in self: + # Refuse all other offers for this property first + other_offers = record.property_id.offer_ids.filtered(lambda o: o.id != record.id) + other_offers.write({'status': 'refused'}) + + # Accept this offer + record.status = 'accepted' + + # Set buyer and selling price on the property + record.property_id.buyer_id = record.partner_id + record.property_id.selling_price = record.price + return True + + def action_refuse(self): + for record in self: + record.status = 'refused' + return True + + # CRUD Method Overrides + @api.model_create_multi + def create(self, vals_list): + # Handle both single record and batch creation + if not isinstance(vals_list, list): + vals_list = [vals_list] + + # Process each record in the batch + for vals in vals_list: + # Get the property record + property_id = vals.get('property_id') + if property_id: + property_record = self.env['estate.property'].browse(property_id) + + # Check if offer price is higher than existing offers + existing_offers = property_record.offer_ids + if existing_offers: + max_existing_price = max(existing_offers.mapped('price')) + if vals.get('price', 0) <= max_existing_price: + raise UserError(f"Offer price must be higher than existing offers. Current highest offer: {max_existing_price}") + + # Set property state to 'Offer Received' + property_record.state = 'offer_received' + + # Always call super() to maintain the flow + return super().create(vals_list) + + \ No newline at end of file diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..88668412ee3 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,15 @@ +from odoo import models, fields + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Real Estate Property Tag" + _order = "name" + + _sql_constraints = [ + ('check_name_unique', 'UNIQUE(name)', 'Property tag name must be unique'), + ] + + # Basic Information + name = fields.Char(required=True) + color = fields.Integer() + \ No newline at end of file diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..dca9e90ef81 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,26 @@ +from odoo import models, fields, api + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Real Estate Property Type" + _order = "sequence, name" + + _sql_constraints = [ + ('check_name_unique', 'UNIQUE(name)', 'Property type name must be unique'), + ] + + # Basic Information + sequence = fields.Integer(default=10) + name = fields.Char(required=True) + + # Relationships + property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties') + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers') + offer_count = fields.Integer(compute='_compute_offer_count', string='Offers Count') + + # Computed Methods + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) + \ No newline at end of file diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..2c7fbf53afd --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,6 @@ +from odoo import fields, models + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many('estate.property', 'salesperson_id', string='Properties', domain=[('state', 'in', ['new', 'offer_received'])]) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..a42bd95f417 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type_user,access_estate_property_type_user,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag_user,access_estate_property_tag_user,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer_user,access_estate_property_offer_user,model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..7c07380b235 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..590cda205b6 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,42 @@ + + + + + estate.property.offer.list + estate.property.offer + + + + + + + + + + + + + + + estate.property.offer.form + estate.property.offer + +
+
+
+ + + + + + + + + +
+
+
+ +
diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml new file mode 100644 index 00000000000..12e9b17ca18 --- /dev/null +++ b/estate/views/estate_property_tag_views.xml @@ -0,0 +1,46 @@ + + + + + estate.property.tag.list + estate.property.tag + + + + + + + + + + estate.property.tag.form + estate.property.tag + +
+ +

+ +

+
+
+
+
+ + + + estate.property.tag.search + estate.property.tag + + + + + + + + + + Property Tags + estate.property.tag + list,form + +
diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..95044f7b09c --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,76 @@ + + + + + estate.property.type.list + estate.property.type + + + + + + + + + + + Property Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + {'default_property_type_id': active_id} + + + + + estate.property.type.form + estate.property.type + +
+ +
+ +
+

+ +

+ + + + + + + + + + + +
+
+
+
+ + + + estate.property.type.search + estate.property.type + + + + + + + + + + + + Property Types + estate.property.type + list,form + + + +
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..5b858108d2f --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,165 @@ + + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + + + + + + +
+
+
+ +
+
+
Expected Price:
+
+ Best Price: +
+
+ Selling Price: +
+
+ +
+
+
+
+
+
+
+
+
+ + + + Estate Properties + estate.property + kanban,list,form + + + {'search_default_available': True} + +
\ No newline at end of file diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..99a7c54b6de --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,24 @@ + + + + + res.users.form.inherit.estate + res.users + + + + + + + + + + + + + + + + + + diff --git a/estate_account/README.md b/estate_account/README.md new file mode 100644 index 00000000000..8921befd37e --- /dev/null +++ b/estate_account/README.md @@ -0,0 +1,17 @@ +# Estate Account Module + +## Description +This module serves as a bridge between the Estate and Account modules, enabling integration between real estate management and accounting functionality. + +## Dependencies +- **estate**: Real Estate Property Management +- **account**: Odoo Accounting Module + +## Status +Currently an empty shell module, ready for future development of estate-accounting integration features. + +## Future Features +- Invoice generation for property sales +- Commission tracking for sales agents +- Payment management integration +- Real estate financial reporting diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..225f6e5d616 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,11 @@ +{ + "name": "Estate Account", + "version": "18.0.1.0.5", + "application": False, # This is a module, not an app + "depends": ["estate", "account"], # Depends on both estate and account modules + 'data': [ + 'security/ir.model.access.csv', + ], + "installable": True, + 'license': 'LGPL-3', +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..89fe4948834 --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1,2 @@ +from . import estate_account +from . import estate_property diff --git a/estate_account/models/estate_account.py b/estate_account/models/estate_account.py new file mode 100644 index 00000000000..fd958125878 --- /dev/null +++ b/estate_account/models/estate_account.py @@ -0,0 +1,9 @@ +from odoo import models, fields + +class EstateAccount(models.Model): + _name = "estate.account" + _description = "Estate Account Integration" + + # Basic Information + name = fields.Char(required=True) + description = fields.Text() diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..6b3284548be --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,42 @@ +from odoo import models, Command +import logging + +_logger = logging.getLogger(__name__) + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_sold(self): + # Add debugging to verify the override is working + _logger.info("Estate Account: action_sold method called for property: %s", self.name) + print(f"Estate Account: Selling property '{self.name}' - Creating invoice") + + # Create invoice for the property sale + for record in self: + # Calculate commission (6% of selling price) and administrative fee + commission_amount = record.selling_price * 0.06 + admin_fee = 100.00 + + # Create the invoice + invoice = self.env['account.move'].create({ + 'partner_id': record.buyer_id.id, + 'move_type': 'out_invoice', # Customer Invoice + 'invoice_line_ids': [ + Command.create({ + 'name': f'Commission for property: {record.name}', + 'quantity': 1, + 'price_unit': commission_amount, + }), + Command.create({ + 'name': 'Administrative fees', + 'quantity': 1, + 'price_unit': admin_fee, + }), + ], + }) + + _logger.info("Estate Account: Created invoice %s for property %s", invoice.name, record.name) + print(f"Estate Account: Created invoice {invoice.name} for property '{record.name}'") + + # Call the parent method to maintain original functionality + return super().action_sold() diff --git a/estate_account/security/ir.model.access.csv b/estate_account/security/ir.model.access.csv new file mode 100644 index 00000000000..0cb3e16f01f --- /dev/null +++ b/estate_account/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_account_user,access_estate_account_user,model_estate_account,base.group_user,1,1,1,1