From 66b1c3afafc05cd4e81b9116b6c3f258081c02f8 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Tue, 17 Jun 2025 13:30:40 +0200 Subject: [PATCH 01/18] [ADD] initial commit --- estate/__init__.py | 0 estate/__manifest__.py | 12 ++++++++++++ 2 files changed, 12 insertions(+) create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..5ce93ddfbff --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,12 @@ +{ + 'name': 'Real estate', + 'description': 'Real estate app', + 'category': 'Estate', + 'application': True, + # 'version': '18.0', + 'author': 'Nicolas Renard', + 'data': [ + ], + 'assets': { + }, +} From 28bb6087ed1a0d2d3f00ed276032f4a8b1919f7f Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Tue, 17 Jun 2025 14:45:58 +0200 Subject: [PATCH 02/18] =?UTF-8?q?[ADD]=20Chapter=203=20super=20modifi?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- estate/__init__.py | 1 + estate/models/__init__.py | 1 + estate/models/estate_property.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 estate/models/__init__.py create mode 100644 estate/models/estate_property.py diff --git a/estate/__init__.py b/estate/__init__.py index e69de29bb2d..0650744f6bc 100644 --- a/estate/__init__.py +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..5e1963c9d2f --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..e16b5964dfb --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,23 @@ +from odoo import fields,models + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real estate properties" + + name = fields.Char(required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date() + expected_price = fields.Float() + selling_price = fields.Float() + bedrooms = fields.Integer() + living_area = fields.Integer() + facades = 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')], + help="This Type is used to tell the garden orientation for a property" + ) From b9f198c35d73e93bf7ae521384d8396182c8e2ed Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Wed, 18 Jun 2025 09:06:15 +0200 Subject: [PATCH 03/18] [ADD] chapter 4 and 5 --- estate/__manifest__.py | 3 +++ estate/models/estate_property.py | 34 +++++++++++++++++--------- estate/security/ir.model.access.csv | 2 ++ estate/views/estate_menus.xml | 8 ++++++ estate/views/estate_property_views.xml | 8 ++++++ 5 files changed, 43 insertions(+), 12 deletions(-) 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/estate/__manifest__.py b/estate/__manifest__.py index 5ce93ddfbff..2ce5d632040 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -6,6 +6,9 @@ # 'version': '18.0', 'author': 'Nicolas Renard', 'data': [ + 'views/estate_property_views.xml', + 'views/estate_menus.xml', + 'security/ir.model.access.csv' ], 'assets': { }, diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index e16b5964dfb..6445c61b8b8 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,23 +1,33 @@ from odoo import fields,models +from dateutil.relativedelta import relativedelta class EstateProperty(models.Model): _name = "estate.property" _description = "Real estate properties" - name = fields.Char(required=True) - description = fields.Text() - postcode = fields.Char() - date_availability = fields.Date() - expected_price = fields.Float() - selling_price = fields.Float() - bedrooms = fields.Integer() - living_area = fields.Integer() - facades = fields.Integer() - garage = fields.Boolean() - garden = fields.Boolean() - garden_area = fields.Integer() + name = fields.Char("Estate name",required=True) + description = fields.Text("Description") + postcode = fields.Char("Postcode") + date_availability = fields.Date("Date availability",default=fields.Date.today() + relativedelta(months=3),copy=False) + expected_price = fields.Float("Expected price") + selling_price = fields.Float("Selling price",readonly=True,copy=False) + bedrooms = fields.Integer("Number of bedrooms",default=2) + living_area = fields.Integer("Living area") + facades = fields.Integer("Facades") + garage = fields.Boolean("Garage") + garden = fields.Boolean("Garden") + garden_area = fields.Integer("Garden area") garden_orientation = fields.Selection( string='Garden orientation', selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], help="This Type is used to tell the garden orientation for a property" ) + active = fields.Boolean("Active",default=True) + state = fields.Selection( + string='State', + selection=[('new', 'New'), ('offer_received', 'Offer received'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('cancelled', 'Canceled')], + help="This is the state of the property", + default="new", + required=True, + copy=False + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..4b6e1b03b72 --- /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,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..f7a1b66402c --- /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..978f2734f38 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,8 @@ + + + + Properties + estate.property + list,form + + \ No newline at end of file From a5deba50cbbe101e2e172f9b0506a10d83af7ee8 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Wed, 18 Jun 2025 11:09:29 +0200 Subject: [PATCH 04/18] [ADD] Chapter 6 --- estate/__manifest__.py | 5 +++- estate/models/estate_property.py | 7 +++-- estate/views/estate_form_view.xml | 40 ++++++++++++++++++++++++++ estate/views/estate_list_view.xml | 18 ++++++++++++ estate/views/estate_menus.xml | 4 +-- estate/views/estate_property_views.xml | 4 +-- estate/views/estate_search.xml | 21 ++++++++++++++ 7 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 estate/views/estate_form_view.xml create mode 100644 estate/views/estate_list_view.xml create mode 100644 estate/views/estate_search.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 2ce5d632040..41ce46bc747 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -8,7 +8,10 @@ 'data': [ 'views/estate_property_views.xml', 'views/estate_menus.xml', - 'security/ir.model.access.csv' + 'views/estate_list_view.xml', + 'views/estate_form_view.xml', + 'views/estate_search.xml', + 'security/ir.model.access.csv', ], 'assets': { }, diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 6445c61b8b8..c4e656b5ecd 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -12,22 +12,23 @@ class EstateProperty(models.Model): expected_price = fields.Float("Expected price") selling_price = fields.Float("Selling price",readonly=True,copy=False) bedrooms = fields.Integer("Number of bedrooms",default=2) - living_area = fields.Integer("Living area") + 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") garden_orientation = fields.Selection( string='Garden orientation', - selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], + selection=[('north', "North"), ('south', "South"), ('east', "East"), ('west', "West")], help="This Type is used to tell the garden orientation for a property" ) active = fields.Boolean("Active",default=True) state = fields.Selection( string='State', - selection=[('new', 'New'), ('offer_received', 'Offer received'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('cancelled', 'Canceled')], + selection=[('new', "New"), ('offer_received', "Offer received"), ('offer_accepted', "Offer Accepted"), ('sold', "Sold"), ('cancelled', "Canceled")], help="This is the state of the property", default="new", required=True, copy=False ) + diff --git a/estate/views/estate_form_view.xml b/estate/views/estate_form_view.xml new file mode 100644 index 00000000000..709d78ce21c --- /dev/null +++ b/estate/views/estate_form_view.xml @@ -0,0 +1,40 @@ + + + + estate.property.form.list + estate.property + +
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
diff --git a/estate/views/estate_list_view.xml b/estate/views/estate_list_view.xml new file mode 100644 index 00000000000..39c3f34b97c --- /dev/null +++ b/estate/views/estate_list_view.xml @@ -0,0 +1,18 @@ + + + + estate.property.list + estate.property + + + + + + + + + + + + + diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index f7a1b66402c..2aadd6f969a 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -2,7 +2,7 @@ - + - \ No newline at end of file + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 978f2734f38..0a238243e57 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -1,8 +1,8 @@ - + Properties estate.property list,form - \ No newline at end of file + diff --git a/estate/views/estate_search.xml b/estate/views/estate_search.xml new file mode 100644 index 00000000000..2a6f5d2096c --- /dev/null +++ b/estate/views/estate_search.xml @@ -0,0 +1,21 @@ + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + \ No newline at end of file From 674da49e5197a4074d58f9463f8e7799bd133a39 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Wed, 18 Jun 2025 14:21:38 +0200 Subject: [PATCH 05/18] [ADD] Chapter 7 --- estate/__manifest__.py | 1 + estate/models/__init__.py | 3 +++ estate/models/estate_property.py | 10 +++++++--- estate/models/estate_property_offer.py | 14 ++++++++++++++ estate/models/estate_property_tag.py | 8 ++++++++ estate/models/estate_property_type.py | 9 +++++++++ estate/security/ir.model.access.csv | 5 ++++- estate/views/estate_form_view.xml | 11 +++++++++++ estate/views/estate_list_view.xml | 2 ++ estate/views/estate_menus.xml | 6 +++++- estate/views/estate_offer_list_view.xml | 14 ++++++++++++++ estate/views/estate_property_views.xml | 12 ++++++++++++ estate/views/estate_search.xml | 4 +++- 13 files changed, 93 insertions(+), 6 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_offer_list_view.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 41ce46bc747..17311b7c22c 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -11,6 +11,7 @@ 'views/estate_list_view.xml', 'views/estate_form_view.xml', 'views/estate_search.xml', + 'views/estate_offer_list_view.xml', 'security/ir.model.access.csv', ], 'assets': { diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 5e1963c9d2f..2f1821a39c1 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -1 +1,4 @@ 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 c4e656b5ecd..e956fd023ea 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -21,7 +21,7 @@ class EstateProperty(models.Model): string='Garden orientation', selection=[('north', "North"), ('south', "South"), ('east', "East"), ('west', "West")], help="This Type is used to tell the garden orientation for a property" - ) + ) active = fields.Boolean("Active",default=True) state = fields.Selection( string='State', @@ -30,5 +30,9 @@ class EstateProperty(models.Model): default="new", required=True, copy=False - ) - + ) + property_type_id = fields.Many2one("estate.property.type") + salesperson_id = fields.Many2one("res.users") + buyer_id = fields.Many2one("res.partner") + tag_ids = fields.Many2many("estate.property.tag") + offers_ids = fields.One2many("estate.property.offer","property_id",string="Offers") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..e1707cf5d38 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,14 @@ +from odoo import fields,models + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Real estate properties offers" + + price = fields.Float("Price",required=True) + status = fields.Selection( + string='Status', + selection=[('accepted', "Accepted"), ('refused', "Refused")], + help="This selection is used to tell whether buying offer is accepted or refused" + ) + partner_id = fields.Many2one("res.partner") + property_id = fields.Many2one("estate.property") \ 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..e4a46bb9789 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,8 @@ +from odoo import fields,models + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Real estate properties tags" + + name = fields.Char("Name",required=True) + diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..598449f3918 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,9 @@ +from odoo import fields,models + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Real estate properties types" + + name = fields.Char("Name",required=True) + + \ No newline at end of file diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index 4b6e1b03b72..fe64532c06a 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,estate_property,model_estate_property,base.group_user,1,1,1,1 \ No newline at end of file +access_estate_property,estate_property,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type,estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag,estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer,estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/estate/views/estate_form_view.xml b/estate/views/estate_form_view.xml index 709d78ce21c..125329b081b 100644 --- a/estate/views/estate_form_view.xml +++ b/estate/views/estate_form_view.xml @@ -9,8 +9,10 @@

