Skip to content

Commit 46bf355

Browse files
committed
[IMP] estate: added inheritance and on create functions.
added python inheritance, model inheritance, view inheritance. added create function to change state from 'new' to 'offer_received'. separated all property action to it's own views file.
1 parent 536d4cc commit 46bf355

12 files changed

+166
-105
lines changed

estate/__manifest__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"data": [
1414
"security/ir.model.access.csv",
1515
"views/estate_property_views.xml",
16+
"views/estate_property_offer_views.xml",
17+
"views/estate_property_tag_views.xml",
18+
"views/estate_property_type_views.xml",
19+
"views/res_users_views.xml",
1620
"views/estate_menus.xml",
1721
],
1822
}

estate/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from . import estate_property_type
44
from . import estate_property_tag
55
from . import estate_property_offer
6+
from . import res_users

estate/models/estate_property.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
from dateutil.relativedelta import relativedelta
3-
from odoo.exceptions import ValidationError
3+
from odoo.exceptions import UserError, ValidationError
44

55
from odoo import api, models, fields, exceptions
66

@@ -54,9 +54,7 @@ class EstateProperty(models.Model):
5454
copy=False,
5555
default="new",
5656
)
57-
property_type_id = fields.Many2one(
58-
"estate.property.type", string="Property Type"
59-
)
57+
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
6058
customer = fields.Many2one("res.partner", string="Customer", copy=False)
6159
salesperson = fields.Many2one(
6260
"res.users", string="Salesperson", default=lambda self: self.env.user
@@ -107,8 +105,20 @@ def action_cancel_offer(self):
107105
@api.constrains("selling_price", "expected_price")
108106
def _check_selling_price_persentage(self):
109107
for record in self:
110-
selling_price_persentage = (record.selling_price / record.expected_price) * 100
111-
if selling_price_persentage >=90 or selling_price_persentage == 0:
108+
selling_price_persentage = (
109+
record.selling_price / record.expected_price
110+
) * 100
111+
if selling_price_persentage >= 90 or selling_price_persentage == 0:
112112
pass
113113
else:
114-
raise ValidationError("the selling price cannot be lower than 90% of the expected price.")
114+
raise ValidationError(
115+
"the selling price cannot be lower than 90% of the expected price."
116+
)
117+
118+
@api.ondelete(at_uninstall=False)
119+
def _unlink_prevent_property_on_state(self):
120+
for record in self:
121+
if record.state not in ("new", "cancelled"):
122+
raise UserError(
123+
"Can Delete property only on 'New' or 'Cancelled' state!"
124+
)

estate/models/estate_property_offer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dateutil.relativedelta import relativedelta
2+
from odoo.exceptions import UserError
23

34
from odoo import api, models, fields
45

@@ -51,3 +52,16 @@ def action_refuse(self):
5152
record.status = "refused"
5253
record.property_id.customer = None
5354
return True
55+
56+
@api.model
57+
def create(self, vals):
58+
if len(vals) > 0:
59+
property = self.env["estate.property"].browse(vals[0]["property_id"])
60+
for record in vals:
61+
if property.state == "new":
62+
property.state = "offer_received"
63+
if record["price"] < property.best_price:
64+
raise UserError(
65+
"Cannot create an offer with a lower amount than an existing offer."
66+
)
67+
return super().create(vals)

estate/models/res_users.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from odoo import fields, models
2+
3+
4+
class ResUser(models.Model):
5+
_inherit = "res.users"
6+
7+
property_ids = fields.One2many(
8+
"estate.property",
9+
"salesperson",
10+
domain="[('state', '!=', 'sold')]",
11+
)

estate/static/icon.png

19.7 KB
Loading

estate/views/estate_menus.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<odoo>
33
<menuitem
44
id="estate_menu_root"
5-
name="Estate Property"
5+
name="Real Estate"
6+
web_icon="estate,static/icon.png"
67
/>
78
<menuitem
89
id="estate_menu_property_advertisement"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="action_estate_property_offer" model="ir.actions.act_window">
4+
<field name="name">Property Offers</field>
5+
<field name="res_model">estate.property.offer</field>
6+
<field name="view_mode">list,form</field>
7+
<field name="domain">[('property_type_id', '=', active_id)]</field>
8+
</record>
9+
10+
<record id="action_estate_offer_view_list" model="ir.ui.view">
11+
<field name="name">estate.property.offer.list</field>
12+
<field name="model">estate.property.offer</field>
13+
<field name="arch" type="xml">
14+
<list string="Offer" editable="bottom" decoration-danger="status=='refused'" decoration-success="status=='accepted'">
15+
<field name="price"/>
16+
<field name="partner_id"/>
17+
<field name="validity" string="Validity(days)"/>
18+
<field name="date_deadline"/>
19+
<button name="action_accept" string="Accept" type="object" icon="fa-check" invisible="status in ('accepted', 'refused')"/>
20+
<button name="action_refuse" string="Refuse" type="object" icon="fa-times" invisible="status in ('accepted', 'refused')"/>
21+
</list>
22+
</field>
23+
</record>
24+
</odoo>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="action_estate_property_tag" model="ir.actions.act_window">
4+
<field name="name">Properties Tags</field>
5+
<field name="res_model">estate.property.tag</field>
6+
<field name="view_mode">list,form</field>
7+
<field name="help" type="html">
8+
<p class="o_view_nocontent_smiling_face">
9+
Create your first Property Tag!
10+
</p>
11+
</field>
12+
</record>
13+
14+
<record id="action_estate_property_tag_view_list" model="ir.ui.view">
15+
<field name="name">estate.property.tag.list</field>
16+
<field name="model">estate.property.tag</field>
17+
<field name="arch" type="xml">
18+
<list string="Tag" editable="bottom">
19+
<field name="name"/>
20+
<field name="color" widget="color_picker"/>
21+
</list>
22+
</field>
23+
</record>
24+
</odoo>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="action_estate_property_type" model="ir.actions.act_window">
4+
<field name="name">Properties Types</field>
5+
<field name="res_model">estate.property.type</field>
6+
<field name="view_mode">list,form</field>
7+
<field name="help" type="html">
8+
<p class="o_view_nocontent_smiling_face">
9+
Create your first Property Type!
10+
</p>
11+
</field>
12+
</record>
13+
14+
<record id="action_estate_property_type_form" model="ir.ui.view">
15+
<field name="name">estate.property.type.form</field>
16+
<field name="model">estate.property.type</field>
17+
<field name="arch" type="xml">
18+
<form name="Property Type List">
19+
<header>
20+
<button class="oe_stat_button" type="action" name="%(estate.action_estate_property_offer)d" icon="fa-list" string="offer"/>
21+
<field name="offer_count"/>
22+
</header>
23+
<sheet>
24+
<h1>
25+
<field name="name"/>
26+
</h1>
27+
<notebook>
28+
<page string="Properties">
29+
<field name="property_ids">
30+
<list>
31+
<field name="name" string="Title"/>
32+
<field name="expected_price"/>
33+
<field name="state"/>
34+
</list>
35+
</field>
36+
</page>
37+
</notebook>
38+
</sheet>
39+
</form>
40+
</field>
41+
</record>
42+
43+
<record id="action_estate_property_type_view_list" model="ir.ui.view">
44+
<field name="name">estate.property.type.list</field>
45+
<field name="model">estate.property.type</field>
46+
<field name="arch" type="xml">
47+
<list string="Types">
48+
<field name="sequence" widget="handle"/>
49+
<field name="name" string="Type"/>
50+
</list>
51+
</field>
52+
</record>
53+
</odoo>

0 commit comments

Comments
 (0)