-
Notifications
You must be signed in to change notification settings - Fork 2.7k
19.0 tutorials taskv #1035
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 taskv #1035
Changes from 16 commits
748a2b7
07ee005
0db978f
b78f9c1
c66d2ad
821328f
afec0e3
b87b0a4
ae44645
898c085
347453f
d490741
220923d
b722b3e
64e100c
03cee0d
61dd212
527af1f
fceec12
0135233
09aff26
16065f8
5f3af82
647c006
67e8dc2
ddd9e28
f233d5c
66c4d7b
cd24f13
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,3 @@ | ||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
|
||
| from . import models | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| 'name': "Real Estate", | ||
| 'version': '1.0', | ||
| 'depends': ['base'], | ||
| 'author': "taskv", | ||
| 'category': 'Tutorials', | ||
| 'description': """ | ||
| Tutorial Project | ||
| """, | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| '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_menus.xml', | ||
| 'views/res_users_views.xml', | ||
| ], | ||
| 'demo': [ | ||
| ], | ||
|
Comment on lines
20
to
22
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 specify demo if it's empty |
||
| 'installable': True, | ||
| 'application': True, | ||
| 'license': 'LGPL-3', | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
|
||
|
||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import res_users | ||
|
Comment on lines
1
to
5
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 just need to sort all imports by alphabetical order like here |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | ||||||||||||||||||||||||||||||||||||||||||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| from odoo import fields, models, api, exceptions | ||||||||||||||||||||||||||||||||||||||||||
| from odoo.tools.float_utils import float_is_zero, float_compare | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| class EstateProperty(models.Model): | ||||||||||||||||||||||||||||||||||||||||||
| _name = 'estate.property' | ||||||||||||||||||||||||||||||||||||||||||
| _description = 'Estate Property' | ||||||||||||||||||||||||||||||||||||||||||
| _order = "id desc" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| name = fields.Char('Title', required=True, default='Unknown', translate='True') | ||||||||||||||||||||||||||||||||||||||||||
| active = fields.Boolean('Active', default=True) | ||||||||||||||||||||||||||||||||||||||||||
| description = fields.Text('Description') | ||||||||||||||||||||||||||||||||||||||||||
| postcode = fields.Char('Postcode') | ||||||||||||||||||||||||||||||||||||||||||
| date_availability = fields.Date('Available From', copy=False, default=fields.Date.add(fields.Date.today(), months=3)) | ||||||||||||||||||||||||||||||||||||||||||
| expected_price = fields.Float('Expected Price', required=True) | ||||||||||||||||||||||||||||||||||||||||||
| selling_price = fields.Float('Selling Price', readonly=True, copy=False) | ||||||||||||||||||||||||||||||||||||||||||
| bedrooms = fields.Integer('Bedrooms', default=2) | ||||||||||||||||||||||||||||||||||||||||||
| living_area = fields.Integer('Living Area (sqm)') | ||||||||||||||||||||||||||||||||||||||||||
| facades = fields.Integer('Facades') | ||||||||||||||||||||||||||||||||||||||||||
| garage = fields.Boolean('Garage') | ||||||||||||||||||||||||||||||||||||||||||
| garden = fields.Boolean('Garden') | ||||||||||||||||||||||||||||||||||||||||||
| garden_area = fields.Integer('Garden Area (sqm)') | ||||||||||||||||||||||||||||||||||||||||||
| garden_orientation = fields.Selection(string='Garden orientation', | ||||||||||||||||||||||||||||||||||||||||||
| selection=[('north', 'North'), | ||||||||||||||||||||||||||||||||||||||||||
| ('south', 'South'), | ||||||||||||||||||||||||||||||||||||||||||
| ('east', 'East'), | ||||||||||||||||||||||||||||||||||||||||||
| ('west', 'West')] | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| garden_orientation = fields.Selection(string='Garden orientation', | |
| selection=[('north', 'North'), | |
| ('south', 'South'), | |
| ('east', 'East'), | |
| ('west', 'West')] | |
| ) | |
| garden_orientation = fields.Selection( | |
| string='Garden orientation', | |
| selection=[ | |
| ('north', 'North'), | |
| ('south', 'South'), | |
| ('east', 'East'), | |
| ('west', 'West'), | |
| ], | |
| ) |
Outdated
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.
Same, the indent is a little bit weird, it looks better to just have one argument per line here
| state = fields.Selection(string='State', | |
| selection=[('new', 'New'), | |
| ('offer_received', 'Offer Received'), | |
| ('offer_accepted', 'Offer Accepted'), | |
| ('sold', 'Sold'), | |
| ('cancelled', 'Cancelled')], | |
| default='new', required=True, copy=False) | |
| state = fields.Selection( | |
| string='State', | |
| selection=[ | |
| ('new', 'New'), | |
| ('offer_received', 'Offer Received'), | |
| ('offer_accepted', 'Offer Accepted'), | |
| ('sold', 'Sold'), | |
| ('cancelled', 'Cancelled'), | |
| ], | |
| default='new', | |
| required=True, | |
| copy=False, | |
| ) |
Outdated
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.
you can just do this
| if record.offer_ids: | |
| record.best_offer = max(record.offer_ids.mapped('price')) | |
| else: | |
| record.best_offer = 0 | |
| record.best_offer = max(record.offer_ids.mapped('price'), default=0.0) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||||||||||||||||
|
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. Same, you don't need to put the odoo license in every file anymore |
||||||||||||||||
|
|
||||||||||||||||
| from odoo import fields, models, api, exceptions | ||||||||||||||||
| from datetime import date, timedelta | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class EstatePropertyOffer(models.Model): | ||||||||||||||||
| _name = 'estate.property.offer' | ||||||||||||||||
| _description = 'Estate Property Offer' | ||||||||||||||||
| _order = "price desc" | ||||||||||||||||
|
|
||||||||||||||||
| price = fields.Float(string='Price') | ||||||||||||||||
| status = fields.Selection(string='Status', copy=False, | ||||||||||||||||
| selection=[('accepted', 'Accepted'), ('refused', 'Refused')]) | ||||||||||||||||
|
||||||||||||||||
| status = fields.Selection(string='Status', copy=False, | |
| selection=[('accepted', 'Accepted'), ('refused', 'Refused')]) | |
| status = fields.Selection( | |
| string='Status', | |
| copy=False, | |
| selection=[('accepted', 'Accepted'), ('refused', 'Refused')] | |
| ) |
Outdated
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.
You already support a list of dicts, you can add @api.model_create_multi decorator
Outdated
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.
You are checking almost the same condition twice
| if 'property_id' in vals and vals.get('property_id'): | |
| if vals.get('property_id'): |
Outdated
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.
Not a problem for the tutorial, but with an actual module, we usually don't use fstrings for errors, as you cannot translate these
Here is an example of how we usually format translated strings with parameters
https://github.com/odoo/odoo/blob/fc658b2e3d9c5afbfa5d00b579bf8928a90dab87/addons/barcodes/models/barcode_rule.py#L41
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||||||||||
|
||||||||||
|
|
||||||||||
| from odoo import fields, models | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class EstatePropertyTag(models.Model): | ||||||||||
| _name = 'estate.property.tag' | ||||||||||
| _description = 'Estate Property Tag' | ||||||||||
| _order = "name" | ||||||||||
|
||||||||||
| _description = 'Estate Property Tag' | |
| _order = "name" | |
| _description = "Estate Property Tag" | |
| _order = 'name' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
|
||
| from odoo import fields, models, api | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = 'Estate Property Type' | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char('Property Type', required=True) | ||
| property_ids = fields.One2many('estate.property', 'property_type_id', 'Properties') | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id', 'Offers') | ||
| offer_count = fields.Integer(compute='_compute_offer_count') | ||
| sequence = fields.Integer() | ||
|
|
||
| _type_name_uniq = models.Constraint( | ||
| 'unique(name)', | ||
| "The property type name must be unique", | ||
| ) | ||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class Users(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many('estate.property', 'salesperson_id', string='Estate Property', | ||
| domain=[('date_availability', '<=', fields.Date.today())]) |
| 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,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem | ||
| id="estate_menu_root" | ||
| name="Real Estate"/> | ||
| <menuitem | ||
| id="properties_menu" | ||
| name="Properties" | ||
| parent="estate_menu_root" | ||
| action="estate_property_action" | ||
| sequence="1"/> | ||
| <menuitem | ||
| id="settings_menu" | ||
| name="Settings" | ||
| parent="estate_menu_root" | ||
| sequence="2"/> | ||
| <menuitem | ||
| id="properties_type_menu" | ||
| name="Property Types" | ||
| parent="settings_menu" | ||
| action="estate_property_type_action" | ||
| sequence="1"/> | ||
| <menuitem | ||
| id="properties_tag_menu" | ||
| name="Property Tags" | ||
| parent="settings_menu" | ||
| action="estate_property_tag_action" | ||
| sequence="2"/> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| <?xml version="1.0"?> | ||||||
| <odoo> | ||||||
| <record id="estate_property_offer_view_form" model="ir.ui.view"> | ||||||
| <field name="name">estate.property.offer.view.form</field> | ||||||
| <field name="model">estate.property.offer</field> | ||||||
| <field name="arch" type="xml"> | ||||||
| <form string="Estate Property Offer"> | ||||||
| <sheet> | ||||||
| <group> | ||||||
| <group> | ||||||
| <field name="price"/> | ||||||
| <field name="partner_id"/> | ||||||
| </group> | ||||||
| <group> | ||||||
| <field name="validity"/> | ||||||
| <field name="date_deadline"/> | ||||||
| <field name="status"/> | ||||||
| </group> | ||||||
| </group> | ||||||
| </sheet> | ||||||
| </form> | ||||||
| </field> | ||||||
| </record> | ||||||
|
|
||||||
| <record id="estate_property_offer_view_list" model="ir.ui.view"> | ||||||
| <field name="name">estate.property.offer.view.list</field> | ||||||
| <field name="model">estate.property.offer</field> | ||||||
| <field name="arch" type="xml"> | ||||||
| <list string="Estate Property Offer" editable="bottom" | ||||||
| decoration-success="status == 'accepted'" | ||||||
| decoration-danger="status == 'refused'"> | ||||||
| <field name="price"/> | ||||||
| <field name="partner_id"/> | ||||||
| <field name="validity"/> | ||||||
| <field name="date_deadline"/> | ||||||
| <button name="action_accept" title="Accept" type="object" icon="fa-check" invisible="status"/> | ||||||
| <button name="action_refuse" title="Refuse" type="object" icon="fa-close" invisible="status"/> | ||||||
|
Comment on lines
+36
to
+37
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. these invisibles don't seem correct. I think it should be
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. Let me explain why I've done like this. |
||||||
| </list> | ||||||
| </field> | ||||||
| </record> | ||||||
|
|
||||||
| <record id="estate_property_offer_action" model="ir.actions.act_window"> | ||||||
| <field name="name">Offers</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> | ||||||
|
||||||
| <field name="domain">[('property_type_id','=',active_id)]</field> | |
| <field name="domain">[('property_type_id', '=', active_id)]</field> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="estate_property_tag_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.view.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Estate Property Tag"> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| <field name="color" widget="color_picker"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.view.list</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Estate Property Tag" editable="bottom"> | ||
| <field name="name"/> | ||
| <field name="color" widget="color_picker"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Estate Property Tag</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,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.
The odoo license in every file is not needed anymore. You can remove it!