Skip to content
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

[ADD] estate: create estate.property model and initial views #107

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4f44de4
[ADD] estate: create estate.property model and initial views
amya-odoo Aug 1, 2024
39a6abb
[ADD] estate: created tree ,form, search in estate module
amya-odoo Aug 2, 2024
0db7313
[ADD] estate: done relation mapping between models, estate_type, offe…
amya-odoo Aug 5, 2024
9564242
[ADD] estate: best offer, validity date, sold/canceled buttons, SQL c…
amya-odoo Aug 6, 2024
cae8bfd
[ADD] estate: add sprinkles, colored offers/tag, add stat/accepte/ref…
amya-odoo Aug 12, 2024
090fd5b
[ADD] estate: models method, inherited the res.users, add estate_acco…
amya-odoo Aug 14, 2024
b189355
[ADD] estate: Add other model interaction and demo data
amya-odoo Aug 20, 2024
27fc6ce
[ADD] estate: Add report for the property, salesman, invoice
amya-odoo Aug 21, 2024
50bb5db
[IMP] estate: created controller of estate to access in website
amya-odoo Aug 22, 2024
6dd52ac
[IMP] estate: implemented the Wizard and Access Right to agent and Ma…
amya-odoo Aug 29, 2024
1e0cd9a
[IMP] estate: Added new wizard task
amya-odoo Sep 3, 2024
45c7b7d
[ADD] dental: created dental module
amya-odoo Sep 4, 2024
58784c3
[IMP] dental: tag view and model included
amya-odoo Sep 5, 2024
028d494
[IMP] dental: invoice
amya-odoo Sep 5, 2024
9b8798f
[ADD] dental: added controller,created web template
amya-odoo Sep 6, 2024
a688159
[IMP] dental: controller for form view personal, medial history
amya-odoo Sep 10, 2024
bb55acf
[ADD] installment: created new module and add features
amya-odoo Sep 17, 2024
16712c7
[IMP] installment: implemented the invoice cron and doc upload
amya-odoo Sep 19, 2024
ababe7f
[IMP] installment: implemented the document upload request wizard
amya-odoo Sep 20, 2024
0b1f226
[ADD] warranty: created new module warranty
amya-odoo Sep 24, 2024
f863581
[IMP] warranty: implemented the on delete warranty with product
amya-odoo Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
'name': "estate",
'version': '0.1',
'depends': ['base', 'mail'],
'description': "Technical practice",
'installable': True,
'application': True,

'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_offer_view.xml',
'views/estate_property_type.xml',
'views/estate_property_tag_view.xml',
'views/estate_menus.xml',
],
'license': 'LGPL-3',
}
4 changes: 4 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
119 changes: 119 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from odoo import models, fields, api
from dateutil.relativedelta import relativedelta
from datetime import date

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from odoo import models, fields, api
from dateutil.relativedelta import relativedelta
from datetime import date
from datetime import date
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models

Generally, we first import external libraries and then we import from odoo. And also take care for the imports in alphabetical order.