+ + @@ -32,6 +34,15 @@ + + + + + + + + + diff --git a/estate/views/estate_list_view.xml b/estate/views/estate_list_view.xml index 39c3f34b97c..216f057aa21 100644 --- a/estate/views/estate_list_view.xml +++ b/estate/views/estate_list_view.xml @@ -6,6 +6,8 @@ + + diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index 2aadd6f969a..7ae61f2577b 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -1,8 +1,12 @@ - + + + + + diff --git a/estate/views/estate_offer_list_view.xml b/estate/views/estate_offer_list_view.xml new file mode 100644 index 00000000000..69cac86c8c7 --- /dev/null +++ b/estate/views/estate_offer_list_view.xml @@ -0,0 +1,14 @@ + + + + estate.offer.list + estate.property.offer + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 0a238243e57..f00d1458473 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -5,4 +5,16 @@ estate.property list,form + + + Property Types + estate.property.type + list,form + + + + Property Tags + estate.property.tag + list,form + diff --git a/estate/views/estate_search.xml b/estate/views/estate_search.xml index 2a6f5d2096c..852711d9e1c 100644 --- a/estate/views/estate_search.xml +++ b/estate/views/estate_search.xml @@ -6,6 +6,8 @@ + + @@ -18,4 +20,4 @@ - \ No newline at end of file + From da60e72c85199f44588085442ec9e7e6f764b293 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Wed, 18 Jun 2025 14:32:55 +0200 Subject: [PATCH 06/18] [ADD] Chapter 7.1 --- estate/__manifest__.py | 1 + estate/views/estate_offer_form_view.xml | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 estate/views/estate_offer_form_view.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 17311b7c22c..3224f7baacc 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -12,6 +12,7 @@ 'views/estate_form_view.xml', 'views/estate_search.xml', 'views/estate_offer_list_view.xml', + 'views/estate_offer_form_view.xml', 'security/ir.model.access.csv', ], 'assets': { diff --git a/estate/views/estate_offer_form_view.xml b/estate/views/estate_offer_form_view.xml new file mode 100644 index 00000000000..2494225dfa9 --- /dev/null +++ b/estate/views/estate_offer_form_view.xml @@ -0,0 +1,20 @@ + + + + estate.offer.form.list + estate.property.offer + +
+ + + + + + + + + +
+
+
+
From 2e90538b7f34cefee73ccfe263ffea5d15c22411 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Wed, 18 Jun 2025 16:28:12 +0200 Subject: [PATCH 07/18] [ADD] Chapter 8 --- estate/__init__.py | 1 + estate/__manifest__.py | 1 + estate/models/__init__.py | 1 + estate/models/estate_property.py | 36 ++++++++++++++++++++----- estate/models/estate_property_offer.py | 28 ++++++++++++++++--- estate/security/ir.model.access.csv | 3 ++- estate/views/estate_form_view.xml | 2 ++ estate/views/estate_offer_form_view.xml | 10 +++---- estate/views/estate_offer_list_view.xml | 2 ++ 9 files changed, 69 insertions(+), 15 deletions(-) diff --git a/estate/__init__.py b/estate/__init__.py index 0650744f6bc..899bcc97f0f 100644 --- a/estate/__init__.py +++ b/estate/__init__.py @@ -1 +1,2 @@ from . import models + diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 3224f7baacc..cbe66ad60b0 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -18,3 +18,4 @@ 'assets': { }, } + diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 2f1821a39c1..9752b464357 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 + diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index e956fd023ea..ef7a927086b 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,4 +1,4 @@ -from odoo import fields,models +from odoo import api, fields, models from dateutil.relativedelta import relativedelta class EstateProperty(models.Model): @@ -31,8 +31,32 @@ class EstateProperty(models.Model): required=True, copy=False ) - property_type_id = fields.Many2one("estate.property.type") - salesperson_id = fields.Many2one("res.users") - buyer_id = fields.Many2one("res.partner") - tag_ids = fields.Many2many("estate.property.tag") - offers_ids = fields.One2many("estate.property.offer","property_id",string="Offers") + property_type_id = fields.Many2one('estate.property.type') + salesperson_id = fields.Many2one('res.users') + buyer_id = fields.Many2one('res.partner') + tag_ids = fields.Many2many('estate.property.tag') + offers_ids = fields.One2many('estate.property.offer','property_id',string="Offers") + + total_area = fields.Integer(compute='_compute_total') + best_price = fields.Float(compute='_compute_best_price') + + @api.depends('living_area','garden_area') + def _compute_total(self): + self.total_area = self.garden_area + self.living_area + + @api.depends('offers_ids.price') + def _compute_best_price(self): + if self.offers_ids.mapped('price'): + self.best_price = max(self.offers_ids.mapped('price')) + else: + self.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 = None + self.garden_orientation = None + diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index e1707cf5d38..e168c7351f7 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,4 +1,6 @@ -from odoo import fields,models +from odoo import fields,models,api +from dateutil.relativedelta import relativedelta + class EstatePropertyOffer(models.Model): _name = "estate.property.offer" @@ -10,5 +12,25 @@ class EstatePropertyOffer(models.Model): selection=[('accepted', "Accepted"), ('refused', "Refused")], help="This selection is used to tell whether buying offer is accepted or refused" ) - partner_id = fields.Many2one("res.partner") - property_id = fields.Many2one("estate.property") \ No newline at end of file + partner_id = fields.Many2one('res.partner') + property_id = fields.Many2one('estate.property') + + validity = fields.Integer(default=7) + create_date = fields.Date(default=fields.Date.today()) + date_deadline = fields.Date(compute='_compute_deadline',inverse='_inverse_validity') + + + @api.depends('validity') + def _compute_deadline(self): + for record in self: + if record.create_date: + record.date_deadline = record.create_date + relativedelta(days=record.validity) + else: + record.date_deadline = fields.Date.today()+ relativedelta(days=record.validity) + + def _inverse_validity(self): + for record in self: + if record.create_date: + record.validity = (record.date_deadline - record.create_date).days + else: + record.date_deadline = (record.date_deadline - fields.Date.today()).days \ No newline at end of file diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index fe64532c06a..7095505221f 100644 --- a/estate/security/ir.model.access.csv +++ b/estate/security/ir.model.access.csv @@ -2,4 +2,5 @@ id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink access_estate_property,estate_property,model_estate_property,base.group_user,1,1,1,1 access_estate_property_type,estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 access_estate_property_tag,estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 -access_estate_property_offer,estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 \ No newline at end of file +access_estate_property_offer,estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 + diff --git a/estate/views/estate_form_view.xml b/estate/views/estate_form_view.xml index 125329b081b..e7b82e76f03 100644 --- a/estate/views/estate_form_view.xml +++ b/estate/views/estate_form_view.xml @@ -18,6 +18,7 @@ + @@ -32,6 +33,7 @@ + diff --git a/estate/views/estate_offer_form_view.xml b/estate/views/estate_offer_form_view.xml index 2494225dfa9..3ee4460078b 100644 --- a/estate/views/estate_offer_form_view.xml +++ b/estate/views/estate_offer_form_view.xml @@ -7,11 +7,11 @@
- - - - - + + + + +
diff --git a/estate/views/estate_offer_list_view.xml b/estate/views/estate_offer_list_view.xml index 69cac86c8c7..ad580774cbb 100644 --- a/estate/views/estate_offer_list_view.xml +++ b/estate/views/estate_offer_list_view.xml @@ -7,6 +7,8 @@ + +
From 84a4fed994bbed8bd950e64f419cb70f5837f81d Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Thu, 19 Jun 2025 09:22:14 +0200 Subject: [PATCH 08/18] [ADD] Chapter 9 --- estate/models/estate_property.py | 20 ++++++++++++++++++++ estate/models/estate_property_offer.py | 18 +++++++++++++++++- estate/views/estate_form_view.xml | 5 +++++ estate/views/estate_offer_list_view.xml | 2 ++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index ef7a927086b..bbb65e31b5a 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,4 +1,5 @@ from odoo import api, fields, models +from odoo.exceptions import UserError from dateutil.relativedelta import relativedelta class EstateProperty(models.Model): @@ -40,6 +41,10 @@ class EstateProperty(models.Model): total_area = fields.Integer(compute='_compute_total') best_price = fields.Float(compute='_compute_best_price') + cancelled = fields.Boolean(default=False) + sold = fields.Boolean(default=False) + + @api.depends('living_area','garden_area') def _compute_total(self): self.total_area = self.garden_area + self.living_area @@ -60,3 +65,18 @@ def _onchange_garden(self): self.garden_area = None self.garden_orientation = None + def action_sold(self): + for record in self: + if not record.state == "cancelled": + record.state = "sold" + else: + raise UserError("You can't sold an house that has been cancelled") + return True + + def action_cancel(self): + for record in self: + if not record.state == "sold": + record.state = "cancelled" + else: + raise UserError("You can't cancel an house that has already been sold") + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index e168c7351f7..e8aa1c0143f 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,4 +1,5 @@ from odoo import fields,models,api +from odoo.exceptions import UserError from dateutil.relativedelta import relativedelta @@ -33,4 +34,19 @@ def _inverse_validity(self): if record.create_date: record.validity = (record.date_deadline - record.create_date).days else: - record.date_deadline = (record.date_deadline - fields.Date.today()).days \ No newline at end of file + record.date_deadline = (record.date_deadline - fields.Date.today()).days + + def action_confirm_offer(self): + for record in self: + if not record.status: + record.status = 'accepted' + record.property_id.buyer_id = record.partner_id + record.property_id.selling_price = record.price + + return True + + def action_refuse_offer(self): + for record in self: + if not record.status: + record.status = 'refused' + return True \ No newline at end of file diff --git a/estate/views/estate_form_view.xml b/estate/views/estate_form_view.xml index e7b82e76f03..42b2bcfe88a 100644 --- a/estate/views/estate_form_view.xml +++ b/estate/views/estate_form_view.xml @@ -5,6 +5,10 @@ estate.property
+
+

