Skip to content

Commit

Permalink
[IMP] estate: implement demo data with valid property offers and part…
Browse files Browse the repository at this point in the history
…ners

- Added demo data for the estate module:
- Created property records with valid details, including pricing and
  availability.
- Added property offers linked to existing partner records to demonstrate
  functionality.
- Ensured that the demo data complies with data integrity constraints.
  • Loading branch information
yasp-odoo committed Aug 30, 2024
1 parent 644cd99 commit ca2a277
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 26 deletions.
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizard
13 changes: 9 additions & 4 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{
'name': 'estate',
'version': '1.0',
'summary': 'An real state management application',
'description': 'Estate_property_module',
'category': 'Sales',
'summary': 'A real estate management application',
'description': 'A module for managing real estate properties, offers, and related entities.',
'category': 'Real Estate',
'author': 'YASP',
'website': 'https://www.yaspestate.com',
'sequence': 1,
'depends': ['base'],
'license': 'LGPL-3',
'data': [
'security/ir.model.access.csv',
'wizard/estate_add_offer_wizard_views.xml',
'data/estate_property_type_data.xml',
'views/estate_property_views.xml',
'views/estate_property_offers_views.xml',
'views/estate_property_types_views.xml',
'views/estate_property_tags_views.xml',
'views/estate_property_offers_views.xml',
'views/res_users_views.xml',
'views/estate_menus.xml'
],
'demo': [
'demo/estate_property_demo.xml'
],
'installable': True,
'application': True,
}
18 changes: 18 additions & 0 deletions estate/data/estate_property_type_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<odoo>
<record id="estate.property_type_residential" model="estate.property.type">
<field name="name">Residential</field>
<field name="sequence">10</field>
</record>
<record id="estate.property_type_commercial" model="estate.property.type">
<field name="name">Commercial</field>
<field name="sequence">20</field>
</record>
<record id="estate.property_type_industrial" model="estate.property.type">
<field name="name">Industrial</field>
<field name="sequence">30</field>
</record>
<record id="estate.property_type_land" model="estate.property.type">
<field name="name">Land</field>
<field name="sequence">40</field>
</record>
</odoo>
75 changes: 75 additions & 0 deletions estate/demo/estate_property_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Create partners if not present
<record id="partner_azure_interior" model="res.partner">
<field name="name">Azure Interior</field>
<field name="email">[email protected]</field>
</record>
<record id="partner_deco_addict" model="res.partner">
<field name="name">Deco Addict</field>
<field name="email">[email protected]</field>
</record> -->

<!-- Property records -->
<record id="property_big_villa" model="estate.property">
<field name="name">Big Villa</field>
<field name="property_type_id" ref="estate.property_type_residential"/>
<field name="state">new</field>
<field name="description">A nice and big villa</field>
<field name="postcode">12345</field>
<field name="date_availability">2020-02-02</field>
<field name="expected_price">1600000</field>
<field name="selling_price">1440000</field>
<field name="bedrooms">6</field>
<field name="living_area">100</field>
<field name="facades">4</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">100000</field>
<field name="garden_orientation">south</field>
</record>

<record id="property_trailer_home" model="estate.property">
<field name="name">Trailer home</field>
<field name="property_type_id" ref="estate.property_type_residential"/>
<field name="state">canceled</field>
<field name="description">Home in a trailer park</field>
<field name="postcode">54321</field>
<field name="date_availability">1970-01-01</field>
<field name="expected_price">100000</field>
<field name="selling_price">90000</field>
<field name="bedrooms">1</field>
<field name="living_area">10</field>
<field name="facades">4</field>
<field name="garage">False</field>
<field name="garden">True</field>
<field name="garden_area">500</field>
<field name="garden_orientation">north</field>
</record>

<!-- Property offers -->
<record id="offer_azure_1" model="estate.property.offer">
<field name="price">10000</field>
<field name="property_id" ref="property_big_villa"/>
<field name="partner_id" ref="base.res_partner_12"/>
<field name="validity">14</field>
<field name="create_date">2023-08-19</field>
</record>

<record id="offer_azure_2" model="estate.property.offer">
<field name="price">1500000</field>
<field name="property_id" ref="property_big_villa"/>
<field name="partner_id" ref="base.res_partner_12"/>
<field name="validity">14</field>
<field name="create_date">2023-08-24</field>
</record>

<record id="offer_deco_addict" model="estate.property.offer">
<field name="price">1500001</field>
<field name="property_id" ref="property_big_villa"/>
<field name="partner_id" ref="base.res_partner_12"/>
<field name="validity">14</field>
<field name="create_date">2023-08-29</field>
</record>
</odoo>
10 changes: 5 additions & 5 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class EstatePropertyOffer(models.Model):
('refused', 'Refused'),
('draft', 'Draft')
], default='draft', copy=False)
state = fields.Selection([
('accepted', 'Accepted'),
('refused', 'Refused'),
('draft', 'Draft')
], default='draft', copy=False)
# state = fields.Selection([
# ('accepted', 'Accepted'),
# ('refused', 'Refused'),
# ('draft', 'Draft')
# ], default='draft', copy=False)

