-
Notifications
You must be signed in to change notification settings - Fork 3.1k
dalio - Technical Training #1233
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 13 commits
3c4ec5c
46f010c
2a943c1
25b1b95
d9454fb
c767015
4faa6cd
c626a8c
f0442fb
4ac7f31
3bd3578
7061f54
a3ebbc7
ae62f85
5aea6e1
64b4e23
6a5844e
67c3197
6649480
9939864
dd2d610
6f8b1c7
a161bf9
04e2c19
e5ac3b6
83a6497
11820f7
24f482b
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 |
|---|---|---|
|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # VSCode preferences | ||
| .vscode/ | ||
| 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,18 @@ | ||
| { | ||
| "name": "Real Estate", | ||
| "version": "19.0.1.0.0", | ||
| "depends": [ | ||
| "base", | ||
| ], | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_type_views.xml", | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_property_offer_views.xml", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_menus.xml", | ||
| ], | ||
| "application": True, | ||
| "author": "dalio", | ||
| "license": "LGPL-3" | ||
| } |
| 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 | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,118 @@ | ||||||||||||||||||||||||||
| from dateutil.relativedelta import relativedelta | ||||||||||||||||||||||||||
| from odoo import models, fields, api | ||||||||||||||||||||||||||
| from odoo.exceptions import UserError, ValidationError | ||||||||||||||||||||||||||
| from odoo.tools import float_is_zero, float_compare | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| class EstateProperty(models.Model): | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| _name = "estate.property" | ||||||||||||||||||||||||||
| _description = "Real Estate Property" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| name = fields.Char(required=True) | ||||||||||||||||||||||||||
| description = fields.Text() | ||||||||||||||||||||||||||
| postcode = fields.Char() | ||||||||||||||||||||||||||
| date_availability = fields.Date(default=lambda self: fields.Date.today() + relativedelta(months=3), copy=False) | ||||||||||||||||||||||||||
| expected_price = fields.Float(required=True) | ||||||||||||||||||||||||||
| selling_price = fields.Float(readonly=True, copy=False) | ||||||||||||||||||||||||||
| 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="Orientation", | ||||||||||||||||||||||||||
| selection=[ | ||||||||||||||||||||||||||
| ("north", "North"), | ||||||||||||||||||||||||||
| ("south", "South"), | ||||||||||||||||||||||||||
| ("west", "West"), | ||||||||||||||||||||||||||
| ("east", "East") | ||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||
| help="Orientation of the garden" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| active = fields.Boolean(default=True) | ||||||||||||||||||||||||||
| state = fields.Selection( | ||||||||||||||||||||||||||
| string="State", | ||||||||||||||||||||||||||
| selection=[ | ||||||||||||||||||||||||||
| ("new", "New"), | ||||||||||||||||||||||||||
| ("offer_received", "Offer Received"), | ||||||||||||||||||||||||||
| ("offer_accepted", "Offer Accepted"), | ||||||||||||||||||||||||||
| ("sold", "Sold"), | ||||||||||||||||||||||||||
| ("cancelled", "Cancelled") | ||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||
| help="State of the property", | ||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||
| copy=False, | ||||||||||||||||||||||||||
| default="new" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||||||||||||||||||||||||||
| salesman_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) | ||||||||||||||||||||||||||
| buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||||||||||||||||||||||||||
|
Mathilde411 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||
| tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||||||||||||||||||||||||||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||||||||||||||||||||||||||
| total_area = fields.Integer(compute="_compute_total_area", string="Total area (sqm)") | ||||||||||||||||||||||||||
| best_price = fields.Float(compute="_compute_best_price", string="Best Offer") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @api.depends("living_area", "garden_area") | ||||||||||||||||||||||||||
| def _compute_total_area(self): | ||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||
| record.total_area = record.living_area + record.garden_area | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @api.depends("offer_ids.price") | ||||||||||||||||||||||||||
| def _compute_best_price(self): | ||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||
| prices = record.offer_ids.mapped("price") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if prices: | ||||||||||||||||||||||||||
| record.best_price = max(prices) | ||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| record.best_price = 0.0 | ||||||||||||||||||||||||||
|
Mathilde411 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @api.onchange("garden") | ||||||||||||||||||||||||||
| def _onchange_garden(self): | ||||||||||||||||||||||||||
| if self.garden: | ||||||||||||||||||||||||||
| self.garden_area = 10 | ||||||||||||||||||||||||||
| self.garden_orientation = "north" | ||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| self.garden_area = 0 | ||||||||||||||||||||||||||
| self.garden_orientation = False | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def action_sold(self): | ||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||
| if record.state == "cancelled": | ||||||||||||||||||||||||||
| raise UserError("Canceled properties cannot be sold.") | ||||||||||||||||||||||||||
| record.state = "sold" | ||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||
|
Comment on lines
+111
to
+116
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
Only one assignation for the whole recordset |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def action_cancel(self): | ||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||
| if record.state == "sold": | ||||||||||||||||||||||||||
| raise UserError("Sold properties cannot be canceled.") | ||||||||||||||||||||||||||
| record.state = "cancelled" | ||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||
|
Comment on lines
+118
to
+123
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. Same as above |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| _check_expected_price = models.Constraint( | ||||||||||||||||||||||||||
| "CHECK(expected_price > 0)", | ||||||||||||||||||||||||||
| "the expected price must be strictly positive.", | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| _check_selling_price = models.Constraint( | ||||||||||||||||||||||||||
| "CHECK(selling_price >= 0)", | ||||||||||||||||||||||||||
| "the selling price must be positive.", | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @api.constrains("selling_price", "expected_price") | ||||||||||||||||||||||||||
| def _check_selling_price(self): | ||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if float_is_zero(record.selling_price, precision_digits=2): | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| lower_bound = 0.9 * record.expected_price | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if float_compare(record.selling_price, lower_bound, precision_digits=2) == -1: | ||||||||||||||||||||||||||
| raise ValidationError( | ||||||||||||||||||||||||||
| "The selling price must be at least 90% of the expected price! " | ||||||||||||||||||||||||||
| "You must reduce the expected price if you want to accept this offer." | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
Mathilde411 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import fields, models, api | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
|
|
||
| _name = "estate.property.offer" | ||
| _description = "Property Offer" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| string="Status", | ||
|
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. String not necessary |
||
| selection=[ | ||
| ("accepted", "Accepted"), | ||
| ("refused", "Refused") | ||
| ], | ||
| help="Status of the offer" | ||
| ) | ||
| partner_id = fields.Many2one('res.partner', string="Partner", required=True) | ||
| property_id = fields.Many2one('estate.property', string="Property", required=True) | ||
| validity = fields.Integer(default=7, string="Validity (days)") | ||
| date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline") | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| base_date = record.create_date or fields.Date.today() | ||
| days_to_add = record.validity or 0 | ||
|
Mathilde411 marked this conversation as resolved.
Outdated
|
||
| record.date_deadline = base_date + relativedelta(days=days_to_add) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| base_date = fields.Date.to_date(record.create_date) or fields.Date.today() | ||
|
Mathilde411 marked this conversation as resolved.
Outdated
|
||
|
|
||
| if record.date_deadline: | ||
| record.validity = (record.date_deadline - base_date).days | ||
| else: | ||
| record.validity = 0 | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
| return True | ||
|
|
||
| def action_refuse(self): | ||
| for record in self: | ||
| record.status = "refused" | ||
|
Mathilde411 marked this conversation as resolved.
Outdated
|
||
| return True | ||
|
|
||
| _check_price = models.Constraint( | ||
| "CHECK(price > 0)", | ||
| "the offer price must be strictly positive.", | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
|
|
||
| _name = "estate.property.tag" | ||
| _description = "Property Tag" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "the name must be unique.", | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
|
|
||
| _name = "estate.property.type" | ||
| _description = "Property Type" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "the name must be unique.", | ||
| ) |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
|
|
||
| <menuitem id="estate_menu_advertisement" name="Advertisements"> | ||
| <menuitem id="estate_property_menu" action="estate_property_action"/> | ||
| </menuitem> | ||
|
|
||
| <menuitem id="estate_menu_configuration" 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <odoo> | ||
| <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="Offers"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="action_accept" string="Accept" type="object" icon="fa-check" invisible="status in ('offer_accepted', 'offer_refused')"/> | ||
| <button name="action_refuse" string="Refuse" type="object" icon="fa-times" invisible="status in ('offer_accepted', 'offer_refused')"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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="Offer"> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <field name="status"/> | ||
| </group> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <odoo> | ||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <odoo> | ||
| <record id="estate_property_type_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Types</field> | ||
| <field name="res_model">estate.property.type</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| </odoo> |
Uh oh!
There was an error while loading. Please reload this page.