diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..d6210b1285d --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..e45dd9af1fc --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,24 @@ +{ + 'name': "Real Estate", + 'version': '1.0', + 'depends': ['base'], + 'author': "taskv", + 'category': 'Tutorials', + 'description': """ + Tutorial Project + """, + '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/estate_menus.xml', + 'views/res_users_views.xml', + ], + 'demo': [ + ], + 'installable': True, + 'application': True, + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..f7e4cc6f3dd --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,7 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..775621559d7 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,107 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, api, exceptions +from odoo.tools.float_utils import float_is_zero, float_compare + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate Property' + _order = "id desc" + + name = fields.Char('Title', required=True, default='Unknown', translate='True') + active = fields.Boolean('Active', default=True) + description = fields.Text('Description') + postcode = fields.Char('Postcode') + date_availability = fields.Date('Available From', copy=False, default=fields.Date.add(fields.Date.today(), months=3)) + expected_price = fields.Float('Expected Price', required=True) + selling_price = fields.Float('Selling Price', readonly=True, copy=False) + bedrooms = fields.Integer('Bedrooms', default=2) + living_area = fields.Integer('Living Area (sqm)') + facades = fields.Integer('Facades') + garage = fields.Boolean('Garage') + garden = fields.Boolean('Garden') + garden_area = fields.Integer('Garden Area (sqm)') + garden_orientation = fields.Selection(string='Garden orientation', + selection=[('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West')] + ) + state = fields.Selection(string='State', + selection=[('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled')], + default='new', required=True, copy=False) + property_type_id = fields.Many2one('estate.property.type', string='Property Type') + property_tag_ids = fields.Many2many('estate.property.tag', string='Property Tag') + buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False, + domain=[('is_company', '=', False)]) + salesperson_id = fields.Many2one('res.users', string='Salesperson', + default=lambda self: self.env.user) + offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers') + total_area = fields.Integer('Total Area (sqm)', compute='_compute_total_area') + best_offer = fields.Float('Best Offer', compute='_compute_best_offer') + + _check_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + 'The expected price must be strictly positive', + ) + + _check_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + 'The selling price must be positive', + ) + + @api.depends('garden_area', 'living_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.garden_area + record.living_area + + @api.depends('offer_ids.price') + def _compute_best_offer(self): + for record in self: + if record.offer_ids: + record.best_offer = max(record.offer_ids.mapped('price')) + else: + record.best_offer = 0 + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + if not float_is_zero(record.selling_price, 4) and float_compare(record.selling_price, + record.expected_price * 0.9, 4) < 0: + raise exceptions.ValidationError("The selling price must be at least 90% of the expected price.") + + @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 = '' + + @api.ondelete(at_uninstall=False) + def _unlink_check_state(self): + for record in self: + if record.state not in ('new', 'cancelled'): + raise exceptions.UserError("Only new and cancelled properties can be deleted.") + + def action_property_sold(self): + self.ensure_one() + if self.state != 'cancelled': + self.state = 'sold' + else: + raise exceptions.UserError("Cancelled properties cannot be sold.") + return True + + def action_property_cancelled(self): + self.ensure_one() + if self.state != 'sold': + self.state = 'cancelled' + else: + raise exceptions.UserError("Sold properties cannot be cancelled.") + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..7a66c2e72e8 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,59 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, api, exceptions +from datetime import date, timedelta + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Estate Property Offer' + _order = "price desc" + + price = fields.Float(string='Price') + status = fields.Selection(string='Status', copy=False, + selection=[('accepted', 'Accepted'), ('refused', 'Refused')]) + partner_id = fields.Many2one('res.partner', string='Customer', required=True) + property_id = fields.Many2one('estate.property', string='Property', required=True) + validity = fields.Integer(string='Validity (days)', default=7) + date_deadline = fields.Date(string='Deadline', compute='_compute_deadline', inverse='_inverse_deadline') + property_type_id = fields.Many2one('estate.property.type', string='Property Type', related="property_id.property_type_id", store=True) + + _check_price = models.Constraint( + 'CHECK(price > 0)', + 'The offer price must be strictly positive', + ) + + @api.depends('validity') + def _compute_deadline(self): + for record in self: + record.date_deadline = (record.create_date if record.create_date else date.today()) + timedelta(days=record.validity) + + def _inverse_deadline(self): + for record in self: + record.validity = (record.date_deadline - (record.create_date.date() if record.create_date else date.today())).days + + @api.model + def create(self, vals_list): + for vals in vals_list: + if 'property_id' in vals and vals.get('property_id'): + current_property = self.env['estate.property'].browse(vals['property_id']) + if 'price' in vals and current_property.best_offer > vals.get('price', 0): + raise exceptions.ValidationError(f'The offer must be higher than {current_property.best_offer}') + if current_property.state == 'new': + current_property.state = 'offer_received' + return super().create(vals_list) + + def action_accept(self): + self.ensure_one() + if self.property_id.state in ('new', 'offer_received'): + self.property_id.state = 'offer_accepted' + self.status = 'accepted' + self.property_id.selling_price = self.price + self.property_id.buyer_id = self.partner_id + return True + + def action_refuse(self): + self.ensure_one() + if not self.status: + self.status = 'refused' + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..648b9ff7da0 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,17 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Estate Property Tag' + _order = "name" + + name = fields.Char(string='Property Tag', required=True) + color = fields.Integer() + + _tag_name_uniq = models.Constraint( + 'unique(name)', + "The property tag name must be unique", + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..aef98daa0d2 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,25 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, api + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Estate Property Type' + _order = "sequence, name" + + name = fields.Char('Property Type', required=True) + property_ids = fields.One2many('estate.property', 'property_type_id', 'Properties') + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', 'Offers') + offer_count = fields.Integer(compute='_compute_offer_count') + sequence = fields.Integer() + + _type_name_uniq = models.Constraint( + 'unique(name)', + "The property type name must be unique", + ) + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..bd1f23c6ac7 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,10 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class Users(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many('estate.property', 'salesperson_id', string='Estate Property', + domain=[('date_availability', '<=', fields.Date.today())]) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..49bca99cac8 --- /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,access_estate_property,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer,access_estate_property_offer,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..18b79afccf6 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..61c83bbc7a4 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,49 @@ + + + + estate.property.offer.view.form + estate.property.offer + +
+ + + + + + + + + + + + + +
+
+
+ + + estate.property.offer.view.list + estate.property.offer + + + + + + + + +
+

+ +

+
+ + + + + + + + + + + + + +
+
+ + + estate.property.type.view.list + estate.property.type + + + + + + + + + + Estate Property Type + 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..54fd0d5f05b --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,148 @@ + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + + + + + + estate.property.view.form + estate.property + +
+
+
+ +
+

+ +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.view.list + estate.property + + + + + + + + + + + + + + + + estate.property.view.kanban + estate.property + + + + + +
+ +
+ Expected price: + +
+
+ Best offer: + +
+
+ Selling price: + +
+ +
+
+
+
+
+
+ + + Estate Property + estate.property + list,form,kanban + + {'search_default_filter_available':1} + + +
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..6dc864c5665 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,19 @@ + + + + + + res.users.view.form.inherit.real.estate + res.users + + + + + + + + + + + + diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..d6210b1285d --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..5d132fb958c --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,18 @@ + +{ + 'name': "Real Estate Invoicing", + 'version': '1.0', + 'depends': ['estate', 'account'], + 'author': "taskv", + 'category': 'Tutorials', + 'description': """ + Tutorial Project + """, + 'data': [ + ], + 'demo': [ + ], + 'installable': True, + 'application': True, + 'license': 'LGPL-3', +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..09b94f90f8d --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import estate_property diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..6ad9adb496b --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,31 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, Command + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_property_sold(self): + invoice_vals_list = [] + for record in self: + if record.state == 'offer_accepted' and record.buyer_id: + invoice_vals = { + 'move_type': 'out_invoice', + 'partner_id': record.buyer_id.id, + 'invoice_line_ids': [ + Command.create({ + "name": "Commission 6%", + "quantity": 1, + "price_unit": record.selling_price * 0.06, + }), + Command.create({ + "name": "Administrative fees", + "quantity": 1, + "price_unit": 100., + }), + ], + } + invoice_vals_list.append(invoice_vals) + self.env['account.move'].sudo().create(invoice_vals_list) + return super().action_property_sold()