diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 2e6514bff10..f92ad8b0fd8 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# Odoo 12.0 - Technical Training +# Odoo 17.0 - Technical Training + +The Technical Training of Odoo 17.0 is available on the +[Tutorial](https://www.odoo.com/documentation/master/developer/howtos/rdtraining.html) diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..4414ec1402f --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,17 @@ +{ + "name": "Real Estate", # The name that will appear in the App list + "version": "17.0.1.0.0", # Version + "application": True, # This line says the module is an App, and not a module + "depends": ["base"], # dependencies + "data": [ + "security/ir.model.access.csv", + "views/estate_actions.xml", # add action bevor all other views, so their every time loaded before + "views/estate_property_views.xml", + "views/estate_property_type_views.xml", + "views/estate_property_tag_views.xml", + "views/estate_property_offer_views.xml", + "views/estate_menus.xml" + ], + "installable": True, + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..09b2099fe84 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,4 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer \ No newline at end of file diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..e249569e13f --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,87 @@ +from dateutil.relativedelta import relativedelta +from odoo import api, fields, models +from odoo.exceptions import ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate Property" + + name = fields.Char() + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date(default=lambda self: fields.Date.today() + relativedelta(months=+3)) + expected_price = fields.Float(required=True) + selling_price = fields.Float(required=True) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer() + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection( + string='Type', + selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West') ], + help="") + state = fields.Selection( + string='State', + selection=[('new', 'New'), ('offer_received', 'Offer Received'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('canceled', 'Canceled') ], + default='new', + help="") + active = fields.Boolean(default=1) + property_type_id = fields.Many2one("estate.property.type") + seller_id = fields.Many2one("res.partner", string="Seller") + buyer_id = fields.Many2one("res.partner", string="Buyer") + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + # the name of 2nd parameter "property_id" is the var string of variable used in offer model + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + # non stored -> not searchable without search method, search="_search_totalarea" + # store=True + totalarea = fields.Float(compute="_compute_totalarea") + + _sql_constraints = [ + ('check_expected_price', 'CHECK(expected_price >= 0)', 'The Expected Price should be positive.'), + ('check_selling_price', 'CHECK(selling_price >= 0)', 'The Selling Price should be positive.') + ] + + @api.depends("living_area", "garden_area") + def _compute_totalarea(self): + for record in self: + record.totalarea = record.living_area + record.garden_area + + @api.onchange("garden") + def _onchange_garden(self): + if self.garden == 1: + self.garden_area = 10 + self.garden_orientation = "north" + else: + self.garden_area = 0 + self.garden_orientation = "" + + def set_status_cancel(self): + if self.state != "sold": + self.state = "canceled" + + def set_status_sold(self): + if self.state != "canceled": + self.state = "sold" + + @api.constrains('expected_price', 'selling_price') + def _check_selling_price(self): + for record in self: + # Skip the check if the selling price is zero (no offer validated yet) + if float_is_zero(record.selling_price, precision_digits=2): + continue + + # Calculate 90% of the expected price + price_limit = record.expected_price * 0.9 + + # Compare the selling price to 90% of the expected price + if float_compare(record.selling_price, price_limit, precision_digits=2) < 0: + raise ValidationError("The selling price cannot be lower than 90% of the expected price.") + + @api.ondelete(at_uninstall=False) + def _check_state_before_deletion(self): + for record in self: + if record.state not in ['new', 'canceled']: + raise ValidationError("You can only delete properties that are in 'New' or 'Canceled' state.") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..7825ffbe854 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,68 @@ +from dateutil.relativedelta import relativedelta +from odoo import api, fields, models +from odoo.exceptions import UserError +from odoo.exceptions import ValidationError + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Estate Property Offer" + + name = fields.Char() + price = fields.Float() + status = fields.Selection( + string='Type', + selection=[('accepted', 'Accepted'), ('refused', 'Refused') ], + help="") + partner_id = fields.Many2one("res.partner", string="Partner") + property_id = fields.Many2one("estate.property", string="Property") + validity = fields.Integer(default=7) + date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) + property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) + + _sql_constraints = [ + ('check_price', 'CHECK(price >= 0)', 'The Offer Price should be positive.') + ] + + @api.depends("validity") + def _compute_date_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_date_deadline(self): + for record in self: + if record.create_date: + record.validity = (record.date_deadline - record.create_date.date()).days + else: + record.validity = (record.date_deadline - fields.Date.today()).days + + def estate_property_offer_accepted_action(self): + for record in self: + record.status = "accepted" + record.property_id.selling_price = record.price + record.property_id.seller_id = record.partner_id + + def estate_property_offer_refused_action(self): + self.status = "refused" + + @api.model + def create(self, vals): + property_id = vals.get('property_id') + if property_id: + property_obj = self.env['estate.property'].browse(property_id) + + # Check if there is any existing offer with a higher price + existing_offers = self.env['estate.property.offer'].search([ + ('property_id', '=', property_id), + ('price', '>', vals.get('price', 0)) + ]) + if existing_offers: + raise ValidationError("You cannot create an offer with a lower price than existing offers.") + + # Set the property state to 'Offer Received' + property_obj.state = 'offer_received' + + return super(EstatePropertyOffer, self).create(vals) \ 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..6e3497321e8 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Estate Property Tag" + + name = fields.Char() + + _sql_constraints = [ + ('check_name_unique', 'UNIQUE(name)', 'The name must be unique!') + ] \ No newline at end of file diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..0f9e8c50e0c --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,18 @@ +from odoo import api, fields, models + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate Property Type" + + name = fields.Char() + 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 = [ + ('check_name_unique', 'UNIQUE(name)', 'The name must be unique!') + ] + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..0db13e578ec --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +estate.access_estate_property,access_estate_property,estate.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,1,1,1 +estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,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 \ No newline at end of file diff --git a/estate/views/estate_actions.xml b/estate/views/estate_actions.xml new file mode 100644 index 00000000000..c54e8d8cce2 --- /dev/null +++ b/estate/views/estate_actions.xml @@ -0,0 +1,9 @@ + + + Property Offers + estate.property.offer + tree,form + [('property_type_id', '=', active_id)] + {'default_property_type_id': active_id} + + diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..4b7fc82e6e6 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..04e8ae64a08 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,25 @@ + + + Estate Property Offer + estate.property.offer + tree,form + + + + estate.property.offer + estate.property.offer + + + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..3c3232c3d1b --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,106 @@ + + + Estate Property + estate.property + tree,form + + + + estate.property.tree + estate.property + + + + + + + + + + + + + + estate.property.tree + estate.property + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + estate.property.search + estate.property + + + + + + + + + + + + + +