-
Notifications
You must be signed in to change notification settings - Fork 3.3k
19.0 tutorials ancha #1357
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
base: 19.0
Are you sure you want to change the base?
19.0 tutorials ancha #1357
Changes from all commits
076ed51
d23e871
b48be13
e27c9fc
13997f0
63d7e80
5a323bf
84072b3
cc8b8c9
ba8b5a0
e1c3eab
ef8a011
4a9cc26
5139800
fbb8e20
7198b8c
2e403aa
75a635b
92fc8e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "estate", | ||
| "category": "", | ||
| "depends": [ | ||
| "base", | ||
| ], | ||
| "application": True, | ||
| "author": "Odoo S.A.", | ||
| "license": "LGPL-3", | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property.xml", | ||
| "views/estate_property_offers.xml", | ||
| "views/estate_property_types.xml", | ||
| "views/estate_property_menus.xml", | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from . import ( | ||
| estate_property, | ||
| estate_property_type, | ||
| estate_property_tags, | ||
| estate_property_offers, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| from odoo import models, fields, api | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Real Estate Property" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True, default="Unknown") | ||
| property_type_id = fields.Many2one("estate.property.type", string="Type") | ||
| description = fields.Text() | ||
| tag_ids = fields.Many2many("estate.property.tags", string="Tags") | ||
| salesman_id = fields.Many2one("res.users", default=lambda self: self.env.user.id) | ||
| buyer_id = fields.Many2one( | ||
| "res.partner", default=lambda self: self.env.user.id, copy=False | ||
| ) | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date(copy=False) | ||
| expected_price = fields.Float(required=True, default=15.6) | ||
| 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() | ||
| total_area = fields.Float(compute="_compute_total_area") | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
| garden_orientation = fields.Selection( | ||
| [ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| string="Garden Orientation", | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| [ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| readonly=True, | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| "estate.property.offers", "property_id", string="Offers" | ||
| ) | ||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", "Expected price must be positive." | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price > 0)", "Property selling price must be positive." | ||
| ) | ||
|
|
||
| @api.constrains("selling_price") | ||
| def _check_selling_price(self): | ||
| if float_compare(self.selling_price, (self.expected_price * 0.9), 2) == -1: | ||
| raise ValidationError( | ||
| "Selling Price must not be less than 90% of expected price." | ||
| ) | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for realEstateProperty in self: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a for loop here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need it because self is a recordset and it's length is not fixed. |
||
| realEstateProperty.total_area = ( | ||
| realEstateProperty.living_area + realEstateProperty.garden_area | ||
| ) | ||
|
|
||
| # @api.onchange("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") | ||
| def _compute_best_price(self): | ||
| self.best_price = max(self.offer_ids.mapped("price")) if self.offer_ids else 0 | ||
|
|
||
| # @api.depends("offer_ids") | ||
| # def _compute_best_price(self): | ||
| # if self.offer_ids: | ||
| # price_list=[] | ||
| # price_list.append(offer.price) | ||
| # for i in range(len(price_list)): | ||
| # for j in range(len(price_list)): | ||
| # if price_list[i]>=price_list[j]: | ||
| # self.best_price= price_list[i] | ||
| # else: | ||
| # self.best_price=0 | ||
| # self.best_price = 0 | ||
| # if self.offer_ids: | ||
| # for offer in self.offer_ids: | ||
| # if offer.price > self.best_price: | ||
| # self.best_price = offer.price | ||
|
|
||
| @api.onchange("garden") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we pass multiple arguments here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| def _onchange_garden(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = "north" | ||
| else: | ||
| self.garden_area = 0 | ||
| self.garden_orientation = "" | ||
|
|
||
| def set_sold(self): | ||
| if self.state == "cancelled": | ||
| raise UserError("Cancelled Properties Cannot be Sold") | ||
| else: | ||
| self.state = "sold" | ||
| return True | ||
|
|
||
| def set_cancel(self): | ||
| if self.state == "sold": | ||
| raise UserError("Sold Properties cannot be Cancelled") | ||
| else: | ||
| self.state = "cancelled" | ||
| return True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo import models, fields, api | ||
|
|
||
|
|
||
| class EstatePropertyOffers(models.Model): | ||
| _name = "estate.property.offers" | ||
| _description = "Property Offers" | ||
|
|
||
| price = fields.Float(string="Price") | ||
| status = fields.Selection( | ||
|
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to explicitly pass string here if you want to have the string name same as the field name.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| [("accepted", "Accepted"), ("refused", "Refused")], | ||
| string="Status", | ||
| copy="False", | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Customer", required=True) | ||
| property_id = fields.Many2one("estate.property", string="Property", required=True) | ||
| validity = fields.Integer(string="Validity", default=7) | ||
| date_deadline = fields.Date( | ||
| string="Date Deadline", | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| ) | ||
| _check_offer_price = models.Constraint( | ||
| "CHECK(price > 0)", "Offer price must be positive." | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date: | ||
| record.date_deadline = record.create_date.date() + timedelta( | ||
| days=record.validity | ||
| ) | ||
| else: | ||
| record.date_deadline = fields.Date.today() + timedelta( | ||
| days=record.validity | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def set_accepted(self): | ||
| for record in self: | ||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id.name = record.partner_id.name | ||
| return True | ||
|
|
||
| def set_refused(self): | ||
| for record in self: | ||
| record.status = "refused" | ||
| return True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class EstatePropertyTags(models.Model): | ||
| _name = "estate.property.tags" | ||
| _description = "Estate Property Tags" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| property_id = fields.Many2one( | ||
| comodel_name="estate.property", | ||
| string="Property", | ||
| ) | ||
| _check_tag_name = models.Constraint( | ||
| "UNIQUE(name)", "Property tag name must be unique." | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Types of estate property" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| _check_property_type = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "Property type must be unique", | ||
| ) |
| 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,access_estate_property,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type,estate.property.type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag,estate.property.tag,model_estate_property_tags,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,estate.property.offer,model_estate_property_offers,base.group_user,1,1,1,1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_action" model="ir.actions.act_window"> | ||
| <field name="name">Properties</field> | ||
| <field name="res_model">estate.property</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
|
|
||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.property.tags</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
|
|
||
| <!--List Property view--> | ||
|
|
||
|
|
||
| <record id="estate_property_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.list</field> | ||
| <field name="model">estate.property</field> | ||
| <field name="arch" type="xml"> | ||
| <list> | ||
| <field name="name"/> | ||
| <field name="tag_ids" widget="many2many_tags"/> | ||
| <field name="expected_price"/> | ||
| <field name="selling_price"/> | ||
| <field name="bedrooms"/> | ||
| <field name="living_area"/> | ||
| <field name="postcode"/> | ||
| <field name="date_availability"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <!--custom Property form view--> | ||
|
|
||
| <record id="estate_property_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.form</field> | ||
| <field name="model">estate.property</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="property"> | ||
| <header> | ||
| <button name="set_sold" type="object" string="Sold"/> | ||
| <button name="set_cancel" type="object" string="Cancel"/> | ||
| </header> | ||
|
|
||
| <div> | ||
| <h1> | ||
| <field name="name"/> | ||
| </h1> | ||
| </div> | ||
| <group> | ||
| <group> | ||
| <field name="state"/> | ||
| <field name="postcode"/> | ||
| <field name="date_availability"/> | ||
| <field name="tag_ids" widget="many2many_tags"/> | ||
|
|
||
| </group> | ||
|
|
||
|
|
||
| <group> | ||
| <field name="expected_price"/> | ||
| <field name="selling_price"/> | ||
| <field name="best_price"/> | ||
| </group> | ||
| </group> | ||
| <notebook> | ||
| <page string="Description"> | ||
| <group> | ||
| <field name="description"/> | ||
| <field name="bedrooms"/> | ||
| <field name="living_area"/> | ||
| <field name="garage"/> | ||
| <field name="garden"/> | ||
| <field name="garden_area"/> | ||
| <field name="garden_orientation"/> | ||
| <field name="facades"/> | ||
| <field name="total_area"/> | ||
| </group> | ||
| </page> | ||
| <page string="Offers"> | ||
| <field name="offer_ids"> | ||
| <list edit="true"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="set_accepted" string="Accept" type="object" icon="fa-check"/> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the working of the attribute
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the attribute "type" mentions what to do when the button is clicked |
||
| <button name="set_refused" string="Refuse" type="object" icon="fa-close"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </page> | ||
| <page string="Other Info"> | ||
| <group> | ||
| <field name="salesman_id"/> | ||
| <field name="buyer_id"/> | ||
| </group> | ||
| </page> | ||
| </notebook> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <!--custom Property search view--> | ||
| <record id="estate_property_view_search" model="ir.ui.view"> | ||
| <field name="name">estate.property.search</field> | ||
| <field name="model">estate.property</field> | ||
| <field name="arch" type="xml"> | ||
| <search> | ||
| <field name="name"/> | ||
| <filter name="group_by_bedrooms" string="Bedrooms" context="{'group_by':'bedrooms'}"/> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYM by context and domain?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Eg. when we want to filter the orders based on the order price greater than 5000
when tasks are created, by default it must be assigned to id = 11. |
||
| <filter name="filter" string="price" domain="[('expected_price', '>', 5000)]"/> | ||
| <filter | ||
| string="Bedrooms" | ||
| name="bedrooms" | ||
| domain="[('bedrooms', '=' , 2)]"/> | ||
|
|
||
|
|
||
| </search> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <menuitem | ||
| id="estate_menu_root" | ||
| name="Real Estate" | ||
| > | ||
| <menuitem | ||
| id="estate_first_level_menu" | ||
| name="Advertisements" | ||
| > | ||
| <menuitem | ||
| id="estate_property_menu_action" | ||
| action="estate_property_action" | ||
| /> | ||
| </menuitem> | ||
|
ancha-odoo marked this conversation as resolved.
|
||
| <menuitem id="estate_property_second_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_menu" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_tags_menu" action="estate_property_tag_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
|
|
||
| </odoo> | ||

Uh oh!
There was an error while loading. Please reload this page.