@@ -12,6 +16,7 @@ + diff --git a/estate/views/estate_offer_list_view.xml b/estate/views/estate_offer_list_view.xml index ad580774cbb..b5fc116d46a 100644 --- a/estate/views/estate_offer_list_view.xml +++ b/estate/views/estate_offer_list_view.xml @@ -9,6 +9,8 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_type_list_view.xml b/estate/views/estate_type_list_view.xml new file mode 100644 index 00000000000..34f007665ee --- /dev/null +++ b/estate/views/estate_type_list_view.xml @@ -0,0 +1,13 @@ + + + + estate.type.list.view + estate.property.type + + + + + + + + From dd90eeca9a05a5562b37fcb521e090ccaf154859 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Fri, 20 Jun 2025 09:21:28 +0200 Subject: [PATCH 11/18] [ADD] Chapter 12 : Inheritance --- estate/__manifest__.py | 1 + estate/models/__init__.py | 2 +- estate/models/estate_property.py | 6 ++++++ estate/models/estate_property_offer.py | 6 ++++++ estate/models/inherited_model.py | 9 +++++++++ estate/views/res_users_view.xml | 17 +++++++++++++++++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 estate/models/inherited_model.py create mode 100644 estate/views/res_users_view.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 728c5413526..4346c35d4e4 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -16,6 +16,7 @@ 'views/estate_type_form_view.xml', 'views/estate_type_list_view.xml', 'views/estate_tag_list_view.xml', + 'views/res_users_view.xml', 'security/ir.model.access.csv', ], 'assets': { diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 9752b464357..c0917a3d550 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -2,4 +2,4 @@ from . import estate_property_type from . import estate_property_tag from . import estate_property_offer - +from . import inherited_model diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index a46053a1284..03f83eaaeb1 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -8,6 +8,12 @@ class EstateProperty(models.Model): _description = "Real estate properties" _order = "id desc" + @api.ondelete(at_uninstall=False) + def _unlink_except_new_or_cancelled(self): + for property in self: + if property.state == 'new' or property.state == 'cancelled': + raise UserError("Can't delete a property that is new or cancelled!") + name = fields.Char("Estate name",required=True) description = fields.Text("Description") postcode = fields.Char("Postcode") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index b5efb1ead97..5f1bb60bbfa 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -8,6 +8,12 @@ class EstatePropertyOffer(models.Model): _description = "Real estate properties offers" _order = "price desc" + @api.model + def create(self, vals): + if self.env['estate.property'].browse(vals['property_id']).state == 'new': + self.env['estate.property'].browse(vals['property_id']).state = 'offer_received' + return super(EstatePropertyOffer,self).create(vals) + price = fields.Float("Price",required=True) status = fields.Selection( string='Status', diff --git a/estate/models/inherited_model.py b/estate/models/inherited_model.py new file mode 100644 index 00000000000..73a1e7327ed --- /dev/null +++ b/estate/models/inherited_model.py @@ -0,0 +1,9 @@ +from odoo import fields,models + +class InheritedModel(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many(comodel_name='estate.property', + inverse_name='salesperson_id', + domain=[("state", "in", ['new', 'offer_received'])]) + \ No newline at end of file diff --git a/estate/views/res_users_view.xml b/estate/views/res_users_view.xml new file mode 100644 index 00000000000..cbb76ec435c --- /dev/null +++ b/estate/views/res_users_view.xml @@ -0,0 +1,17 @@ + + + + + res.users.view + res.users + + + + + + + + + + + From 12860004d0980f4e622d25e5b894fe0a20194628 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Fri, 20 Jun 2025 10:12:02 +0200 Subject: [PATCH 12/18] [ADD] Chapter 13 : Interact with other modules --- estate/__manifest__.py | 1 + estate/models/estate_property_offer.py | 2 +- estate_account/__init__.py | 2 ++ estate_account/__manifest__.py | 16 ++++++++++++ estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 28 +++++++++++++++++++++ estate_account/security/ir.model.access.csv | 2 ++ 7 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py create mode 100644 estate_account/models/__init__.py create mode 100644 estate_account/models/estate_property.py create mode 100644 estate_account/security/ir.model.access.csv diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 4346c35d4e4..39a87d929ea 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -21,5 +21,6 @@ ], 'assets': { }, + 'license': 'LGPL-3', } diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 5f1bb60bbfa..731200f3821 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -56,7 +56,7 @@ def action_confirm_offer(self): record.status = 'accepted' record.property_id.buyer_id = record.partner_id record.property_id.selling_price = record.price - record.property_id.state = 'sold' + record.property_id.state = 'offer_accepted' return True diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..899bcc97f0f --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1,2 @@ +from . import models + diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..7a58e49aa50 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,16 @@ +{ + 'name': 'Real estate invoicing link', + 'description': 'Real estate app for invoicing link', + 'category': 'Estate', + 'application': True, + # 'version': '18.0', + 'author': 'Nicolas Renard', + 'depends': [ + 'estate', + 'account', + ], + 'data': [ + 'security/ir.model.access.csv', + ], + 'license': 'LGPL-3', +} \ No newline at end of file diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..f4c8fd6db6d --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property \ No newline at end of file diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..537a4975286 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,28 @@ +from odoo import Command, fields, models + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_sold(self): + self._create_account_move() + return super().action_sold() + + def _create_account_move(self): + for property in self: + self.env["account.move"].create({ + "partner_id": property.buyer_id.id, + "move_type": "out_invoice", + "line_ids": [ + Command.create({ + 'name': f' 6 % Downpayment for {property.name} (total price: {property.selling_price})', + 'quantity': 1, + 'price_unit': property.selling_price * 0.06, + }), + Command.create({ + 'name': "Admin Fees", + 'quantity': 1, + 'price_unit': 100, + }) + ], + }) \ No newline at end of file diff --git a/estate_account/security/ir.model.access.csv b/estate_account/security/ir.model.access.csv new file mode 100644 index 00000000000..d9d6ba57cc5 --- /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_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 From 39017688c1449d22fc5fe1ad97671bf6a6e9438d Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Fri, 20 Jun 2025 11:21:44 +0200 Subject: [PATCH 13/18] [ADD] Chapter 14 : Kanban ! --- estate/__manifest__.py | 1 + estate/views/estate_kanban_view.xml | 34 ++++++++++++++++++++++++++ estate/views/estate_property_views.xml | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 estate/views/estate_kanban_view.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 39a87d929ea..908f87661b3 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -16,6 +16,7 @@ 'views/estate_type_form_view.xml', 'views/estate_type_list_view.xml', 'views/estate_tag_list_view.xml', + 'views/estate_kanban_view.xml', 'views/res_users_view.xml', 'security/ir.model.access.csv', ], diff --git a/estate/views/estate_kanban_view.xml b/estate/views/estate_kanban_view.xml new file mode 100644 index 00000000000..734cd763473 --- /dev/null +++ b/estate/views/estate_kanban_view.xml @@ -0,0 +1,34 @@ + + + + estate.kanban + estate.property + + + + + +
+
+
+ Expected price : +
+ +
+ Best offer : +
+ +
+ Selling Price: +
+ +
+ +
+
+
+
+
+
+
+
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index e995ff1155e..539e70f9865 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -3,7 +3,7 @@ Properties estate.property - list,form + list,form,kanban {'search_default_active': True} From 478bd116daacb1fd9146428680fe9e25a48819e6 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Tue, 24 Jun 2025 09:28:07 +0200 Subject: [PATCH 14/18] [ADD] Chapter 1 : OWL Components --- awesome_owl/static/src/card/card.js | 26 ++++++++++++++ awesome_owl/static/src/card/card.xml | 16 +++++++++ awesome_owl/static/src/counter/counter.js | 23 ++++++++++++ awesome_owl/static/src/counter/counter.xml | 9 +++++ awesome_owl/static/src/playground.js | 18 ++++++++-- awesome_owl/static/src/playground.xml | 12 +++++-- awesome_owl/static/src/todolist/todoitem.js | 29 +++++++++++++++ awesome_owl/static/src/todolist/todoitem.xml | 11 ++++++ awesome_owl/static/src/todolist/todolist.js | 38 ++++++++++++++++++++ awesome_owl/static/src/todolist/todolist.xml | 12 +++++++ awesome_owl/views/templates.xml | 1 + estate/views/estate_type_form_view.xml | 4 +-- 12 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 awesome_owl/static/src/card/card.js create mode 100644 awesome_owl/static/src/card/card.xml create mode 100644 awesome_owl/static/src/counter/counter.js create mode 100644 awesome_owl/static/src/counter/counter.xml create mode 100644 awesome_owl/static/src/todolist/todoitem.js create mode 100644 awesome_owl/static/src/todolist/todoitem.xml create mode 100644 awesome_owl/static/src/todolist/todolist.js create mode 100644 awesome_owl/static/src/todolist/todolist.xml diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..848b752a91a --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,26 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "my_module.Card"; + + + setup() { + this.state = useState({ isToggled: true }); + } + + static props = { + title: {type: String}, + slots: { + type: Object, + shape: { default:true }, + }, + } + + toggle() { + this.state.isToggled = !this.state.isToggled; + if (this.props.onChange) { + this.props.onChange(this.state.isToggled); + } + } + +} \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..1bed5ffa13f --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,16 @@ + + + +
+
+
+ + +
+

+ +

+
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..bdf0317990b --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,23 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "my_module.Counter"; + + static props = { + initialValue: { type: Number, optional: true, default: 0, validate: (value) => value >= 0 }, + onChange: { type: Function, optional: true }, + }; + + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + if (this.props.onChange) { + this.props.onChange(); + } + } + +} \ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..795de536fc3 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + +
+

