From 3e5bf34dd12de70ce886a3da51e97678c6f8db74 Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Thu, 5 Dec 2024 22:34:49 +0530 Subject: [PATCH 01/16] Created a model, manifest and init files --- estate/__init__.py | 2 ++ estate/__manifest__.py | 14 ++++++++++++++ estate/models/__init__.py | 1 + estate/models/estate_property.py | 7 +++++++ 4 files changed, 24 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 diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 0000000000..635d180cc3 --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import estate_property diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 0000000000..05e46e0f00 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,14 @@ +{ + 'name': 'estate', + + 'category': 'real estate', + + 'summary': 'create a estate property', + + 'website': 'https://www.odoo.com', + + 'depends': ['base'], + 'installable': True, + 'application': True, + 'license': 'LGPL-3', +} \ No newline at end of file diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 0000000000..5e1963c9d2 --- /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 0000000000..d1b83a2ecc --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,7 @@ +from odoo import models, fields + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + +# more to understand \ No newline at end of file From 5b7168634b2e6d5b73a30389c6e677ff533a0f00 Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Fri, 6 Dec 2024 11:40:25 +0530 Subject: [PATCH 02/16] [ADD] estate: creating a estate model it contain information related to model. It is based on estate application. --- estate/__init__.py | 2 +- estate/models/estate_property.py | 10 +++++++--- estate/models/fields.sql | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 estate/models/fields.sql diff --git a/estate/__init__.py b/estate/__init__.py index 635d180cc3..899bcc97f0 100644 --- a/estate/__init__.py +++ b/estate/__init__.py @@ -1,2 +1,2 @@ from . import models -from . import estate_property + diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index d1b83a2ecc..0149f1d8f0 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,7 +1,11 @@ from odoo import models, fields class EstateProperty(models.Model): - _name = "estate.property" - _description = "Real Estate Property" + _name = "test_model" + _description = "Test Model" + name = fields.Char(name ='table') + + + + -# more to understand \ No newline at end of file diff --git a/estate/models/fields.sql b/estate/models/fields.sql new file mode 100644 index 0000000000..84753754a7 --- /dev/null +++ b/estate/models/fields.sql @@ -0,0 +1,2 @@ +$ psql -d rd-demo +rd-demo=# \d estate_property From 817879458f56dd84af16ef47d30c8c0a7a6bf50f Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Fri, 6 Dec 2024 18:53:01 +0530 Subject: [PATCH 03/16] [IMP] estate: updated information for estate It covers different chapters of real estate. It has various updated features. --- estate/__manifest__.py | 7 ++++ estate/models/estate_property.py | 38 +++++++++++++++++-- estate/security/ir.model.access.csv | 2 + estate/views/estate_menus.xml | 7 ++++ estate/views/estate_property_views.xml | 52 ++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 3 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 05e46e0f00..b5cd523466 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -11,4 +11,11 @@ 'installable': True, 'application': True, 'license': 'LGPL-3', + + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_menus.xml', + ], + } \ No newline at end of file diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 0149f1d8f0..c50056c0b4 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,9 +1,41 @@ from odoo import models, fields +from datetime import timedelta, date class EstateProperty(models.Model): - _name = "test_model" - _description = "Test Model" - name = fields.Char(name ='table') + _name = "estate.property" + _description = "Real Estate Property" + name = fields.Char(required=True) + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + date_availability = fields.Date(copy=False, default=lambda self: date.today() + timedelta(days=90)) + expected_price = fields.Float(string="Expected Price", required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + active = fields.Boolean(default=True) + living_area = fields.Integer(string="Living Area (sqm)") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage Available") + garden = fields.Boolean(string="Garden Available") + garden_area = fields.Integer(string="Garden Area (sqm)") + garden_orientation = fields.Selection( + string="Garden Orientation", + selection=[ + ('north', "North"), + ('south', "South"), + ('east', "East"), + ('west', "West") + ] + ) + state = fields.Selection([ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled') + ], 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 0000000000..a6992df6d3 --- /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_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 0000000000..49cb5f5b2e --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 0000000000..3f88d5653b --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,52 @@ + + + + estate.property.list + estate.property + + + + + + + + + + + + + + estate.property.form + estate.property + +
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ + Estate Property + estate.property + list,form + + +
\ No newline at end of file From 4167f29a8f8714b511c1c62af147e3c6bcf9607d Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Mon, 9 Dec 2024 19:06:00 +0530 Subject: [PATCH 04/16] [IMP] estate: created views It has various views with many to one and many to many fields. --- estate/__init__.py | 2 + estate/__manifest__.py | 3 +- estate/models/__init__.py | 2 + estate/models/estate_advertisement.py | 1 + estate/models/estate_property.py | 3 +- estate/models/estate_property_type.py | 0 estate/models/estate_settings.py | 9 ++++ estate/views/estate_advertisement_views.xml | 0 estate/views/estate_menu_type.xml | 0 estate/views/estate_menus.xml | 9 ++-- estate/views/estate_property_type_views.xml | 0 estate/views/estate_property_views.xml | 54 ++++++++++++++++----- estate/views/estate_settings_views.xml | 22 +++++++++ 13 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 estate/models/estate_advertisement.py create mode 100644 estate/models/estate_property_type.py create mode 100644 estate/models/estate_settings.py create mode 100644 estate/views/estate_advertisement_views.xml create mode 100644 estate/views/estate_menu_type.xml create mode 100644 estate/views/estate_property_type_views.xml create mode 100644 estate/views/estate_settings_views.xml diff --git a/estate/__init__.py b/estate/__init__.py index 899bcc97f0..9405915fa4 100644 --- a/estate/__init__.py +++ b/estate/__init__.py @@ -1,2 +1,4 @@ from . import models + + diff --git a/estate/__manifest__.py b/estate/__manifest__.py index b5cd523466..64723f51c7 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -15,7 +15,8 @@ 'data': [ 'security/ir.model.access.csv', 'views/estate_property_views.xml', - 'views/estate_menus.xml', + 'views/estate_settings_views.xml', + 'views/estate_menus.xml' ], } \ No newline at end of file diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 5e1963c9d2..fc2e9bef49 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -1 +1,3 @@ from . import estate_property +from . import estate_property_type +from . import estate_settings \ No newline at end of file diff --git a/estate/models/estate_advertisement.py b/estate/models/estate_advertisement.py new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/estate/models/estate_advertisement.py @@ -0,0 +1 @@ + diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index c50056c0b4..e3e62cd215 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -9,7 +9,7 @@ class EstateProperty(models.Model): postcode = fields.Char(string="Postcode") date_availability = fields.Date(copy=False, default=lambda self: date.today() + timedelta(days=90)) expected_price = fields.Float(string="Expected Price", required=True) - selling_price = fields.Float(readonly=True, copy=False) + selling_price = fields.Float(copy=False) bedrooms = fields.Integer(default=2) active = fields.Boolean(default=True) living_area = fields.Integer(string="Living Area (sqm)") @@ -33,7 +33,6 @@ class EstateProperty(models.Model): ('sold', 'Sold'), ('cancelled', 'Cancelled') ], required=True, copy=False, default='new') - diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/estate/models/estate_settings.py b/estate/models/estate_settings.py new file mode 100644 index 0000000000..14f420f14c --- /dev/null +++ b/estate/models/estate_settings.py @@ -0,0 +1,9 @@ +from odoo import models, fields + +class EstateSettings(models.Model): + _name = 'estate.settings' + _description = 'Estate Settings' + + default_property_type = fields.Char(string="Default Property Type") + enable_notifications = fields.Boolean(string="Enable Notifications") + diff --git a/estate/views/estate_advertisement_views.xml b/estate/views/estate_advertisement_views.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/estate/views/estate_menu_type.xml b/estate/views/estate_menu_type.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index 49cb5f5b2e..379e4a056c 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -1,7 +1,10 @@ - - - + + + + + + diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 3f88d5653b..0f6d5941ec 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -5,13 +5,14 @@ estate.property - - + - - - + + + + + @@ -23,30 +24,59 @@ - - + + + - + + + + - + - + + + + + + + + + + + - - + + + + estate.property.search + estate.property + + + + + + + + + + + Estate Property estate.property list,form + \ No newline at end of file diff --git a/estate/views/estate_settings_views.xml b/estate/views/estate_settings_views.xml new file mode 100644 index 0000000000..1fcc06dea1 --- /dev/null +++ b/estate/views/estate_settings_views.xml @@ -0,0 +1,22 @@ + + + Settings + estate.settings + form + + + + estate.settings.form + estate.settings + +
+ + + + + + +
+
+
+
\ No newline at end of file From a3687ebb09febfdb2512f6d2accdc25ca6b620ea Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Tue, 10 Dec 2024 19:11:35 +0530 Subject: [PATCH 05/16] [IMP] estate: added various attributes It has information related to compute fields. --- estate/__manifest__.py | 6 ++- estate/models/__init__.py | 5 +- estate/models/best_price.py | 0 estate/models/estate_best.py | 13 +++++ estate/models/estate_property.py | 22 +++++--- estate/models/estate_property_offer | 0 estate/models/estate_property_offer.py | 12 +++++ estate/models/estate_property_tags.py | 6 +++ estate/models/estate_property_type.py | 8 +++ estate/models/estate_settings.py | 18 ++++--- estate/views/estate_best_views.xml | 16 ++++++ estate/views/estate_menu_type.xml | 17 ++++++ estate/views/estate_menus.xml | 17 +++--- estate/views/estate_property_offer_views.xml | 20 ++++++++ estate/views/estate_property_tags_views.xml | 30 +++++++++++ estate/views/estate_property_type_views.xml | 49 ++++++++++++++++++ estate/views/estate_property_views.xml | 54 ++++++++++++-------- estate/views/estate_settings_views.xml | 22 -------- 18 files changed, 249 insertions(+), 66 deletions(-) create mode 100644 estate/models/best_price.py create mode 100644 estate/models/estate_best.py create mode 100644 estate/models/estate_property_offer create mode 100644 estate/models/estate_property_offer.py create mode 100644 estate/models/estate_property_tags.py create mode 100644 estate/views/estate_best_views.xml create mode 100644 estate/views/estate_property_offer_views.xml create mode 100644 estate/views/estate_property_tags_views.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 64723f51c7..47c6dcfcac 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -15,7 +15,11 @@ 'data': [ 'security/ir.model.access.csv', 'views/estate_property_views.xml', - 'views/estate_settings_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tags_views.xml', + #'views/estate_property_offer_views.xml', + 'views/estate_menu_type_xml', + 'views/estate_best_views.xml', 'views/estate_menus.xml' ], diff --git a/estate/models/__init__.py b/estate/models/__init__.py index fc2e9bef49..9af2f4db1d 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_settings \ No newline at end of file +from . import estate_property_tags +from . import estate_property_offer +from . import estate_settings +from . import estate_best \ No newline at end of file diff --git a/estate/models/best_price.py b/estate/models/best_price.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/estate/models/estate_best.py b/estate/models/estate_best.py new file mode 100644 index 0000000000..90efc69ae8 --- /dev/null +++ b/estate/models/estate_best.py @@ -0,0 +1,13 @@ +from odoo import models, fields, api + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate Property' + + offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") + best_price = fields.Float(string="Best Price", compute="_compute_best_price", store=True) + + @api.depends('offer_ids.price') + def _compute_best_price(self): + for record in self: + record.best_price = max(record.offer_ids.mapped('price'), default=0) \ No newline at end of file diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index e3e62cd215..d73221ec52 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -32,11 +32,17 @@ class EstateProperty(models.Model): ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('cancelled', 'Cancelled') - ], required=True, copy=False, default='new') - - - - - - - + ], required=True, copy=False, default='new') + property_type_id = fields.Many2one('estate.property.type', string="Property Type") + buyer_id = fields.Many2one('res.partner', string="Buyer") + seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) + name = fields.Char(string="Tag", required=True) + status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") + partner_id = fields.Many2one('res.partner', string="Partner", required=True) + salesperson = fields.Char(string = "Salesperson", required=True) + buyer = fields.Char(string = "Buyers", required=True) + price = fields.Float(string="Price") + partners = fields.Char(string = "Partner", required=True) + Tag = fields.Many2one('estate.property.tag' , string="Tags") + total_area = fields.Float(string="Total Area (sqm)", compute="_compute_total_area", store=True) + best_offers = fields.Float(string="Best Offers") diff --git a/estate/models/estate_property_offer b/estate/models/estate_property_offer new file mode 100644 index 0000000000..e69de29bb2 diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 0000000000..ca123107bc --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,12 @@ +from odoo import models, fields +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Real Estate Property Offer' + + price = fields.Float(string="Price", required=True) + status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") + partner_id = fields.Many2one('res.partner', string="Partner", required=True) + property_id = fields.Many2one('estate.property', string="Property", required=True) + + + diff --git a/estate/models/estate_property_tags.py b/estate/models/estate_property_tags.py new file mode 100644 index 0000000000..66a624c2ff --- /dev/null +++ b/estate/models/estate_property_tags.py @@ -0,0 +1,6 @@ +from odoo import models, fields +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Real Estate Property Tag' + + name = fields.Char(string="Tag Name", required=True) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py index e69de29bb2..4bd6ad2fdb 100644 --- a/estate/models/estate_property_type.py +++ b/estate/models/estate_property_type.py @@ -0,0 +1,8 @@ +from odoo import models, fields +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Real Estate Property Type' + name = fields.Char(string="Property Type", required=True) + property_type_id = fields.Many2one('estate.property.type', string="Property Type") + buyer_id = fields.Many2one('res.partner', string="Buyer") + seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) diff --git a/estate/models/estate_settings.py b/estate/models/estate_settings.py index 14f420f14c..4f5b53a616 100644 --- a/estate/models/estate_settings.py +++ b/estate/models/estate_settings.py @@ -1,9 +1,15 @@ -from odoo import models, fields +from odoo import models, fields, api +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate Property' -class EstateSettings(models.Model): - _name = 'estate.settings' - _description = 'Estate Settings' + living_area = fields.Float(string="Living Area (sqm)") + garden_area = fields.Float(string="Garden Area (sqm)") + total_area = fields.Float(string="Total Area (sqm)", compute="_compute_total_area", store=True) + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = (record.living_area or 0) + (record.garden_area or 0) - default_property_type = fields.Char(string="Default Property Type") - enable_notifications = fields.Boolean(string="Enable Notifications") diff --git a/estate/views/estate_best_views.xml b/estate/views/estate_best_views.xml new file mode 100644 index 0000000000..6814403dfe --- /dev/null +++ b/estate/views/estate_best_views.xml @@ -0,0 +1,16 @@ + + + estate.property.form + estate.property.best + +
+ + + + + + +
+
+
+
\ No newline at end of file diff --git a/estate/views/estate_menu_type.xml b/estate/views/estate_menu_type.xml index e69de29bb2..ee018aa0bf 100644 --- a/estate/views/estate_menu_type.xml +++ b/estate/views/estate_menu_type.xml @@ -0,0 +1,17 @@ + + + estate.property.form + estate.property.prop + +
+ + + + + + + +
+
+
+
\ No newline at end of file diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index 379e4a056c..8025ddd9d4 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -1,10 +1,11 @@ - - - + - - - - - + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 0000000000..c7c985733e --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,20 @@ + + + estate.property.offers + estate.property.offer + +
+ + + + + + + + + + +
+
+
+
diff --git a/estate/views/estate_property_tags_views.xml b/estate/views/estate_property_tags_views.xml new file mode 100644 index 0000000000..5c1a3c0f9c --- /dev/null +++ b/estate/views/estate_property_tags_views.xml @@ -0,0 +1,30 @@ + + + Property Tags + estate.property.tag + list,form + + + estate.property.tag.form + estate.property.tag + +
+ + + + + +
+
+
+ + + estate.property.tag.list + estate.property.tag + + + + + + +
\ No newline at end of file diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml index e69de29bb2..42e6d2d64c 100644 --- a/estate/views/estate_property_type_views.xml +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,49 @@ + + + Property Types + estate.property.type + list,form + + + estate.property.type.form + estate.property.type + +
+ + + + + +
+
+
+ + estate.property.type.list + estate.property.type + + + + + + + + + + + +
\ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 0f6d5941ec..cfbcbde11f 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -11,7 +11,7 @@ - + @@ -24,34 +24,50 @@ - + + + - + - + + - + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -76,7 +92,5 @@ Estate Property estate.property list,form - - -
\ No newline at end of file + diff --git a/estate/views/estate_settings_views.xml b/estate/views/estate_settings_views.xml index 1fcc06dea1..e69de29bb2 100644 --- a/estate/views/estate_settings_views.xml +++ b/estate/views/estate_settings_views.xml @@ -1,22 +0,0 @@ - - - Settings - estate.settings - form - - - - estate.settings.form - estate.settings - -
- - - - - - -
-
-
-
\ No newline at end of file From 56dbb8bce55e9ddfa3dd062c0851fe0a66751cd3 Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Wed, 11 Dec 2024 10:13:33 +0530 Subject: [PATCH 06/16] updated info --- estate/__manifest__.py | 6 +++--- estate/models/__init__.py | 8 ++++---- estate/models/estate_property.py | 4 ++-- estate/views/estate_menu_type.xml | 2 +- estate/views/estate_menus.xml | 15 ++++++--------- estate/views/estate_property_type_views.xml | 12 ++++++------ estate/views/estate_property_views.xml | 13 ++++++------- 7 files changed, 28 insertions(+), 32 deletions(-) diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 47c6dcfcac..cd5c1b4e90 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -16,10 +16,10 @@ 'security/ir.model.access.csv', 'views/estate_property_views.xml', 'views/estate_property_type_views.xml', - 'views/estate_property_tags_views.xml', + # 'views/estate_property_tags_views.xml', #'views/estate_property_offer_views.xml', - 'views/estate_menu_type_xml', - 'views/estate_best_views.xml', + # 'views/estate_menu_type_xml', + # 'views/estate_best_views.xml', 'views/estate_menus.xml' ], diff --git a/estate/models/__init__.py b/estate/models/__init__.py index 9af2f4db1d..5d2889b77f 100644 --- a/estate/models/__init__.py +++ b/estate/models/__init__.py @@ -1,6 +1,6 @@ from . import estate_property from . import estate_property_type -from . import estate_property_tags -from . import estate_property_offer -from . import estate_settings -from . import estate_best \ No newline at end of file +# from . import estate_property_tags +# from . import estate_property_offer +# from . import estate_settings +# from . import estate_best \ No newline at end of file diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index d73221ec52..3dcf910ad4 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -36,13 +36,13 @@ class EstateProperty(models.Model): property_type_id = fields.Many2one('estate.property.type', string="Property Type") buyer_id = fields.Many2one('res.partner', string="Buyer") seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) - name = fields.Char(string="Tag", required=True) + # name = fields.Char(string="Tag", required=True) status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") partner_id = fields.Many2one('res.partner', string="Partner", required=True) salesperson = fields.Char(string = "Salesperson", required=True) buyer = fields.Char(string = "Buyers", required=True) price = fields.Float(string="Price") partners = fields.Char(string = "Partner", required=True) - Tag = fields.Many2one('estate.property.tag' , string="Tags") + tag = fields.Many2one('estate.property.tag' , string="Tags") total_area = fields.Float(string="Total Area (sqm)", compute="_compute_total_area", store=True) best_offers = fields.Float(string="Best Offers") diff --git a/estate/views/estate_menu_type.xml b/estate/views/estate_menu_type.xml index ee018aa0bf..c0680341f2 100644 --- a/estate/views/estate_menu_type.xml +++ b/estate/views/estate_menu_type.xml @@ -8,7 +8,7 @@ - + diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index 8025ddd9d4..b007aa18cd 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -1,11 +1,8 @@ - - - - - - - - - + + + + + + diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml index 42e6d2d64c..4b622676b4 100644 --- a/estate/views/estate_property_type_views.xml +++ b/estate/views/estate_property_type_views.xml @@ -1,10 +1,10 @@ - + + + - - - - - - - + \ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 9e46a16980..93d6069193 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -1,6 +1,12 @@ - + + Properties + estate.property + list,form + + + estate.property.list estate.property @@ -16,16 +22,23 @@ - + estate.property.form estate.property
+
+
- + + @@ -35,6 +48,7 @@ + @@ -47,8 +61,8 @@ - - + + @@ -63,6 +77,8 @@ + + @@ -73,7 +89,7 @@
- + estate.property.search estate.property @@ -86,10 +102,5 @@ - - - Estate Property - estate.property - list,form
diff --git a/estate/views/estate_settings_views.xml b/estate/views/estate_settings_views.xml deleted file mode 100644 index e69de29bb2..0000000000 From 7fafa5a49d9f5ff9fbd685cf24b1672c933709dd Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Thu, 12 Dec 2024 18:41:03 +0530 Subject: [PATCH 08/16] [IMP]estate: Added constraints. --- estate/models/estate_property.py | 37 ++++++++++++++++----- estate/models/estate_property_offer.py | 26 +++++++++------ estate/models/estate_property_type.py | 2 ++ estate/views/estate_property_tags_views.xml | 4 +-- estate/views/estate_property_type_views.xml | 29 +++++++--------- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 4174379ded..119f9b429a 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -3,6 +3,9 @@ from odoo import models, fields, api from odoo.exceptions import UserError from odoo.exceptions import ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + class EstateProperty(models.Model): _name = "estate.property" @@ -37,7 +40,6 @@ class EstateProperty(models.Model): property_type_id = fields.Many2one('estate.property.type', string="Property Type") buyer_id = fields.Many2one('res.partner', string="Buyer") seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) - # name = fields.Char(string="Tag", required=True) status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") partner_id = fields.Many2one('res.partner', string="Partner", required=True) salesperson = fields.Char(string = "Salesperson", required=True) @@ -58,6 +60,13 @@ class EstateProperty(models.Model): compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) + tag_ids = fields.Many2many( + 'estate.property.tag', + string='Tags' + ) + offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") + best_price = fields.Float(string="Best Price", compute="_compute_best_price", store=True) + @api.onchange('garden') def _onchange_garden(self): if self.garden: @@ -66,10 +75,7 @@ def _onchange_garden(self): else: self.garden_area = 0 self.garden_orientation = False - tag_ids = fields.Many2many( - 'estate.property.tag', - string='Tags' - ) + def action_cancel(self): for record in self: if record.state == 'sold': @@ -82,19 +88,19 @@ def action_sold(self): raise UserError("A cancelled property cannot be sold.") record.state = 'sold' - sql_constraints = [ + _sql_constraints = [ ('expected_price_positive', 'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'), ('selling_price_positive', 'CHECK(selling_price >= 0)', 'The selling price must be positive.') ] + @api.constrains('expected_price') def _check_expected_price(self): for record in self: if record.expected_price <= 0: raise ValidationError("The expected price must be strictly positive.") - offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") - best_price = fields.Float(string="Best Price", compute="_compute_best_price", store=True) + @api.depends('offer_ids.price') def _compute_best_price(self): @@ -104,4 +110,17 @@ def _compute_best_price(self): @api.depends('living_area', 'garden_area') def _compute_total_area(self): for record in self: - record.total_area = (record.living_area or 0) + (record.garden_area or 0) \ No newline at end of file + record.total_area = (record.living_area or 0) + (record.garden_area or 0) + + @api.constrains('expected_price', 'selling_price') + def _check_selling_price(self): + for record in self: + if float_is_zero(record.selling_price, precision_rounding=0.01): + continue + min_price = record.expected_price * 0.9 + if float_compare(record.selling_price, min_price, precision_rounding=0.01) < 0: + raise ValidationError( + "The selling price cannot be lower than 90% of the expected price." + ) + + \ No newline at end of file diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index e28c20bb68..7e7b4e37a4 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -50,19 +50,23 @@ def _inverse_date_deadline(self): else: record.validity = 7 def action_accept(self): - for record in self: - if record.property_id.state == 'sold': - raise UserError("You cannot accept an offer for a sold property.") - record.property_id.buyer_id = record.partner_id - record.property_id.selling_price = record.price - record.property_id.state = 'sold' - record.property_id.offer_ids.filtered(lambda o: o.id != record.id).write({'state': 'refused'}) - record.state = 'accepted' + if self.property_id.state == 'sold': + raise UserError("Cannot accept offers for sold properties.") + existing_offer = self.search([ + ('property_id', '=', self.property_id.id), + ('status', '=', 'accepted') + ]) + if existing_offer: + raise UserError("Only one offer can be accepted per property.") + self.status = 'accepted' + self.property_id.selling_price = self.price + self.property_id.buyer_id = self.env.user.partner_id def action_refuse(self): - for record in self: - record.state = 'refused' -_sql_constraints = [ + if self.status == 'accepted': + raise UserError("Accepted offers cannot be refused.") + self.status = 'refused' + _sql_constraints = [ ('offer_price_positive', 'CHECK(price > 0)', 'The offer price must be strictly positive.') ] diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py index faa924d1d6..031e8295b3 100644 --- a/estate/models/estate_property_type.py +++ b/estate/models/estate_property_type.py @@ -6,6 +6,8 @@ class EstatePropertyType(models.Model): property_type_id = fields.Many2one('estate.property.type', string="Property Type") buyer_id = fields.Many2one('res.partner', string="Buyer") seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) + property_ids = fields.One2many('estate.property', 'property_type_id', string="Properties") + _sql_constraints = [ diff --git a/estate/views/estate_property_tags_views.xml b/estate/views/estate_property_tags_views.xml index 228f79bf71..26df67ae2f 100644 --- a/estate/views/estate_property_tags_views.xml +++ b/estate/views/estate_property_tags_views.xml @@ -4,7 +4,7 @@ estate.property.tag list,form - + estate.property.tag.form estate.property.tag @@ -19,7 +19,7 @@ - + estate.property.tag.list estate.property.tag diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml index a4aa0ab65d..9ff04a431c 100644 --- a/estate/views/estate_property_type_views.xml +++ b/estate/views/estate_property_type_views.xml @@ -8,11 +8,21 @@ estate.property.type.form estate.property.type -
+ + + + + + + + + + +
@@ -27,20 +37,5 @@
- - estate.property.type - estate.property.type - -
- - - - - - - - -
-
-
+ \ No newline at end of file From 17a1bb47dbdbf3786c922bfb81dd29a6aa067cc6 Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Fri, 13 Dec 2024 19:02:49 +0530 Subject: [PATCH 09/16] [IMP]estate: Added inline and widget. --- estate/models/estate_property.py | 11 +++-- estate/models/estate_property_offer.py | 4 +- estate/models/estate_property_tags.py | 1 + estate/models/estate_property_type.py | 13 ++++-- estate/security/ir.model.access.csv | 3 ++ estate/views/estate_menus.xml | 8 ++-- estate/views/estate_property_offer_views.xml | 5 ++- estate/views/estate_property_tags_views.xml | 4 +- estate/views/estate_property_type_views.xml | 46 ++++++++++---------- estate/views/estate_property_views.xml | 17 ++++---- 10 files changed, 65 insertions(+), 47 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 119f9b429a..41e2903664 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -10,6 +10,7 @@ class EstateProperty(models.Model): _name = "estate.property" _description = "Real Estate Property" + _order = 'id desc' name = fields.Char(required=True) description = fields.Text(string="Description") postcode = fields.Char(string="Postcode") @@ -31,12 +32,14 @@ class EstateProperty(models.Model): ('east', "East"), ('west', "West") ] - ) - state = fields.Selection([ + ) + state = fields.Selection(selection=[ ('new', 'New'), + ('received', 'Offer Received'), + ('accepted', 'Offer Accepted'), ('sold', 'Sold'), - ('refused', 'Refused') - ], string="Status",required=True, default='new') + ('cancelled', 'Cancelled'), + ], default='new', string="Status", copy=False) property_type_id = fields.Many2one('estate.property.type', string="Property Type") buyer_id = fields.Many2one('res.partner', string="Buyer") seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 7e7b4e37a4..ddf33e585d 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -7,8 +7,8 @@ class EstatePropertyOffer(models.Model): _name = 'estate.property.offer' _description = 'Real Estate Property Offer' - - price = fields.Float(string="Offer Price", required=True) + _order = 'price desc' + price = fields.Float() status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") partner_id = fields.Many2one('res.partner', string="Partner", required=True) property_id = fields.Many2one('estate.property', string="Property", required=True) diff --git a/estate/models/estate_property_tags.py b/estate/models/estate_property_tags.py index 0178fadaf8..70c72b2aa6 100644 --- a/estate/models/estate_property_tags.py +++ b/estate/models/estate_property_tags.py @@ -2,6 +2,7 @@ class EstatePropertyTag(models.Model): _name = 'estate.property.tag' _description = 'Real Estate Property Tag' + _order = "name" name = fields.Char(string="Tag Name", required=True) tag_ids = fields.Many2many( diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py index 031e8295b3..b3c39a5c40 100644 --- a/estate/models/estate_property_type.py +++ b/estate/models/estate_property_type.py @@ -2,14 +2,21 @@ class EstatePropertyType(models.Model): _name = 'estate.property.type' _description = 'Real Estate Property Type' + _order = "sequence,name" + sequence = fields.Integer(default=10) name = fields.Char(string="Type Name", required=True) property_type_id = fields.Many2one('estate.property.type', string="Property Type") buyer_id = fields.Many2one('res.partner', string="Buyer") seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) property_ids = fields.One2many('estate.property', 'property_type_id', string="Properties") - - - + expected_price = fields.Float(string="Expected Price", required=True) + state = fields.Selection(selection=[ + ('new', 'New'), + ('received', 'Offer Received'), + ('accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], default='new', string="Status", copy=False) _sql_constraints = [ ('unique_type_name', 'UNIQUE(name)', 'The property type name must be unique.') diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index a6992df6d3..f54c8c5950 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_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1 +estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,0,1,0 +estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,0,0,0 +estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,0,1,0 \ No newline at end of file diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index 6ff7c6d349..8b80a9506b 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -3,7 +3,7 @@ - - - - + + + + \ 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 c79f77d746..cf2d00b674 100644 --- a/estate/views/estate_property_offer_views.xml +++ b/estate/views/estate_property_offer_views.xml @@ -1,5 +1,6 @@ + - + estate.property.offers estate.property.offer @@ -26,7 +27,7 @@ - + estate.property.offer.list estate.property.offer diff --git a/estate/views/estate_property_tags_views.xml b/estate/views/estate_property_tags_views.xml index 26df67ae2f..4e0feb2220 100644 --- a/estate/views/estate_property_tags_views.xml +++ b/estate/views/estate_property_tags_views.xml @@ -1,3 +1,4 @@ + Property Tags @@ -25,7 +26,8 @@ - + + diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml index 9ff04a431c..0ed5abb2fc 100644 --- a/estate/views/estate_property_type_views.xml +++ b/estate/views/estate_property_type_views.xml @@ -1,41 +1,41 @@ + - + Property Types estate.property.type list,form - + estate.property.type.form estate.property.type -
- - - - - - - - - - - - - - + + +

