-
Notifications
You must be signed in to change notification settings - Fork 2.8k
vijan - Technical Training #1055
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
Open
VincentJanssen-Code
wants to merge
18
commits into
odoo:master
Choose a base branch
from
odoo-dev:master-tutorial-vijan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e778fbb
[IMP] estate: Server101 Finished Chapter 2
VincentJanssen-Code 79dd837
[IMP] estate: Server101 Finished Chapter 3
VincentJanssen-Code 2e0633c
[IMP] estate: Server101 Finished Chapter 4
VincentJanssen-Code c3b8617
[IMP] estate: Server101 Finished Chapter 5
VincentJanssen-Code 136d519
[IMP] estate: Server101 Finished Chapter 6
VincentJanssen-Code 2d93191
[IMP] estate: Server101 Finished Chapter 7
VincentJanssen-Code 5952c23
[IMP] estate: Server101 Finished Chapter 8
VincentJanssen-Code 5490607
[IMP] estate: Server101 Finished Chapter 9
VincentJanssen-Code e908e63
[IMP] estate: Server101 Finished Chapter 10
VincentJanssen-Code 090b2e9
[IMP] estate: Server101 Finished Chapter 11
VincentJanssen-Code ed5ba1c
[IMP] estate : Server101 Finished Chapter 12
VincentJanssen-Code 6d2bf4b
[IMP] estate: Server101 Finished Chapter 13
VincentJanssen-Code 165fe70
[IMP] estate: Server101 Finshed Chapter 14
VincentJanssen-Code e70a0b6
[FIX] estate: Added error message translation useing self.env._() an…
VincentJanssen-Code dceda6c
[IMP] awesome_owl: Web Framework Finished Chapter 1 Part 1-8
VincentJanssen-Code 5044748
[IMP] awesome_owl: Web Framework Finished Chapter 1 Part 9-14
VincentJanssen-Code 0e666a2
[IMP] awesome_owl: Web Framework Finished Chapter 2 Part 1-6
VincentJanssen-Code 0e4179c
[IMP] awsome_owl: Framework Finished Chapter 7-12
VincentJanssen-Code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| from . import models |
This file contains hidden or 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,21 @@ | ||
| { | ||
| 'name': "estate", | ||
| 'description': "test", | ||
| 'depends': [ | ||
| 'base_setup' | ||
| ], | ||
| 'category': "Tutorials", | ||
| 'installable': True, | ||
| 'application': True, | ||
| 'data': [ | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_menu_views.xml', | ||
| 'views/res_user_views.xml', | ||
| 'security/ir.model.access.csv'], | ||
| 'author': 'Odoo S.A.', | ||
| 'license': 'LGPL-3' | ||
|
|
||
| } |
This file contains hidden or 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,5 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import res_user |
This file contains hidden or 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,96 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import fields, models, api | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
| from odoo.exceptions import ValidationError, UserError | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Property" | ||
| _order = "id desc" | ||
|
|
||
| _positif_expected_price = models.Constraint("CHECK (expected_price >= 0)", "A price can't be negatif") | ||
| _positif_selling_price = models.Constraint("CHECK (selling_price >= 0)", "A price can't be negatif") | ||
|
|
||
| state = fields.Selection(selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled") | ||
| ], default='new') | ||
|
|
||
| active = fields.Boolean('Active', default=True) | ||
| name = fields.Char(required=True, default="Unkown") | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date("Available From", copy=False, default=lambda self: fields.Datetime.today() + relativedelta(months=3)) | ||
| last_seen = fields.Date("Last Seen", default=lambda self: fields.Datetime.now()) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| best_price = fields.Float(string="Best Price", compute="_compute_best_price") | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer() | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| garden_orientation = fields.Selection(selection=[ | ||
| ('north', 'North'), | ||
| ('south', 'South'), | ||
| ('east', 'East'), | ||
| ('west', 'West')]) | ||
|
|
||
| total_area = fields.Float(compute="_compute_total_area", string="Total Area") | ||
| property_type_id = fields.Many2one("estate.property.type", string="Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer") | ||
| seller_id = fields.Many2one("res.users", default=lambda self: self.env.user, string="Seller") | ||
| tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
|
|
||
| def sell_property(self): | ||
| for record in self: | ||
| if (record.state == "cancelled"): | ||
| raise UserError("Can't sell cancelled property.") | ||
| record.state = "sold" | ||
| return True | ||
|
|
||
| def cancel_property(self): | ||
| for record in self: | ||
| if (record.state == "sold"): | ||
| raise UserError("Can't cancel sold property.") | ||
| record.state = "cancelled" | ||
| return True | ||
|
|
||
| @api.depends('living_area', 'garden_area') | ||
| def _compute_total_area(self): | ||
| for record in self: | ||
| record.total_area = record.garden_area + record.living_area | ||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| if (not record.offer_ids): | ||
| record.best_price = 0 | ||
| continue | ||
|
|
||
| record.best_price = max(record.offer_ids.mapped('price')) | ||
|
|
||
| @api.onchange("garden") | ||
| def _on_change_garden(self): | ||
| self.garden_area = 10 if self.garden else 0 | ||
| self.garden_orientation = 'north' if self.garden else '' | ||
|
|
||
| @api.constrains('selling_price', 'expected_price') | ||
| def _constrain_prices(self): | ||
| for record in self: | ||
| if float_is_zero(record.selling_price, 2): | ||
| continue | ||
| if (float_compare(record.selling_price, record.expected_price * 0.8, 2) == -1): | ||
| raise ValidationError(f"Selling price is too low {record.selling_price}") | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_excpet_cancel_new(self): | ||
| for record in self: | ||
| if (record.state != 'new' and record.state != 'cancel'): | ||
| raise UserError("Can't delete non-new and non-cancelled property") |
This file contains hidden or 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,59 @@ | ||
| from datetime import datetime, time | ||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import fields, models, api | ||
| from odoo.exceptions import UserError | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Property Offer" | ||
| _order = "price desc" | ||
|
|
||
| _postif_price = models.Constraint("CHECK (price > 0)", "A price can't be negatif") | ||
|
|
||
| price = fields.Float(string="Price") | ||
| 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_type_id = fields.Many2one(related="property_id.property_type_id", store=True) | ||
| validity = fields.Integer(string="Validity Duration", default=7) | ||
| date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline") | ||
|
|
||
| def accept_offer(self): | ||
| for record in self: | ||
| if (record.property_id.selling_price == 0): | ||
| record.status = "accepted" | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = 'offer_accepted' | ||
| return True | ||
|
|
||
| def refused_offer(self): | ||
| for record in self: | ||
| record.status = "refused" | ||
| return True | ||
|
|
||
| @api.depends("validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| if (isinstance(record.create_date, bool)): | ||
| record.date_deadline = fields.Datetime.now() + relativedelta(days=record.validity) | ||
| return | ||
| record.date_deadline = record.create_date + relativedelta(days=record.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (datetime.combine(record.date_deadline, time()) - record.create_date).days | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| for record in vals_list: | ||
| property = self.env['estate.property'].browse(record['property_id']) | ||
| if (float_compare(record['price'], property.best_price, 2) == -1): | ||
| raise UserError("This offer is lower than what has already been offered.") | ||
| property.state = 'offer_received' | ||
| return super().create(vals_list) | ||
This file contains hidden or 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,12 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Property Tag" | ||
| _order = "name asc" | ||
|
|
||
| _unique_tag = models.UniqueIndex("(name)", "Tag name must be unique in database") | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() |
This file contains hidden or 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,20 @@ | ||
| from odoo import fields, models, api | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Property Type" | ||
| _order = "sequence, name asc" | ||
|
|
||
| _unique_type = models.UniqueIndex("(name)", "Property type name must be unique in database") | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
| sequence = fields.Integer('Sequence', default=1, help="use to order the list inside the type view") | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
| offer_count = fields.Integer(compute='_compute_offer_count') | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) |
This file contains hidden or 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,6 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
| property_ids = fields.One2many("estate.property", "seller_id", domain="['|',('state','=','Offer_Received'),('state','=','New')]") |
This file contains hidden or 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,5 @@ | ||
| id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
| access_estate_property_model,access_estate_property_model,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type_model,access_estate_property_type_model,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag_model,access_estate_property_tag_model,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer_model,access_estate_property_offer_model,model_estate_property_offer,base.group_user,1,1,1,1 | ||
VincentJanssen-Code marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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,12 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Estate"> | ||
| <menuitem id="estate_property_menu" name="Property"> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_model_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_menu_acion" action="estate_property_type_model_action"/> | ||
| <menuitem id="estate_property_tag_menu_acion" action="estate_property_tag_model_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> | ||
VincentJanssen-Code marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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,45 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_offer_model_action" model="ir.actions.act_window"> | ||
| <field name ="name">Property Offer</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list,form</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_model_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 string="Property offer form"> | ||
| <sheet> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id" string="Partner"/> | ||
| <field name ="status"/> | ||
| <field name="date_deadline"/> | ||
| <field name="validity"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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 string="Property offer list" editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'"> | ||
| <field name="price"/> | ||
| <field name ="partner_id"/> | ||
| <field name="date_deadline"/> | ||
| <field name="validity"/> | ||
| <field name="property_type_id"/> | ||
| <button name="accept_offer" type="object" string="Accept" icon="fa-check" invisible="status == 'accepted' or status == 'refused'"/> | ||
| <button name="refused_offer" type="object" string="Refuse" icon="fa-times" invisible="status == 'accepted' or status == 'refused'"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> | ||
VincentJanssen-Code marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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,34 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_tag_model_action" model="ir.actions.act_window"> | ||
| <field name ="name">Property Tag</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_model_form" model="ir.ui.view"> | ||
VincentJanssen-Code marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <field name ="name">estate.property.tag.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property list"> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| <record id="estate_property_tag_model_list" model="ir.ui.view"> | ||
| <field name ="name">estate.property.tag.list</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property tag list" editable="bottom"> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
|
|
||
| </odoo> | ||
This file contains hidden or 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,56 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_type_model_action" model="ir.actions.act_window"> | ||
| <field name ="name">Property Type</field> | ||
| <field name="res_model">estate.property.type</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_model_form" model="ir.ui.view"> | ||
| <field name ="name">estate.property.type.form</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property type Form"> | ||
| <sheet> | ||
| <div class="oe_button_box"> | ||
| <button name="%(estate.estate_property_offer_model_action)d" string="Offers" class="oe_stat_button" type="action" icon="fa-bars"> | ||
| <div class="o_stat_info"> | ||
| <span class="o_stat_value"> | ||
| <field name="offer_count"/> | ||
| </span> | ||
| <span class="o_stat_text"> | ||
| Offers | ||
| </span> | ||
| </div> | ||
| </button> | ||
| </div> | ||
| <group> | ||
| <h1 class="mb32"> | ||
| <field name="name"/> | ||
| </h1> | ||
| </group> | ||
| <field name="property_ids"> | ||
| <list> | ||
| <field name="name"/> | ||
| <field name="expected_price"/> | ||
| <field name="state"/> | ||
| </list> | ||
| </field> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_model_list" model="ir.ui.view"> | ||
| <field name ="name">estate.property.type.list</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property type list"> | ||
| <field name="sequence" widget="handle"/> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.