Skip to content

Commit

Permalink
[IMP] estate: added inheritance models to the estate module
Browse files Browse the repository at this point in the history
After this commit:
-Added python inheritance
-Added Model inheritance
-Added view inheritance
  • Loading branch information
pkgu-odoo committed Aug 14, 2024
1 parent 9f7c697 commit 51bfb56
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'views/estate_property_type_view.xml',
'views/estate_property_tag.xml',
'views/estate_property_offer.xml',
'views/res_user.xml',
'views/estate_menus.xml'
],
'installable': True,
Expand Down
1 change: 1 addition & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import estate_property_type
from . import estate_property_tag
from . import estate_peoperty_offer
from . import res_user
13 changes: 13 additions & 0 deletions estate/models/estate_peoperty_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EstatePropertyOffer(models.Model):
_name = 'estate.property.offer'
_description = 'Estate Property offer'
_order = 'price desc'

price = fields.Float('Price')
status = fields.Selection([
('accepted', 'Accepted'),
Expand Down Expand Up @@ -76,3 +77,15 @@ def _check_offer_price(self):
for record in self:
if record.price <= 0:
raise ValidationError("Price must be strictly positive.")

@api.model
def create(self, vals):
property_id = self.env['estate.property'].browse(vals['property_id'])
existing_offers = self.search([('property_id', '=', property_id.id)])
for offer in existing_offers:
if vals['price'] < offer.price:
raise UserError(
"You cannot create an offer with an amount lower than an existing offer."
)
property_id.state = 'offer_received'
return super().create(vals)
11 changes: 10 additions & 1 deletion estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class EstateProperty(models.Model):
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('canceled', 'Canceled')
('canceled', 'Canceled'),
('available', 'Available')
], required=True, default='new', copy=False)
property_type_id = fields.Many2one(
'estate.property.type', string="Property Type")
Expand Down Expand Up @@ -97,3 +98,11 @@ def _check_selling_price(self):
if record.expected_price > 0:
if record.selling_price and float_compare(record.selling_price, record.expected_price * 0.9, precision_rounding=0.01) < 0:
raise ValidationError("The selling price must be at least 90% of the expected price.")

@api.ondelete(at_uninstall=False)
def _check_state_before_delete(self):
for record in self:
if record.state not in ['new', 'canceled']:
raise UserError(
"You cannot delete a property unless its state is 'New' or 'Canceled'."
)
2 changes: 1 addition & 1 deletion estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EstatePropertyTypes(models.Model):
sequence = fields.Integer('Sequence')
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers')
offer_count = fields.Integer(
string='Offers',
string=' Number of Offers',
compute='_compute_offer_count',
store=True
)
Expand Down
12 changes: 12 additions & 0 deletions estate/models/res_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models, fields


class ResUsers(models.Model):
_inherit = 'res.users'

property_ids = fields.One2many(
comodel_name='estate.property',
inverse_name='sell_person_id',
string='Properties',
domain="[('state', '=', 'available')]"
)
9 changes: 3 additions & 6 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@
filter_domain="[('living_area', '>=', self)]"/>
<filter name="available" string="Available"
domain="['|', ('state', '=', 'new'), ('state', '=', 'offer_received')]" />


<group expand="1" string="Group By">
<filter name="group_by_postcode" string="Postcode"
context="{'group_by':'postcode'}" />
Expand All @@ -129,11 +127,10 @@
</record>

<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Estate Properties</field>
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('state', '=', 'available')]</field>
<field name="context">{}</field>
</record>

<field name="context">{'search_default_available': 1}</field>
</record>
</odoo>
26 changes: 26 additions & 0 deletions estate/views/res_user.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_users_form_inherited" model="ir.ui.view">
<field name="name">res.users.form.inherited</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Properties">
<field name="property_ids">
<tree>
<field name="name" string="Title"/>
<field name="property_type_id" string="Property Type"/>
<field name="postcode" string="Postcode"/>
<field name="tag_ids" string="Tags"/>
<field name="bedrooms" string="Bedrooms"/>
<field name="living_area" string="Living Area (sqm)"/>
<field name="expected_price" string="Expected Price"/>
<field name="selling_price" string="Selling Price"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 51bfb56

Please sign in to comment.