-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You'll have to re-write this commit message
- Loading branch information
Showing
11 changed files
with
188 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
from . import estate_property_infos | ||
from . import estate_property | ||
from . import estate_property_infos, estate_property, estate_property_offer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from odoo import api, exceptions, fields, models | ||
from datetime import date | ||
from dateutil.relativedelta import relativedelta | ||
|
||
|
||
class Estate_Property_Offer(models.Model): | ||
_name = "estate_property_offer" | ||
_description = "Estate Property Offers" | ||
_order = "price desc" | ||
|
||
price = fields.Float( | ||
string="Price" | ||
) | ||
|
||
status = fields.Selection( | ||
[("accepted", "Accepted"), ("refused", "Refused")], | ||
readonly=True, | ||
copy=False, | ||
string="Status" | ||
) | ||
|
||
partner_id = fields.Many2one( | ||
'res.partner', | ||
required=True, | ||
string="Partner" | ||
) | ||
|
||
property_id = fields.Many2one( | ||
'estate_property', | ||
string="Property" | ||
) | ||
|
||
validity = fields.Integer( | ||
default=7, | ||
string="Validity (days)" | ||
) | ||
|
||
deadline = fields.Date( | ||
compute="_compute_deadline", | ||
copy=False, | ||
string="Deadline" | ||
) | ||
|
||
_sql_constraints = [ | ||
("check_positive_price", "CHECK(price > 0.0)", "Offer Price should be a positive number (higher than 0).") | ||
] | ||
|
||
@api.depends("validity") | ||
def _compute_deadline(self): | ||
for record in self: | ||
record.deadline = date.today() + relativedelta(days=+record.validity) | ||
|
||
def _inverse_deadline(self): | ||
for record in self: | ||
record.validity = relativedelta(date.today(), record.deadline) | ||
|
||
def action_accept(self): | ||
for record in self: | ||
if not any(offer_status == "accepted" for offer_status in record.property_id.offer_ids.mapped("status")): | ||
# Set values in the Property itself | ||
record.property_id.selling_price = record.price | ||
record.property_id.buyer = record.partner_id | ||
|
||
record.status = "accepted" | ||
else: | ||
raise exceptions.UserError("An offer has already been accepted.") | ||
return True | ||
|
||
def action_refuse(self): | ||
for record in self: | ||
if record.status == "accepted": | ||
# Set values in the Property itself | ||
record.property_id.selling_price = 0.0 | ||
record.property_id.buyer = None | ||
record.status = "refused" | ||
return True |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<!-- List view --> | ||
<record id="estate_property_offer_view_list" model="ir.ui.view"> | ||
<field name="name">estate_property_offer_list</field> | ||
<field name="model">estate_property_offer</field> | ||
<field name="arch" type="xml"> | ||
<list editable="top"> | ||
<field name="price"/> | ||
<field name="partner_id"/> | ||
<field name="validity"/> | ||
<field name="deadline"/> | ||
<button name="action_accept" type="object" string="Accept" icon="fa-check"/> | ||
<button name="action_refuse" type="object" string="Refuse" icon="fa-times"/> | ||
<field name="status"/> | ||
</list> | ||
</field> | ||
</record> | ||
|
||
<record id="estate_property_offer_view" model="ir.actions.act_window"> | ||
<field name="name">Offers</field> | ||
<field name="res_model">estate_property_offer</field> | ||
<field name="view_mode">list</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.