-
Notifications
You must be signed in to change notification settings - Fork 2.7k
ngtpn - Technical Training #1024
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
nguyenntph
wants to merge
19
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-training-ngtpn
base: 19.0
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 all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
51a3f88
[ADD] estate: Add module
nguyenntph a184c4a
[IMP] estate: Add name / expected price to property model
nguyenntph 6500c2a
[IMP] estate: Add access right
nguyenntph 812c7c1
[IMP] estate: Add UIs / Update fields
nguyenntph 99bba1f
[IMP] estate: Fix xml indentation
nguyenntph f5deed0
[IMP] estate: Use date helper / Rename model
nguyenntph 2ca4042
[IMP] estate: Add list / form / search UI
nguyenntph 719f23a
[IMP] estate: Add perperty type / tag / offer
nguyenntph 5051e18
[IMP] estate: Compute / Inverse field value
nguyenntph 9deb164
[IMP] estate: Add actions
nguyenntph e23811d
[IMP] estate: Add validation conditions
nguyenntph 829d49e
[IMP] estate: Sprinkes
nguyenntph 979ac8f
[REF] estate: Update view files
nguyenntph dae9bd4
[IMP] estate: Sprinkles (cont)
nguyenntph 5feba0e
[IMP] estate: Inheritance
nguyenntph 6ffae9b
[ADD] estate_account: Init
nguyenntph 30a5051
[IMP] estate_account: Create account move on sold properties
nguyenntph 2e499ad
[IMP] estate: Kanban view
nguyenntph 02624c7
[REF] estate: Refactor based on guidelines and feedbacks
nguyenntph 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
Some comments aren't visible on the classic Files Changed page.
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': 'Real Estate', | ||
| 'license': 'LGPL-3', | ||
| 'version': '1.0', | ||
| 'depends': ['base'], | ||
| 'author': 'Odoo S.A.', | ||
| 'category': 'Category', | ||
| 'description': """ | ||
| Real Estate Advertisement module | ||
| """, | ||
| 'application': True, | ||
| '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_user_views.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| } | ||
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 estate_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,120 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_is_zero, float_compare | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'Estate Properties' | ||
| _order = 'id desc' | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| copy=False, | ||
| default=fields.Date.add(fields.Date.today(), months=3), | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| best_price = fields.Float(compute='_compute_best_price') | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer() | ||
| garden_area = fields.Integer() | ||
| total_area = fields.Integer(compute='_compute_total_area') | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_orientation = fields.Selection( | ||
| string='Garden orientation', | ||
| selection=[ | ||
| ('north', 'North'), | ||
| ('south', 'South'), | ||
| ('east', 'East'), | ||
| ('west', 'West'), | ||
| ], | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| string='State', | ||
| required=True, | ||
| default='new', | ||
| selection=[ | ||
| ('new', 'New'), | ||
| ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer Accepted'), | ||
| ('sold', 'Sold'), | ||
| ('cancelled', 'Cancelled'), | ||
| ], | ||
| ) | ||
| property_type_id = fields.Many2one( | ||
| 'estate.property.type', string='Property Type', | ||
| ) | ||
| buyer_id = fields.Many2one( | ||
| 'res.partner', string='Buyer', copy=False, | ||
| ) | ||
| salesperson_id = fields.Many2one( | ||
| 'res.users', string='Salesperson', | ||
| default=lambda self: self.env.user, | ||
| ) | ||
| tag_ids = fields.Many2many('estate.property.tag', string='Tags') | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers') | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'The expected price of a property should be strictly positive.', | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', | ||
| 'The selling price of a property should be positive.', | ||
| ) | ||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| record.best_price = max(record.offer_ids.mapped('price'), default=0.0) | ||
|
|
||
| @api.depends('living_area', 'garden_area') | ||
| def _compute_total_area(self): | ||
| for record in self: | ||
| living_area = record.living_area or 0 | ||
| garden_area = record.garden_area or 0 | ||
| record.total_area = living_area + garden_area | ||
|
|
||
| @api.constrains('selling_price', 'expected_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if ( | ||
| not float_is_zero(record.selling_price, 2) | ||
| and float_compare(record.selling_price, record.expected_price * 0.90, 2) < 0 | ||
| ): | ||
| raise ValidationError("Selling price cannot be lower than 90% of expected price") | ||
|
|
||
| @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 = None | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled(self): | ||
| for record in self: | ||
| if record.state not in ['new', 'cancelled']: | ||
| raise UserError(f"Can't delete property in {record.state} state") | ||
|
|
||
| def action_mark_as_sold(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| raise UserError('Cannot sell cancelled properties') | ||
|
|
||
| record.state = 'sold' | ||
|
|
||
| def action_mark_as_cancelled(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError('Cannot cancel sold properties') | ||
|
|
||
| record.state = 'cancelled' |
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,70 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = 'Estate Offers' | ||
| _order = 'price desc' | ||
|
|
||
| price = fields.Float(required=True) | ||
| status = fields.Selection( | ||
| string='Status', | ||
| selection=[ | ||
| ('accepted', 'Accepted'), | ||
| ('refused', 'Refused'), | ||
| ], | ||
| ) | ||
| partner_id = fields.Many2one('res.partner', string='Partner') | ||
| property_id = fields.Many2one('estate.property', string='Property') | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date(compute='_compute_date_deadline', inverse="_inverse_date_deadline") | ||
| property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) | ||
|
|
||
| _check_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The price of an offer should be strictly positive.', | ||
| ) | ||
|
|
||
| @api.depends('create_date', 'validity') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| created_date = record.create_date or fields.Date.today() | ||
| record.date_deadline = fields.Date.add( | ||
| created_date, days=record.validity, | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| created_date = record.create_date.date() or fields.Date.today() | ||
| record.validity = (record.date_deadline - created_date).days | ||
|
|
||
| @api.model | ||
| def create(self, val_lists): | ||
| for vals in val_lists: | ||
| linked_property = self.env['estate.property'].browse(vals['property_id']) | ||
| if vals['price'] < linked_property.best_price: | ||
| raise UserError('Offer price cannot be lower than existing offers') | ||
|
|
||
| linked_property.state = 'offer_received' | ||
| return super().create(val_lists) | ||
nguyenntph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def action_mark_as_accepted(self): | ||
| for record in self: | ||
| if ( | ||
| record.property_id.state not in ('new', 'offer_received') | ||
| ): | ||
| raise UserError('Cannot accept offer in this state') | ||
|
|
||
| record.status = 'accepted' | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.state = 'offer_accepted' | ||
|
|
||
| def action_mark_as_refused(self): | ||
| for record in self: | ||
| if record.status == 'accepted': | ||
| record.property_id.state = 'offer_received' | ||
| record.property_id.selling_price = 0.0 | ||
| record.property_id.buyer_id = None | ||
| record.status = 'refused' | ||
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,15 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = 'Estate Property Tags' | ||
| _order = 'name asc' | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| 'unique (name)', | ||
| 'The name of a tag should be unique.', | ||
| ) |
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,22 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = 'Estate Property Types' | ||
| _order = 'name asc' | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many( | ||
| 'estate.property', 'property_type_id', string="Properties", | ||
| ) | ||
| sequence = fields.Integer('Sequence', default=1, help="Used to order property types.") | ||
| offer_ids = fields.One2many( | ||
| 'estate.property.offer', 'property_type_id', string="Offers", | ||
| ) | ||
| 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,9 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstateUser(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many( | ||
| 'estate.property', 'salesperson_id', string='Real Estate Properties', | ||
| ) |
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,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 |
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,11 @@ | ||
| <odoo> | ||
| <menuitem id="menu_root" name="Real Estate"> | ||
| <menuitem id="advertisement" name="Advertisement"> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="settings" 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> | ||
| </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,59 @@ | ||
| <odoo> | ||
| <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> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_view_tree" 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="Offers" | ||
| editable="bottom" | ||
| decoration-success="status == 'accepted'" | ||
| decoration-danger="status == 'refused'" | ||
| > | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity" string="Validity (days)"/> | ||
| <field name="date_deadline" string="Deadline"/> | ||
| <button | ||
| name="action_mark_as_accepted" | ||
| type="object" | ||
| icon="fa-check" | ||
| title="accept" | ||
| invisible="status" | ||
| /> | ||
| <button | ||
| name="action_mark_as_refused" | ||
| type="object" | ||
| icon="fa-times" | ||
| title="refuse" | ||
| invisible="status" | ||
| /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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="partner_id"/> | ||
| <field name="price"/> | ||
| <field name="status"/> | ||
| <field name="validity" string="Validity (days)"/> | ||
| <field name="date_deadline" string="Deadline"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </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,33 @@ | ||
| <odoo> | ||
| <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> | ||
|
|
||
| <record id="estate_property_tag_view_tree" 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 Types" editable="bottom"> | ||
| <field name="name"/> | ||
| <field name="color" widget="color_picker"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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"/> | ||
| <field name="color" widget="color_picker"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </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.