+
+ + + + + + + + + + +
- + estate.property.type.list estate.property.type - - + + + - - -
\ No newline at end of file +
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 93d6069193..cd843d3fe7 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -27,18 +27,18 @@ estate.property
- -
+
+ +
+ - + - @@ -46,8 +46,7 @@ - - + @@ -72,6 +71,7 @@ + @@ -79,8 +79,9 @@ - + + From a4b2e365c173655f5b4966c84a5f33eda70c3d54 Mon Sep 17 00:00:00 2001 From: shai-odoo Date: Mon, 16 Dec 2024 18:56:29 +0530 Subject: [PATCH 10/16] [IMP]estate: Added the sprinkles and inheritance part. --- estate/models/estate_property.py | 44 +++++++++++-- estate/models/estate_property_offer.py | 65 +++++++++++++------ estate/models/estate_property_resusers.py | 10 +++ estate/models/estate_property_tags.py | 1 + estate/models/estate_property_type.py | 34 ++++++---- estate/security/ir.model.access.csv | 6 +- estate/views/estate_property_offer_views.xml | 20 +++--- .../views/estate_property_resusers_views.xml | 20 ++++++ estate/views/estate_property_tags_views.xml | 4 +- estate/views/estate_property_type_views.xml | 30 ++++++--- estate/views/estate_property_views.xml | 61 +++++++++++------ estate_account/__init__.py | 0 estate_account/__manifest__.py | 12 ++++ 13 files changed, 227 insertions(+), 80 deletions(-) create mode 100644 estate/models/estate_property_resusers.py create mode 100644 estate/views/estate_property_resusers_views.xml create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 41e2903664..2142f107b2 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -35,21 +35,22 @@ class EstateProperty(models.Model): ) state = fields.Selection(selection=[ ('new', 'New'), - ('received', 'Offer Received'), - ('accepted', 'Offer Accepted'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('cancelled', 'Cancelled'), ], default='new', string="Status", copy=False) - property_type_id = fields.Many2one('estate.property.type', string="Property Type") + property_type_id = fields.Many2one('estate.property.type', string="Property Type",required=True, + options={'no_create': True, 'no_edit': True}) buyer_id = fields.Many2one('res.partner', string="Buyer") - seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) + seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user,required=False) status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") - partner_id = fields.Many2one('res.partner', string="Partner", required=True) + partner_id = fields.Many2one('res.partner', string="Partner",required=True, ondelete='restrict') salesperson = fields.Char(string = "Salesperson", required=True) buyer = fields.Char(string = "Buyers", required=True) price = fields.Float(string="Price") partners = fields.Char(string = "Partner", required=True) - tag = fields.Many2one('estate.property.tag' , string="Tags") + tag_ids = fields.Many2one('estate.property.tag' , string="Tags") total_area = fields.Float(string="Total Area (sqm)", compute="_compute_total_area", store=True,copy=False) best_offers = fields.Float(string="Best Offers") offer_ids = fields.One2many( @@ -69,6 +70,10 @@ class EstateProperty(models.Model): ) offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") best_price = fields.Float(string="Best Price", compute="_compute_best_price", store=True) + offer_received = fields.Boolean(string="Offer Received", compute="_compute_offer_received", store=True) + offer_accepted = fields.Boolean(string="Offer Accepted", compute="_compute_offer_accepted", store=True) + + @api.onchange('garden') def _onchange_garden(self): @@ -125,5 +130,30 @@ def _check_selling_price(self): raise ValidationError( "The selling price cannot be lower than 90% of the expected price." ) - +def action_sold(self): + self.state = 'sold' + +def action_cancel(self): + self.state = 'canceled' + + +@api.depends('state') +def _compute_offer_received(self): + for record in self: + record.offer_received = record.state == 'offer_received' + +@api.depends('state') +def _compute_offer_accepted(self): + for record in self: + record.offer_accepted = record.state == 'offer_accepted' + +@api.ondelete(at_uninstall=False) +def _check_state_on_delete(self): + for record in self: + if record.state not in ('new', 'cancelled'): + raise UserError( + "You cannot delete a property unless it is in 'New' or 'Cancelled' state." + ) + + \ No newline at end of file diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index ddf33e585d..2610f4468c 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -9,13 +9,15 @@ class EstatePropertyOffer(models.Model): _description = 'Real Estate Property Offer' _order = 'price desc' price = fields.Float() - status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") + state= fields.Selection([('new', 'New'),('accepted', 'Accepted'), ('refused', 'Refused')], string= "Status" ,default='new') partner_id = fields.Many2one('res.partner', string="Partner", required=True) property_id = fields.Many2one('estate.property', string="Property", required=True) + status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string="Status") property_type_id = fields.Many2one( related='property_id.property_type_id', string="Property Type", - readonly=True + readonly=True, + store=True ) buyer_id = fields.Many2one( 'res.partner', @@ -33,6 +35,8 @@ class EstatePropertyOffer(models.Model): inverse="_inverse_date_deadline", store=True ) + def action_offer_accepted(self): + pass @api.depends('create_date', 'validity') def _compute_date_deadline(self): @@ -49,26 +53,49 @@ def _inverse_date_deadline(self): record.validity = max(delta, 0) else: record.validity = 7 - def action_accept(self): - if self.property_id.state == 'sold': - raise UserError("Cannot accept offers for sold properties.") - existing_offer = self.search([ - ('property_id', '=', self.property_id.id), - ('status', '=', 'accepted') - ]) - if existing_offer: - raise UserError("Only one offer can be accepted per property.") - self.status = 'accepted' - self.property_id.selling_price = self.price - self.property_id.buyer_id = self.env.user.partner_id - def action_refuse(self): - if self.status == 'accepted': - raise UserError("Accepted offers cannot be refused.") - self.status = 'refused' + def action_offer_accepted(self): + for record in self: + record.status = 'accepted' + record.property_id.selling_price = record.price + record.property_id.buyer_id = record.partner_id + + # set status 'refused' in the other offers of that particular property + for offer in record.property_id.offer_ids: + if offer.id != record.id: + offer.status = 'refused' + return True + + def action_offer_refused(self): + for record in self: + record.status = 'refused' + return True + _sql_constraints = [ ('offer_price_positive', 'CHECK(price > 0)', 'The offer price must be strictly positive.') - ] + ] + + + @api.model + def create(self, vals): + # Ensure property_id exists in vals + property_id = self.env['estate.property'].browse(vals.get('property_id')) + if not property_id: + raise UserError("The property associated with this offer does not exist.") + + # Check if the new offer amount is lower than any existing offers + existing_offers = self.search([('property_id', '=', property_id.id)]) + for offer in existing_offers: + if vals.get('price', 0.0) <= offer.price: + raise UserError( + "You cannot create an offer with a price lower than an existing offer." + ) + + # Update the property's state to 'Offer Received' + property_id.state = 'offer_received' + + # Create the offer as usual + return super(EstatePropertyOffer, self).create(vals) diff --git a/estate/models/estate_property_resusers.py b/estate/models/estate_property_resusers.py new file mode 100644 index 0000000000..70f6fa0170 --- /dev/null +++ b/estate/models/estate_property_resusers.py @@ -0,0 +1,10 @@ +from odoo import models, fields +class ResUsers(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many( + 'estate.property', + 'seller_id', + string="Properties", + domain=[('state', 'in', ['new', 'offer_received'])] + ) diff --git a/estate/models/estate_property_tags.py b/estate/models/estate_property_tags.py index 70c72b2aa6..3851ba579b 100644 --- a/estate/models/estate_property_tags.py +++ b/estate/models/estate_property_tags.py @@ -5,6 +5,7 @@ class EstatePropertyTag(models.Model): _order = "name" name = fields.Char(string="Tag Name", required=True) + color = fields.Integer(string='Color') tag_ids = fields.Many2many( 'estate.property.tag', 'estate_property_tag_rel', diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py index b3c39a5c40..38fdacf54d 100644 --- a/estate/models/estate_property_type.py +++ b/estate/models/estate_property_type.py @@ -1,25 +1,35 @@ -from odoo import models, fields +from odoo import models, fields, api class EstatePropertyType(models.Model): _name = 'estate.property.type' _description = 'Real Estate Property Type' _order = "sequence,name" + sequence = fields.Integer(default=10) name = fields.Char(string="Type Name", required=True) - property_type_id = fields.Many2one('estate.property.type', string="Property Type") - buyer_id = fields.Many2one('res.partner', string="Buyer") - seller_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user) property_ids = fields.One2many('estate.property', 'property_type_id', string="Properties") - expected_price = fields.Float(string="Expected Price", required=True) - state = fields.Selection(selection=[ - ('new', 'New'), - ('received', 'Offer Received'), - ('accepted', 'Offer Accepted'), - ('sold', 'Sold'), - ('cancelled', 'Cancelled'), - ], default='new', string="Status", copy=False) + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string="Offers") + offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count") + _sql_constraints = [ ('unique_type_name', 'UNIQUE(name)', 'The property type name must be unique.') ] + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) + + def action_view_offers(self): + self.ensure_one() + return { + 'type': 'ir.actions.act_window', + 'name': 'Offers', + 'view_mode': 'tree,form', + 'res_model': 'estate.property.offer', + 'domain': [('property_type_id', '=', self.id)], + 'context': {'default_property_type_id': self.id}, + } + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index f54c8c5950..2fd4e26afb 100644 --- a/estate/security/ir.model.access.csv +++ b/estate/security/ir.model.access.csv @@ -1,5 +1,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_estate_property_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1 -estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,0,1,0 -estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,0,0,0 -estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,0,1,0 \ No newline at end of file +estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 +estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 +estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 \ 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 cf2d00b674..c9135883aa 100644 --- a/estate/views/estate_property_offer_views.xml +++ b/estate/views/estate_property_offer_views.xml @@ -1,23 +1,26 @@ + + Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + estate.property.offers estate.property.offer -
-
+ - + @@ -31,9 +34,10 @@ estate.property.offer.list estate.property.offer - + + diff --git a/estate/views/estate_property_resusers_views.xml b/estate/views/estate_property_resusers_views.xml new file mode 100644 index 0000000000..2a10279529 --- /dev/null +++ b/estate/views/estate_property_resusers_views.xml @@ -0,0 +1,20 @@ + + + res.users.form.property.ids + res.users + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_tags_views.xml b/estate/views/estate_property_tags_views.xml index 4e0feb2220..4aed43666e 100644 --- a/estate/views/estate_property_tags_views.xml +++ b/estate/views/estate_property_tags_views.xml @@ -13,7 +13,7 @@ - + @@ -24,7 +24,7 @@ estate.property.tag.list estate.property.tag - + diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml index 0ed5abb2fc..a3f04aeeb5 100644 --- a/estate/views/estate_property_type_views.xml +++ b/estate/views/estate_property_type_views.xml @@ -4,15 +4,23 @@ Property Types estate.property.type list,form -
- + + estate.property.type.form estate.property.type
- -

-
+
+ +
+ +

+ +

+ @@ -27,15 +35,17 @@
-
- + + estate.property.type.list estate.property.type - - + + - +
+ +
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index cd843d3fe7..f1d566834c 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -4,21 +4,26 @@ Properties estate.property list,form +
estate.property.list estate.property - + + + - + @@ -29,16 +34,23 @@
+

+ + +

+ +
+
+
- - + @@ -59,9 +71,9 @@ - - - + + + @@ -71,15 +83,22 @@ - - - - - - - - + + + + + + + - +
+ +

- + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index f1d566834c..582c857e54 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -3,8 +3,36 @@ Properties estate.property - list,form - + kanban,list,form + + + + estate.property.kanban + estate.property + + + + +
+ + + + +
Expected Price: +
+
Best Price: +
+
Selling Price: +
+ +
+ +
+
+
+
@@ -16,8 +44,8 @@ decoration-muted="state == 'sold'"> - - + + @@ -36,7 +64,7 @@