Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit, custom addons folder with estate and estate_account modules #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Odoo 12.0 - Technical Training
# Odoo 16.0 - Technical Training

The Technical Training of Odoo 16.0 is available on the
[Tutorial](https://www.odoo.com/documentation/master/developer/howtos/rdtraining.html)
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions __manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
'name': 'Estate',
'depends': ['base'],
'installable': True,
'application': True,
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_menus.xml',
'views/res_users_views.xml'
],
'license': 'LGPL-3'
}
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
11 changes: 11 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Estate", # The name that will appear in the App list
"version": "16.0", # Version
"application": True, # This line says the module is an App, and not a module
"depends": ["base"], # dependencies
"data": [

],
"installable": True,
'license': 'LGPL-3',
}
Empty file added estate/models.py
Empty file.
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
130 changes: 130 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from odoo import models, fields, api
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = "estate.property"
_description = "The real estate properties model"
_order = "id desc"

# Fields

name = fields.Char(required=True, string='Name')
description = fields.Text(
default='when duplicated, status and date are not copied')
postcode = fields.Char(help='this is the postcode')
date_availability = fields.Date(
copy=False, default=lambda self: fields.Datetime.now() + relativedelta(months=3))
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
active = fields.Boolean(default=True)

# computed fields

total_area = fields.Float(compute="_compute_total_area")
best_price = fields.Float(
compute="_compute_best_offer", string='Best Offer', default=0)

# Selection fields

