Skip to content

Commit c93ae8a

Browse files
committed
[IMP] estate: chapter15 - corrected code after review
- Removed un necessary assert (for the unused imports in the __init__ files) - Renamed looping variables' names for better readability (property instead of record, and offer instead of record) - Added auto_install property to True in the estate_account link module (used to auto install dependencies when we install estate_account)
1 parent d270336 commit c93ae8a

14 files changed

+123
-61
lines changed

awesome_owl/static/src/Card/card.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @odoo-module **/
2+
3+
import { Component } from "@odoo/owl";
4+
5+
export class Card extends Component {
6+
static template = "awesome_owl.card";
7+
}

awesome_owl/static/src/Card/card.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.card">
5+
<div class="card d-inline-block m-2" style="width: 300px;">
6+
<div class="card-body">
7+
<h5 class="card-title">
8+
<t t-esc="props.title"/>
9+
</h5>
10+
<p class="card-text">
11+
<t t-esc="props.content"/>
12+
</p>
13+
</div>
14+
</div>
15+
</t>
16+
17+
</templates>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
5+
export class Counter extends Component {
6+
static template = "awesome_owl.counter";
7+
8+
counter = useState({ value: 0 });
9+
10+
increment() {
11+
this.counter.value++;
12+
}
13+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.counter">
5+
<div>
6+
<p>
7+
<t t-esc="counter.value"/>
8+
</p>
9+
<button t-on-click="increment">Increment</button>
10+
</div>
11+
</t>
12+
13+
</templates>

awesome_owl/static/src/playground.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/** @odoo-module **/
22

33
import { Component } from "@odoo/owl";
4+
import { Counter } from './Counter/counter';
5+
import { Card } from './Card/card';
46

57
export class Playground extends Component {
68
static template = "awesome_owl.playground";
9+
10+
static components = { Card };
711
}

awesome_owl/static/src/playground.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.playground">
5-
<div class="p-3">
6-
hello world
5+
<div class="card d-inline-block m-4" style="width: 320px;">
6+
<Card title="'card 1'" content="'content of card 1'"/>
7+
<Card title="'card 2'" content="'content of card 2'"/>
78
</div>
89
</t>
910

estate/__manifest__.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
'name': 'Estate',
3+
'summary': "Module to manage properties",
4+
'description': """
5+
This module is used to manage any type of properties and also to manage the selling pipeline for each property
6+
""",
7+
'author': 'Odoo',
8+
'version': '1.0',
39
'depends': ['base'],
410
'application': True,
511
'license': 'LGPL-3',

estate/models/__init__.py

-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@
33
from . import estate_property_tag
44
from . import estate_property_offer
55
from . import res_users
6-
7-
assert estate_property
8-
assert estate_property_type
9-
assert estate_property_tag
10-
assert estate_property_offer
11-
assert res_users

estate/models/estate_property.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from odoo import api, models, fields
2-
from odoo.exceptions import UserError, ValidationError
31
from dateutil.relativedelta import relativedelta
42

3+
from odoo import _, api, models, fields
4+
from odoo.exceptions import UserError, ValidationError
55
from odoo.tools.float_utils import float_compare, float_is_zero
66

77

@@ -22,7 +22,7 @@ class EstateProperty(models.Model):
2222
postcode = fields.Char()
2323
date_availability = fields.Date(
2424
copy=False,
25-
default=_default_date_availability()
25+
default=_default_date_availability
2626
)
2727
state = fields.Selection(
2828
string='Status',
@@ -70,46 +70,46 @@ def group_by_empty(self, types, domain):
7070
return types.search([]) # this is equivalent to return self.env['estate.property.type'].search([])
7171

7272
def action_set_sold(self):
73-
for record in self:
74-
if record.state == 'cancelled':
75-
raise UserError("Canceled properties cannot be set as sold.")
76-
record.state = 'sold'
73+
for property in self:
74+
if property.state == 'cancelled':
75+
raise UserError(_("Canceled properties cannot be set as sold."))
76+
property.state = 'sold'
7777
return True
7878

7979
def action_cancel(self):
80-
for record in self:
81-
if record.state == 'sold':
82-
raise UserError("Sold properties cannot be canceled.")
83-
record.state = 'cancelled'
80+
for property in self:
81+
if property.state == 'sold':
82+
raise UserError(_("Sold properties cannot be canceled."))
83+
property.state = 'cancelled'
8484
return True
8585

8686
@api.ondelete(at_uninstall=False)
8787
def _check_unlink_state(self):
88-
for record in self:
89-
if record.state not in ('new', 'cancelled'):
90-
raise UserError("You cannot delete a property that is not in 'New' or 'Cancelled' state.")
88+
for property in self:
89+
if property.state not in ('new', 'cancelled'):
90+
raise UserError(_("You cannot delete a property that is not in 'New' or 'Cancelled' state."))
9191

9292
@api.constrains('expected_price', 'selling_price')
9393
def _check_selling_price(self):
94-
for record in self:
95-
if not float_is_zero(record.expected_price, precision_digits=2):
96-
accepted_offers = record.offers_ids.filtered(lambda o: o.status == 'accepted')
94+
for property in self:
95+
if not float_is_zero(property.expected_price, precision_digits=2):
96+
accepted_offers = property.offers_ids.filtered(lambda o: o.status == 'accepted')
9797
if accepted_offers:
98-
if float_compare(record.selling_price, record.expected_price * 0.90, precision_digits=2) == -1:
98+
if float_compare(property.selling_price, property.expected_price * 0.90, precision_digits=2) == -1:
9999
raise ValidationError("Selling price cannot be lower than 90 percent of expected price")
100100

101101
@api.depends('living_area', 'garden_area')
102102
def _compute_total_area(self):
103-
for record in self:
104-
record.total_area = record.living_area + record.garden_area
103+
for property in self:
104+
property.total_area = property.living_area + property.garden_area
105105

106106
@api.depends('offers_ids.price')
107107
def _compute_best_price(self):
108-
for record in self:
109-
if record.offers_ids:
110-
record.best_price = max(record.offers_ids.mapped('price'))
108+
for property in self:
109+
if property.offers_ids:
110+
property.best_price = max(property.offers_ids.mapped('price'))
111111
else:
112-
record.best_price = 0.0
112+
property.best_price = 0.0
113113

114114
@api.onchange('garden')
115115
def _onchange_garden(self):

estate/models/estate_property_offer.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import api, models, fields
1+
from odoo import _, api, models, fields
22
from dateutil.relativedelta import relativedelta
33

44
from odoo.exceptions import UserError
@@ -41,7 +41,7 @@ def create(self, vals):
4141
if existing_offer_prices:
4242
max_existing_offer = max(existing_offer_prices)
4343
if float_compare(price, max_existing_offer, precision_digits=2) < 0:
44-
raise UserError("Cannot create an offer with a price lower than an existing offer")
44+
raise UserError(_("Cannot create an offer with a price lower than an existing offer"))
4545

4646
if prop.state == 'new':
4747
prop.write({'state': 'offer_received'})
@@ -50,34 +50,34 @@ def create(self, vals):
5050
return new_offer
5151

5252
def action_accept(self):
53-
for record in self:
54-
accepted_offers = record.property_id.offers_ids.filtered(lambda o: o.status == 'accepted')
53+
for offer in self:
54+
accepted_offers = offer.property_id.offers_ids.filtered(lambda o: o.status == 'accepted')
5555
if accepted_offers:
56-
raise UserError("Another offer has already been accepted for this property.")
57-
record.status = 'accepted'
58-
record.property_id.state = 'offer_accepted'
59-
record.property_id.selling_price = record.price
60-
record.property_id.buyer_id = record.partner_id
56+
raise UserError(_("Another offer has already been accepted for this property."))
57+
offer.status = 'accepted'
58+
offer.property_id.state = 'offer_accepted'
59+
offer.property_id.selling_price = offer.price
60+
offer.property_id.buyer_id = offer.partner_id
6161
return True
6262

6363
def action_refuse(self):
64-
for record in self:
65-
record.status = 'refused'
64+
for offer in self:
65+
offer.status = 'refused'
6666
return True
6767

6868
@api.depends('create_date', 'validity')
6969
def _compute_date_deadline(self):
70-
for record in self:
71-
if record.create_date:
72-
base_date = record.create_date.date()
70+
for offer in self:
71+
if offer.create_date:
72+
base_date = offer.create_date.date()
7373
else:
7474
base_date = fields.Date.today()
75-
record.date_deadline = base_date + relativedelta(days=record.validity)
75+
offer.date_deadline = base_date + relativedelta(days=offer.validity)
7676

7777
def _inverse_date_deadline(self):
78-
for record in self:
79-
if record.create_date:
80-
base_date = record.create_date.date()
78+
for offer in self:
79+
if offer.create_date:
80+
base_date = offer.create_date.date()
8181
else:
8282
base_date = fields.Date.today()
83-
record.validity = (record.date_deadline - base_date).days
83+
offer.validity = (offer.date_deadline - base_date).days

estate/views/estate_property_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<field name="facades"/>
137137
<filter name="available" string="Available" domain="[('state', 'in', ['new', 'offer_received'])]"/>
138138
<group expand="1" string="Group By">
139-
<filter string="Postcode" name="postcode" context="{'group_by':'postcode'}"/>
139+
<filter string="Postcode" name="postcode" context="{'group_by': 'postcode'}"/>
140140
</group>
141141
</search>
142142
</field>

estate/views/res_users_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
</field>
1414
</record>
1515
</data>
16-
</odoo>
16+
</odoo>

estate_account/__manifest__.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
'name': "Real Estate Accounting Link",
3+
'summary': "Link estate and account modules for creating invoice",
4+
'description': """
5+
This module is used as a bridge between estate and account modules in order to create an invoice automatically when marking a property as sold
6+
""",
7+
'author': 'Odoo',
8+
'version': '1.0',
39
'depends': [
410
'estate',
511
'account',
612
],
713
'data': [
814
],
915
'installable': True,
16+
'auto_install': True,
1017
'application': False,
1118
'license': 'LGPL-3',
1219
}

estate_account/models/estate_property.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import models, Command
1+
from odoo import _, models, Command
22
from odoo.exceptions import UserError
33

44

@@ -11,14 +11,14 @@ def action_set_sold(self):
1111
if not self:
1212
return res
1313

14-
for record in self:
15-
if not record.buyer_id:
16-
raise UserError("Cannot create invoice: Buyer is not set for property")
14+
for property in self:
15+
if not property.buyer_id:
16+
raise UserError(_("Cannot create invoice: Buyer is not set for property"))
1717

18-
if record.selling_price <= 0:
19-
raise UserError("Cannot create invoice: Selling price must be positive for property")
18+
if property.selling_price <= 0:
19+
raise UserError(_("Cannot create invoice: Selling price must be positive for property"))
2020

21-
commission = record.selling_price * 0.06
21+
commission = property.selling_price * 0.06
2222
admin_fees = 100.00
2323

2424
invoice_line_commands = [
@@ -35,7 +35,7 @@ def action_set_sold(self):
3535
]
3636

3737
invoice_vals = {
38-
'partner_id': record.buyer_id.id,
38+
'partner_id': property.buyer_id.id,
3939
'move_type': 'out_invoice',
4040
'invoice_line_ids': invoice_line_commands,
4141
}

0 commit comments

Comments
 (0)