Counter:

+ +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..747cfba8da3 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,21 @@ /** @odoo-module **/ - -import { Component } from "@odoo/owl"; +import { Card } from "./card/card"; +import { Counter } from "./counter/counter"; +import { TodoList } from "./todolist/todolist"; +import { Component, useState, markup} from "@odoo/owl"; export class Playground extends Component { static template = "awesome_owl.playground"; + + static components = {Counter,Card,TodoList} + + setup() { + this.state = useState({ safe_title: markup("
some content
"), sum:0 }); + } + + incrementSum(){ + this.state.sum++; + } + } + diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..d9c64c4e587 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,16 @@ - + + +
- hello world + Counter sum : +
+ +
+
-
+ \ No newline at end of file diff --git a/awesome_owl/static/src/todolist/todoitem.js b/awesome_owl/static/src/todolist/todoitem.js new file mode 100644 index 00000000000..02606c4a8ba --- /dev/null +++ b/awesome_owl/static/src/todolist/todoitem.js @@ -0,0 +1,29 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "my_module.TodoItem"; + + static props = { + todo: { type: Object, + shape: { + id: { type: Number, default: 0 }, + description: { type: String, default: "" }, + isCompleted: { type: Boolean, default: false }, + } + }, + toggleState: { type: Function, optional: true }, + removeTodo: { type: Function, optional: true }, + + } + + onChange() { + this.props.toggleState(this.props.todo.id); + } + + onRemove() { + this.props.removeTodo(this.props.todo.id); + } + + + +} \ No newline at end of file diff --git a/awesome_owl/static/src/todolist/todoitem.xml b/awesome_owl/static/src/todolist/todoitem.xml new file mode 100644 index 00000000000..25a42233df0 --- /dev/null +++ b/awesome_owl/static/src/todolist/todoitem.xml @@ -0,0 +1,11 @@ + + + +
  • + + - + + +
  • +
    +
    diff --git a/awesome_owl/static/src/todolist/todolist.js b/awesome_owl/static/src/todolist/todolist.js new file mode 100644 index 00000000000..ea5fada6773 --- /dev/null +++ b/awesome_owl/static/src/todolist/todolist.js @@ -0,0 +1,38 @@ +import { Component, useState, useRef, onMounted } from "@odoo/owl"; +import { TodoItem } from "./todoitem"; + +export class TodoList extends Component { + static template = "my_module.TodoList"; + + static components = {TodoItem} + + setup() { + this.todos = useState([]); + this.inputRef = useRef('focus-input'); + onMounted(() => { + this.inputRef.el.focus() + }); + } + + toggleTodo(id) { + const todo = this.todos.find(todo => todo.id === id); + if (todo){ + todo.isCompleted = !todo.isCompleted + } + } + + removeTodo(id) { + const index = this.todos.findIndex(todo => todo.id === id); + if (index !== -1) { + this.todos.splice(index, 1); + } + } + + addTodo(ev){ + if (ev.keyCode === 13){ + this.todos.push({id: this.todos.length + 1, description: ev.target.value.trim(), isCompleted: false}) + ev.target.value = "" //reinit + } + + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/todolist/todolist.xml b/awesome_owl/static/src/todolist/todolist.xml new file mode 100644 index 00000000000..d7aa260a97f --- /dev/null +++ b/awesome_owl/static/src/todolist/todolist.xml @@ -0,0 +1,12 @@ + + + + +
      + + + + +
    +
    +
    \ No newline at end of file diff --git a/awesome_owl/views/templates.xml b/awesome_owl/views/templates.xml index aa54c1a7241..3df6b44bd5b 100644 --- a/awesome_owl/views/templates.xml +++ b/awesome_owl/views/templates.xml @@ -5,6 +5,7 @@ + diff --git a/estate/views/estate_type_form_view.xml b/estate/views/estate_type_form_view.xml index 5fe3644aff4..627c276a33c 100644 --- a/estate/views/estate_type_form_view.xml +++ b/estate/views/estate_type_form_view.xml @@ -5,7 +5,7 @@ estate.property.type
    -
    +
    -
    - From 347605db3040ddc6b2f30d2cf40c8816250680c2 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Wed, 25 Jun 2025 10:07:35 +0200 Subject: [PATCH 15/18] [ADD] Chapter 2 (2.1->2.8) : Build a dashboard --- awesome_dashboard/__manifest__.py | 4 ++ awesome_dashboard/static/src/dashboard.js | 10 ----- awesome_dashboard/static/src/dashboard.xml | 8 ---- .../static/src/dashboard/dashboard.js | 41 +++++++++++++++++ .../static/src/dashboard/dashboard.scss | 3 ++ .../static/src/dashboard/dashboard.xml | 34 ++++++++++++++ .../dashboard_item/dashboard_item.js | 22 +++++++++ .../dashboard_item/dashboard_item.xml | 15 +++++++ .../src/dashboard/pie_chart/pie_chart.js | 45 +++++++++++++++++++ .../src/dashboard/pie_chart/pie_chart.xml | 10 +++++ .../src/dashboard/statistics_service.js | 22 +++++++++ .../static/src/dashboard_loader.js | 15 +++++++ awesome_owl/__init__.py | 2 +- awesome_owl/static/src/card/card.js | 2 +- awesome_owl/static/src/card/card.xml | 2 +- awesome_owl/static/src/counter/counter.js | 2 +- awesome_owl/static/src/counter/counter.xml | 2 +- awesome_owl/static/src/playground.xml | 2 +- awesome_owl/static/src/todolist/todoitem.js | 2 +- awesome_owl/static/src/todolist/todolist.js | 2 +- awesome_owl/static/src/todolist/todolist.xml | 2 +- 21 files changed, 220 insertions(+), 27 deletions(-) delete mode 100644 awesome_dashboard/static/src/dashboard.js delete mode 100644 awesome_dashboard/static/src/dashboard.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.js create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.scss create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml create mode 100644 awesome_dashboard/static/src/dashboard/statistics_service.js create mode 100644 awesome_dashboard/static/src/dashboard_loader.js diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..59d70791d98 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,7 +24,11 @@ 'assets': { 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', + ('remove', 'awesome_dashboard/static/src/dashboard/**/*'), ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*' + ] }, 'license': 'AGPL-3' } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index 637fa4bb972..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,10 +0,0 @@ -/** @odoo-module **/ - -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/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..5974915d6ab --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,41 @@ +/** @odoo-module **/ + +import { Component, onWillStart, useState } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { Layout } from "@web/search/layout"; +import { AwesomeDashboardItem } from "./dashboard_item/dashboard_item" +import { PieChart } from "./pie_chart/pie_chart"; +import { useService } from "@web/core/utils/hooks"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + + static components = {Layout, AwesomeDashboardItem, PieChart} + + setup() { + this.action = useService("action"); + this.statistic = useState(useService("awesome_dashboard.statistics")) + this.display = { + controlPanel: {}, + }; + } + + openCustomerView() { + this.action.doAction("base.action_partner_form"); + } + + openLeads() { + this.action.doAction({ + type: "ir.actions.act_window", + name: "All leads", + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + }); + } + +} + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..a1281d8303e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: grey; +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..469d6fd381c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,34 @@ + + + + + + + + + +
    + + Number of new orders this month + + + Total amount of new orders this month + + + Average amount of t-shirt by order this month + + + Number of cancelled orders this month + + + Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’ + + + Shirt orders by size + + +
    +
    +
    + +
    diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..2bb81caae09 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,22 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class AwesomeDashboardItem extends Component { + static template = "awesome_dashboard.AwesomeDashboardItem"; + + static props = { + slots: { + type: Object, + shape: { + default: Object + }, + }, + size: { + type: Number, + default: 1, + optional: true, + }, + }; + +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..768719886a5 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,15 @@ + + + + +
    +
    + +
    +

    +
    +
    +
    +
    + +
    diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js new file mode 100644 index 00000000000..e2ce48aed4d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,45 @@ +import { loadJS } from "@web/core/assets"; +import { getColor } from "@web/core/colors/colors"; +import { Component, onWillStart, useRef, onMounted, onWillUnmount, onWillUpdateProps } from "@odoo/owl"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + static props = { + label: String, + data: Object, + }; + + setup() { + this.canvasRef = useRef("canvas"); + onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); + onMounted(() => { + this.renderChart(); + }); + onWillUpdateProps(() => { + this.chart.destroy() + this.renderChart() + }) + onWillUnmount(() => { + this.chart.destroy(); + }); + } + + renderChart() { + const labels = Object.keys(this.props.data); + const data = Object.values(this.props.data); + const color = labels.map((_, index) => getColor(index)); + this.chart = new Chart(this.canvasRef.el, { + type: "pie", + data: { + labels: labels, + datasets: [ + { + label: this.props.label, + data: data, + backgroundColor: color, + }, + ], + }, + }); + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..9be0991dcbc --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + +
    +
    + +
    +
    +
    +
    \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/statistics_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js new file mode 100644 index 00000000000..2fc0873ae90 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,22 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +const statisticsService = { + start() { + const statistics = reactive({ isReady: false }); + + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + } + + setInterval(loadData,10000); + loadData(); + + return statistics; + + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..06ae51de339 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,15 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +class AwesomeDashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; + +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); \ No newline at end of file diff --git a/awesome_owl/__init__.py b/awesome_owl/__init__.py index 457bae27e11..b0f26a9a602 100644 --- a/awesome_owl/__init__.py +++ b/awesome_owl/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from . import controllers \ No newline at end of file +from . import controllers diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js index 848b752a91a..b8d1c45eb03 100644 --- a/awesome_owl/static/src/card/card.js +++ b/awesome_owl/static/src/card/card.js @@ -23,4 +23,4 @@ export class Card extends Component { } } -} \ No newline at end of file +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml index 1bed5ffa13f..ed065afc3e6 100644 --- a/awesome_owl/static/src/card/card.xml +++ b/awesome_owl/static/src/card/card.xml @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js index bdf0317990b..7bf14855720 100644 --- a/awesome_owl/static/src/counter/counter.js +++ b/awesome_owl/static/src/counter/counter.js @@ -20,4 +20,4 @@ export class Counter extends Component { } } -} \ No newline at end of file +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml index 795de536fc3..66085c8102d 100644 --- a/awesome_owl/static/src/counter/counter.xml +++ b/awesome_owl/static/src/counter/counter.xml @@ -6,4 +6,4 @@ - \ No newline at end of file + diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index d9c64c4e587..792b60f9aee 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/awesome_owl/static/src/todolist/todoitem.js b/awesome_owl/static/src/todolist/todoitem.js index 02606c4a8ba..5f110178a2e 100644 --- a/awesome_owl/static/src/todolist/todoitem.js +++ b/awesome_owl/static/src/todolist/todoitem.js @@ -26,4 +26,4 @@ export class TodoItem extends Component { -} \ No newline at end of file +} diff --git a/awesome_owl/static/src/todolist/todolist.js b/awesome_owl/static/src/todolist/todolist.js index ea5fada6773..6867d3dbda1 100644 --- a/awesome_owl/static/src/todolist/todolist.js +++ b/awesome_owl/static/src/todolist/todolist.js @@ -35,4 +35,4 @@ export class TodoList extends Component { } } -} \ No newline at end of file +} diff --git a/awesome_owl/static/src/todolist/todolist.xml b/awesome_owl/static/src/todolist/todolist.xml index d7aa260a97f..c57f129946e 100644 --- a/awesome_owl/static/src/todolist/todolist.xml +++ b/awesome_owl/static/src/todolist/todolist.xml @@ -9,4 +9,4 @@ - \ No newline at end of file + From 0a3f6d04ecb067a0e621d37f318fbec4243cb188 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Thu, 26 Jun 2025 09:15:56 +0200 Subject: [PATCH 16/18] [ADD] Chapter 2 (2.8 -> 2.11) --- .../static/src/dashboard/dashboard.js | 62 ++++++++++++++++- .../static/src/dashboard/dashboard.scss | 2 +- .../static/src/dashboard/dashboard.xml | 46 +++++++------ .../dashboard_item/dashboard_item.xml | 7 +- .../static/src/dashboard/dashboard_items.js | 67 +++++++++++++++++++ .../src/dashboard/number_card/number_card.js | 11 +++ .../src/dashboard/number_card/number_card.xml | 11 +++ .../pie_chart_card/pie_chart_card.js | 13 ++++ .../pie_chart_card/pie_chart_cards.xml | 7 ++ 9 files changed, 197 insertions(+), 29 deletions(-) create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_items.js create mode 100644 awesome_dashboard/static/src/dashboard/number_card/number_card.js create mode 100644 awesome_dashboard/static/src/dashboard/number_card/number_card.xml create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.xml diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js index 5974915d6ab..ed77251f373 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -3,27 +3,46 @@ import { Component, onWillStart, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; +import { Dialog } from "@web/core/dialog/dialog"; import { AwesomeDashboardItem } from "./dashboard_item/dashboard_item" -import { PieChart } from "./pie_chart/pie_chart"; import { useService } from "@web/core/utils/hooks"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; - static components = {Layout, AwesomeDashboardItem, PieChart} + static components = {Layout, AwesomeDashboardItem} setup() { this.action = useService("action"); this.statistic = useState(useService("awesome_dashboard.statistics")) + this.items = registry.category("awesome_dashboard").getAll(); + this.dialog = useService("dialog"); this.display = { controlPanel: {}, }; + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] + }); } openCustomerView() { this.action.doAction("base.action_partner_form"); } + openConfiguration() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this), + }) + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } + openLeads() { this.action.doAction({ type: "ir.actions.act_window", @@ -36,6 +55,43 @@ class AwesomeDashboard extends Component { }); } + } -registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); \ No newline at end of file + +class ConfigurationDialog extends Component { + static template = "awesome_dashboard.ConfigurationDialog"; + static components = { Dialog, CheckBox }; + static props = ["close", "items", "disabledItems", "onUpdateConfiguration"]; + + setup() { + this.items = useState(this.props.items.map((item) => { + return { + ...item, + enabled: !this.props.disabledItems.includes(item.id), + } + })); + } + + done() { + this.props.close(); + } + + onChange(checked, changedItem) { + changedItem.enabled = checked; + const newDisabledItems = Object.values(this.items).filter( + (item) => !item.enabled + ).map((item) => item.id) + + browser.localStorage.setItem( + "disabledDashboardItems", + newDisabledItems, + ); + + this.props.onUpdateConfiguration(newDisabledItems); + } + +} + + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss index a1281d8303e..90e1493325f 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.scss +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -1,3 +1,3 @@ .o_dashboard { background-color: grey; -} \ No newline at end of file +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml index 469d6fd381c..4114bc55f9f 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -7,28 +7,36 @@ + + +
    - - Number of new orders this month - - - Total amount of new orders this month - - - Average amount of t-shirt by order this month - - - Number of cancelled orders this month - - - Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’ - - - Shirt orders by size - - + + + + + +
    + + + + Which cards do you whish to see ? + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml index 768719886a5..ec35c48d323 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -1,15 +1,10 @@ -
    -
    -

    -
    - -
    + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js new file mode 100644 index 00000000000..a8642967e34 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,67 @@ +/** @odoo-module **/ + +import { NumberCard } from "./number_card/number_card" +import { PieChartCard } from "./pie_chart_card/pie_chart_card" +import { registry } from "@web/core/registry"; + +export const items = [ + { + id: "average_quantity", + description: "Average amount of t-shirt", + Component: NumberCard, + props: (data) => ({ + title: "Average amount of t-shirt by order this month", + value: data.average_quantity, + }) + }, + { + id: "average_time", + description: "Average time for an order", + Component: NumberCard, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + value: data.average_time, + }) + }, + { + id: "number_new_orders", + description: "New orders this month", + Component: NumberCard, + props: (data) => ({ + title: "Number of new orders this month", + value: data.nb_new_orders, + }) + }, + { + id: "cancelled_orders", + description: "Cancelled orders this month", + Component: NumberCard, + props: (data) => ({ + title: "Number of cancelled orders this month", + value: data.nb_cancelled_orders, + }) + }, + { + id: "amount_new_orders", + description: "amount orders this month", + Component: NumberCard, + props: (data) => ({ + title: "Total amount of new orders this month", + value: data.total_amount, + }) + }, + { + id: "pie_chart", + description: "Shirt orders by size", + Component: PieChartCard, + size: 2, + props: (data) => ({ + title: "Shirt orders by size", + values: data.orders_by_size, + }) + } +] + +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id,item) +}) diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.js b/awesome_dashboard/static/src/dashboard/number_card/number_card.js new file mode 100644 index 00000000000..98122393699 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,11 @@ +import { Component} from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + + static props = { + title: String, + value: Number, + }; + +} diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..e5071bec301 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,11 @@ + + + +
    + +
    +

    +
    +
    +
    +
    diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..3c532abae73 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,13 @@ +import { Component} from "@odoo/owl"; +import { PieChart } from "../pie_chart/pie_chart"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = {PieChart} + + static props = { + title: String, + values: Object, + }; + +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.xml new file mode 100644 index 00000000000..819f0c5000a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.xml @@ -0,0 +1,7 @@ + + + + + + + From e0c81e233f8388b5bd6abb91e6b9ff86c6042a96 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Thu, 26 Jun 2025 10:02:14 +0200 Subject: [PATCH 17/18] [FIX] Fixing ruff --- estate/__init__.py | 1 - estate/__manifest__.py | 1 - estate/models/estate_property.py | 30 ++++++++++----------- estate/models/estate_property_offer.py | 34 ++++++++++++------------ estate/models/estate_property_tag.py | 6 ++--- estate/models/estate_property_type.py | 11 ++++---- estate/models/inherited_model.py | 4 +-- estate/views/estate_kanban_view.xml | 2 +- estate_account/__init__.py | 1 - estate_account/__manifest__.py | 2 +- estate_account/models/__init__.py | 2 +- estate_account/models/estate_property.py | 4 +-- 12 files changed, 48 insertions(+), 50 deletions(-) diff --git a/estate/__init__.py b/estate/__init__.py index 899bcc97f0f..0650744f6bc 100644 --- a/estate/__init__.py +++ b/estate/__init__.py @@ -1,2 +1 @@ from . import models - diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 908f87661b3..4fa3963872c 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -24,4 +24,3 @@ }, 'license': 'LGPL-3', } - diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 03f83eaaeb1..d17615d9d24 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,8 +1,9 @@ from odoo import api, fields, models from odoo.exceptions import UserError, ValidationError -from odoo.tools.float_utils import float_compare, float_is_zero, float_round +from odoo.tools.float_utils import float_compare from dateutil.relativedelta import relativedelta + class EstateProperty(models.Model): _name = "estate.property" _description = "Real estate properties" @@ -14,13 +15,13 @@ def _unlink_except_new_or_cancelled(self): if property.state == 'new' or property.state == 'cancelled': raise UserError("Can't delete a property that is new or cancelled!") - name = fields.Char("Estate name",required=True) + name = fields.Char("Estate name", required=True) description = fields.Text("Description") postcode = fields.Char("Postcode") - date_availability = fields.Date("Date availability",default=fields.Date.today() + relativedelta(months=3),copy=False) + date_availability = fields.Date("Date availability", default=fields.Date.today() + relativedelta(months=3), copy=False) expected_price = fields.Float("Expected price") - selling_price = fields.Float("Selling price",readonly=True,copy=False) - bedrooms = fields.Integer("Number of bedrooms",default=2) + selling_price = fields.Float("Selling price", readonly=True, copy=False) + bedrooms = fields.Integer("Number of bedrooms", default=2) living_area = fields.Integer("Living area (sqm)") facades = fields.Integer("Facades") garage = fields.Boolean("Garage") @@ -31,7 +32,7 @@ def _unlink_except_new_or_cancelled(self): selection=[('north', "North"), ('south', "South"), ('east', "East"), ('west', "West")], help="This Type is used to tell the garden orientation for a property" ) - active = fields.Boolean("Active",default=True) + active = fields.Boolean("Active", default=True) state = fields.Selection( string='State', selection=[('new', "New"), ('offer_received', "Offer received"), ('offer_accepted', "Offer Accepted"), ('sold', "Sold"), ('cancelled', "Canceled")], @@ -44,7 +45,7 @@ def _unlink_except_new_or_cancelled(self): salesperson_id = fields.Many2one('res.users') buyer_id = fields.Many2one('res.partner') tag_ids = fields.Many2many('estate.property.tag') - offers_ids = fields.One2many('estate.property.offer','property_id',string="Offers") + offers_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") total_area = fields.Integer(compute='_compute_total') best_price = fields.Float(compute='_compute_best_price') @@ -60,7 +61,7 @@ def _unlink_except_new_or_cancelled(self): 'The selling price has to be >= 0') ] - @api.depends('living_area','garden_area') + @api.depends('living_area', 'garden_area') def _compute_total(self): self.total_area = self.garden_area + self.living_area @@ -82,23 +83,22 @@ def _onchange_garden(self): def action_sold(self): for record in self: - if not record.state == "cancelled": + if record.state != "cancelled": record.state = "sold" else: raise UserError("You can't sold an house that has been cancelled") return True - + def action_cancel(self): for record in self: - if not record.state == "sold": + if record.state != "sold": record.state = "cancelled" else: raise UserError("You can't cancel an house that has already been sold") return True - - @api.constrains('selling_price','expected_price') + + @api.constrains('selling_price', 'expected_price') def _check_selling_price(self): for record in self: - if record.selling_price != 0 and float_compare(record.selling_price,record.expected_price*0.9,precision_rounding=2) < 0: + if record.selling_price != 0 and float_compare(record.selling_price, record.expected_price * 0.9, precision_rounding=2) < 0: raise ValidationError("The selling price must be equal or higher than 90% of the selling price.") - diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 731200f3821..38ff4457746 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,5 +1,4 @@ -from odoo import fields,models,api -from odoo.exceptions import UserError +from odoo import fields, models, api from dateutil.relativedelta import relativedelta @@ -8,24 +7,27 @@ class EstatePropertyOffer(models.Model): _description = "Real estate properties offers" _order = "price desc" - @api.model + @api.model_create_multi def create(self, vals): - if self.env['estate.property'].browse(vals['property_id']).state == 'new': - self.env['estate.property'].browse(vals['property_id']).state = 'offer_received' - return super(EstatePropertyOffer,self).create(vals) + for val in vals: + val_property_id = val.get('property_id') + property = self.env['estate.property'].browse(val_property_id) + if property.state == 'new': + property.state = 'offer_received' + return super().create(vals) - price = fields.Float("Price",required=True) + price = fields.Float("Price", required=True) status = fields.Selection( string='Status', selection=[('accepted', "Accepted"), ('refused', "Refused")], - help="This selection is used to tell whether buying offer is accepted or refused" + help="This selection is used to tell whether buying offer is accepted or refused" ) partner_id = fields.Many2one('res.partner') property_id = fields.Many2one('estate.property') validity = fields.Integer(default=7) create_date = fields.Date(default=fields.Date.today()) - date_deadline = fields.Date(compute='_compute_deadline',inverse='_inverse_validity') + date_deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_validity') property_type_id = fields.Many2one(related='property_id.property_type_id', store=True) @@ -40,9 +42,8 @@ def _compute_deadline(self): if record.create_date: record.date_deadline = record.create_date + relativedelta(days=record.validity) else: - record.date_deadline = fields.Date.today()+ relativedelta(days=record.validity) - - + record.date_deadline = fields.Date.today() + relativedelta(days=record.validity) + def _inverse_validity(self): for record in self: if record.create_date: @@ -53,15 +54,14 @@ def _inverse_validity(self): def action_confirm_offer(self): for record in self: if not record.status: - record.status = 'accepted' + record.status = 'accepted' record.property_id.buyer_id = record.partner_id record.property_id.selling_price = record.price record.property_id.state = 'offer_accepted' - return True - + def action_refuse_offer(self): for record in self: if not record.status: - record.status = 'refused' - return True \ No newline at end of file + record.status = 'refused' + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py index e1cb40234c8..6dc59239dcf 100644 --- a/estate/models/estate_property_tag.py +++ b/estate/models/estate_property_tag.py @@ -1,14 +1,14 @@ -from odoo import fields,models +from odoo import fields, models + class EstatePropertyTag(models.Model): _name = "estate.property.tag" _description = "Real estate properties tags" _order = "name" - name = fields.Char("Name",required=True) + name = fields.Char("Name", required=True) color = fields.Integer("Color") _sql_constraints = [ ('name_unique', 'unique(name)', 'Each name must be unique.'), ] - diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py index ebbe6f993fa..da56168854b 100644 --- a/estate/models/estate_property_type.py +++ b/estate/models/estate_property_type.py @@ -1,15 +1,16 @@ -from odoo import fields,models,api +from odoo import fields, models, api + class EstatePropertyType(models.Model): _name = "estate.property.type" _description = "Real estate properties types" _order = "sequence, name" - name = fields.Char("Name",required=True) - property_ids = fields.One2many('estate.property','property_type_id') + name = fields.Char("Name", required=True) + property_ids = fields.One2many('estate.property', 'property_type_id') sequence = fields.Integer("Sequence", default=1, help="Used to order stages. Lower is better.") - offer_ids = fields.One2many('estate.property.offer','property_type_id') + offer_ids = fields.One2many('estate.property.offer', 'property_type_id') offer_count = fields.Integer(compute='_compute_count') _sql_constraints = [ @@ -21,4 +22,4 @@ def _compute_count(self): self.offer_count = len(self.offer_ids) def go_to_offer_button(self): - return True \ No newline at end of file + return True diff --git a/estate/models/inherited_model.py b/estate/models/inherited_model.py index 73a1e7327ed..45d9b8a2e6e 100644 --- a/estate/models/inherited_model.py +++ b/estate/models/inherited_model.py @@ -1,4 +1,5 @@ -from odoo import fields,models +from odoo import fields, models + class InheritedModel(models.Model): _inherit = "res.users" @@ -6,4 +7,3 @@ class InheritedModel(models.Model): property_ids = fields.One2many(comodel_name='estate.property', inverse_name='salesperson_id', domain=[("state", "in", ['new', 'offer_received'])]) - \ No newline at end of file diff --git a/estate/views/estate_kanban_view.xml b/estate/views/estate_kanban_view.xml index 734cd763473..afc78f44f18 100644 --- a/estate/views/estate_kanban_view.xml +++ b/estate/views/estate_kanban_view.xml @@ -7,7 +7,7 @@ - +
    diff --git a/estate_account/__init__.py b/estate_account/__init__.py index 899bcc97f0f..0650744f6bc 100644 --- a/estate_account/__init__.py +++ b/estate_account/__init__.py @@ -1,2 +1 @@ from . import models - diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py index 7a58e49aa50..4e48e0e6aee 100644 --- a/estate_account/__manifest__.py +++ b/estate_account/__manifest__.py @@ -13,4 +13,4 @@ 'security/ir.model.access.csv', ], 'license': 'LGPL-3', -} \ No newline at end of file +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py index f4c8fd6db6d..5e1963c9d2f 100644 --- a/estate_account/models/__init__.py +++ b/estate_account/models/__init__.py @@ -1 +1 @@ -from . import estate_property \ No newline at end of file +from . import estate_property diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py index 537a4975286..621a1e15428 100644 --- a/estate_account/models/estate_property.py +++ b/estate_account/models/estate_property.py @@ -1,4 +1,4 @@ -from odoo import Command, fields, models +from odoo import Command, models class EstateProperty(models.Model): @@ -25,4 +25,4 @@ def _create_account_move(self): 'price_unit': 100, }) ], - }) \ No newline at end of file + }) From d2bc9b0cbf0b6a48870f7bede5dbf10ec6138376 Mon Sep 17 00:00:00 2001 From: Nicolas Renard Date: Mon, 30 Jun 2025 10:28:11 +0200 Subject: [PATCH 18/18] [ADD] Unit test --- estate/models/estate_property.py | 2 ++ estate/models/estate_property_offer.py | 3 ++ estate/tests/__init__.py | 1 + estate/tests/test_estate.py | 40 ++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 estate/tests/__init__.py create mode 100644 estate/tests/test_estate.py diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index d17615d9d24..e05e35b1aa1 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -87,6 +87,8 @@ def action_sold(self): record.state = "sold" else: raise UserError("You can't sold an house that has been cancelled") + if not record.offers_ids: + raise UserError("There are no offers on this property, thus it can't be sold") return True def action_cancel(self): diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 38ff4457746..8d7790121ea 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,4 +1,5 @@ from odoo import fields, models, api +from odoo.exceptions import UserError from dateutil.relativedelta import relativedelta @@ -14,6 +15,8 @@ def create(self, vals): property = self.env['estate.property'].browse(val_property_id) if property.state == 'new': property.state = 'offer_received' + elif property.state == 'sold': + raise UserError("Can't create an offer on a solded property") return super().create(vals) price = fields.Float("Price", required=True) diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..dfd37f0be11 --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_estate diff --git a/estate/tests/test_estate.py b/estate/tests/test_estate.py new file mode 100644 index 00000000000..df98975472f --- /dev/null +++ b/estate/tests/test_estate.py @@ -0,0 +1,40 @@ +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError +from odoo.tests import tagged + + +# The CI will run these tests after all the modules are installed, +# not right after installing the one defining it. +@tagged('post_install', '-at_install') +class EstateTestCase(TransactionCase): + + @classmethod + def setUpClass(cls): + # add env on cls and many other things + super().setUpClass() + + # create the data for each tests. By doing it in the setUpClass instead + # of in a setUp or in each test case, we reduce the testing time and + # the duplication of code. + cls.properties = cls.env['estate.property'].create({'name': 'test'}) + + def test_creation_area(self): + """Test that the total_area is computed like it should.""" + self.properties.living_area = 20 + self.assertRecordValues(self.properties, [ + {'name': 'test', 'total_area': '20'}, + ]) + + def test_create_offer_for_solded_property(self): + """Test that offers can't be create for solded properties.""" + self.properties.state = 'sold' + with self.assertRaises(UserError, msg="Should not be able to create an offer for a sold property"): + self.env['estate.property.offer'].create({ + 'property_id': self.properties.id, + 'price': 150000.0, + }) + + def test_sell_property_with_no_offers(self): + """Test that offers can't be create for solded properties.""" + with self.assertRaises(UserError, msg="Should not be able to sell a property with no offers"): + self.properties.action_sold()