-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[ADD] estate: basic module creation #1245
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
Open
simal-odoo
wants to merge
17
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-technical-training-simal
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
94ed96c
[ADD] estate: basic module creation
simal-odoo 3702745
[ADD] estate: models and basic fields
simal-odoo ef29dbe
[ADD] estate: add access rights for property model
simal-odoo 2ba81c0
[ADD] estate: add basic user interface
simal-odoo 6aa8bbe
[CLN] estate: implemented requested changes
simal-odoo 70fa394
[ADD] estate: add views
simal-odoo 32f65b1
[ADD] estate: add models and relations
simal-odoo 00ddb13
[ADD] estate: computed fields and onchanges
simal-odoo 3cb24f9
[ADD] estate: added actions
simal-odoo 149b4e5
[FIX] estate: cleaned and fixed code
simal-odoo c2166b8
[ADD] estate: add constraints
simal-odoo 9d33bd0
[IMP] estate: add basic test cases
vandroogenbd 3aa2c7a
[ADD] estate: Add the sprinkles
simal-odoo c585ab1
[ADD] estate: Add the sprinkles
simal-odoo 5d80f29
[ADD] estate: Inheritance
simal-odoo 60938a8
[ADD] estate_account: creation and link with estate
simal-odoo a320c8f
[ADD] estate: creation of kanban view
simal-odoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| 'name': "Estate", | ||
| 'summary': """ | ||
| The Real Estate Advertisement module | ||
| """, | ||
|
|
||
| 'description': """ | ||
| The Real Estate Advertisement module | ||
| """, | ||
| 'author': "Odoo", | ||
| 'website': "https://www.odoo.com/", | ||
| 'category': 'Tutorials', | ||
| 'version': '19.0.0.1.0', | ||
| 'application': True, | ||
| 'depends': [ | ||
| 'base', | ||
| ], | ||
| 'data': [ | ||
| 'data/ir.model.access.csv', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_menus.xml', | ||
| 'views/res_users.xml', | ||
| ], | ||
| 'license': 'LGPL-3', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
| estate_property_access_user,estate.property.user,model_estate_property,base.group_user,1,1,1,1 | ||
| estate_property_type_access_user,estate.property.type.user,model_estate_property_type,base.group_user,1,1,1,1 | ||
| estate_property_tag_access_user,estate.property.tag.user,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| estate_property_offer_access_user,estate.property.offer.user,model_estate_property_offer,base.group_user,1,1,1,1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer, res_users |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| from odoo import api, fields, models, exceptions, tools | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Estate Property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char('Property Name', required=True) | ||
| description = fields.Text() | ||
| property_type_id = fields.Many2one( | ||
| 'estate.property.type') | ||
| buyer_id = fields.Many2one('res.partner', copy=False) | ||
| salesperson_id = fields.Many2one( | ||
| 'res.users', default=lambda self: self.env.uid) | ||
| tag_ids = fields.Many2many( | ||
| 'estate.property.tag', string="Property Tag") | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_id') | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date('Availability Date', copy=False, | ||
| default=lambda self: fields.Date.add(fields.Date.today(), months=3)) | ||
| expected_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 Area') | ||
| garden_orientation = fields.Selection( | ||
| selection=[ | ||
| ('north', 'North'), | ||
| ('south', 'South'), | ||
| ('east', 'East'), | ||
| ('west', 'West'), | ||
| ], | ||
| ) | ||
| total_area = fields.Integer(compute="_compute_total_area") | ||
| best_price = fields.Float('Best Offer', compute="_compute_best_price") | ||
| selling_price = fields.Float( | ||
| compute="_compute_selling_price", readonly=True, copy=False) | ||
| state = fields.Selection( | ||
| selection=[ | ||
| ('new', 'New'), | ||
| ('offer received', 'Offer Received'), | ||
| ('offer accepted', 'Offer Accepted'), | ||
| ('sold', 'Sold'), | ||
| ('cancelled', 'Cancelled'), | ||
| ], | ||
| default='new', | ||
| required=True, | ||
| ) | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_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 line in self: | ||
| line.best_price = max(line.mapped('offer_ids.price'), default=0) | ||
|
|
||
| @api.depends('offer_ids.status', 'offer_ids.price') | ||
| def _compute_selling_price(self): | ||
| for line in self: | ||
| accepted_offer = line.offer_ids.filtered( | ||
| lambda o: o.status == 'accepted') | ||
| if accepted_offer: | ||
| line.selling_price = accepted_offer[0].price | ||
| line.buyer_id = accepted_offer[0].partner_id | ||
| else: | ||
| line.selling_price = 0 | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise exceptions.UserError( | ||
| "You cannot cancel a sold property.") | ||
| else: | ||
| record.state = 'cancelled' | ||
| return True | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| raise exceptions.UserError( | ||
| "You cannot mark a cancelled property as sold.") | ||
| else: | ||
| record.state = 'sold' | ||
| return True | ||
|
|
||
| @api.constrains('selling_price', 'expected_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if tools.float_is_zero(record.selling_price, precision_digits=2): | ||
| continue | ||
|
|
||
| if tools.float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1: | ||
| raise exceptions.ValidationError( | ||
| "The selling price cannot be less than 90% of the expected price.") | ||
|
|
||
| @api.onchange('garden') | ||
| def _onchange_garden(self): | ||
| if not self.garden: | ||
| self.garden_area = 0 | ||
| self.garden_orientation = False | ||
| else: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = 'north' | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled(self): | ||
| for record in self: | ||
| if record.state not in ['new', 'cancelled']: | ||
| raise exceptions.UserError( | ||
| "You cannot delete a property that is not 'New' or 'Cancelled'!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| from datetime import timedelta | ||
| from odoo import api, fields, models, exceptions | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Estate Property Offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| partner_id = fields.Many2one("res.partner", required=True) | ||
| property_id = fields.Many2one("estate.property", required=True) | ||
| property_type_id = fields.Many2one( | ||
| related="property_id.property_type_id", store=True) | ||
| validity = fields.Integer("Validity (days)", default=7) | ||
| date_deadline = fields.Date( | ||
| "Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) | ||
| status = fields.Selection( | ||
| selection=[ | ||
| ('accepted', 'Accepted'), | ||
| ('refused', 'Refused'), | ||
| ], | ||
| copy=False, | ||
| ) | ||
|
|
||
| _check_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The offer price must be strictly positive.', | ||
| ) | ||
|
|
||
| @api.depends('create_date', 'validity') | ||
| def _compute_date_deadline(self): | ||
| for offer in self: | ||
| start_date = fields.Date.to_date( | ||
| offer.create_date) or fields.Date.today() | ||
| offer.date_deadline = start_date + timedelta(days=offer.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for offer in self: | ||
| if offer.date_deadline: | ||
| start_date = fields.Date.to_date( | ||
| offer.create_date) or fields.Date.today() | ||
| offer.validity = (offer.date_deadline - start_date).days | ||
| else: | ||
| offer.validity = 0 | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| prop = self.env['estate.property'].browse(vals['property_id']) | ||
| if prop.offer_ids: | ||
| max_offer = max(prop.offer_ids.mapped('price')) | ||
| if vals.get('price') < max_offer: | ||
| raise exceptions.UserError( | ||
| ("The offer must be higher than %.2f") % max_offer) | ||
| prop.state = 'offer received' | ||
|
|
||
| return super().create(vals_list) | ||
|
|
||
| def action_accept(self): | ||
| for offer in self: | ||
| existing_accepted = self.env['estate.property.offer'].search([ | ||
| ('property_id', '=', offer.property_id.id), | ||
| ('status', '=', 'accepted') | ||
| ]) | ||
| if existing_accepted: | ||
| raise exceptions.UserError( | ||
| "An offer for this property has already been accepted.") | ||
| offer.status = 'accepted' | ||
| offer.property_id.selling_price = offer.price | ||
| offer.property_id.state = 'offer accepted' | ||
|
|
||
| def action_refuse(self): | ||
| for offer in self: | ||
| offer.status = 'refused' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tag" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char('Property Tag Name', required=True) | ||
| color = fields.Integer('Color') | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "Property tag names must be unique.", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char('Property Type Name', required=True) | ||
| property_ids = fields.One2many( | ||
| 'estate.property', 'property_type_id', string='Properties') | ||
| offer_ids = fields.One2many( | ||
| 'estate.property.offer', 'property_type_id', string='Offers') | ||
| offer_count = fields.Integer( | ||
| compute="_compute_offer_count", string="Number of Offers") | ||
| sequence = fields.Integer(default=1) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "Property type names must be unique.", | ||
| ) | ||
|
|
||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| 'estate.property', 'salesperson_id') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import test_estate_property |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from odoo.exceptions import ValidationError | ||
| from odoo.tests import TransactionCase | ||
| from odoo import Command | ||
|
|
||
|
|
||
| class TestEstateProperty(TransactionCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.estate = cls.env['estate.property'].create({ | ||
| 'name': 'Super test estate', | ||
| 'expected_price': 100000.0, | ||
| 'state': 'new', | ||
| }) | ||
| cls.test_partner = cls.env['res.partner'].create({ | ||
| 'name': 'Maman ours', | ||
| }) | ||
|
|
||
| def test_estate_best_price(self): | ||
| ''' | ||
| Ensure best price is correctly updated when an offer is received. | ||
| ''' | ||
| self.assertEqual(self.estate.best_price, 0.0) | ||
| self.estate.offer_ids = [Command.create({ | ||
| 'price': 125000.0, | ||
| 'partner_id': self.test_partner.id, | ||
| })] | ||
| self.assertEqual(self.estate.best_price, 125000.0) | ||
|
|
||
| def test_accept_offer_south_facing_garden(self): | ||
| ''' | ||
| Ensure offers for estates with south-facing gardens can only be accepted if above expected | ||
| price. | ||
| ''' | ||
| self.estate.expected_price = 500000 | ||
| self.estate.offer_ids = [Command.create({ | ||
| 'price': 475000.0, | ||
| 'partner_id': self.test_partner.id, | ||
| })] | ||
| with self.assertRaises(ValidationError): | ||
| self.estate.offer_ids.accept_offer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Estate"> | ||
| <menuitem id="estate_menu_advertisement" name="Advertisements"> | ||
| <menuitem id="estate_property_menu" action="estate_property_action"/> | ||
| </menuitem> | ||
|
|
||
| <menuitem id="estate_menu_settings" name="Settings"> | ||
| <menuitem id="estate_property_type_menu" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_tag_menu" action="estate_property_tag_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <odoo> | ||
| <record id="estate_property_offer_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.form</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="New Property Offer"> | ||
| <sheet> | ||
| <group> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| <field name="status" /> | ||
| </group> | ||
| </sheet> | ||
| </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="Property Offers" editable="bottom" decoration-success="status=='accepted'" decoration-danger="status=='refused'"> | ||
| <field name="price" width="200px"/> | ||
| <field name="partner_id" width="240px" /> | ||
| <field name="validity" width="240px" /> | ||
|
Comment on lines
+25
to
+27
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. Why the widths here ? Would this work correctly on all screen sizes or just yours ? |
||
| <field name="date_deadline" /> | ||
| <button name="action_accept" type="object" icon="fa-check" title="Accept" invisible='status'/> | ||
| <button name="action_refuse" type="object" icon="fa-times" title="Refuse" invisible='status'/> | ||
| <field name="status" optional="hide"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here