Skip to content

Commit b3830f1

Browse files
committed
[IMP] [FIX] Overall Code polishing and debugging the runbot.
- Polished the code to respect the coding guidelines. - Corrected the order of views within the menifest of the 'estate' module. This is an exercise on the tutorial "Server Framework 101: Chapter 15"
1 parent e9f5a95 commit b3830f1

13 files changed

+55
-24
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
],
1010
'data': [
1111
"views/estate_property_views.xml",
12+
"views/estate_property_offer_views.xml",
1213
"views/estate_property_type_views.xml",
1314
"views/estate_property_tag_views.xml",
14-
"views/estate_property_offer_views.xml",
1515
"views/estate_menus.xml",
1616
"security/ir.model.access.csv",
1717
"views/res_users_views.xml",

estate/models/estate_property.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class EstateProperty(models.Model):
4747
offer_ids = fields.One2many('estate.property.offer', 'property_id')
4848

4949
# Computed Fields
50-
total_area =fields.Integer('Property Total Area', compute='_calculate_total_area')
50+
total_area = fields.Integer('Property Total Area', compute='_calculate_total_area')
5151
best_price = fields.Float('Property Best Offer', digits=(16, 2), readonly=True, copy=False, compute='_get_best_price')
5252

5353
# Ordering
@@ -63,19 +63,19 @@ class EstateProperty(models.Model):
6363
@api.constrains('selling_price')
6464
def _check_selling_price_not_lower_90p_expected_price(self):
6565
for property in self:
66-
if property.selling_price==0:
66+
if property.selling_price == 0:
6767
continue
6868
comparing_result = tools.float_compare(property.selling_price, 0.9 * property.expected_price, precision_digits=6)
6969
if comparing_result < 0:
7070
raise ValidationError("Can't accept an offer with an amount less than 90% of the expected price.")
7171

7272
@api.depends('offer_ids')
7373
def _get_best_price(self):
74-
_best_offer = 0
7574
for property in self:
75+
best_offer = 0
7676
for offer in property.offer_ids:
77-
_best_offer = max(_best_offer, offer.price)
78-
property.best_price = _best_offer
77+
best_offer = max(best_offer, offer.price)
78+
property.best_price = best_offer
7979

8080
@api.depends('living_area', 'garden_area')
8181
def _calculate_total_area(self):
@@ -112,7 +112,6 @@ def action_property_cancel(self):
112112
property.state = 'cancelled'
113113
return True
114114

115-
# Offers Interactions
116115
# Update Property Status based on offer creations/removals
117116
@api.onchange('offer_ids')
118117
def _update_property_state(self):
@@ -162,4 +161,3 @@ def _unlink_except_new_cancelled(self):
162161
for property in self:
163162
if property.state not in ('new', 'cancelled'):
164163
raise ValidationError("You can't delete properties that are neither new nor cancelled.")
165-

estate/models/estate_property_offer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import timedelta, datetime
1+
from datetime import timedelta
22
from odoo import fields, models, api
33
from odoo.exceptions import ValidationError
44

@@ -33,29 +33,29 @@ class EstatePropertyOffer(models.Model):
3333
def _compute_offer_deadline(self):
3434
for offer in self:
3535
if not offer.create_date:
36-
_create_date = fields.Date.today()
36+
create_date = fields.Date.today()
3737
else:
38-
_create_date = offer.create_date
39-
offer.deadline = _create_date + timedelta(days=offer.validity_days)
38+
create_date = offer.create_date
39+
offer.deadline = create_date + timedelta(days=offer.validity_days)
4040

4141
def _inverse_offer_deadline(self):
4242
for offer in self:
4343
if not offer.create_date:
44-
_create_date = fields.Date.today()
44+
create_date = fields.Date.today()
4545
else:
46-
_create_date = offer.create_date.date()
47-
offer.validity_days = (offer.deadline - _create_date).days
46+
create_date = offer.create_date.date()
47+
offer.validity_days = (offer.deadline - create_date).days
4848

4949
# Actions
5050
def action_offer_accept(self):
5151
for offer in self:
52-
if not offer.status == 'accepted':
52+
if offer.status != 'accepted':
5353
offer.property_id._notify_offer_accepted(offer)
5454
return True
5555

5656
def action_offer_refuse(self):
5757
for offer in self:
58-
if not offer.status == 'refused':
58+
if offer.status != 'refused':
5959
offer.property_id._notify_offer_refused(offer)
6060
return True
6161

estate/models/estate_property_tag.py

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

44
class EstatePropertyTag(models.Model):
55
_name = 'estate.property.tag'
6-
_description = "property tag description"
6+
_description = "property tag description"
77
name = fields.Char('Property Tag', required=True)
88
color = fields.Integer()
99

estate/models/estate_property_type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class EstatePropertyType(models.Model):
1010
name = fields.Char('Property Type', required=True)
1111
_order = "sequence, name"
1212

13-
name = fields.Char('Property Type', required=True)
1413
description = fields.Char('Description', required=False)
1514
property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties')
1615

estate/models/res_partner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from odoo import fields, models
22

3+
34
class User(models.Model):
45
_inherit = "res.partner"
5-
property_ids = fields.One2many(comodel_name='estate.property', inverse_name="buyer_id")
6+
property_ids = fields.One2many(comodel_name='estate.property', inverse_name="buyer_id")

estate/models/res_users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from odoo import fields, models
22

3+
34
class User(models.Model):
45
_inherit = "res.users"
5-
property_ids = fields.One2many(comodel_name='estate.property', inverse_name="salesman_id")
6+
property_ids = fields.One2many(comodel_name='estate.property', inverse_name="salesman_id")

estate_account/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

estate_account/__manifest__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
'name': 'estate_account',
3+
'version': '1.0',
4+
'sequence': 15,
5+
'summary': 'estate-account summary',
6+
'description': "",
7+
'depends': [
8+
'estate',
9+
'account'
10+
],
11+
'data': [
12+
'views/account_move_views.xml',
13+
'views/estate_property_views.xml',
14+
# "security/ir.model.access.csv"
15+
],
16+
'demo': [
17+
],
18+
'installable': True,
19+
'application': True,
20+
'auto_install': False
21+
}

estate_account/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import account_move
2+
from . import estate_property

estate_account/models/account_move.py

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

33

44
class AccountMove(models.Model):

estate_account/models/estate_property.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ def _create_account_move(self):
2222
Command.create(dict(name="6% Down Payment", quantity=0.06, price_unit=offer.price)),
2323
Command.create(dict(name="Administrative Fees", quantity=1, price_unit=100))
2424
],
25-
property_id = self.id,
25+
property_id=self.id,
2626
)]
2727
)
2828
return
2929

30-
3130
def action_property_sold(self):
3231
for property in self:
3332
property._create_account_move()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="estate_property_account_move_action_statbutton" model="ir.actions.act_window">
4+
<field name="name">Invoices</field>
5+
<field name="res_model">account.move</field>
6+
<field name="view_mode">list</field>
7+
<field name="domain">[('property_id', '=', active_id)]</field>
8+
</record>
9+
</odoo>

0 commit comments

Comments
 (0)