state = fields.Selection(
required=True,
copy=False,
default='new',
selection=[('new', 'New'), ('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('canceled', 'Canceled')],
)

garden_orientation = fields.Selection(
string='Garden Orientation',
selection=[('north', 'North'), ('south', 'South'),
('east', 'East'), ('west', 'West')],
help="Garden Orientation: North, South, East and West."
)

# Relational Fields

property_type_id = fields.Many2one('estate.property.type')

# user_id = fields.Many2one('res.users')

property_tag_ids = fields.Many2many('estate.property.tag')

offer_ids = fields.One2many('estate.property.offer', 'property_id')

sales_person_id = fields.Many2one(
'res.users', string='Salesperson', default=lambda self: self.env.user)

buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False)

# Constraints

_sql_constraints = [
('check_expected_price', 'CHECK(expected_price > 0)',
'The expected price must be strictly positive.'),

('check_selling_price', 'CHECK(selling_price >= 0)',
'The selling price must be strictly positive.'),
]

@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
if record.selling_price and record.selling_price < 0.9 * record.expected_price:
raise ValidationError("The selling price must be at least 90% of the expected price! You must reduce the epected price if you want to accept this offer.")

# compute methods

@api.depends("living_area", "garden_area")
def _compute_total_area(self):
for record in self:
record.total_area = record.living_area + record.garden_area

@api.depends("offer_ids.price")
def _compute_best_offer(self):
for record in self:
record.best_price = max(
[offer.price for offer in record.offer_ids], default=0)

# onchange methods

@api.onchange("garden")
def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = 'north'
else:
self.garden_area = 0
self.garden_orientation = ''

# Action Methods

def action_sold_property(self):
for record in self:
if record.state != 'canceled':
record.state = 'sold'
else:
raise UserError("Canceled properties cannot be sold.")

def action_cancel_property(self):
for record in self:
if record.state != 'sold':
record.state = 'canceled'
else:
raise UserError("Sold properties cannot be canceled.")

# CRUD Methods:

@api.ondelete(at_uninstall=False)
def _unlink_except_new_canceled(self):
if any(rec.state not in ('new', 'canceled') for rec in self):
raise UserError("only new and canceled properties can be deleted!")
86 changes: 86 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from odoo import models, fields, api
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError

class EstatePropertyOffer(models.Model):
_name = 'estate.property.offer'
_description = "The property offer model"
_order = "price desc"


# Fields

price = fields.Float()
validity = fields.Integer(default=7)

# Selectoin Fields

status = fields.Selection(
copy=False,
selection=[('accepted', 'Accepted'), ('refused', 'Refused')]
)

# Relational Fields

partner_id = fields.Many2one('res.partner', required=True)
property_id = fields.Many2one('estate.property', required=True)

property_type_id = fields.Many2one(
'estate.property.type', related='property_id.property_type_id', store=True)

# Compute Fields

deadline_date = fields.Date(
compute='_compute_deadline_date', inverse='_inverse_deadline_date')

# Constraints

_sql_constraints = [
('check_offer_price', 'CHECK(price > 0)',
'The offer price must be strictly positive.'),
]

# Compute Methods

@api.depends("create_date", "validity")
def _compute_deadline_date(self):
for offer in self:
date = offer.create_date.date() if offer.create_date else fields.Date.today()
offer.deadline_date = date + relativedelta(days=offer.validity)

def _inverse_deadline_date(self):
for offer in self:
date = offer.create_date.date() if offer.create_date else fields.Date.today()
offer.validity = (offer.deadline_date - date).days

# Action Methods

def action_accept_offer(self):
for record in self:
offers = record.property_id.offer_ids
for offer in offers:
offer.action_refuse_offer()
record.status = 'accepted'
record.property_id.state = 'offer_accepted'
record.property_id.selling_price = record.price
record.property_id.buyer_id = record.partner_id
return True


def action_refuse_offer(self):
for record in self:
record.status = 'refused'
if record.status == 'accepted':
record.property_id.selling_price = None
record.property_id.buyer_id = None
return True

# CRUD Methods:

@api.model
def create(self, vals):
properties = self.env['estate.property'].browse(vals['property_id'])
properties.state = 'offer_received'
if vals['price'] < properties.best_price:
raise UserError(f"The offer must be higher than {properties.best_price}")
return super().create(vals)
17 changes: 17 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import models, fields


class EstatePropertyTag(models.Model):
_name = 'estate.property.tag'
_description = "The property tag model"
_order = "tag_name"
_rec_name = 'tag_name'


tag_name = fields.Char(required=True)
color = fields.Integer()

_sql_constraints = [
('name_uniq', 'UNIQUE (tag_name)',
'The Tag name must be unique!')
]
47 changes: 47 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from odoo import models, fields, api

class EstatePropertyType(models.Model):
_name = 'estate.property.type'
_description = "The property type model"
_order = "sequence"
_rec_name = 'property_type'

# Fields

property_type = fields.Char()

# Relational Fields

property_ids = fields.One2many('estate.property', 'property_type_id')

offer_ids = fields.One2many('estate.property.offer', 'property_type_id')

# Compute Fields

offer_count = fields.Integer(compute='_check_offer_count')

sequence = fields.Integer('Sequence', default=1,
help="Used to order stages. Lower is better.")

_sql_constraints = [
('type_unique', 'UNIQUE (property_type)',
'The Property type must be unique!')
]

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

# def view_offers(self):
# self.ensure_one()
# return {
# "type": "ir.actions.act_window",
# "name": "Property Offers",
# "res_model": "estate.property.offer",
# "view_mode": "tree,form"
# # "domain": [("change_id", "=", self.id)],
# # "context": "{'create': False}"
# }


7 changes: 7 additions & 0 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models

class RecUsers(models.Model):
_inherit = "res.users"

property_ids = fields.One2many(
'estate.property', 'sales_person_id', domain=[('state', 'in', ('new', 'offer_received'))])
9 changes: 9 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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
19 changes: 19 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>

<menuitem id="estate_menu_root" name="Real Estate">

<menuitem id="advertisements_menu" name="Advertisements">
<menuitem id="estate_property_menu_action" action="estate_property_action"/>
</menuitem>

<menuitem id="settings_menu" name="Settings">
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/>
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action"/>
</menuitem>

</menuitem>

</data>
</odoo>
Loading