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: created estate module #113

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
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',
'license': 'LGPL-3',
'depends': ['base_setup', 'mail'],
'description': "Technical Training",
'installable': True,
'application': True,

'data': [
'security/ir.model.access.csv',
'view/estate_property_views.xml',
'view/estate_property_offer_views.xml',
'view/estate_property_type_views.xml',
'view/estate_property_tag_views.xml',
'view/estate_menus.xml',
],
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
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
82 changes: 82 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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, model

generally we import the external libraries first and then imports from odoo in alphabetical orders

from odoo.exceptions import UserError, ValidationError


class estate_property(models.Model):
_name = "estate_property"

Choose a reason for hiding this comment

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

Suggested change
_name = "estate_property"
_name = "estate.property"

we use . while giving model name as per convention make sure to check in other files also.

_description = "Estate Property"
_order = "sequence, id desc"
_inherit = ['mail.thread', 'mail.activity.mixin']
name = fields.Char(required=True)
description = fields.Text()
sequence = fields.Integer('Sequence')
postcode = fields.Char()
date_availability = fields.Date(default=date.today() + relativedelta(month=3))
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True)
bedrooms = fields.Integer(default=2)
livingArea = fields.Integer()
garage = fields.Integer()
facades = fields.Integer()
garden = fields.Boolean()
garden_area = fields.Integer()
active = fields.Boolean(default=True)
state = fields.Selection(default='new', selection=[('new', 'New'), ('offer_received', 'Offer Received'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('canceled', 'Canceled')], tracking=True)
garden_orientation = fields.Selection(selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')])
property_type = fields.Many2one("estate_property_type", string="Property Type")
salesperson_id = fields.Many2one('res.users', string='Selesperson', default=lambda self: self.env.user)
buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False, ondelete='cascade')
tag_ids = fields.Many2many("estate_property_tag", string="Tags")
offer_ids = fields.One2many('estate_property_offer', 'property_id')
total_area = fields.Float(compute="_compute_total")
best_offer = fields.Float(compute="_best_offer")
_sql_constraints = [
('check_Expected_price', 'CHECK(expected_price > 0)', 'Expected Price must be strictly positive'),
('check_selling_price', 'CHECK(selling_price >= 0)', 'Selling Price selling price must be positive'),
('unique_name', 'UNIQUE(name)', 'Property type name must be unique')
]

@api.depends()
def _compute_total(self):
for record in self:
record.total_area = record.garden_area + record.livingArea

@api.depends('offer_ids')
def _best_offer(self):
maximum_price = 0
for record in self.offer_ids:
if record.price > maximum_price:
maximum_price = record.price
self.best_offer = maximum_price

@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 = ''

def button_action_sold(self):
if self.state == "canceled":
raise UserError("Can't be Sold")
else:
self.state = "sold"

def button_action_cancled(self):
if self.state == "sold":
raise UserError("Can't be Cancle, It is already Sold")
else:
self.state = "canceled"

@api.constrains('selling_price', 'expected_price')
def _price_constrains(self):
for record in self:
if record.selling_price > 0:
if record.selling_price < 0.9 * record.expected_price:
raise ValidationError("Selling price cannot be lower than 90% of the expected price")
else:
pass
65 changes: 65 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from odoo import models, fields, api
from datetime import date
from datetime import timedelta
from odoo.exceptions import UserError


class estate_property_offer(models.Model):
_name = "estate_property_offer"
_description = "Estate Property offer"
price = fields.Float()
_order = "sequence, price desc"
sequence = fields.Integer('Sequence')
_sql_constraints = [
('offer_price', 'CHECK(price > 0)', 'offer price must be strictly positive')
]
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)
date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_validity", string="Deadline")
property_type_id = fields.Many2one(related="property_id.property_type", store=True)

@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.date_deadline:
record.date_deadline = today + (record.validity - (record.date_deadline - today).days)
else:
record.date_deadline = timedelta(days=record.validity) + 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.date_deadline:
record.date_deadline = today + (record.validity - (record.date_deadline - today).days)
else:
record.date_deadline = timedelta(days=record.validity) + today
record.date_deadline = record.property_id.create_date + relativedelta(
days=record.validity
)

Can we do something like this? But make sure to check all the cases.


@api.ondelete(at_uninstall=False)
def _deletion_check(self):
for record in self:
if record.status == 'accepted':
record.property_id.buyer_id = None
record.property_id.selling_price = 0

def _inverse_validity(self):
for record in self:
today1 = fields.Date.from_string(record.create_date)
updated_deadline_date = fields.Date.from_string(record.date_deadline)
record.validity = (updated_deadline_date - today1).days

Choose a reason for hiding this comment

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

Suggested change
today1 = fields.Date.from_string(record.create_date)
updated_deadline_date = fields.Date.from_string(record.date_deadline)
record.validity = (updated_deadline_date - today1).days
record.validity = (record.date_deadline - record.property_id.create_date.date()).days

we write the inverse method just after the compute.


def action_confirm(self):
if self.property_id.buyer_id:
raise UserError("Validation Error!, It is already accepted")
else:
self.property_id.selling_price = self.price
self.property_id.buyer_id = self.partner_id
self.status = 'accepted'
self.property_id.state = 'offer_accepted'

