-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] estate: best offer, validity date, sold/canceled buttons, SQL c…
…onstraint - Create Best Offer field with computed - Create the Offer date with Validation date - Create sold, canceled, accepted, refused button - Create validation warning on negative number - Add SQL constraint - Covered from chapter 8 to 10
- Loading branch information
Showing
8 changed files
with
163 additions
and
34 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,8 +1,56 @@ | ||
from odoo import models, fields | ||
from odoo import models, fields, api | ||
from datetime import timedelta, date | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name='estate.property.offer' | ||
_description='Estate Property Offer' | ||
_name = 'estate.property.offer' | ||
_description = 'Estate Property Offer' | ||
price = fields.Float() | ||
status = fields.Selection(copy=False, selection=[('accepted', 'Accepted'), ('refused', 'Refused')]) | ||
partner_id = fields.Many2one('res.partner', required=True) | ||
property_id = fields.Many2one('estate.property', required=True) | ||
property_id = fields.Many2one('estate.property', required=True) | ||
validity = fields.Integer(default=7) | ||
deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline') | ||
|
||
@api.depends('validity') | ||
def _compute_deadline(self): | ||
for record in self: | ||
today = record.create_date | ||
if today: | ||
today = record.create_date | ||
else: | ||
today = date.today() | ||
if record.validity: | ||
record.deadline = today + timedelta(days=record.validity) | ||
else: | ||
record.deadline = today | ||
|
||
def _inverse_deadline(self): | ||
for record in self: | ||
if record.deadline: | ||
# Convert create_date to a date object | ||
today = fields.Date.to_date(record.create_date) | ||
# Convert deadline to a date object | ||
deadline_date = fields.Date.from_string(record.deadline) | ||
record.validity = (deadline_date - today).days | ||
else: | ||
record.validity = 7 # Default to 7 if deadline is not set | ||
|
||
@api.depends('property_id') | ||
def action_status_accept(self): | ||
self.status = 'accepted' | ||
price_percent = (self.price / self.property_id.expected_price) * 100 | ||
if price_percent > 90: | ||
self.property_id.selling_price = self.price | ||
self.property_id.buyer_id = self.partner_id | ||
else: | ||
raise ValidationError("The selling price must be at least 90%") | ||
|
||
def aciton_status_refused(self): | ||
self.status = 'refused' | ||
|
||
_sql_constraints = [ | ||
('check_price', 'CHECK(price >= 0)', | ||
'The Price of Offer should be positive'), | ||
] |
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,5 +1,8 @@ | ||
from odoo import models, fields | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name ='estate.property.tag' | ||
_description ='Estate Property tag' | ||
_name = 'estate.property.tag' | ||
_description = 'Estate Property tag' | ||
name = fields.Char(required=True) | ||
_sql_constraints = [('name_uniq', 'unique (name)', "Tag name already exists!")] |
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,6 +1,7 @@ | ||
from odoo import fields,models | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Real Estate Property Type" | ||
name = fields.Char(required=True) | ||
|
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,39 @@ | ||
<odoo> | ||
|
||
<record id='estate_property_offer_tree' model='ir.ui.view'> | ||
<field name="name">estate_property_offer</field> | ||
<field name="model">estate.property.offer</field> | ||
<field name="arch" type="xml"> | ||
<tree sample="1"> | ||
<field name='price'/> | ||
<field name='partner_id'/> | ||
|
||
<field name='validity' string='Validity (days)'/> | ||
<field name='deadline'/> | ||
<button name="action_status_accept" type="object" icon="fa-check" /> | ||
<button name="aciton_status_refused" type="object" icon="fa-times"/> | ||
<field name='status'/> | ||
</tree> | ||
</field> | ||
|
||
</record> | ||
|
||
|
||
<record id='estate_property_offer_form' model='ir.ui.view'> | ||
<field name="name">estate_property_offer_form</field> | ||
<field name="model">estate.property.offer</field> | ||
<field name="arch" type="xml"> | ||
<form > | ||
<sheet> | ||
<group> | ||
<field name='price'/> | ||
<field name='partner_id'/> | ||
<field name="validity"/> | ||
<field name="deadline"/> | ||
<field name='status'/> | ||
</group> | ||
</sheet> | ||
</form> | ||
</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
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