Skip to content

Commit 96af3d0

Browse files
[IMP] estate: Server101 Finished Chapter 11
1 parent d56b56b commit 96af3d0

8 files changed

+51
-18
lines changed

estate/models/estate_property.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dateutil.relativedelta import relativedelta
2-
from odoo import fields, models, api, exceptions
2+
from odoo import fields, models, api
33
from odoo.tools.float_utils import float_compare, float_is_zero
44
from odoo.exceptions import ValidationError, UserError
55

@@ -9,8 +9,8 @@ class EstateProperty(models.Model):
99
_description = "Property"
1010
_order = "id desc"
1111

12-
_positif_expected_price = models.Constraint("CHECK (expected_price > 0)", "A price can't be negatif")
13-
_positif_selling_price = models.Constraint("CHECK (selling_price > 0)", "A price can't be negatif")
12+
_positif_expected_price = models.Constraint("CHECK (expected_price >= 0)", "A price can't be negatif")
13+
_positif_selling_price = models.Constraint("CHECK (selling_price >= 0)", "A price can't be negatif")
1414

1515
state = fields.Selection(selection=[
1616
("new", "New"),
@@ -79,7 +79,7 @@ def _compute_best_price(self):
7979
@api.onchange("garden")
8080
def _on_change_garden(self):
8181
self.garden_area = 10 if self.garden else 0
82-
self.garden_orientation = 'North' if self.garden else ''
82+
self.garden_orientation = 'north' if self.garden else ''
8383

8484
@api.constrains('selling_price', 'expected_price')
8585
def _constrain_prices(self):

estate/models/estate_property_offer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ class EstatePropertyOffer(models.Model):
1717

1818
partner_id = fields.Many2one('res.partner', required=True)
1919
property_id = fields.Many2one('estate.property', required=True)
20+
property_type_id = fields.Many2one(related="property_id.property_type_id", store=True)
2021
validity = fields.Integer(string="Validity Duration", default=7)
2122
date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline")
2223

24+
2325
def accept_offer(self):
2426
for record in self:
2527
if (record.property_id.selling_price == 0):
2628
record.status = "accepted"
2729
record.property_id.buyer_id = record.partner_id
2830
record.property_id.selling_price = record.price
31+
record.property_id.state = 'offer_accepted'
2932
return True
3033

3134
def refused_offer(self):

estate/models/estate_property_tag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ class EstatePropertyTag(models.Model):
99
_unique_tag = models.UniqueIndex("(name)", "Tag name must be unique in database")
1010

1111
name = fields.Char(required=True)
12+
color = fields.Integer()

estate/models/estate_property_type.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import fields, models
1+
from odoo import fields, models, api
22

33

44
class EstatePropertyType(models.Model):
@@ -11,3 +11,10 @@ class EstatePropertyType(models.Model):
1111
name = fields.Char(required=True)
1212
property_ids = fields.One2many("estate.property", "property_type_id")
1313
sequence = fields.Integer('Sequence', default=1, help="use to order the list inside the type view")
14+
offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
15+
offer_count = fields.Integer(compute='_compute_offer_count')
16+
17+
@api.depends("offer_ids")
18+
def _compute_offer_count(self):
19+
for record in self:
20+
record.offer_count = len(record.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?xml version="1.0"?>
22
<odoo>
33

4+
<record id="estate_property_offer_model_action" model="ir.actions.act_window">
5+
<field name ="name">Property Offer</field>
6+
<field name="res_model">estate.property.offer</field>
7+
<field name="view_mode">list,form</field>
8+
<field name="domain">[('property_type_id', '=', active_id)]</field>
9+
</record>
10+
411
<record id="estate_property_offer_model_form" model="ir.ui.view">
512
<field name ="name">estate.property.offer.form</field>
613
<field name="model">estate.property.offer</field>
@@ -23,14 +30,14 @@
2330
<field name="name">estate.property.offer.list</field>
2431
<field name="model">estate.property.offer</field>
2532
<field name="arch" type="xml">
26-
<list string="Property offer list">
33+
<list string="Property offer list" editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
2734
<field name="price"/>
2835
<field name ="partner_id"/>
2936
<field name="date_deadline"/>
3037
<field name="validity"/>
31-
<button name="accept_offer" type="object" string="Accept" icon="fa-check"/>
32-
<button name="refused_offer" type="object" string="Refuse" icon="fa-times"/>
33-
<field name ="status"/>
38+
<field name="property_type_id"/>
39+
<button name="accept_offer" type="object" string="Accept" icon="fa-check" invisible="status == 'accepted' or status == 'refused'"/>
40+
<button name="refused_offer" type="object" string="Refuse" icon="fa-times" invisible="status == 'accepted' or status == 'refused'"/>
3441
</list>
3542
</field>
3643
</record>

estate/views/estate_property_tag_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,15 @@
2020
</form>
2121
</field>
2222
</record>
23+
<record id="estate_property_tag_model_list" model="ir.ui.view">
24+
<field name ="name">estate.property.tag.list</field>
25+
<field name="model">estate.property.tag</field>
26+
<field name="arch" type="xml">
27+
<list string="Property tag list" editable="bottom">
28+
<field name="name"/>
29+
</list>
30+
</field>
31+
</record>
32+
2333

2434
</odoo>

estate/views/estate_property_type_views.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<field name="arch" type="xml">
1414
<form string="Property type Form">
1515
<sheet>
16+
<div class="oe_stat_button">
17+
<button name="estate.estate_property_offer_model_action" string="Offers" type="action"/>
18+
</div>
1619
<group>
1720
<h1 class="mb32">
1821
<field name="name"/>

estate/views/estate_property_views.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55
<field name ="name">Property</field>
66
<field name="res_model">estate.property</field>
77
<field name="view_mode">list,form</field>
8+
<field name="context">{'search_default_available':True}</field>
89
</record>
910

1011
<record id="estate_property_view_list" model="ir.ui.view">
1112
<field name="name">estate.property.list</field>
1213
<field name="model">estate.property</field>
1314
<field name="arch" type="xml">
14-
<list string="Property list">
15+
<list string="Property list" decoration-bf="state == 'offer_accepted'" decoration-success="state == 'offer_accepted' or state == 'offer_recieved'" decoration-muted="state == 'sold'">
1516
<field name="name"/>
1617
<field name ="postcode"/>
1718
<field name ="bedrooms"/>
1819
<field name ="expected_price"/>
1920
<field name ="selling_price"/>
20-
<field name ="date_availability"/>
21+
<field name ="date_availability" optional="True"/>
2122
</list>
2223
</field>
2324
</record>
25+
2426
<record id="estate_property_model_form" model="ir.ui.view">
2527
<field name ="name">estate.property.form</field>
2628
<field name="model">estate.property</field>
2729
<field name="arch" type="xml">
2830
<form string="Property list">
2931
<header>
30-
<button name="sell_property" type="object" string="Sell"/>
31-
<button name="cancel_property" type="object" string="Cancel"/>
32+
<button name="sell_property" type="object" string="Sell" invisible="state == 'sold' or state == 'cancelled'"/>
33+
<button name="cancel_property" type="object" string="Cancel" invisible="state == 'sold' or state == 'cancelled'"/>
3234
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold,cancelled"/>
3335
</header>
3436
<sheet>
@@ -38,7 +40,7 @@
3840
</h1>
3941
</group>
4042
<group>
41-
<field name="tag_ids" widget="many2many_tags"/>
43+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
4244

4345
</group>
4446
<group>
@@ -62,13 +64,13 @@
6264
<field name="facades"/>
6365
<field name="garage"/>
6466
<field name="garden"/>
65-
<field name="garden_area"/>
66-
<field name="garden_orientation"/>
67+
<field name="garden_area" invisible="not garden"/>
68+
<field name="garden_orientation" invisible="not garden"/>
6769
<field name="total_area"/>
6870
</group>
6971
</page>
7072
<page string="Offers">
71-
<field name="offer_ids"/>
73+
<field name="offer_ids" readonly=" state == 'sold' or state =='cancelled' or state == 'offer_accepted'"/>
7274
</page>
7375
<page string="Other Info">
7476
<group>
@@ -92,7 +94,7 @@
9294
<field name="postcode"/>
9395
<field name="expected_price"/>
9496
<field name="bedrooms"/>
95-
<field name="living_area"/>
97+
<field name="living_area" filter_domain="[('living_area','>=',int(self))]"/>
9698
<field name="facades"/>
9799
<filter string="Available" name="available" domain="['|',('state','=','Offer_Received'),('state','=','New')]"/>
98100
<filter string="Postcodes" name="postcodes" context="{'group_by':'postcode'}"/>

0 commit comments

Comments
 (0)