Skip to content

Commit

Permalink
[IMP] estate, estate_account: Implemented suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nape-odoo committed Nov 22, 2024
1 parent a54cf51 commit 814a36c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 61 deletions.
2 changes: 0 additions & 2 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# license

from . import models
5 changes: 2 additions & 3 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

{
'name': 'Real estate',
'version': '0.0',
Expand All @@ -18,5 +16,6 @@

'views/estate_menu_views.xml',
],
'application': True
'application': True,
'license': 'AGPL-3'
}
2 changes: 0 additions & 2 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

from . import estate_property
from . import estate_property_type
from . import estate_property_tag
Expand Down
23 changes: 11 additions & 12 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# licence

from odoo import api
from odoo import fields
from odoo import models
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_is_zero
from odoo.tools.float_utils import float_compare


class EstateProperty(models.Model):
_name = 'estate.property'
_description = "Estate property"
_order = "id desc"
# Constraints
_sql_constraints = [
('check_name_unique', 'UNIQUE(name)',
'The property title must be unique'),
('check_price_positive', 'CHECK(expected_price > 0)',
'The expected price must be strictly positive.'),
]

name = fields.Char("Title", required=True, translate=True)
description = fields.Text("Property description")
Expand All @@ -32,7 +38,7 @@ class EstateProperty(models.Model):
('south', "South"),
('east', "East"),
('west', "West"),
],
],
default=None,
)
# Reserved
Expand All @@ -45,7 +51,7 @@ class EstateProperty(models.Model):
('accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
],
required=True,
copy=False,
default='new',
Expand All @@ -59,18 +65,11 @@ class EstateProperty(models.Model):
# Computed
area_total = fields.Float("Total area", compute='_compute_area_total')
best_offer = fields.Float("Best offer", compute='_compute_best_offer')
# Constraints
_sql_constraints = [
('check_name_unique', 'UNIQUE(name)',
'The property title must be unique'),
('check_price_positive', 'CHECK(expected_price >= 0)',
'The expected price must be strictly positive.'),
]

@api.constrains('expected_price', 'selling_price')
def _check_price_good(self):
for record in self:
if (not float_is_zero(record.selling_price, precision_digits=3)) and (record.selling_price < record.expected_price * 0.9):
if (not float_is_zero(record.selling_price, precision_digits=3)) and (float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=3) < 0):
raise ValidationError(self.env._("The offer price is unaccetably low!"))

def _compute_area_total(self):
Expand Down
21 changes: 10 additions & 11 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# licence

from odoo import api
from odoo import fields
from odoo import models
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_compare


class EstatePropertyOffer(models.Model):
_name = 'estate.property.offer'
_description = "Property offers"
_order = "price desc"
# Constrains
_sql_constraints = [
('check_price_positive', 'CHECK(price > 0)',
'The offer price must be strictly positive.'),
]

name = fields.Char("Name", required=False, default="- no name -")
price = fields.Float("Offer price", required=True)
Expand All @@ -20,7 +24,7 @@ class EstatePropertyOffer(models.Model):
selection=[
('accepted', "Accepted"),
('refused', "Refused"),
],
],
default=None,
)
# Relational
Expand All @@ -29,11 +33,6 @@ class EstatePropertyOffer(models.Model):
property_type_id = fields.Many2one(related='property_id.property_type_id')
# Computed
date_deadline = fields.Date("Deadline date", compute='_compute_deadline', inverse='_inverse_deadline')
# Constrains
_sql_constraints = [
('check_price_positive', 'CHECK(price >= 0)',
'The offer price must be strictly positive.'),
]

@api.depends('validity', 'create_date')
def _compute_deadline(self):
Expand All @@ -60,8 +59,8 @@ def action_refuse(self):

@api.model
def create(self, vals):
if (self.env['estate.property'].browse(vals['property_id']).state == 'new' and
vals['price'] < self.env['estate.property'].browse(vals['property_id']).best_offer):
property = self.env['estate.property'].browse(vals['property_id'])
if property.state != 'new' and (float_compare(vals['price'], property.best_offer, precision_digits=3) < 0):
raise UserError(self.env._("A better priced offer already exists."))
setattr(self.env['estate.property'].browse(vals['property_id']), 'state', 'recieved')
property.state = 'recieved'
return super().create(vals)
10 changes: 4 additions & 6 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

from odoo import fields
from odoo import models

Expand All @@ -8,12 +6,12 @@ class EstatePropertyTag(models.Model):
_name = 'estate.property.tag'
_description = "Property tag"
_order = "name asc"

name = fields.Char("Tag", required=True, translate=True)
description = fields.Text("Tag description")
color = fields.Integer()
# Constraints
_sql_constraints = [
('check_name_unique', 'UNIQUE(name)',
'The property type name must be unique'),
]

name = fields.Char("Tag", required=True, translate=True)
description = fields.Text("Tag description")
color = fields.Integer()
12 changes: 5 additions & 7 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

from odoo import fields
from odoo import models
from odoo import api
Expand All @@ -9,6 +7,11 @@ class EstatePropertyType(models.Model):
_name = 'estate.property.type'
_description = "Property type"
_order = "name asc"
# Constraints
_sql_constraints = [
('check_name_unique', 'UNIQUE(name)',
'The property type name must be unique'),
]

name = fields.Char("Type", required=True, translate=True)
sequence = fields.Integer('Sequence', default=1, help="Used to order types manually.")
Expand All @@ -17,11 +20,6 @@ class EstatePropertyType(models.Model):
property_ids = fields.One2many('estate.property', 'property_type_id', string="Properties")
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string="Offers")
offer_count = fields.Integer("Offer count", compute='_compute_offer_count')
# Constraints
_sql_constraints = [
('check_name_unique', 'UNIQUE(name)',
'The property type name must be unique'),
]

@api.depends('offer_ids')
def _compute_offer_count(self):
Expand Down
2 changes: 0 additions & 2 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

from odoo import fields
from odoo import models

Expand Down
2 changes: 1 addition & 1 deletion estate/views/res_users_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
</xpath>
</field>
</record>
</odoo>
</odoo>
2 changes: 0 additions & 2 deletions estate_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# license

from . import models
8 changes: 2 additions & 6 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

{
'name': 'Real estate accounting link',
'version': '0.0',
Expand All @@ -8,8 +6,6 @@
'estate',
'account',
],
'data': [

],
'application': False
'application': False,
'license': 'AGPL-3'
}
4 changes: 1 addition & 3 deletions estate_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# licence

from . import estate_property
from . import estate_property
4 changes: 0 additions & 4 deletions estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# licence

from odoo import models
from odoo import Command

Expand All @@ -10,11 +8,9 @@ class EstateProperty(models.Model):
def action_set_sold(self):
partner_id = self.salesperson_id.id
move_type = 'out_invoice'
# journal_id = self.env['account.journal'].search([])[0].id # Tutorial chapter 13 incorrectly lists this field as being required
self.env['account.move'].sudo().create({
'partner_id': partner_id,
'move_type': move_type,
# 'journal_id': journal_id,
'invoice_line_ids': [
Command.create({'name': self.name, 'quantity': 0.06, 'price_unit': self.selling_price}),
Command.create({'name': "Administrative fees", 'quantity': 1, 'price_unit': 100.00}),
Expand Down

0 comments on commit 814a36c

Please sign in to comment.