-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] Estate: Add Estate Module #1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
1db6465
ab538e1
33bbbad
a69a5df
f7d4a9d
9a83653
de16c22
99a6c32
ef69a5c
f4a1ad9
c80da02
b9a1488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
|
|
||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from . import controllers | ||
| from . import controllers | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| 'name': "Real Estate", | ||
| 'version': "1.0.0", | ||
| 'depends': ['base', 'web'], | ||
| 'author': "john addams", | ||
| 'category': "Tutorials", | ||
| 'description': "ytyut", | ||
| 'application': True, | ||
| 'installable': True, | ||
| 'license': 'LGPL-3', | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_tag.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_offer.xml', | ||
| 'views/estate_property_type.xml', | ||
| 'views/estate_menus.xml', | ||
| 'views/estate_maintenance.xml' | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from .import estate_property_maintenance |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,116 @@ | ||||||
| from odoo import fields, models, api | ||||||
| from odoo.exceptions import UserError, ValidationError | ||||||
| from odoo.tools.float_utils import float_compare | ||||||
|
|
||||||
| class homePlan(models.Model): | ||||||
shtha-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| _name = 'estate.property' | ||||||
| _description = "this is home plan" | ||||||
| _order = "id desc" | ||||||
|
|
||||||
| name = fields.Char("Plan Name", required=True, default="Unknown") | ||||||
| description = fields.Char("Description") | ||||||
| postcode = fields.Char("Post code", required=True) | ||||||
| date_availability = fields.Datetime( | ||||||
| "Available till", | ||||||
| copy=False, | ||||||
| default=fields.Date.add(fields.Date.today(), months=3), | ||||||
| ) | ||||||
| last_seen = fields.Datetime("Last Seen", default=fields.Datetime.now) | ||||||
| expected_price = fields.Float("Expected Price") | ||||||
| selling_price = fields.Float("Selling price", copy=False, readonly=True) | ||||||
| bedrooms = fields.Integer("bedrooms", default=2) | ||||||
| living_area = fields.Integer("Living area") | ||||||
| facades = fields.Integer("facades") | ||||||
| garage = fields.Boolean("Garage", default=True) | ||||||
| garden = fields.Boolean("Garden") | ||||||
| garden_area = fields.Integer("Garden area", default=0) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a need to give a default value here? |
||||||
| total_area = fields.Float("Total area", compute='_compute_total_area', store=True) | ||||||
| best_price = fields.Float("Best price", compute='_compute_best_price', store=True) | ||||||
| total_maintenance_cost = fields.Float( compute='_compute_total_maintenance', store=True) | ||||||
| active = fields.Boolean("Active", default=True) | ||||||
| property_type_id = fields.Many2one("estate.property.type") | ||||||
| salesman_id = fields.Many2one("res.users", default=lambda self: self.env.user) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this default value calculated and why can't we directly write |
||||||
| buyer_id = fields.Many2one("res.partner", copy=False) | ||||||
| property_tag_ids = fields.Many2many("estate.property.tag") | ||||||
| offer_ids = fields.One2many("estate.property.offer", "property_id") | ||||||
| sequence = fields.Integer('Sequence', help="Used to order stages. Lower is better.") | ||||||
| maintenance_ids = fields.One2many("estate.property.maintenance", "property_id") | ||||||
| state = fields.Selection( | ||||||
| [ | ||||||
| ('new', "New"), | ||||||
| ('offer_received', "Offer received"), | ||||||
| ('offer_accepted', "Offer accepted"), | ||||||
| ('sold', "Sold"), | ||||||
| ('cancelled', "Cancelled"), | ||||||
| ], | ||||||
| default='new', | ||||||
| copy=False, | ||||||
| ) | ||||||
|
|
||||||
| garden_orientation_direction = fields.Selection( | ||||||
| [('north', "North"), ('east', "East"), ('west', "West"), ('south', "South")] | ||||||
| ) | ||||||
|
|
||||||
| _check_expected_price = models.Constraint( | ||||||
| 'CHECK(expected_price > 0)', "The expected price must be Strictly positive" | ||||||
| ) | ||||||
| _check_property_selling_price = models.Constraint( | ||||||
| 'CHECK(selling_price > 0)', "The expected price must be Strictly positive" | ||||||
| ) | ||||||
|
|
||||||
| @api.depends('living_area', 'garden_area') | ||||||
| def _compute_total_area(self): | ||||||
| for line in self: | ||||||
| line.total_area = line.living_area + line.garden_area | ||||||
|
|
||||||
| @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.0) | ||||||
|
|
||||||
| @api.onchange('garden') | ||||||
| def _onchange_partner(self): | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Give meaningful names |
||||||
| for record in self: | ||||||
| if record.garden: | ||||||
| record.garden_area = 10 | ||||||
| record.garden_orientation_direction = 'east' | ||||||
|
|
||||||
| else: | ||||||
| record.garden_area = 0 | ||||||
| record.garden_orientation_direction = False | ||||||
|
|
||||||
| @api.constrains('selling_price', 'expected_price') | ||||||
| def _check_selling_price(self): | ||||||
| for record in self: | ||||||
| if record.selling_price and float_compare( | ||||||
| record.selling_price, (0.9 * record.expected_price) | ||||||
| ,2 ) == -1 : | ||||||
|
Comment on lines
+85
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain the params of float_compare |
||||||
| raise ValidationError( | ||||||
| "The selling price cannot be lower than 90% of the expected price." | ||||||
| ) | ||||||
|
|
||||||
| def action_sold(self): | ||||||
| for record in self: | ||||||
| if record.state == 'cancelled': | ||||||
|
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you optimize and write this without loop? |
||||||
| raise UserError(message="You can't sold once you have cancelled") | ||||||
| elif record.maintenance_ids.filtered(lambda r : r.status != 'Done'): | ||||||
| raise UserError("maintamce remain") | ||||||
| else: | ||||||
| record.state = 'sold' | ||||||
| return True | ||||||
|
|
||||||
| def action_Cancel(self): | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| for record in self: | ||||||
| if record.state == 'sold': | ||||||
| raise UserError(message="You can't Cancel once you have sold") | ||||||
| else: | ||||||
| record.state = 'cancelled' | ||||||
|
|
||||||
| return True | ||||||
|
|
||||||
| @api.depends('maintenance_ids.cost') | ||||||
| def _compute_total_maintenance(self): | ||||||
| for record in self: | ||||||
| record.total_maintenance_cost = sum(record.maintenance_ids.mapped('cost')) | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from odoo import fields, models, api | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
| class EstatePropertyMaintenanceRequest(models.Model): | ||
| _name = 'estate.property.maintenance' | ||
| _description = "this is property maintenance model" | ||
|
|
||
| title = fields.Char("Title", required=True, default="Unknown") | ||
| cost = fields.Float('Price') | ||
| status = fields.Selection( | ||
| [ | ||
| ('new', "New"), | ||
| ('approved', "Approved"), | ||
| ('Done', "Done"), | ||
| ], | ||
| default='new', | ||
| ) | ||
|
|
||
| property_id = fields.Many2one('estate.property', required=True) | ||
|
|
||
| # _check_cost = models.Constraint( | ||
| # 'CHECK(cost > 0)', "The expected cost must be Strictly positive" | ||
| # ) | ||
|
|
||
| @api.constrains('status') | ||
| def _check_cost(self): | ||
| for record in self: | ||
| if record.status == 'approved' and record.cost <= 0: | ||
| raise ValidationError( | ||
| "The Cost must be Positive" | ||
| ) | ||
|
|
||
| def action_approved(self): | ||
| self.status = 'Done' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from odoo import fields, models, api | ||
| from odoo.exceptions import UserError | ||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = "this is property offer model" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float('Price') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not needed to give a string if it's same as the field name. |
||
| status = fields.Selection( | ||
| [('accepted', "Accepted"), ('refused', "Refused")], copy=False | ||
| ) | ||
| validity = fields.Integer("Validity", default=7) | ||
| date_deadline = fields.Date( | ||
| "date_deadline", compute="_compute_date_deadline", inverse="inverse_date_deadline" | ||
| ) | ||
| partner_id = fields.Many2one('res.partner', required=True) | ||
| property_id = fields.Many2one('estate.property', readonly=True) | ||
| property_type_id = fields.Many2one( | ||
| "estate.property.type", | ||
| related="property_id.property_type_id", | ||
| store=True, | ||
| string="Property Type" | ||
| ) | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| 'CHECK( price > 0)', "The offer price must be Strictly positive" | ||
| ) | ||
|
|
||
| @api.depends('validity') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| record.date_deadline = fields.Date.add( | ||
| record.create_date or fields.Date.today(), days=record.validity | ||
| ) | ||
|
|
||
| def inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def action_confirm(self): | ||
| for record in self: | ||
| if record.property_id.state == 'offer_accepted': | ||
| raise UserError(message="You can't Accept multiple offer") | ||
| else: | ||
| record.status = 'accepted' | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = 'offer_accepted' | ||
| for offer in record.property_id.offer_ids: | ||
| if record.id != offer.id: | ||
| offer.status='refused' | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| record.status = 'refused' | ||
| return True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = "this is property tag model" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char("tag", required=True) | ||
| color = fields.Integer("Color") | ||
| _check_unique_propertyTag = models.Constraint( | ||
| 'UNIQUE(name)', "The Property tag must be unique" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from odoo import fields, models, api | ||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = "this is property model" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char("Type", required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
|
|
||
| _check_unique_propertyType = models.Constraint( | ||
| "UNIQUE(name)", "The Property type must be unique" | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| "estate.property.offer", | ||
| "property_type_id", | ||
| string="Offers" | ||
| ) | ||
|
|
||
| offer_count = fields.Integer( | ||
| string="Offer count", | ||
| compute="_compute_offer_count" | ||
| ) | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 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 | ||
| access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 | ||
| access_estate_property_maintenance,access_estate_property_maintenance,model_estate_property_maintenance,base.group_user,1,1,1,1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a line at the end of file |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="model_maintenance_action" model="ir.actions.act_window"> | ||
| <field name="name">maintenance</field> | ||
| <field name="res_model">estate.property.maintenance</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| <record id="estate_property_tag_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.maintenance.list</field> | ||
| <field name="model">estate.property.maintenance</field> | ||
| <field name="arch" type="xml" > | ||
| <list string="Channel" editable="bottom" > | ||
| <field string="title" name="title"/> | ||
| <field string="cost" name="cost"/> | ||
| <field string="title" name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="menu_root" name="Estate"> | ||
| <menuitem id="first_level_menu" name="Menu"> | ||
| <menuitem id="estate_model_menu_action" action="model_menu_action"/> | ||
| <menuitem id="estate_model_maintenance" action="model_maintenance_action"/> | ||
| </menuitem> | ||
| <menuitem id="first_level_menu_estate_property_type" name="Setting"> | ||
| <menuitem id="estate_property_action" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_action_tag" action="estate_property_tag_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <record id="estate_property_offer_action" model="ir.actions.act_window"> | ||
| <field name="name">Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| <record id="estate_property_offer_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.list</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml" > | ||
| <list string="Channel" editable="bottom" > | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name ="validity"/> | ||
| <field name ="date_deadline"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property tag</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list</field> | ||
| </record> | ||
| <record id="estate_property_tag_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.list</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml" > | ||
| <list string="Channel" editable="bottom" > | ||
| <field string="name" name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
Uh oh!
There was an error while loading. Please reload this page.