partner_id = fields.Many2one('res.partner', string='Partner', required=True)
property_id = fields.Many2one('estate.property', string='Property', required=True, ondelete='cascade')
Expand Down
1 change: 1 addition & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ access_estate_property,access_estate_property,model_estate_property,base.group_u
access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
access_estate_add_offer_wizard,access_estate_add_offer_wizard,model_estate_add_offer_wizard,base.group_user,1,1,1,1
5 changes: 2 additions & 3 deletions estate/views/estate_property_offers_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
<field name="name">estate.property.offer.list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<tree string="Property Offers" decoration-danger="state == 'refused'"
decoration-success="state == 'accepted'" editable="bottom">
<tree string="Property Offers" decoration-danger="status == 'refused'"
decoration-success="status == 'accepted'" editable="bottom">
<field name="price"/>
<field name="partner_id"/>
<field name="status"/>
<field name="validity"/>
<field name="date_deadline"/>
<field name="property_id"/>
<field name="state"/>
</tree>
</field>
</record>
Expand Down
44 changes: 30 additions & 14 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@
<kanban
default_group_by="property_type_id"
records_draggable='False'>
<field name="property_type_id"/>
<field name="state"/>
<field name="best_price"/>
<field name="selling_price"/>
<field name="expected_price"/>
<field name="property_type_id" />
<field name="state" />
<field name="best_price" />
<field name="selling_price" />
<field name="expected_price" />
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click oe_kanban_card">
<div class="oe_kanban_title">
<strong><field name="name" /></strong>
<strong>
<field name="name" />
</strong>
</div>
<div class="oe_kanban_prices">
<div t-if="record.state.raw_value == 'offer_received'" class="oe_kanban_best_price">
<strong>Best Price:</strong> <field name="best_price" />
<div t-if="record.state.raw_value == 'offer_received'"
class="oe_kanban_best_price">
<strong>Best Price:</strong>
<field name="best_price" />
</div>
<div t-if="record.state.raw_value == 'offer_accepted'" class="oe_kanban_selling_price">
<strong>Selling Price:</strong> <field name="selling_price" />
<div t-if="record.state.raw_value == 'offer_accepted'"
class="oe_kanban_selling_price">
<strong>Selling Price:</strong>
<field name="selling_price" />
</div>
<div class="oe_kanban_expected_price">
<strong>Expected Price:</strong> <field name="expected_price" />
<strong>Expected Price:</strong>
<field name="expected_price" />
</div>
</div>
<div class="oe_kanban_tags">
Expand All @@ -43,7 +50,7 @@
</templates>
</kanban>
</field>
</record>
</record>
<record id="estate_property_list" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
Expand All @@ -61,12 +68,18 @@
<field name="date_availability" optional="hidden" />
<field name="buyer_id" />
<field name="seller_id" />
<field name="state" column_invisible="1" />
<field name="state" invisible="1" />
<field name="property_type_id" />
<field name="tag_ids" widget="many2many_tags" />
<header>
<button name="%(estate.action_estate_property_offer_wizard)d" string="Add Offer"
type="action" class="oe_highlight" />
</header>

</tree>
</field>
</record>

<record id="estate_property_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
Expand Down Expand Up @@ -167,11 +180,14 @@
<field name="tag_ids" widget="many2many_tags" />
<filter string="Available Properties" name="available_properties"
domain="[('state', 'in', ['new', 'offer_received'])]" />
<filter string="Offer Accepted" name="offer_accepted"
domain="[('state', '=', 'offer_accepted')]" />
<group string="Group By">
<filter string="Postcode" name="group_by_postcode"
context="{'group_by':'postcode'}" />
</group>
</search>
</field>
</record>
</odoo>

</odoo>
1 change: 1 addition & 0 deletions estate/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_add_offer_wizard
34 changes: 34 additions & 0 deletions estate/wizard/estate_add_offer_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from odoo import models, fields
from odoo.exceptions import UserError


class EstateAddOfferWizard(models.TransientModel):
_name = 'estate.add.offer.wizard'
_description = 'Add Offer Wizard'

price = fields.Float(string="Offer Price", required=True)
offer_status = fields.Selection([
('accepted', 'Accepted'),
('refused', 'Refused')
], string="Offer Status")
buyer_id = fields.Many2one('res.partner', string="Buyer", required=True)

def action_add_offer(self):
active_ids = self.env.context.get('active_ids')
properties = self.env['estate.property'].browse(active_ids).filtered(
lambda p: p.expected_price <= self.price
)
for p in properties:
if p.state in ['new', 'offer_received']:
offer = p.offer_ids.create({
'property_id': p.id,
'price': self.price,
'partner_id': self.buyer_id.id,
'status': self.offer_status or 'new' # Ensure status is set
})
# Update the property state if necessary
if p.state == 'offer_received' and self.offer_status == 'accepted':
offer.status = 'accepted'
else:
raise UserError('Property must be in new or offer received state')
return {'type': 'ir.actions.act_window_close'}
26 changes: 26 additions & 0 deletions estate/wizard/estate_add_offer_wizard_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<odoo>
<record id="estate_add_offer_wizard_form" model="ir.ui.view">
<field name="name">estate.add.offer.wizard.form</field>
<field name="model">estate.add.offer.wizard</field>
<field name="arch" type="xml">
<form string="Add Offer">
<group>
<field name="price"/>
<field name="offer_status"/>
<field name="buyer_id"/>
</group>
<footer>
<button string="Make an Offer" type="object" name="action_add_offer" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_estate_property_offer_wizard" model="ir.actions.act_window">
<field name="name">Estate Property Offer Wizard</field>
<field name="res_model">estate.add.offer.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="estate.estate_add_offer_wizard_form"/>
<field name="target">new</field>
</record>
</odoo>

0 comments on commit ca2a277

Please sign in to comment.