-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Server framework 101 #1339
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
LucasDaniOV
wants to merge
1
commit into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-onboarding-luoud
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
Server framework 101 #1339
Changes from all commits
Commits
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,17 @@ | ||
| { | ||
| "name": "Real Estate", | ||
| "depends": ["base"], | ||
| "installable": True, | ||
| "application": True, | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_offer_views.xml", | ||
| "views/estate_property_type_views.xml", | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_menus.xml", | ||
| "views/res_users_views.xml", | ||
| ], | ||
| "author": "Odoo S.A.", | ||
| "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 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import 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,149 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Real Estate Property Model" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char("Title", required=True, translate=True) | ||
|
LucasDaniOV marked this conversation as resolved.
|
||
| description = fields.Text(string="Description", required=True, translate=True) | ||
| postcode = fields.Char("Postcode", required=True) | ||
| expected_price = fields.Float("Expected Price", required=True) | ||
| selling_price = fields.Float("Selling Price", readonly=True, copy=False) | ||
| bedrooms = fields.Integer("Bedrooms", required=True, default=2) | ||
| living_area = fields.Integer("Living Area (sqm)", required=True) | ||
| facades = fields.Integer("Facades", required=True) | ||
| garage = fields.Boolean("Garage", required=True) | ||
| garden = fields.Boolean("Garden", required=True) | ||
| garden_area = fields.Integer("Garden Area") | ||
| active = fields.Boolean(string="Active", required=True, default=True) | ||
|
|
||
| date_availability = fields.Date( | ||
| string="Available From", | ||
| copy=False, | ||
| default=fields.Date.today() + relativedelta(months=3), | ||
| ) | ||
|
|
||
| garden_orientation = fields.Selection( | ||
| string="Garden Orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| help="Mucho calor o poco calor", | ||
| ) | ||
|
|
||
| state = fields.Selection( | ||
| string="State", | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
|
|
||
| property_type_id = fields.Many2one("estate.property.type", string="Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
| salesperson_id = fields.Many2one( | ||
| "res.users", | ||
| string="Salesman", | ||
| default=lambda self: self.env.user, | ||
| ) | ||
| property_tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
| property_offer_ids = fields.One2many( | ||
| "estate.property.offer", | ||
| "property_id", | ||
| string="Offers", | ||
| ) | ||
|
|
||
| total_area = fields.Float(compute="_compute_total_area", string="Total Area (sqm)") | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for property in self: | ||
| property.total_area = property.living_area + property.garden_area | ||
|
|
||
| best_price = fields.Float(compute="_compute_best_price", string="Best Offer") | ||
|
|
||
| @api.depends("property_offer_ids.price") | ||
| def _compute_best_price(self): | ||
| for property in self: | ||
| if len(property.property_offer_ids) > 0: | ||
| property.best_price = max( | ||
| offer.price for offer in property.property_offer_ids | ||
| ) | ||
| else: | ||
| property.best_price = 0 | ||
|
|
||
| @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 sell_property(self): | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| raise UserError(self.env._("Cancelled properties cannot be sold")) | ||
| if property.state in ["offer_accepted", "sold"]: | ||
| raise UserError(self.env._("Property is already sold")) | ||
| property.state = "sold" | ||
| return True | ||
|
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. fyi (i dont know if its explained in the tutorial) actions can return action objects so you can say things like: open this popup, reload the page, redirect to here |
||
|
|
||
| def cancel_property(self): | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| raise UserError(self.env._("Property is already cancelled")) | ||
| if property.state in ["offer_accepted", "sold"]: | ||
| raise UserError(self.env._("Sold properties cannot be cancelled")) | ||
| property.state = "cancelled" | ||
| return True | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price >= 0)", | ||
| "The expected price should be positive", | ||
| ) | ||
| _check_bedrooms = models.Constraint( | ||
| "CHECK(bedrooms >= 0)", | ||
| "The amount of bedrooms should be at least 0", | ||
| ) | ||
| _check_living_area = models.Constraint( | ||
| "CHECK(living_area >= 0)", | ||
| "The living area should be at least 0", | ||
| ) | ||
| _check_facades = models.Constraint( | ||
| "CHECK(facades >= 0)", | ||
| "The amount of facades should be at least 0", | ||
| ) | ||
| _check_garden_area = models.Constraint( | ||
| "CHECK(garden_area >= 0)", | ||
| "The garden area should be at least 0", | ||
| ) | ||
|
|
||
| @api.constrains("selling_price") | ||
| def _check_selling_price(self): | ||
| for property in self: | ||
| if property.selling_price < 0.9 * property.expected_price: | ||
| raise ValidationError( | ||
| self.env._( | ||
| "Selling price cannot be lower than ninety percent of expected price", | ||
| ), | ||
| ) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _prevent_unlink_if_new_or_cancelled(self): | ||
| if any(property.state not in ("new", "cancelled") for property in self): | ||
| raise UserError(self.env._("Can only delete New or Cancelled properties")) | ||
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,78 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Offer on a property" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float(string="Price") | ||
| status = fields.Selection( | ||
| string="Status", | ||
| selection=[("accepted", "Accepted"), ("refused", "Refused")], | ||
| copy=False, | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Buyer", required=True) | ||
| property_id = fields.Many2one("estate.property", string="Property", required=True) | ||
|
|
||
| validity = fields.Integer(string="Validity (days)", default=7) | ||
| date_deadline = fields.Date( | ||
| string="Deadline", | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| ) | ||
|
|
||
| property_type_id = fields.Many2one( | ||
| related="property_id.property_type_id", store=True, | ||
| ) | ||
|
|
||
| @api.depends("validity") | ||
| def _compute_date_deadline(self): | ||
| for property_offer in self: | ||
| property_offer.date_deadline = fields.Date.today() + relativedelta( | ||
| days=property_offer.validity, | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for property_offer in self: | ||
| delta = property_offer.date_deadline - fields.Date.today() | ||
| property_offer.validity = delta.days | ||
|
|
||
| def accept_offer(self): | ||
| for property_offer in self: | ||
| if property_offer.property_id.state in ["new", "offer_received"]: | ||
| property_offer.property_id.state = "offer_accepted" | ||
| property_offer.property_id.buyer_id = property_offer.partner_id | ||
| property_offer.property_id.selling_price = property_offer.price | ||
| property_offer.status = "accepted" | ||
| else: | ||
| raise UserError( | ||
| self.env._( | ||
| "Cannot accept offer for already sold or cancelled property", | ||
| ), | ||
| ) | ||
| return True | ||
|
|
||
| def refuse_offer(self): | ||
| for property_offer in self: | ||
| if property_offer.status == "accepted": | ||
| raise UserError(self.env._("Cannot refuse already accepted offer")) | ||
| if property_offer.property_id.state in ["new", "offer_received"]: | ||
| property_offer.status = "refused" | ||
| return True | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| property_ids = [vals["property_id"] for vals in vals_list] | ||
| properties = self.env["estate.property"].browse(property_ids) | ||
|
|
||
| for vals in vals_list: | ||
| property = properties.browse(vals["property_id"]) | ||
| if property and (vals["price"] < property.best_price): | ||
| raise UserError(self.env._("Offer must be higher than best price")) | ||
|
|
||
| properties.write({"state": "offer_received"}) | ||
| return super().create(vals_list) |
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 = "Real Estate Property Tag" | ||
| _order = "name" | ||
|
|
||
| _name_uniq = models.Constraint( | ||
| "unique(name)", | ||
| "A tag with the same name already exists.", | ||
| ) | ||
|
|
||
| name = fields.Char("Title", required=True) | ||
| color = fields.Integer() |
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 = "Real Estate Property Type" | ||
| _order = "name" | ||
|
|
||
| _name_uniq = models.Constraint( | ||
| "unique(name)", | ||
| "A type with the same name already exists.", | ||
| ) | ||
|
|
||
| name = fields.Char("Title", required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
| sequence = fields.Integer( | ||
| "Sequence", default=1, help="Used to order property-types. Lower is better." | ||
| ) | ||
|
|
||
| offer_ids = fields.One2many("estate.property.offer", "property_type_id") | ||
| offer_count = fields.Integer(compute="_offer_count") | ||
|
|
||
| def _offer_count(self): | ||
| for property_type in self: | ||
| property_type.offer_count = len(property_type.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,10 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "salesperson_id", | ||
| domain=[("state", "in", ["new", "offer_received"])], | ||
| ) |
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 | ||
| 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 |
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 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_property_menu" name="Advertisements"> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_property_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_tag_menu_action" 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,37 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <record id="estate_property_offer_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"/></group> | ||
| <group><field name="partner_id"/></group> | ||
| <group><field name="validity"/></group> | ||
| <group><field name="date_deadline"/></group> | ||
| <group><field name="status"/></group> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_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" editable="bottom" decoration-danger="status == 'refused'" decoration-success="status == 'accepted'"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="accept_offer" string="Accept" type="object" icon="fa-check" invisible="status"/> | ||
| <button name="refuse_offer" string="Refuse" type="object" icon="fa-times" invisible="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| <record id="estate_property_offer_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list,form</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</field> | ||
| </record> | ||
| </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,32 @@ | ||
| <?xml version="1.0"?> | ||
| <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> | ||
| <record id="estate_property_tag_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| <field name="color" widget="color_picker"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| <record id="estate_property_tag_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="Tags" editable="bottom"> | ||
| <field name="name"/> | ||
| <field name="color" widget="color_picker"/> | ||
| </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.
Uh oh!
There was an error while loading. Please reload this page.