From 583577d14e2d5fce88aa9540d52bdefff72c2c69 Mon Sep 17 00:00:00 2001 From: "Bryce (brbu)" Date: Tue, 15 Sep 2026 15:57:04 +0200 Subject: [PATCH 1/8] [ADD] First commit with chapters 1 to 5 --- README.md | 11 +++++++++ estate/__init__.py | 2 ++ estate/__manifest__.py | 17 ++++++++++++++ estate/models/__init__.py | 3 +++ estate/models/estate_property.py | 32 ++++++++++++++++++++++++++ estate/security/ir.model.access.csv | 2 ++ estate/views/estate_menus.xml | 8 +++++++ estate/views/estate_property_views.xml | 8 +++++++ 8 files changed, 83 insertions(+) create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py create mode 100644 estate/models/__init__.py create mode 100644 estate/models/estate_property.py create mode 100644 estate/security/ir.model.access.csv create mode 100644 estate/views/estate_menus.xml create mode 100644 estate/views/estate_property_views.xml diff --git a/README.md b/README.md index a0158d919ee..4df77238b4f 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,14 @@ tutorial's solutions, and one for the [Master the Odoo web framework](https://www.odoo.com/documentation/latest/developer/tutorials/master_odoo_web_framework.html) tutorial's solutions. For example, `17.0`, `17.0-discover-js-framework-solutions` and `17.0-master-odoo-web-framework-solutions`. + + +./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -d rd-demo -u estate + +dropdb rd-demo +createdb rd-demo +psql -d rd-demo + + +lsof -i :8069 + diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..24c19d687df --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1,2 @@ + +from . import models \ No newline at end of file diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..a79b3a6f780 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,17 @@ +{ + 'name': 'My Estate', + 'version': '1.9', + 'summary': 'Test module to remember how it works mdr', + 'website': 'https://www.odoo.com/app/estate', + 'depends': [ + 'base', + ], + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_menus.xml', + ], + 'installable': True, + 'application': True, + 'author': 'brbu', +} \ No newline at end of file diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..7ab21cb4332 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,3 @@ + +from . import estate_property + diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..84cbe0ce138 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields + + +class EstateProperty(models.Model): + _name = "estate_property" + _description = "Properties of the estate" + + name = fields.Char(required=True, string="Title") + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date(copy=False, default=lambda self: fields.Date.add(fields.Date.today(), 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() + facade = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection( + string="Garden Orientation", + selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")], + ) + active = fields.Boolean(default=True) + state = fields.Selection( + string="Status", + selection=[("new","New"), ("offer-received","Offer Received"), ("offer-accepted","Offer Accepted"), ("sold","Sold"), ("canceled","Canceled")], + required=True, + copy=False, + default="new" + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..976b61e8cb3 --- /dev/null +++ b/estate/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_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..1c6580c8901 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..74faf4e528d --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,8 @@ + + + + Estate Properties + estate_property + list,form + + From 9bbe27eab336b9a85ec4a06a50f5163d4bcf9233 Mon Sep 17 00:00:00 2001 From: "Bryce (brbu)" Date: Wed, 16 Sep 2026 11:01:51 +0200 Subject: [PATCH 2/8] [IMP] Chapters 6+7 --- README.md | 2 +- estate/__manifest__.py | 3 + estate/models/__init__.py | 3 + estate/models/estate_property.py | 31 ++++-- estate/models/estate_property_offer.py | 18 ++++ estate/models/estate_property_tag.py | 11 ++ estate/models/estate_property_type.py | 11 ++ estate/security/ir.model.access.csv | 5 +- estate/views/estate_menus.xml | 4 + estate/views/estate_property_offer_views.xml | 32 ++++++ estate/views/estate_property_tag_views.xml | 44 ++++++++ estate/views/estate_property_type_views.xml | 44 ++++++++ estate/views/estate_property_views.xml | 102 ++++++++++++++++++- 13 files changed, 296 insertions(+), 14 deletions(-) create mode 100644 estate/models/estate_property_offer.py create mode 100644 estate/models/estate_property_tag.py create mode 100644 estate/models/estate_property_type.py create mode 100644 estate/views/estate_property_offer_views.xml create mode 100644 estate/views/estate_property_tag_views.xml create mode 100644 estate/views/estate_property_type_views.xml diff --git a/README.md b/README.md index 4df77238b4f..76006291f67 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ tutorial's solutions. For example, `17.0`, `17.0-discover-js-framework-solutions `17.0-master-odoo-web-framework-solutions`. -./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -d rd-demo -u estate +./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -d rd-demo -u estate --dev xml dropdb rd-demo createdb rd-demo diff --git a/estate/__manifest__.py b/estate/__manifest__.py index a79b3a6f780..155ad375335 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -9,6 +9,9 @@ 'data': [ 'security/ir.model.access.csv', 'views/estate_property_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_offer_views.xml', 'views/estate_menus.xml', ], 'installable': True, diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 7ab21cb4332..84ee8fd3850 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -1,3 +1,6 @@ from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 84cbe0ce138..586af27bef3 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -3,30 +3,41 @@ class EstateProperty(models.Model): - _name = "estate_property" + _name = "estate.property" _description = "Properties of the estate" name = fields.Char(required=True, string="Title") description = fields.Text() + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + + property_type_id = fields.Many2one("estate.property.type", string="Property Type") + salesperson_id = fields.Many2one("res.users", default=lambda self: self.env.user) + buyer_id = fields.Many2one("res.partner", copy=False) + offer_ids = fields.One2many("estate.property.offer", "property_id", copy=False) + postcode = fields.Char() - date_availability = fields.Date(copy=False, default=lambda self: fields.Date.add(fields.Date.today(), months=3)) - expected_price = fields.Float(required=True) - selling_price = fields.Float(readonly=True, copy=False) + date_availability = fields.Date(copy=False, string="Available From", default=lambda self: fields.Date.add(fields.Date.today(), months=3)) + expected_price = fields.Float(required=True, string="Expected Price") + selling_price = fields.Float(readonly=True, string="Selling Price", copy=False) + bedrooms = fields.Integer(default=2) - living_area = fields.Integer() - facade = fields.Integer() - garage = fields.Boolean() - garden = fields.Boolean() - garden_area = fields.Integer() + living_area = fields.Integer(string="Living Area (sqm)") + facade = fields.Integer(string="Façade") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area (sqm)") garden_orientation = fields.Selection( string="Garden Orientation", selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")], ) + active = fields.Boolean(default=True) state = fields.Selection( string="Status", - selection=[("new","New"), ("offer-received","Offer Received"), ("offer-accepted","Offer Accepted"), ("sold","Sold"), ("canceled","Canceled")], + selection=[("new","New"), ("offer_received","Offer Received"), ("offer_accepted","Offer Accepted"), ("sold","Sold"), ("canceled","Canceled")], required=True, copy=False, default="new" ) + + diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..2fa7ba25518 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Property offers for the estate" + + price = fields.Float() + status = fields.Selection( + string="Status", + selection=[("accepted", "Accepted"), ("refused", "Refused"), ("pending", "Pending")], + copy=False, + ) + partner_id = fields.Many2one("res.partner", copy=False) + property_id = fields.Many2one("estate.property", string="Property", copy=False) + + diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..3e9577e1f1a --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Property tags for the estate" + + name = fields.Char(required=True) + + diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..5f28ea080c9 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Property types of the estate" + + name = fields.Char(required=True) + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index 976b61e8cb3..49bca99cac8 100644 --- a/estate/security/ir.model.access.csv +++ b/estate/security/ir.model.access.csv @@ -1,2 +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 \ No newline at end of file +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 index 1c6580c8901..1d2a5e28d81 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -4,5 +4,9 @@ + + + + \ No newline at end of file diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..167158eba51 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,32 @@ + + + + + estate.property.offer.list + estate.property.offer + + + + + + + + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + +
+
+
+ +
\ No newline at end of file diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml new file mode 100644 index 00000000000..efdea2583e3 --- /dev/null +++ b/estate/views/estate_property_tag_views.xml @@ -0,0 +1,44 @@ + + + + + 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 + + +
\ No newline at end of file diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..8514121dd48 --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,44 @@ + + + + + estate.property.type.list + estate.property.type + + + + + + + + + estate.property.type.form + estate.property.type + +
+ +

+ +

+
+
+
+
+ + + estate.property.type.search + estate.property.type + + + + + + + + + Property Types + estate.property.type + list,form + + +
\ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 74faf4e528d..61b25788051 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -1,8 +1,106 @@ + + estate.property.list + estate.property + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + + - Estate Properties - estate_property + Properties + estate.property list,form +
From feaafd02f21a3ba0e442e35d1c4a742fbdf056f5 Mon Sep 17 00:00:00 2001 From: "Bryce (brbu)" Date: Wed, 16 Sep 2026 11:38:59 +0200 Subject: [PATCH 3/8] [IMP] Chapter 8 --- estate/models/estate_property.py | 24 ++++++++++++++++++++++-- estate/models/estate_property_offer.py | 15 +++++++++++++-- estate/views/estate_property_views.xml | 2 ++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 586af27bef3..a8a3596777f 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from odoo import models, fields +from odoo import models, fields, api class EstateProperty(models.Model): @@ -14,6 +14,7 @@ class EstateProperty(models.Model): salesperson_id = fields.Many2one("res.users", default=lambda self: self.env.user) buyer_id = fields.Many2one("res.partner", copy=False) offer_ids = fields.One2many("estate.property.offer", "property_id", copy=False) + best_offer = fields.Float(compute="_compute_best_offer", string="Best Offer", store=True) postcode = fields.Char() date_availability = fields.Date(copy=False, string="Available From", default=lambda self: fields.Date.add(fields.Date.today(), months=3)) @@ -30,7 +31,8 @@ class EstateProperty(models.Model): string="Garden Orientation", selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")], ) - + total_area = fields.Integer(string="Total Area (sqm)", compute="_compute_total_area", store=True) + active = fields.Boolean(default=True) state = fields.Selection( string="Status", @@ -40,4 +42,22 @@ class EstateProperty(models.Model): default="new" ) + @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_offer(self): + for record in self: + if record.offer_ids: + record.best_offer = max(record.offer_ids.mapped("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 = None diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 2fa7ba25518..ed0831dfe23 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from odoo import models, fields +from odoo import models, fields, api class EstatePropertyOffer(models.Model): @@ -12,7 +12,18 @@ class EstatePropertyOffer(models.Model): selection=[("accepted", "Accepted"), ("refused", "Refused"), ("pending", "Pending")], copy=False, ) + validity = fields.Integer(string="Validity (days)", default=7) + date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) + partner_id = fields.Many2one("res.partner", copy=False) property_id = fields.Many2one("estate.property", string="Property", copy=False) - + @api.depends("create_date", "validity") + def _compute_date_deadline(self): + for record in self: + record.date_deadline = fields.Date.add(record.create_date, days=record.validity) + + @api.depends("date_deadline", "create_date") + def _inverse_date_deadline(self): + for record in self: + record.validity = (record.date_deadline - record.create_date).days diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 61b25788051..3fb871a2bf2 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -36,6 +36,7 @@ + @@ -51,6 +52,7 @@ + From 6f1b022225d4f6891628e77aa6b7da6d255d8320 Mon Sep 17 00:00:00 2001 From: "Bryce (brbu)" Date: Wed, 16 Sep 2026 12:14:15 +0200 Subject: [PATCH 4/8] [IMP] Chapter 9 --- estate/models/estate_property.py | 20 +++++++++++++--- estate/models/estate_property_offer.py | 25 ++++++++++++++++++-- estate/views/estate_property_offer_views.xml | 2 ++ estate/views/estate_property_views.xml | 6 +++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index a8a3596777f..89b85210f0d 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from odoo import models, fields, api +from odoo import models, fields, api, exceptions class EstateProperty(models.Model): @@ -36,10 +36,10 @@ class EstateProperty(models.Model): active = fields.Boolean(default=True) state = fields.Selection( string="Status", - selection=[("new","New"), ("offer_received","Offer Received"), ("offer_accepted","Offer Accepted"), ("sold","Sold"), ("canceled","Canceled")], + selection=[("new","New"), ("offer_received","Offer Received"), ("offer_accepted","Offer Accepted"), ("sold","Sold"), ("cancelled","Cancelled")], required=True, copy=False, - default="new" + default="new", ) @api.depends("living_area", "garden_area") @@ -61,3 +61,17 @@ def _onchange_garden(self): else: self.garden_area = 0 self.garden_orientation = None + + def action_sold(self): + for record in self: + if record.state == "cancelled": + raise exceptions.UserError("A cancelled property cannot be sold !") + record.state = "sold" + return True + + def action_cancelled(self): + for record in self: + if record.state == "sold": + raise exceptions.UserError("A sold property cannot be cancelled !") + record.state = "cancelled" + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index ed0831dfe23..664a70c58f8 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from odoo import models, fields, api +from odoo import models, fields, api, _ class EstatePropertyOffer(models.Model): @@ -9,8 +9,9 @@ class EstatePropertyOffer(models.Model): price = fields.Float() status = fields.Selection( string="Status", - selection=[("accepted", "Accepted"), ("refused", "Refused"), ("pending", "Pending")], + selection=[("accepted", "Accepted"), ("refused", "Refused")], copy=False, + readonly=True, ) validity = fields.Integer(string="Validity (days)", default=7) date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) @@ -27,3 +28,23 @@ def _compute_date_deadline(self): def _inverse_date_deadline(self): for record in self: record.validity = (record.date_deadline - record.create_date).days + + def action_accept(self): + for record in self: + for other_offer in record.property_id.offer_ids: + if other_offer.status == "accepted" : + other_offer.status = None + Warning("An other offer acceptation was cancelled : only one offer can be accepted at a time !") + record.status = "accepted" + 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: + if record.status == "accepted": + record.property_id.buyer_id = None + record.property_id.selling_price = 0 + record.status = "refused" + return True + \ No newline at end of file diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml index 167158eba51..89f871b6c73 100644 --- a/estate/views/estate_property_offer_views.xml +++ b/estate/views/estate_property_offer_views.xml @@ -9,6 +9,8 @@ + + +

+ + + + + + + + + + + + +
@@ -30,6 +56,7 @@ estate.property.type + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index a21251c85ea..c23fa48aec5 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -4,14 +4,18 @@ estate.property.list estate.property - + - + + - + @@ -22,8 +26,9 @@
-
@@ -31,12 +36,11 @@ - + - - + @@ -56,16 +60,14 @@ - - + + - - - + @@ -91,7 +93,7 @@ - + @@ -99,6 +101,7 @@ + @@ -109,6 +112,8 @@ Properties estate.property list,form + + {'search_default_available': True} From a1d1b057ed2392c079bc16fca44f8c2a0dc0698c Mon Sep 17 00:00:00 2001 From: "Bryce (brbu)" Date: Fri, 18 Sep 2026 10:26:13 +0200 Subject: [PATCH 7/8] [FIX] Style & co --- estate/__init__.py | 1 - estate/models/__init__.py | 1 - estate/models/estate_property.py | 56 +++++++++++++------------- estate/models/estate_property_offer.py | 15 +++---- estate/models/estate_property_tag.py | 1 - estate/models/estate_property_type.py | 1 - 6 files changed, 33 insertions(+), 42 deletions(-) diff --git a/estate/__init__.py b/estate/__init__.py index a9e3372262c..0650744f6bc 100644 --- a/estate/__init__.py +++ b/estate/__init__.py @@ -1,2 +1 @@ - from . import models diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 449b55018ae..2f1821a39c1 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -1,4 +1,3 @@ - from . import estate_property from . import estate_property_type from . import estate_property_tag diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 4e2033a66d6..c0c531bd3b3 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError from odoo.tools.float_utils import float_compare, float_is_zero @@ -39,12 +38,28 @@ class EstateProperty(models.Model): active = fields.Boolean(default=True) state = fields.Selection( string="Status", - selection=[("new","New"), ("offer_received","Offer Received"), ("offer_accepted","Offer Accepted"), ("sold","Sold"), ("cancelled","Cancelled")], + selection=[("new", "New"), ("offer_received", "Offer Received"), ("offer_accepted", "Offer Accepted"), ("sold", "Sold"), ("cancelled", "Cancelled")], required=True, copy=False, default="new", ) + _positive_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + 'The expected price should be strictly positive.', + ) + + _positive_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + 'The selling price should be strictly positive.', + ) + + @api.constrains("selling_price", "expected_price") + def _check_selling_price(self): + for record in self: + if not float_is_zero(record.selling_price, 2) and float_compare(record.selling_price, record.expected_price * 0.9, 2) == -1: + raise ValidationError(_("The selling price must be at least 90% of the expected price !")) + @api.depends("living_area", "garden_area") def _compute_total_area(self): for record in self: @@ -55,10 +70,9 @@ def _compute_best_offer(self): for record in self: valid_offers = record.offer_ids.filtered(lambda offer: offer.status != "refused") record.best_offer = max(valid_offers.mapped("price"), default=0) - if valid_offers and record.state=="new": + if valid_offers and record.state == "new": record.state = "offer_received" - def _update_state_from_offers(self): for record in self: if record.offer_ids.filtered(lambda offer: offer.status == "accepted"): @@ -67,7 +81,7 @@ def _update_state_from_offers(self): record.state = "offer_received" else: record.state = "new" - + @api.onchange("garden") def _onchange_garden(self): if self.garden: @@ -76,39 +90,23 @@ def _onchange_garden(self): else: self.garden_area = 0 self.garden_orientation = False - + + @api.ondelete(at_uninstall=False) + def _only_if_new_or_cancelled(self): + for record in self: + if record.state != 'new' and record.state != 'cancelled': + raise UserError("Can't delete property that is not new or cancelled !") + def action_sold(self): for record in self: if record.state == "cancelled": raise UserError("A cancelled property cannot be sold !") record.state = "sold" return True - + def action_cancelled(self): for record in self: if record.state == "sold": raise UserError("A sold property cannot be cancelled !") record.state = "cancelled" return True - - _positive_expected_price = models.Constraint( - 'CHECK(expected_price > 0)', - 'The expected price should be strictly positive.', - ) - - _positive_selling_price = models.Constraint( - 'CHECK(selling_price >= 0)', - 'The selling price should be strictly positive.', - ) - - @api.constrains("selling_price", "expected_price") - def _check_selling_price(self): - for record in self: - if not float_is_zero(record.selling_price, 2) and float_compare(record.selling_price, record.expected_price*0.9, 2) == -1: - raise ValidationError(_("The selling price must be at least 90% of the expected price !")) - - @api.ondelete(at_uninstall=False) - def _only_if_new_or_cancelled(self): - for record in self: - if record.state != 'new' and record.state != 'cancelled': - raise UserError("Can't delete property that is not new or cancelled !") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index e1cfca3f809..0a7ca973e7a 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- -from odoo import models, fields, api, _ -from odoo.exceptions import UserError +from odoo import models, fields, api class EstatePropertyOffer(models.Model): @@ -27,7 +25,7 @@ def _compute_date_deadline(self): for record in self: start_date = record.create_date.date() if record.create_date else fields.Date.today() record.date_deadline = fields.Date.add(start_date, days=record.validity) - + @api.depends("date_deadline", "create_date") def _inverse_date_deadline(self): for record in self: @@ -36,15 +34,15 @@ def _inverse_date_deadline(self): def action_accept(self): for record in self: for other_offer in record.property_id.offer_ids: - if other_offer.status == "accepted" : + if other_offer.status == "accepted": other_offer.status = False - Warning("An other offer acceptation was cancelled : only one offer can be accepted at a time !") + raise Warning("An other offer acceptation was cancelled : only one offer can be accepted at a time !") record.status = "accepted" record.property_id.buyer_id = record.partner_id record.property_id.selling_price = record.price record.property_id._update_state_from_offers() return True - + def action_reset(self): for record in self: if record.status == "accepted": @@ -53,7 +51,7 @@ def action_reset(self): record.status = False record.property_id._update_state_from_offers() return True - + def action_refuse(self): for record in self: if record.status == "accepted": @@ -67,4 +65,3 @@ def action_refuse(self): 'CHECK(price > 0)', 'The offer prices should be strictly positive.', ) - diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py index 3d809d35281..befc5d1f037 100644 --- a/estate/models/estate_property_tag.py +++ b/estate/models/estate_property_tag.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import models, fields diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py index a63d06e651c..8d635e2b976 100644 --- a/estate/models/estate_property_type.py +++ b/estate/models/estate_property_type.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import models, fields, api From 52edd425429dc4c61b1cb18eddfd0204e7c1b909 Mon Sep 17 00:00:00 2001 From: "Bryce (brbu)" Date: Fri, 18 Sep 2026 11:39:34 +0200 Subject: [PATCH 8/8] [IMP] Chapter 12 + Style --- .gitignore | 3 -- README.md | 10 ------ estate/__manifest__.py | 3 +- estate/models/__init__.py | 1 + estate/models/estate_property.py | 32 ++++++++++++-------- estate/models/estate_property_offer.py | 15 ++++++++- estate/models/res_users.py | 8 +++++ estate/security/ir.model.access.csv | 1 + estate/views/estate_property_offer_views.xml | 4 +-- estate/views/res_users_views.xml | 19 ++++++++++++ 10 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 estate/models/res_users.py create mode 100644 estate/views/res_users_views.xml diff --git a/.gitignore b/.gitignore index f618994c548..b6e47617de1 100644 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,3 @@ dmypy.json # Pyre type checker .pyre/ - -# Perso -README.md diff --git a/README.md b/README.md index 0fbe0e2b416..a0158d919ee 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,3 @@ tutorial's solutions, and one for the [Master the Odoo web framework](https://www.odoo.com/documentation/latest/developer/tutorials/master_odoo_web_framework.html) tutorial's solutions. For example, `17.0`, `17.0-discover-js-framework-solutions` and `17.0-master-odoo-web-framework-solutions`. - - -./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -d rd-demo -u estate --dev xml - -dropdb rd-demo -createdb rd-demo -psql -d rd-demo - - -lsof -i :8069 diff --git a/estate/__manifest__.py b/estate/__manifest__.py index c165768917f..63dc6bbdca3 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -13,8 +13,9 @@ 'views/estate_property_type_views.xml', 'views/estate_property_tag_views.xml', 'views/estate_menus.xml', + 'views/res_users_views.xml', ], 'installable': True, 'application': True, - 'author': 'brbu', + 'author': 'Odoo S.A.', } diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 2f1821a39c1..9a2189b6382 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -2,3 +2,4 @@ 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 index c0c531bd3b3..5ffd3530a3e 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -36,9 +36,10 @@ class EstateProperty(models.Model): total_area = fields.Integer(string="Total Area (sqm)", compute="_compute_total_area", store=True) active = fields.Boolean(default=True) + locked = fields.Boolean(compute="_compute_locked", string="Locked", store=True) state = fields.Selection( string="Status", - selection=[("new", "New"), ("offer_received", "Offer Received"), ("offer_accepted", "Offer Accepted"), ("sold", "Sold"), ("cancelled", "Cancelled")], + selection=[("new", "New"), ("offer_received", "Offer Received"), ("offer_accepted", "Offer Accepted"), ("sold", "Sold"), ("cancelled", "Cancelled")], required=True, copy=False, default="new", @@ -70,17 +71,11 @@ def _compute_best_offer(self): for record in self: valid_offers = record.offer_ids.filtered(lambda offer: offer.status != "refused") record.best_offer = max(valid_offers.mapped("price"), default=0) - if valid_offers and record.state == "new": - record.state = "offer_received" - def _update_state_from_offers(self): + @api.depends("state") + def _compute_locked(self): for record in self: - if record.offer_ids.filtered(lambda offer: offer.status == "accepted"): - record.state = "offer_accepted" - elif any(not offer.status for offer in record.offer_ids): - record.state = "offer_received" - else: - record.state = "new" + record.locked = record.state in ("sold", "cancelled") @api.onchange("garden") def _onchange_garden(self): @@ -95,18 +90,29 @@ def _onchange_garden(self): def _only_if_new_or_cancelled(self): for record in self: if record.state != 'new' and record.state != 'cancelled': - raise UserError("Can't delete property that is not new or cancelled !") + raise UserError(_("Can't delete property that is not new or cancelled !")) def action_sold(self): for record in self: if record.state == "cancelled": - raise UserError("A cancelled property cannot be sold !") + raise UserError(_("A cancelled property cannot be sold !")) + if not record.offer_ids.filtered(lambda offer: offer.status == "accepted"): + raise UserError(_("A property with no accepted offer can't be sold !")) record.state = "sold" return True def action_cancelled(self): for record in self: if record.state == "sold": - raise UserError("A sold property cannot be cancelled !") + raise UserError(_("A sold property cannot be cancelled !")) record.state = "cancelled" return True + + def _update_state_from_offers(self): + for record in self: + if record.offer_ids.filtered(lambda offer: offer.status == "accepted"): + record.state = "offer_accepted" + elif any(not offer.status for offer in record.offer_ids): + record.state = "offer_received" + else: + record.state = "new" diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 0a7ca973e7a..df0cf4b9d3f 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,4 +1,5 @@ -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.exceptions import UserError class EstatePropertyOffer(models.Model): @@ -19,6 +20,7 @@ class EstatePropertyOffer(models.Model): partner_id = fields.Many2one("res.partner", copy=False) property_id = fields.Many2one("estate.property", string="Property", copy=False) property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) + property_locked = fields.Boolean(related="property_id.locked") @api.depends("create_date", "validity") def _compute_date_deadline(self): @@ -31,6 +33,17 @@ def _inverse_date_deadline(self): for record in self: record.validity = (record.date_deadline - record.create_date.date()).days + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property_instance = self.env['estate.property'].browse(vals['property_id']) + if vals['price'] < property_instance.best_offer: + raise UserError(_("Can't create an offer with a lower price than an existing offer !")) + if property_instance.state == "new": + property_instance.state = "offer_received" + + return super().create(vals_list) + def action_accept(self): for record in self: for other_offer in record.property_id.offer_ids: diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..31ece0d7eb4 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,8 @@ +from odoo import models, fields + + +class ResUsers(models.Model): + _inherit = ["res.users"] + _name = 'res.users' + + property_ids = fields.One2many("estate.property", "salesperson_id", copy=False, domain="['|', ('state', '=', 'new'), ('state', '=', 'offer_received')]") diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index 49bca99cac8..4b81304b274 100644 --- a/estate/security/ir.model.access.csv +++ b/estate/security/ir.model.access.csv @@ -3,3 +3,4 @@ access_estate_property,access_estate_property,model_estate_property,base.group_u 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 +access_res_users,access_res_users,model_res_users,base.group_user,1,1,1,1 diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml index 3907134aeee..245f4e099c7 100644 --- a/estate/views/estate_property_offer_views.xml +++ b/estate/views/estate_property_offer_views.xml @@ -12,8 +12,8 @@ -