-
Notifications
You must be signed in to change notification settings - Fork 2k
[ADD] estate:Create first Estate module #731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remarks. :)
Estate/__manifest__.py
Outdated
'application':True, | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a blank line at the end of the file.
Estate/models/__init__.py
Outdated
@@ -0,0 +1 @@ | |||
from . import estate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Estate/models/estate.py
Outdated
|
||
from odoo import fields, models | ||
class Estate(models.Model): | ||
_name="estate" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank spaces around equal signs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remarks 👍
realestate/__manifest__.py
Outdated
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are plenty of unnecessary blank lines in your files.
realestate/models/realestate.py
Outdated
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like here :)
Remove these lines here and elsewhere in your code.
</menuitem> | ||
|
||
|
||
</odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here a blank line is missing at the end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remarks! Keep going! :)
self.garden_orientation = "north" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.garden_orientation = "" | |
self.garden_orientation = False |
record.total_area = record.living_area + record.garden_area | ||
|
||
@api.depends("offer_ids") | ||
def _max_offer_price(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method should start with _compute_...
for record in self: | ||
record.total_area = record.living_area + record.garden_area | ||
|
||
@api.depends("offer_ids") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends only on offer_ids, not offer_ids.price, which means the method won’t be triggered when an offer’s price changes, unless a new offer is added/removed.
realestate/models/realestate.py
Outdated
|
||
@api.depends("offer_ids") | ||
def _max_offer_price(self): | ||
self.best_price = max(self.offer_ids.mapped("price"), default=0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sets self.best_price assuming self is a single record, but compute methods must support recordsets.
You should loop through self.
@@ -8,3 +9,18 @@ class Offer(models.Model): | |||
status = fields.Selection([("accepted", "Accepted"), ("refused", "Refused")]) | |||
buyer_id = fields.Many2one("buyer") | |||
property_id = fields.Many2one("realestate") | |||
validity = fields.Integer() | |||
deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good habit to add the suffix _date
on a Date field.
@naja628 And a last one for you. |
realestate/models/offer.py
Outdated
|
||
def set_offer_accepted(self): | ||
self.ensure_one() | ||
record = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why??
if record.property_id.state == "sold": | ||
raise UserError("This property is already sold") | ||
record.status = "accepted" | ||
record.property_id.selling_price = record.price |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use 'mappedto avoid repeating
record.property_id`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello :)
[Sorry I see Serge also did a 2nd pass on your code too -- I guess you will have 2 2nd reviews]
I left some comments on your code
I see you haven't reacted to Serge's previous suggestions yet -- could you do that too please?
from . import realestate | ||
from . import owner | ||
from . import types | ||
from . import tags | ||
from . import seller | ||
from . import buyer | ||
from . import offer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: by convention, we prefix model names with the name of the module
from . import realestate | |
from . import owner | |
from . import types | |
from . import tags | |
from . import seller | |
from . import buyer | |
from . import offer | |
from . import realestate_property | |
from . import realesate_owner | |
.... |
realestate/__manifest__.py
Outdated
"security/ir.model.access.csv", | ||
"views/estate_view.xml", | ||
"views/owner_view.xml", | ||
"views/type_view.xml", | ||
"views/tag_view.xml", | ||
"views/seller_view.xml", | ||
"views/buyer_view.xml", | ||
"views/offer_view.xml", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly the files could be named realestate_owner_view.xml
...
|
||
|
||
class Buyer(models.Model): | ||
_name = "buyer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_name = "buyer" | |
_name = "realestate_buyer" |
(etc...)
status = fields.Selection(related="offer_ids.status") | ||
price = fields.Float(related="offer_ids.price") | ||
validity = fields.Integer(related="offer_ids.validity") | ||
deadline = fields.Date(related="offer_ids.deadline") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot created related fields that pass through an x2many (you can look at the warning in the Doc)
What are you trying to accomplish here? What do you think the value should be?
</menuitem> | ||
|
||
|
||
</odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of your files are missing the eol character at the end of the last line (hence the red signs in the github ui) -- could you configure your editor so it doesn't do that please?
_sql_constraints = [ | ||
( | ||
"check_expected_price", | ||
"CHECK(expected_price> 0)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick:
"CHECK(expected_price> 0)", | |
"CHECK(expected_price > 0)", |
(more places)
for record in self: | ||
if record.selling_price < 0.9 * record.expected_price: | ||
raise ValidationError( | ||
"Selling price must be at least 90'%' of the expected price" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- why the quotes around the
%
- try wrap user facing text in a call to
_
so it can be translated
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick:
I like the idea of separating things but 2 blank lines is a bit overkill ^^
realestate/views/estate_view.xml
Outdated
<search> | ||
<field name="postcode" /> | ||
<field name='name' /> | ||
<filter name='is_garden' string='With Garden' domain="[('garden','=', 'True')]" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: do you think is_garden
is a good name for what this represents?
@adak-ahmed You can click on the button "Ready for review" and try to make runbot happy. :) The commit titles don't follow the guidelines. |
Adding manifest and fields.