from odoo.exceptions import UserError, ValidationError


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real Estate Property Data"
_inherit = ["mail.thread", "mail.activity.mixin"]
name = fields.Char(required=True)
description = fields.Char()
postcode = fields.Char()
date_availability = fields.Date(
copy=False, default=date.today() + relativedelta(months=3)
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(copy=False, readonly=True)
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)
state = fields.Selection(
required=True,
copy=False,
default="new",
selection=[
("new", "New"),
("offer_recived", "Offer Recieved"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("canceled", "Canceled"),
],
tracking=True,
)
garden_orientation = fields.Selection(
selection=[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
]
)
_order = "id desc"
salesman_id = fields.Many2one(
"res.users", # The model this field relates to
string="Salesman", # Label for the field
default=lambda self: self.env.user, # Set default to the current user's partner
)
buyer_id = fields.Many2one(
"res.partner", # The model this field relates to
string="Buyer", # Label for the field
copy=False, # Prevent the field value from being copied when duplicating the record
)

tag_ids = fields.Many2many("estate.property.tag", string="Tags", ondelete="cascade")
offer_ids = fields.One2many("estate.property.offer", "property_id")
total = fields.Integer(compute="total_area")
best_offer = fields.Float(compute="best_offer_selete", store=True)
property_type_id = fields.Many2one("estate.property.type")

sql_constraints = [
(
"check_expected_price",
"CHECK(expected_price > 0)",
"The Expected Price of Property should be positive",
),
(
"check_selling_price",
"CHECK(selling_price >= 0 )",
"The Selling Price of Property should be Positive",
),
("name_uniq", "unique (name)", "Property name already exists!"),
]

@api.depends("living_area", "garden_area")
def total_area(self):
for recorde in self:
recorde.total = recorde.living_area + recorde.garden_area

@api.depends("offer_ids")
def best_offer_selete(self):
temp = 0
for offer in self.offer_ids:
if offer.price > temp:
temp = offer.price
self.best_offer = temp

@api.onchange("garden")
def garden_change(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = ""

def status_action_sold_button(self):
if self.state == "canceled":
raise UserError("Canceled property can't be sold")
else:
self.state = "sold"

def status_action_canceled_button(self):
if self.state == "sold":
raise UserError("Sold property can't be canceled")
else:
self.state = "canceled"

@api.constrains("selling_price", "expexted_price")
def _check_date_end(self):
for record in self:
if record.selling_price > 0:
price_percent = (record.selling_price / record.expected_price) * 100
if price_percent < 90:
raise ValidationError("Selling Price must be at least 90%")
75 changes: 75 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from odoo import models, fields, api
from datetime import timedelta, date
from odoo.exceptions import ValidationError


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Estate Property Offer"
_order = "price desc"
price = fields.Float()
status = fields.Selection(
copy=False, selection=[("accepted", "Accepted"), ("refused", "Refused")]
)
partner_id = fields.Many2one("res.partner", required=True)
property_id = fields.Many2one("estate.property", required=True)
validity = fields.Integer(default=7)
deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline")
property_type_id = fields.Many2one(related='property_id.property_type_id', store=True)

@api.ondelete(at_uninstall=False)
def _check_offer(self):
for record in self:
if record.status == "accepted":
# raise ValidationError("Accepted offer have benn deleted")
record.property_id.selling_price = 0
record.property_id.buyer_id = None
else:
pass

@api.depends("validity")
def _compute_deadline(self):
for record in self:
today = record.create_date
if today:
today = record.create_date
else:
today = date.today()
if record.validity:
record.deadline = today + timedelta(days=record.validity)
else:
record.deadline = today

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
today = record.create_date
if today:
today = record.create_date
else:
today = date.today()
if record.validity:
record.deadline = today + timedelta(days=record.validity)
else:
record.deadline = today
record.deadline = record.property_id.create_date + relativedelta(
days=record.validity
)

Can you give it a try but make sure to check all the cases


def _inverse_deadline(self):
for record in self:
if record.deadline:
# Convert create_date to a date object
today = fields.Date.to_date(record.create_date)
# Convert deadline to a date object
deadline_date = fields.Date.from_string(record.deadline)
record.validity = (deadline_date - today).days
else:
record.validity = 7 # Default to 7 if deadline is not set

def action_status_accept(self):
self.status = "accepted"
price_percent = 0
if self.property_id.expected_price != 0:
price_percent = (self.price / self.property_id.expected_price) * 100
if price_percent > 90:
self.property_id.selling_price = self.price
self.property_id.buyer_id = self.partner_id
else:
raise ValidationError("The selling price must be at least 90%")

def aciton_status_refused(self):
if self.status == "accepted":
self.property_id.selling_price = 0
self.property_id.buyer_id = None
self.status = "refused"
else:
self.status = "refused"

_sql_constraints = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we define SQL constraints just after field definition

("check_price", "CHECK(price >= 0)", "The Price of Offer should be positive"),
]
10 changes: 10 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import models, fields


class EstatePropertyTag(models.Model):
_name = 'estate.property.tag'
_description = 'Estate Property tag'
name = fields.Char(required=True)
_sql_constraints = [('name_uniq', 'unique (name)', "Tag name already exists!")]
_order = 'name'
color = fields.Integer()
20 changes: 20 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import fields, models, api


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Real Estate Property Type"
name = fields.Char(required=True)
property_id = fields.One2many('estate.property', 'property_type_id')
_order = 'sequence, name'
sequence = fields.Integer('Sequence', help="Used to order stages. Lower is better.")
offers_ids = fields.One2many('estate.property.offer', 'property_type_id')
offer_count = fields.Integer(compute='_offers_count', help="Number of offers")

@api.depends('offers_ids.property_type_id')
def _offers_count(self):
for record in self:
if record.offers_ids:
record.offer_count = len(record.offers_ids)
else:
record.offer_count = 0
6 changes: 6 additions & 0 deletions estate/security/ir.model.access.csv
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
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1

14 changes: 14 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<menuitem id="estate_property_root" name="Real Estate">

<menuitem id="estate_property_first_level_menu" name="Advertisment">
<menuitem id="estate_property_model_menu_action" action="estate_property_action"/>
</menuitem>

<menuitem id="estate_property_type_level_menu" name="Setting">
<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>
51 changes: 51 additions & 0 deletions estate/views/estate_property_offer_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<odoo>

<record id='estate_property_offer_tree' model='ir.ui.view'>
<field name="name">estate_property_offer</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<tree editable="bottom" sample="1" decoration-danger="status in ('refused', 'Refused')" decoration-success="status in ('accepted', 'Accepted')">
<field name='price'/>
<field name='partner_id'/>

<field name='validity' string='Validity (days)'/>
<field name='deadline'/>
<button name="action_status_accept" invisible="status in ('accepted', 'refused')" title="accept" type="object" icon="fa-check" />
<button name="aciton_status_refused" invisible="status in ('accepted', 'refused')" title="refused" type="object" icon="fa-times"/>
<field name='status' column_invisible='1' />
</tree>
</field>

</record>


<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 >
<sheet>
<group >
<field name='price'/>
<field name='partner_id'/>
<field name="validity"/>
<field name="deadline"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_estate_property_offer" model="ir.actions.act_window">
<field name="name">Estate Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>
<record id="action_estate_property_offer_y" model="ir.actions.act_window">
<field name="name">Estate Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>

</odoo>
24 changes: 24 additions & 0 deletions estate/views/estate_property_tag_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<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">tree,form</field>

<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new Property product
</p>
</field>
</record>

<record id='estate_property_tag_tree' model='ir.ui.view'>
<field name="name">estate_property_tag</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<tree editable="bottom" sample="1">
<field name='name'/>
</tree>
</field>

</record>
</odoo>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a blank line at the EOF

Loading