Skip to content

Commit

Permalink
[IMP] estate: stat button on property type for related offers
Browse files Browse the repository at this point in the history
- Implemented `property_type_id` to `estate.property.offer` as a related field.
- Implemented `offer_ids` and `offer_count` to `estate.property.type` to track
  related offers.
- Implemented a stat button on `estate.property.type` to view related offers
  with a filtered domain.
  • Loading branch information
yasp-odoo committed Aug 21, 2024
1 parent 51ec85a commit a88922e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
3 changes: 1 addition & 2 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class EstateProperty(models.Model):
required=True,
copy=False,
default='new',
readonly=True,
track_visibility='onchange'
readonly=True
)
property_type_id = fields.Many2one('estate.property.type', string='Property Type')
buyer_id = fields.Many2one('res.partner', string='Buyer')
Expand Down
6 changes: 6 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ class EstatePropertyOffer(models.Model):
('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')
property_type_id = fields.Many2one(
related='property_id.property_type_id',
store=True,
string='Property Type'
)
validity = fields.Integer(string='Validity (days)', default=7)
date_deadline = fields.Date(string='Deadline', compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True)

Expand Down
26 changes: 25 additions & 1 deletion estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields
from odoo import models, fields, api


class EstatePropertyType(models.Model):
Expand All @@ -9,6 +9,30 @@ class EstatePropertyType(models.Model):
sequence = fields.Integer(string="Sequence", default=10)
name = fields.Char('Name', required=True)
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(
string=' Offers Count',
compute='_compute_offer_count'
)

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)

def action_open_offers(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': 'Property Offers',
'res_model': 'estate.property.offer',
'view_mode': 'tree,form',
'domain': [('property_type_id', '=', self.id)],
}

_sql_constraints = [
('unique_type_name', 'UNIQUE(name)', 'The property type name must be unique.')
Expand Down
2 changes: 1 addition & 1 deletion estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="estate_menu_root" name="Estate">
<menuitem id="estate_menu_properties" name="Properties">
<menuitem id="estate_menu_properties" name="Property">
<menuitem id="estate_property_menu" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_menu_properties_types" name="Settings">
Expand Down
6 changes: 6 additions & 0 deletions estate/views/estate_property_offers_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@
</tree>
</field>
</record>
<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>

</odoo>
31 changes: 21 additions & 10 deletions estate/views/estate_property_types_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form string="Property Type">
<header>
<button name="action_open_offers" type="object" string=" Open Offers"
class="oe_stat_button" icon="fa-list-alt">
<field name="offer_count" widget="statinfo" class="oe_inline" />
</button>
</header>
<sheet>
<group>
<field name="name"/>
<field name='name' />
</group>
<field name="property_ids">
<tree>
<field name="name"/>
<field name="expected_price"/>
<field name="state"/>
</tree>
</field>
<notebook>
<page string="Properties">
<field name="property_ids">
<tree string='Property'>
<field name='name' />
<field name='expected_price' />
<field name='state' />
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
Expand All @@ -29,8 +39,9 @@
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<tree string="Property Types">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="sequence" widget="handle" />
<field name="name" />
<field name="offer_count" />
</tree>
</field>
</record>
Expand Down

0 comments on commit a88922e

Please sign in to comment.