Skip to content

Commit

Permalink
[IMP] estate: kanban view for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
aizu-odoo committed Nov 25, 2024
1 parent 4ac219a commit 5e36068
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
10 changes: 5 additions & 5 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import api, fields, models, _
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero
from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -63,7 +63,7 @@ class EstateProperty(models.Model):
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_digits=2) and float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) <= 0:
raise ValidationError("The selling price cannot be lower than 90 percent of the expected price.")
raise ValidationError(self.env._("The selling price cannot be lower than 90 percent of the expected price."))


@api.depends('living_area', 'garden_area')
Expand All @@ -81,7 +81,7 @@ def _compute_best_price(self):
def _prevent_property_deletion(self):
for record in self:
if record.state not in ('new', 'cancelled'):
raise UserError(_("Only new or cancelled properties can be deleted."))
raise UserError(self.env._("Only new or cancelled properties can be deleted."))

@api.onchange('garden')
def _onchange_garden(self):
Expand All @@ -97,13 +97,13 @@ def action_set_sold(self):
if record.state != 'cancelled':
record.state = 'sold'
else:
raise UserError(_("Sold properties cannot be cancelled."))
raise UserError(self.env._("Sold properties cannot be cancelled."))
return True

def action_set_cancelled(self):
for record in self:
if record.state != 'sold':
record.state = 'cancelled'
else:
raise UserError(_("Sold properties cannot be cancelled."))
raise UserError(self.env._("Sold properties cannot be cancelled."))
return True
6 changes: 3 additions & 3 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import api, fields, models, _
from odoo import api, fields, models
from odoo.exceptions import UserError
from dateutil.relativedelta import relativedelta

Expand Down Expand Up @@ -32,9 +32,9 @@ def _compute_date_deadline(self):
def create(self, vals_list):
for vals in vals_list:
if self.price < self.env['estate.property'].browse(vals['property_id']).best_price:
raise UserError(_("You cannot put in an offer that is lower than the current best price."))
raise UserError(self.env_("You cannot put in an offer that is lower than the current best price."))
self.env['estate.property'].browse(vals['property_id']).state = 'offer_received'
return super(EstatePropertyOffer, self).create(vals_list)
return super().create(vals_list)

def _inverse_date_deadline(self):
for record in self:
Expand Down
2 changes: 1 addition & 1 deletion estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1
37 changes: 36 additions & 1 deletion estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@
</field>
</record>

<record id="estate_property_view_kanban" model="ir.ui.view">
<field name="name">estate.property.kanban</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<kanban default_group_by="property_type_id">
<field name="state"/>
<templates>
<t t-name="kanban-box">
<div>
<strong class="o_kanban_record_title">
<field name="name"/>
</strong>
<div class="o_kanban_record_subtitle">
Expected Price:
<field name="expected_price" widget="monetary"/>
</div>
<t t-debug=""/>
<div t-if="record.state.raw_value == 'offer_received'" class="o_kanban_record_subtitle">
Best Price:
<field name="best_price" widget="monetary"/>
</div>
<div t-if="['offer_accepted','sold'].includes(record.state.raw_value)" class="o_kanban_record_subtitle">
Selling Price:
<field name="selling_price" widget="monetary"/>
</div>
<div>
<field name="property_tag_ids"/>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>

<record id="estate_property_view_search" model="ir.ui.view">
<field name="name">estate.property.search</field>
<field name="model">estate.property</field>
Expand Down Expand Up @@ -134,7 +169,7 @@
<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Estate Property</field>
<field name="res_model">estate.property</field>
<field name="view_mode">list,form</field>
<field name="view_mode">list,form,kanban</field>
<field name="context">{'search_default_state':True}</field>
</record>

Expand Down
2 changes: 1 addition & 1 deletion estate_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import models
from . import models
2 changes: 1 addition & 1 deletion estate_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import estate_property
from . import estate_property
2 changes: 1 addition & 1 deletion estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def action_set_sold(self):
]
}
self.env['account.move'].create(invoice_values)
return super(EstateProperty, self).action_set_sold()
return super().action_set_sold()

0 comments on commit 5e36068

Please sign in to comment.