-
Notifications
You must be signed in to change notification settings - Fork 3.3k
19.0 tutorials amtha #1376
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 amtha #1376
Changes from all commits
d87cc90
350ef88
bdaafbc
95e2760
5371919
f888899
a6e7ce2
2f23484
6583a65
7481584
5da110c
9533150
bab61c0
f9dce55
9f22c07
0b416ba
9d5c18a
cb60158
05d7e93
26ccc80
b00f3b5
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", | ||
| "version": "1.0", | ||
| "depends": ["base"], | ||
| "application": True, | ||
| "category": "Tutorials", | ||
| "author": "Odoo S.A", | ||
| "license": "LGPL-3", | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "view/estate_property_views.xml", | ||
| "view/estate_property_type_views.xml", | ||
| "view/estate_property_tag_views.xml", | ||
| "view/estate_property_offer_views.xml", | ||
| "view/estate_menus.xml", | ||
| ], | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||||||||||||||||||||||||||||
| from datetime import timedelta | ||||||||||||||||||||||||||||||||||
| from odoo import fields, models, api | ||||||||||||||||||||||||||||||||||
| from odoo.exceptions import UserError, ValidationError | ||||||||||||||||||||||||||||||||||
| from odoo.tools import float_compare, float_is_zero | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| class EstateProperty(models.Model): | ||||||||||||||||||||||||||||||||||
| _name = "estate.property" | ||||||||||||||||||||||||||||||||||
| _description = "Estate Property" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| name = fields.Char(required=True) | ||||||||||||||||||||||||||||||||||
| total_area = fields.Integer(compute="_compute_total_area") | ||||||||||||||||||||||||||||||||||
| description = fields.Text() | ||||||||||||||||||||||||||||||||||
| postcode = fields.Char() | ||||||||||||||||||||||||||||||||||
| property_type_id = fields.Many2one( | ||||||||||||||||||||||||||||||||||
| "estate.property.type", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| buyer_id = fields.Many2one( | ||||||||||||||||||||||||||||||||||
| "res.partner", | ||||||||||||||||||||||||||||||||||
| copy=False, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| salesperson_id = fields.Many2one( | ||||||||||||||||||||||||||||||||||
| "res.users", | ||||||||||||||||||||||||||||||||||
| default=lambda self: self.env.user, | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+24
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 add string explicitly if you want it to be similar to the field name itself.
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. Remove string attributes from fields where the default field label is already appropriate.
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. |
||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| tag_ids = fields.Many2many( | ||||||||||||||||||||||||||||||||||
| "estate.property.tag", | ||||||||||||||||||||||||||||||||||
| string="Tags", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| offer_ids = fields.One2many( | ||||||||||||||||||||||||||||||||||
| "estate.property.offer", | ||||||||||||||||||||||||||||||||||
| "property_id", | ||||||||||||||||||||||||||||||||||
| string="Offers", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| best_price = fields.Float( | ||||||||||||||||||||||||||||||||||
| string="Best Offer", | ||||||||||||||||||||||||||||||||||
| compute="_compute_best_price", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| date_availability = fields.Date( | ||||||||||||||||||||||||||||||||||
| copy=False, | ||||||||||||||||||||||||||||||||||
| default=lambda self: fields.Date.today() + timedelta(days=90), | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| expected_price = fields.Float() | ||||||||||||||||||||||||||||||||||
| 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() | ||||||||||||||||||||||||||||||||||
| garden_orientation = fields.Selection( | ||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||
| ('north', "North"), | ||||||||||||||||||||||||||||||||||
| ('south', "South"), | ||||||||||||||||||||||||||||||||||
| ('east', "East"), | ||||||||||||||||||||||||||||||||||
| ('west', "West"), | ||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+61
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.
Suggested change
Try to keep the key i.e the technical strings in single quotes and the values which are to be displayed to the user in double quotes
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. Done |
||||||||||||||||||||||||||||||||||
| 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", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| _check_selling_price = models.Constraint( | ||||||||||||||||||||||||||||||||||
| "CHECK(selling_price >= 0)", | ||||||||||||||||||||||||||||||||||
| "A property selling price must be positive", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| _check_expected_price = models.Constraint( | ||||||||||||||||||||||||||||||||||
| "CHECK(expected_price > 0)", | ||||||||||||||||||||||||||||||||||
| "A property expected price must be strictly positive", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @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_price(self): | ||||||||||||||||||||||||||||||||||
| for property in self: | ||||||||||||||||||||||||||||||||||
| if property.offer_ids: | ||||||||||||||||||||||||||||||||||
| property.best_price = max(property.offer_ids.mapped("price")) | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| property.best_price = 0 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @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 = False | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @api.constrains("selling_price", "expected_price") | ||||||||||||||||||||||||||||||||||
| def check_price(self): | ||||||||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||||||||
| if float_is_zero(record.selling_price, precision_rounding=0.01): | ||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||
| minimum_price = record.expected_price * 0.9 | ||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||
| float_compare( | ||||||||||||||||||||||||||||||||||
| record.selling_price, | ||||||||||||||||||||||||||||||||||
| minimum_price, | ||||||||||||||||||||||||||||||||||
| precision_rounding=0.01, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| < 0 | ||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||
| raise ValidationError( | ||||||||||||||||||||||||||||||||||
|
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. When would you raise
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. UserError : use when the user perform invalid action.usually use in button and action methods and stop the current operation Both will show an error popup to the user, but UserError is used when a user performs an action that is not allowed, and ValidationError is used when entered or modified data fails a validation |
||||||||||||||||||||||||||||||||||
| " the selling price cannot be lower than 90% of the expected price" | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def action_sold(self): | ||||||||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||||||||
| if record.state == "cancelled": | ||||||||||||||||||||||||||||||||||
| raise UserError("Cancelled property cannot be sold.") | ||||||||||||||||||||||||||||||||||
| record.state = "sold" | ||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def action_cancel(self): | ||||||||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||||||||
| if record.state == "sold": | ||||||||||||||||||||||||||||||||||
| raise UserError("Sold property cannot be cancelled.") | ||||||||||||||||||||||||||||||||||
| record.state = "cancelled" | ||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from odoo import fields, models, api | ||
| from datetime import timedelta | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Property Offer" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| [ | ||
| ("accepted", "Accepted"), | ||
| ("refused", "Refused"), | ||
| ], | ||
| copy=False, | ||
| ) | ||
| partner_id = fields.Many2one( | ||
| "res.partner", | ||
| required=True, | ||
| ) | ||
| property_id = fields.Many2one( | ||
| "estate.property", | ||
| required=True, | ||
| ) | ||
| validity = fields.Integer( | ||
| string="Validity (days)", | ||
| default=7, | ||
| ) | ||
| deadline = fields.Date( | ||
| string="Deadline", | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| store=True, | ||
| ) | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| "CHECK(price>0)", | ||
| "Offer price must be strictly positive.", | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| create_date = ( | ||
| record.create_date.date() if record.create_date else fields.Date.today() | ||
| ) | ||
| record.deadline = create_date + timedelta(days=record.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date and record.deadline: | ||
| record.validity = (record.deadline - record.create_date.date()).days | ||
|
|
||
| def action_confirm(self): | ||
| for record in self: | ||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| record.status = "refused" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Property Tag" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _check_tag_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
|
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. Will this unique work for all the case? |
||
| "A property tag name must be unique", | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Property Type" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _check_property_type_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "A property type name 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_tag,estate.property.tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,estate.property.offer,model_estate_property_offer,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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <!--TOP MENU--> | ||
| <menuitem id="estate_menu_root" name="Real Estate"/> | ||
| <!--CATEGORY MENU--> | ||
| <menuitem id="estate_property_menu" | ||
| name="Advertisements" | ||
| parent="estate_menu_root"/> | ||
| <menuitem id="estate_property_menu1" | ||
| name="Setting" | ||
| parent="estate_menu_root"/> | ||
| <menuitem id="estate_property_menu_action" | ||
| name="Properties" | ||
| parent="estate_property_menu" | ||
| action="estate_property_action"/> | ||
| <menuitem | ||
| id="estate_property_type_menu" | ||
| name="Property Types" | ||
| parent="estate_property_menu1" | ||
| action="estate_property_type_action"/> | ||
| <menuitem | ||
| id="estate_property_tag_menu" | ||
| name="Property Tags" | ||
| parent="estate_property_menu1" | ||
| action="estate_property_tag_action" | ||
| /> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <!-- Action --> | ||
| <record id="estate_property_offer_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| <!-- 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 string="Property Offers"> | ||
| <field name="property_id"/> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="deadline"/> | ||
| <button name="action_confirm" string="Confirm" 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. When to use type
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. type = "object" : used when execute python method defined on the model. |
||
| <button name="action_cancel" string="Cancel" type="object" icon="fa-times"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| <!-- Form View --> | ||
| <record id="estate_property_offer_view_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"> | ||
| <sheet> | ||
| <group> | ||
| <field name="property_id"/> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="deadline"/> | ||
| <field name="status" readonly="True"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| </odoo> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <!-- Action --> | ||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| <!-- List View --> | ||
| <record id="estate_property_tag_view_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 Tags"> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| <!-- Form View --> | ||
| <record id="estate_property_tag_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property Tag"> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| </odoo> |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other options are there for licensing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/home/odoo/odoo19/community/odoo/addons/base/models/ir_module.py == line no. : 296
GPL-2,GPL-3,AGPL-3,LGPL-3,OEEL-1,OPL-1