diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000000..71eadb11ae8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "files.insertFinalNewline": true +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index c4fb245621b..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..5fa56eb3065 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,24 @@ +{ + 'name': "Real Estate", + 'depends': ['base'], + 'application': True, + 'author': "Jeanne Delneste", + 'category': "Real Estate/Brokerage", + 'license': "LGPL-3", + 'data': [ + 'views/estate_property_views.xml', + 'views/estate_property_user_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_menus.xml', + 'data/estate.property.type.csv', + 'security/ir.model.access.csv', + # 'security/security.xml' + ], + 'demo': [ + 'demo/estate_property_demo.xml', + 'demo/estate_property_offer_demo.xml', + 'demo/estate_property_type_demo.xml', + ] +} diff --git a/estate/data/estate.property.type.csv b/estate/data/estate.property.type.csv new file mode 100644 index 00000000000..8832da81125 --- /dev/null +++ b/estate/data/estate.property.type.csv @@ -0,0 +1,5 @@ +"id","name" +type_1,"Residential" +type_2,"Commercial" +type_3,"Industrial" +type_4,"Land" diff --git a/estate/demo/estate_property_demo.xml b/estate/demo/estate_property_demo.xml new file mode 100644 index 00000000000..ea923baeb99 --- /dev/null +++ b/estate/demo/estate_property_demo.xml @@ -0,0 +1,47 @@ + + + Big Villa + new + A nice big villa + 12345 + 2020-02-02 + 1600000 + 6 + 100 + 4 + True + True + 100000 + south + + + + Trailer home + cancelled + Home in a trailer park + 54321 + 1970-01-01 + 100000 + 120000 + 1 + 10 + 4 + False + + + + Countryside Ranch + Beautiful ranch with horses + 12345 + 2025-01-01 + 5000000 + + + + diff --git a/estate/demo/estate_property_offer_demo.xml b/estate/demo/estate_property_offer_demo.xml new file mode 100644 index 00000000000..81736cee41c --- /dev/null +++ b/estate/demo/estate_property_offer_demo.xml @@ -0,0 +1,32 @@ + + + + + 1000000 + 14 + + + + + + 1500000 + 14 + + + + + + 1500001 + 14 + + + + + + + + + + + + diff --git a/estate/demo/estate_property_type_demo.xml b/estate/demo/estate_property_type_demo.xml new file mode 100644 index 00000000000..3cfb1081910 --- /dev/null +++ b/estate/demo/estate_property_type_demo.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..f0021fa8e22 --- /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 estate_property_user diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..fbce5a87836 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,103 @@ +from odoo import api, models, fields +from odoo.exceptions import UserError +import datetime +from dateutil.relativedelta import relativedelta +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate Property" + _order = "id desc" + + name = fields.Char(required=True) + description = fields.Text() + postcode = fields.Char() + notes = fields.Html() + date_availability = fields.Date(copy=False, default=lambda self: datetime.date.today() + relativedelta(months=3)) + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer() + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection(selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")]) + active = fields.Boolean(default=True) + state = fields.Selection(selection=[ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled")], + copy=False, required=True, default="new") + property_type_id = fields.Many2one("estate.property.type", string="Type") + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) + salesperson_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + total_area = fields.Integer(compute="_compute_total_area", string="Total Area (sqm)") + best_price = fields.Float(compute="_compute_best_price", string="Best Offer") + + _positive_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + 'The expected price of a property must be strictly positive' + ) + _positive_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + 'The selling price of a property must be positive' + ) + + @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") + if len(prices) > 0: + record.best_price = max(prices) + else: + record.best_price = 0 + + @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 = None + + def sell_property(self): + self.ensure_one() + if self.state == "cancelled": + raise UserError("Error - You cannot sell a cancelled property !") + offers = self.offer_ids.search([('property_id', '=', self.id)]) + if len(offers.filtered(lambda offer: offer.status == 'accepted')) == 0: + raise UserError("Error - No offer created for this property !") + self.state = "sold" + return True + + def cancel_property(self): + self.ensure_one() + if self.state == "sold": + raise UserError("Error - You cannot cancel a sold property !") + self.state = "cancelled" + return True + + @api.constrains('expected_price', 'selling_price') + def _check_selling_price(self): + for record in self: + if not float_is_zero(record.selling_price, precision_digits=3): + if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=3) < 0: + raise UserError(r"The selling price must be at least 90% of the expected price !") + + @api.ondelete(at_uninstall=False) + def _unlike_if_stats_new_or_cancelled(self): + for record in self: + if record.state in ('new', 'cancelled'): + raise UserError("You cannot delete a new or cancelled property !") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..81fe311c6e9 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,58 @@ +from odoo import api, models, fields +from odoo.exceptions import UserError +import datetime + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Estate Property Offer" + _order = "price desc" + + price = fields.Float() + status = fields.Selection(copy=False, selection=[("accepted", "Accepted"), ("refused", "Refused")]) + partner_id = fields.Many2one("res.partner", required=True, string="Partner") + property_id = fields.Many2one("estate.property", required=True) + validity = fields.Integer(default=7, string="Validity (days)") + date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline", string="Deadline") + property_type_id = fields.Many2one(related="property_id.property_type_id") + + _positive_price = models.Constraint( + 'CHECK(price > 0)', + 'The price of an offer must be strictly positive' + ) + + @api.depends("create_date", "validity") + def _compute_deadline(self): + for offer in self: + offer.date_deadline = fields.Date.add((offer.create_date or datetime.date.today()), days=offer.validity) + + def _inverse_deadline(self): + for offer in self: + delta = offer.date_deadline - (fields.Date.to_date(offer.create_date) or fields.Date.to_date(datetime.date.today())) + offer.validity = delta.days + + def accept_offer(self): + for offer in self: + for other_offer in offer.property_id.offer_ids: + if other_offer.status == "accepted" and offer.id != other_offer.id: + raise UserError("An offer is already accepted...") + offer.status = "accepted" + offer.property_id.buyer_id = offer.partner_id + offer.property_id.selling_price = offer.price + offer.property_id.state = 'offer_accepted' + + def refuse_offer(self): + for offer in self: + offer.status = "refused" + + @api.model_create_multi + def create(self, vals_list): + for val in vals_list: + if self.env['estate.property'].browse(val['property_id']).state == 'sold': + raise UserError("You cannot create an offer for a sold property !") + offers = self.env['estate.property.offer'].search([('property_id', '=', val['property_id'])]) + if offers and val['price'] < max(offers.mapped('price')): + raise UserError("You cannot create an offer with a lower amount than an existing offer !") + offers = super().create(vals_list) + offers.property_id.state = 'offer_received' + return offers diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..1b7e45ba6c0 --- /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 = "Estate Property Tag" + _order = "name asc" + + name = fields.Char(required=True) + color = fields.Integer() + + _unique_tag = models.Constraint( + 'unique(name)', + 'The 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..5d5a8232571 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,23 @@ +from odoo import api, models, fields + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate Property Type" + _order = "name asc" + + name = fields.Char(required=True) + property_ids = fields.One2many("estate.property", "property_type_id") + sequence = fields.Integer('Sequence', default=1) + offer_ids = fields.One2many("estate.property.offer", "property_type_id") + offer_count = fields.Integer(compute="_compute_count_offer") + + _unique_type = models.Constraint( + 'unique(name)', + 'The type name must be unique', + ) + + @api.depends("offer_ids") + def _compute_count_offer(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/estate_property_user.py b/estate/models/estate_property_user.py new file mode 100644 index 00000000000..936bb684f2d --- /dev/null +++ b/estate/models/estate_property_user.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class PropertyUser(models.Model): + _inherit = "res.users" + _description = "Property User" + + property_ids = fields.One2many("estate.property", "salesperson_id", 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..a90b03a38c6 --- /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 +estate.access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 +estate.access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 +estate.access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 +estate.access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..c613c60ae1a --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_property diff --git a/estate/tests/test_property.py b/estate/tests/test_property.py new file mode 100644 index 00000000000..6ad08e7a712 --- /dev/null +++ b/estate/tests/test_property.py @@ -0,0 +1,77 @@ +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError +from odoo.tests import tagged, Form + + +@tagged('post_install', '-at_install') +class EstatePropertySoldTestCase(TransactionCase): + + @classmethod + def setUpClass(cls): + + super().setUpClass() + + cls.property = cls.env['estate.property'].create( + [{ + 'name': 'Beautiful House', + 'expected_price': 100000, + }] + ) + + def test_sell_offer(self): + + # (1) Try to sell a property with no offer. + with self.assertRaises(UserError): + self.property.sell_property() + + partner = self.env['res.partner'].create( + [{ + 'name': 'My Favorite Partner' + }] + ) + offer = self.env['estate.property.offer'].create( + [{ + 'price': 95000, + 'partner_id': partner.id, + 'property_id': self.property.id + }] + ) + + # (2) After creating an offer, try to sell the property with no accepted offer. + with self.assertRaises(UserError): + self.property.sell_property() + + offer.status = 'accepted' + self.property.sell_property() + + # (3) After selling it, verify the state of the property. + self.assertEqual(self.property.state, 'sold') + + # (4) Lastly, verify that we cannot create an offer for a sold property. + with self.assertRaises(UserError): + self.env['estate.property.offer'].create({ + 'partner_id': partner.id, + 'property_id': self.property.id, + }) + + def test_garden_checkbox(self): + + property_form = Form(self.property) + property_form.garden = True + + # (1) Verify the default values of the garden area and orientation. + self.assertEqual(property_form.garden_area, 10) + self.assertEqual(property_form.garden_orientation, "north") + + property_form.garden_area = 120 + property_form.garden_orientation = "south" + + # (2) Reset the garden to False and check the default values. + property_form.garden = False + self.assertEqual(property_form.garden_area, 0) + self.assertIsNot(property_form.garden_orientation, True) + + # (3) Reset the garden to True and verify the default values of the garden area and orientation. + property_form.garden = True + self.assertEqual(property_form.garden_area, 10) + self.assertEqual(property_form.garden_orientation, "north") diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..4481368c70d --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..33256821cd6 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,26 @@ + + + + estate.property.offer.list + estate.property.offer + + + + + + + + +
+

+
+ + + + + + + + + + + + + + +
+
+ + + Property Types + estate.property.type + list,form + +
diff --git a/estate/views/estate_property_user_views.xml b/estate/views/estate_property_user_views.xml new file mode 100644 index 00000000000..bbdd5e2c9c7 --- /dev/null +++ b/estate/views/estate_property_user_views.xml @@ -0,0 +1,18 @@ + + + + + res.users.view.form.inherit.estate + res.users + + + + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..c7371232bea --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,140 @@ + + + + estate.property.form + estate.property + +
+
+
+ +
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + +
+ +
+
+ Expected Price: + +
+
+ Best Offer: + +
+
+ Selling Price: + +
+
+ +
+
+
+
+
+
+ + + Properties + estate.property + list,form,kanban + {'search_default_available': True} + +
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..68e5acf8a58 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,7 @@ +{ + 'name': "Real Estate Accounting", + 'depends': ['estate', 'account', 'base'], + 'author': "Odoo S.A.", + 'license': "LGPL-3", + 'data': [], +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..5e1963c9d2f --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +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..10865dabfb4 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,33 @@ +from odoo import models +from odoo import Command + + +class EstatePropertyAccount(models.Model): + _inherit = 'estate.property' + + def sell_property(self): + self.ensure_one() + buyer = self.buyer_id + invoice_values = { + 'move_type': 'out_invoice', + 'partner_id': buyer.id, + 'line_ids': [ + Command.create({ + 'name': self.name, + 'quantity': 1, + 'price_unit': self.selling_price + }), + Command.create({ + 'name': 'Taxes', + 'quantity': 1, + 'price_unit': self.selling_price * 0.06 + }), + Command.create({ + 'name': 'Administrative fees', + 'quantity': 1, + 'price_unit': 100.00 + }) + ] + } + self.env['account.move'].create(invoice_values) + return super().sell_property()