def action_refused(self):
if self.status == 'accepted' and self.property_id.buyer_id == self.partner_id:
self.status = 'refused'
self.property_id.buyer_id = None
self.property_id.selling_price = 0
self.property_id.state = 'new'
else:
self.status = "refused"
14 changes: 14 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo import models, fields


class estate_property_tag(models.Model):
_name = "estate_property_tag"
_description = "Estate Property Tag"
name = fields.Char(required=True)
_order = " sequence, name"
sequence = fields.Integer('Sequence')
color = fields.Integer()

_sql_constraints = [
('unique_tag', 'UNIQUE(name)', 'Property Tag name must be unique')
]
17 changes: 17 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import api, models, fields


class estate_property_type(models.Model):
_name = "estate_property_type"
_description = "Estate Property Type"
name = fields.Char(required=True)
_order = "sequence, name"
sequence = fields.Integer('Sequence')
property_list_id = fields.One2many('estate_property', 'property_type')
offer_ids = fields.One2many("estate_property_offer", "property_type_id", string="offers")
offer_count = fields.Integer(string="Numbers of offer", compute='_compute_offer_count', store=True)

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
5 changes: 5 additions & 0 deletions estate/security/ir.model.access.csv
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.access_estate_property,access_estate_property,estate.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
12 changes: 12 additions & 0 deletions estate/view/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<menuitem id="estate_property_root" name="Real Estate">
<menuitem id="estate_property_level_menu" name="Advertisement">
<menuitem id="estate_property_menu_action" action="estate_property_action" name="property"/>
</menuitem>

<menuitem id="estate_property_type_level_menu" name="Setting">
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action" name="Property type"/>
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action" name="property tag" />
</menuitem>
</menuitem>
</odoo>
52 changes: 52 additions & 0 deletions estate/view/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<odoo>
<record id="action_account_estate_property_offer_tree" model="ir.ui.view">
<field name="name">estate_property_offer_tree</field>
<field name="model">estate_property_offer</field>
<field name="arch" type="xml">
<tree sample="1" editable="bottom" decoration-success="status in ('accepted')" decoration-danger="status in ('refused')" >

<field name = 'sequence' widget = 'handle'/>
<field name='price' />
<field name='partner_id' />
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_confirm" type="object" title="confirm" icon="fa-check" invisible="status in ('accepted', 'refused')"/>
<button name="action_refused" type="object" title="refused" icon="fa-times" invisible="status in ('accepted', 'refused')"/>

<field name='status' invisible="status in ('accepted', 'refused')"/>
</tree>
</field>
</record>


<record id="action_account_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="date_deadline"/>
<field name='status' />

</group>
</sheet>
</form>
</field>
</record>

<record id="estate_property_offer_check" 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>

Choose a reason for hiding this comment

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

Missing newline at EOF

22 changes: 22 additions & 0 deletions estate/view/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<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>
</record>


<record id = "estate_property_tag_list_action" model = "ir.ui.view">
<field name = "name">estate_property_tag_list</field>
<field name = "model">estate_property_tag</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name = "sequence" widget = "handle" />
<field name = "name"/>

</tree>

</field>

Choose a reason for hiding this comment

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

Suggested change

</record>
</odoo>
65 changes: 65 additions & 0 deletions estate/view/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<odoo>

<record id="estate_property_type_action" model="ir.actions.act_window">
<field name="name">Property Type</field>
<field name="res_model">estate_property_type</field>
<field name="view_mode">tree,form</field>
</record>

<record id="estate_property_type_list_action" model="ir.ui.view">
<field name="name">estate_property_type_form</field>
<field name="model">estate_property_type</field>
<field name="arch" type="xml">
<tree>
<field name='sequence' widget='handle' />
<field name="name" />

</tree>
</field>

</record>

<record id="estate_property_list_action" model="ir.ui.view">
<field name="name">estate_property_type_form</field>
<field name="model">estate_property_type</field>
<field name="arch" type="xml">

<form>

<button type="action" name="%(estate.estate_property_offer_check)d" string="offers" class="oe_stat_button"
icon="fa-ticket">

<div class="o_stat_info">
<field name="offer_count" widget="statinfo" string="" />
<span class="o_stat_text"> Offer</span>
</div>

</button>

Choose a reason for hiding this comment

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

Suggested change
<button type="action" name="%(estate.estate_property_offer_check)d" string="offers" class="oe_stat_button"
icon="fa-ticket">
<div class="o_stat_info">
<field name="offer_count" widget="statinfo" string="" />
<span class="o_stat_text"> Offer</span>
</div>
</button>
<div name="button_box">
<button class="oe_stat_button" type="action" name="%(estate.action_estate_property_offer)d"
icon="fa-ticket">
<field string="Offers" name="offer_count" widget="statinfo"/>
</button>
</div>

we can do something like this to format stat button.



<header>
<h1>
<field name="name" placeholder="e.g House">

</field>
</h1>
</header>
<notebook>
<page string="properties">
<field name="property_list_id">
<tree>
<field name="name" />
<field name="expected_price" />
<field name="state" />

</tree>

</field>

</page>
</notebook>
</form>
</field>
</record>

</odoo>
Loading