Skip to content

Commit b422b27

Browse files
committed
[IMP] estate: chapter11 part1
1 parent 259a7b3 commit b422b27

9 files changed

+75
-19
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
'name': 'Estate',
33
'version': '0.1',
4+
'license': 'LGPL-3',
45
'application': True,
56
'author': 'matho',
67
'depends': [

estate/models/estate_property.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstateProperty(models.Model):
77
_name = "estate.property"
88
_description = "Estate Property"
9+
_order = "id desc"
910
_check_expected_price = models.Constraint("CHECK(expected_price>0)", "Le prix doit être strictement positif.")
1011
_check_selling_price = models.Constraint("CHECK(selling_price>=0)", "Le prix doit être positif.")
1112

@@ -33,6 +34,7 @@ class EstateProperty(models.Model):
3334
salesman = fields.Many2one("res.users")
3435
buyer = fields.Many2one("res.partner", copy=False)
3536
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
37+
property_type_id = fields.Many2one("estate.property.type")
3638
offer_ids = fields.One2many("estate.property.offer", "property_id")
3739
total_area = fields.Float(compute="_compute_total")
3840
best_price = fields.Float(compute="_compute_highest_price")
@@ -67,5 +69,5 @@ def action_mark_as_cancelled(self):
6769
@api.constrains("selling_price", "expected_price")
6870
def _check_selling_price_is_ok(self):
6971
for record in self:
70-
if float_compare(self.selling_price, 0.9 * self.expected_price, 2) == -1:
72+
if self.selling_price and float_compare(self.selling_price, 0.9 * self.expected_price, 2) == -1:
7173
raise ValidationError("Le prix de vente doit valoir au moins 90 pourcents du prix attendu.")

estate/models/estate_property_offer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
class EstatePropertyOffer(models.Model):
55
_name = "estate.property.offer"
6-
_description = "ici je mets une phrase 4"
6+
_description = "Estate Property Offer"
7+
_order = "price desc"
78
_check_price = models.Constraint("CHECK(price>0)", "Le prix doit être strictement positif.")
89

910
price = fields.Float()
@@ -24,6 +25,7 @@ def _inverse_deadline(self):
2425

2526
def action_accept(self):
2627
self.status = "Accepted"
28+
self.property_id.state="Offer Accepted"
2729
self.property_id.buyer = self.partner_id
2830
self.property_id.selling_price = self.price
2931
return True

estate/models/estate_property_tag.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
6-
_description = "ici je mets une phrase 3"
6+
_description = "Estate Property Tag"
7+
_order = "name"
78
_name_unique = models.Constraint("unique (name)", "Ce tag existe déjà.")
89

910
name = fields.Char(required=True)
11+
color = fields.Integer()

estate/models/estate_property_type.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
6-
_description = "ici je mets une phrase 2"
6+
_description = "Estate Property Type"
7+
_order = "name"
78
_name_unique = models.Constraint("unique (name)", "Ce type de propriété existe déjà.")
89

910
name = fields.Char(required=True)
11+
property_ids = fields.One2many("estate.property", "property_type_id")
12+
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")

estate/views/estate_menus.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<menuitem id="test_model_menu_action" action="mon_action"/>
66
</menuitem>
77
<menuitem id="settings_menu" name="Settings">
8-
<menuitem id="test_model_menu_action2" action="mon_action2"/>
8+
<menuitem id="test_model_menu_action2" action="estate_property_type_action"/>
99
<menuitem id="test_model_menu_action3" action="mon_action3"/>
1010
</menuitem>
1111
</menuitem>

estate/views/estate_property_tag_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
<field name="view_mode">list,form</field>
77
</record>
88

9+
<record id="estate_property_tag_view_list" model="ir.ui.view">
10+
<field name="name">estate.property.tag.view.list</field>
11+
<field name="model">estate.property.tag</field>
12+
<field name="arch" type="xml">
13+
<list editable="bottom">
14+
<field name="name"/>
15+
</list>
16+
</field>
17+
</record>
18+
919

1020
</data>
1121
</odoo>
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
<odoo>
22
<data>
3-
<record id="mon_action2" model="ir.actions.act_window">
3+
<record id="estate_property_type_action" model="ir.actions.act_window">
44
<field name="name">Property Types</field>
55
<field name="res_model">estate.property.type</field>
66
<field name="view_mode">list,form</field>
77
</record>
88

9+
<record id="estate_property_type_view_list" model="ir.ui.view">
10+
<field name="name">estate.property.type.view.list</field>
11+
<field name="model">estate.property.type</field>
12+
<field name="arch" type="xml">
13+
<list>
14+
<field name="name"/>
15+
<field name="sequence" widget="handle"/>
16+
</list>
17+
</field>
18+
</record>
19+
20+
<record id="estate_property_type_view_form" model="ir.ui.view">
21+
<field name="name">estate.property.type.view.form</field>
22+
<field name="model">estate.property.type</field>
23+
<field name="arch" type="xml">
24+
<form string="Property Type">
25+
<sheet>
26+
<h1>
27+
<field name="name"/>
28+
</h1>
29+
<notebook>
30+
<page string="Properties">
31+
<field name="property_ids">
32+
<list>
33+
<field name="name" string="Title"/>
34+
<field name="expected_price"/>
35+
<field name="state"/>
36+
</list>
37+
</field>
38+
</page>
39+
</notebook>
40+
</sheet>
41+
</form>
42+
</field>
43+
</record>
44+
945

1046
</data>
1147
</odoo>

estate/views/estate_property_views.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
<field name="view_mode">list,form</field>
88
</record>
99

10-
<record id="estate_property_view_form" model="ir.ui.view">
10+
<record id="estate_property_view_list" model="ir.ui.view">
1111
<field name="name">estate.property.view.list</field>
1212
<field name="model">estate.property</field>
1313
<field name="arch" type="xml">
14-
<list string="Channel" >
14+
<list editable="bottom">
1515
<field name="name"/>
1616
<field name="postcode"/>
1717
<field name="bedrooms"/>
1818
<field name="living_area"/>
1919
<field name="expected_price"/>
2020
<field name="selling_price"/>
21-
<field name="date_availability"/>
21+
<field name="date_availability" optional="hide"/>
2222
</list>
2323
</field>
2424
</record>
@@ -29,18 +29,19 @@
2929
<field name="arch" type="xml">
3030
<form string="Test">
3131
<header>
32-
<button name="action_mark_as_sold" type="object" string="Sold"/>
33-
<button name="action_mark_as_cancelled" type="object" string="Cancelled"/>
32+
<button name="action_mark_as_sold" type="object" string="Sold" invisible="state in ['Offer Accepted', 'Sold', 'Cancelled']"/>
33+
<button name="action_mark_as_sold" type="object" string="Sold" class="btn-primary" invisible="state != 'Offer Accepted'"/>
34+
<button name="action_mark_as_cancelled" type="object" string="Cancelled" invisible="state == 'Sold' or state == 'Cancelled'"/>
35+
<field name="state" widget="statusbar" statusbar_visible="New,Offer Received,Offer Accepted,Sold"/>
3436
</header>
3537
<sheet>
3638
<h1>
3739
<field name="name"/>
3840
</h1>
39-
<group>
40-
<field name="tag_ids" widget="many2many_tags"/>
41-
</group>
4241
<group>
4342
<group>
43+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
44+
<field name="property_type_id" options="{'no_create_edit': True}"/>
4445
<field name="postcode"/>
4546
<field name="date_availability"/>
4647
</group>
@@ -59,15 +60,14 @@
5960
<field name="facades"/>
6061
<field name="garage"/>
6162
<field name="garden"/>
62-
<field name="garden_area"/>
63-
<field name="garden_orientation"/>
64-
<field name="state"/>
63+
<field name="garden_area" invisible="not garden"/>
64+
<field name="garden_orientation" invisible="not garden"/>
6565
<field name="total_area"/>
6666
</group>
6767
</page>
6868
<page string="Offers">
69-
<field name="offer_ids">
70-
<list string="Channel" >
69+
<field name="offer_ids" readonly="state in ['Offer Accepted', 'Sold', 'Cancelled']">
70+
<list editable="bottom">
7171
<field name="price"/>
7272
<field name="partner_id"/>
7373
<button name="action_accept" type="object" icon="fa-check" string="accept"/>

0 commit comments

Comments
 (0)