-
Notifications
You must be signed in to change notification settings - Fork 105
[ADD] estate module #874
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
Draft
mgo-adhoc
wants to merge
1
commit into
ingadhoc:19.0
Choose a base branch
from
adhoc-dev:19.0-t-1234-mgo
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.
+646
−0
Draft
[ADD] estate module #874
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,19 @@ | ||
| { | ||
| "name": "Real Estate Management", | ||
| "depends": ["base"], | ||
| "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/res_users_views.xml", | ||
| "views/estate_menus.xml", | ||
| ], | ||
| "author": "ADHOC SA", | ||
| "license": "AGPL-3", | ||
| "auto_install": False, | ||
| "installable": True, | ||
| "version": "19.0.1.0.0", | ||
| } | ||
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_offer | ||
| from . import estate_property_tag | ||
| from . import estate_property_type | ||
| 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,106 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
| # commit nuevo | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Real Estate Properties" | ||
| # Esto esta obsoleto | ||
| # _sql_constraints = [ | ||
| # ("check_expected_price", "CHECK(expected_price > 0)", "The expected price must be strictly positive."), | ||
| # ( | ||
| # "check_selling_price", | ||
| # "CHECK(selling_price IS NULL OR selling_price > 0)", | ||
| # "The selling price must be positive.", | ||
| # ), | ||
| # ] | ||
| _order = "id desc" # Ordenar por id descendente para mostrar los registros más recientes primero | ||
|
|
||
| # Se podria poner un atributo "String" en caso de que quiera mostrar algo distinto al nombre | ||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date(copy=False, default=lambda self: fields.Date.add(fields.Date.today(), months=3)) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Integer(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() | ||
| active = fields.Boolean(default=True) | ||
| garden_orientation = fields.Selection([("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")]) | ||
| state = fields.Selection( | ||
| [ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("canceled", "Canceled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", required=True) | ||
| field1 = fields.Char() | ||
| user_id = fields.Many2one( | ||
| "res.users", | ||
| string="Salesperson", | ||
| default=lambda self: self.env.user, | ||
| required=True, | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
| tag_ids = fields.Many2many("estate.property.tag") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id") # Hay que poner el inverso | ||
| total_area = fields.Integer(compute="_compute_total_area") | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| # import pdb; pdb.set_trace() | ||
| 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: | ||
| record.best_price = max(record.offer_ids.mapped("price")) if record.offer_ids else 0.0 | ||
|
|
||
| @api.depends("garden") | ||
| def _compute_garden(self): | ||
| for record in self: | ||
| if record.garden: | ||
| record.garden_area = 10 | ||
| record.garden_orientation = "north" | ||
| else: | ||
| record.garden_area = 0 | ||
| record.garden_orientation = False | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| if record.state == "canceled": | ||
| raise UserError("Only accepted offers can be sold.") | ||
| record.state = "sold" | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == "sold": | ||
| raise UserError("Sold properties cannot be canceled.") | ||
| record.state = "canceled" | ||
|
|
||
| def unlink(self): | ||
| for record in self: | ||
| if record.state not in ("new", "canceled"): | ||
| raise UserError("You can only delete properties in state 'New' or 'Canceled'.") | ||
| return super().unlink() | ||
|
|
||
| # Esto no me funcionaba, lo hice de otra forma arriba, sobreescribiendo unlink | ||
| # @api.ondelete() | ||
| # def _ondelete_restrict_sold(self): | ||
| # for record in self: | ||
| # if record.state not in ("new", "canceled"): | ||
| # raise UserError("You can only delete properties in state 'New' or 'Canceled'.") |
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,69 @@ | ||
| 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 = "Property Offers" | ||
| _sql_constraints = [ | ||
| ("check_offer_price", "CHECK(price > 0)", "The offer price must be strictly positive."), | ||
| ] | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection([("accepted", "Accepted"), ("refused", "Refused")], copy=False) | ||
| partner_id = fields.Many2one("res.partner", required=True) | ||
| property_id = fields.Many2one("estate.property", required=True) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline") | ||
| property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id") | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| record.date_deadline = ( | ||
| (record.create_date + relativedelta(days=record.validity)).date() if record.create_date else False | ||
| ) | ||
|
|
||
| @api.depends("date_deadline", "create_date") | ||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = ( | ||
| (record.date_deadline - record.create_date).days if record.date_deadline and record.create_date else 0 | ||
| ) | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| if record.property_id.state not in ["new", "offer_received"]: | ||
| raise UserError("Only new or offer received properties can accept an offer.") | ||
| record.status = "accepted" | ||
| record.property_id.state = "offer_accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.partner_id = record.partner_id | ||
|
|
||
| def action_reject(self): | ||
| for record in self: | ||
| record.status = "refused" | ||
|
|
||
| @api.constrains("price", "property_id.expected_price") | ||
| def _check_price(self): | ||
| for record in self: | ||
| if record.price < 0.9 * record.property_id.expected_price: | ||
| raise UserError("The offer price must be at least 90% of the expected price.") | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| records = super().create(vals_list) | ||
| for rec in records: | ||
| # Encuentra la mayor oferta, menos la actual | ||
| other_offers = rec.property_id.offer_ids.filtered(lambda o: o.id != rec.id) | ||
| max_other = max(other_offers.mapped("price")) if other_offers else 0.0 | ||
| if max_other and rec.price < max_other: | ||
| raise UserError("You cannot create an offer with a lower price than an existing offer.") | ||
|
|
||
| # actualiza estado a oferta recibida si es nuevo | ||
| if rec.property_id.state == "new": | ||
| rec.property_id.state = "offer_received" | ||
|
|
||
| return records |
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,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Property Tags" | ||
| _sql_constraints = [ | ||
| ("unique_tag_name", "UNIQUE(name)", "The tag name must be unique."), | ||
| ] | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(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,21 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Property Types" | ||
| _sql_constraints = [ | ||
| ("unique_property_type_name", "UNIQUE(name)", "The property type name must be unique."), | ||
| ] | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") | ||
| sequence = fields.Integer(default=10) | ||
| offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers") | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
|
|
||
| @api.depends("offer_ids") | ||
| 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,12 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "user_id", | ||
| string="Properties", | ||
| 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,14 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
| <!-- Boton general --> | ||
| <menuitem id="real_estate_menu" name="Real Estate"/> | ||
|
|
||
| <!-- Menu de Advertisements --> | ||
| <menuitem id="advertisements_menu" name="Advertisements" parent="real_estate_menu"/> | ||
| <menuitem id="properties_menu" action="estate_property_action" parent="advertisements_menu"/> | ||
|
|
||
| <!-- Menu de settings --> | ||
| <menuitem id="settings_menu" name="Settings" sequence="100" parent="real_estate_menu"/> | ||
| <menuitem id="property_types_menu" action="estate_property_type_action" parent="settings_menu"/> | ||
| <menuitem id="property_tags_menu" action="estate_property_tag_action" parent="settings_menu"/> | ||
| </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,51 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
|
|
||
| <!-- | ||
| Agregue esto | ||
| --> | ||
| <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> | ||
| <!-- Vista de Lista --> | ||
| <record id="estate_property_offer_list_view" 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-danger="status == 'refused'" decoration-success="status == 'accepted'"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="property_type_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="action_accept" string="Accept" type="object" invisible="status in ('accepted', 'refused')"/> | ||
| <button name="action_reject" string="Refuse" type="object" invisible="status in ('accepted', 'refused')"/> | ||
| <field name="status" invisible="True"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <!-- Vista de Formulario --> | ||
| <record id="estate_property_offer_form_view" 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="Property Tag"> | ||
| <sheet> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="status"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <field name="property_type_id"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </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,39 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
|
|
||
| <!--Vista basica--> | ||
| <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> | ||
|
|
||
| <!-- Vista de Lista --> | ||
| <record id="estate_property_tag_list_view" 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="Property Tags" editable="bottom"> | ||
| <field name="name" string="Title"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <!-- Vista de Formulario --> | ||
| <record id="estate_property_tag_form_view" 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 string="Property Tag"> | ||
| <sheet> | ||
| <div> | ||
| <h1> | ||
| <field name="name" placeholder="Title"/> | ||
| </h1> | ||
| </div> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> |
Oops, something went wrong.
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.
Lo que te faltaria aca defini por las dudas y que siempre hacemos es el auto-install: en false, application: True en este caso.
installabel: True, y muy importante la version : "19.0.1.0.0" en este caso