From b5d21c8e0c3d877dccc72c9747c133c1155251cf Mon Sep 17 00:00:00 2001 From: ppch-odoo Date: Tue, 4 Feb 2025 18:58:21 +0530 Subject: [PATCH 01/10] [IMP] Estate - estate module improved by adding below features - configuration added in estate module - auto install of invoice on check invoice from settings of estate - demo data added for property types and tags - improve code formatting by reading code guidelines - property image added to property model - kanban view added with property image - graph view and pivot view added for property page - access rights and record rules are added for agent and manager - chatter added - logs in chatter when state of property changed - reports added for property and salesperson - controller added - web page added with pagination and filter - wizard added to make offer for multiple properties - test cases added for real estate module --- estate/__init__.py | 3 + estate/__manifest__.py | 35 +++ estate/controllers/__init__.py | 1 + estate/controllers/main.py | 47 ++++ estate/data/estate_property_tag_demo.xml | 20 ++ estate/data/estate_property_type_demo.xml | 20 ++ estate/data/website_estate_menu.xml | 9 + estate/demo/demo_data.xml | 89 ++++++ estate/models/__init__.py | 6 + estate/models/property.py | 148 ++++++++++ estate/models/property_offer.py | 94 +++++++ estate/models/property_tag.py | 17 ++ estate/models/property_type.py | 29 ++ estate/models/res_config_settings.py | 7 + estate/models/res_users.py | 7 + estate/report/estate_property_reports.xml | 26 ++ estate/report/estate_property_templates.xml | 162 +++++++++++ estate/security/estate_rules.xml | 24 ++ estate/security/estate_security.xml | 19 ++ estate/security/ir.model.access.csv | 12 + estate/tests/__init__.py | 1 + estate/tests/test_estate.py | 75 +++++ estate/views/estate_menu.xml | 51 ++++ estate/views/estate_property_offer_views.xml | 49 ++++ estate/views/estate_property_tag_views.xml | 46 ++++ estate/views/estate_property_type_views.xml | 78 ++++++ estate/views/estate_property_views.xml | 258 ++++++++++++++++++ estate/views/property_templates.xml | 141 ++++++++++ estate/views/res_config_settings_views.xml | 29 ++ estate/views/res_users_views.xml | 16 ++ estate/wizard/__init__.py | 1 + estate/wizard/estate_property_offer_wizard.py | 20 ++ .../estate_property_offer_wizard_views.xml | 29 ++ estate_account/__init__.py | 1 + estate_account/__manifest__.py | 15 + estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 30 ++ ...tate_account_estate_property_templates.xml | 10 + 38 files changed, 1626 insertions(+) create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py create mode 100644 estate/controllers/__init__.py create mode 100644 estate/controllers/main.py create mode 100644 estate/data/estate_property_tag_demo.xml create mode 100644 estate/data/estate_property_type_demo.xml create mode 100644 estate/data/website_estate_menu.xml create mode 100644 estate/demo/demo_data.xml create mode 100644 estate/models/__init__.py create mode 100644 estate/models/property.py create mode 100644 estate/models/property_offer.py create mode 100644 estate/models/property_tag.py create mode 100644 estate/models/property_type.py create mode 100644 estate/models/res_config_settings.py create mode 100644 estate/models/res_users.py create mode 100644 estate/report/estate_property_reports.xml create mode 100644 estate/report/estate_property_templates.xml create mode 100644 estate/security/estate_rules.xml create mode 100644 estate/security/estate_security.xml create mode 100644 estate/security/ir.model.access.csv create mode 100644 estate/tests/__init__.py create mode 100644 estate/tests/test_estate.py create mode 100644 estate/views/estate_menu.xml create mode 100644 estate/views/estate_property_offer_views.xml create mode 100644 estate/views/estate_property_tag_views.xml create mode 100644 estate/views/estate_property_type_views.xml create mode 100644 estate/views/estate_property_views.xml create mode 100644 estate/views/property_templates.xml create mode 100644 estate/views/res_config_settings_views.xml create mode 100644 estate/views/res_users_views.xml create mode 100644 estate/wizard/__init__.py create mode 100644 estate/wizard/estate_property_offer_wizard.py create mode 100644 estate/wizard/estate_property_offer_wizard_views.xml create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py create mode 100644 estate_account/models/__init__.py create mode 100644 estate_account/models/estate_property.py create mode 100644 estate_account/report/estate_account_estate_property_templates.xml diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..e4f4917aea4 --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1,3 @@ +from . import controllers +from . import models +from . import wizard diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..6be0f405635 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,35 @@ +{ + 'name': "Estate", + 'version': '1.0', + 'depends': ['base', 'mail', 'website'], + 'author': "ppch", + 'category': 'Real Estate/Brokerage', + 'description': """ + Estate Module + """, + 'license': "LGPL-3", + 'data': [ + 'security/estate_security.xml', + 'security/estate_rules.xml', + 'security/ir.model.access.csv', + 'views/res_config_settings_views.xml', + 'views/res_users_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_offer_views.xml', + 'wizard/estate_property_offer_wizard_views.xml', + 'views/estate_property_views.xml', + 'views/estate_menu.xml', + 'report/estate_property_templates.xml', + 'report/estate_property_reports.xml', + 'views/property_templates.xml', + 'data/website_estate_menu.xml', + ], + 'demo': [ + 'data/estate_property_tag_demo.xml', + 'data/estate_property_type_demo.xml', + 'demo/demo_data.xml', + ], + 'installable': True, + 'application': True, +} diff --git a/estate/controllers/__init__.py b/estate/controllers/__init__.py new file mode 100644 index 00000000000..12a7e529b67 --- /dev/null +++ b/estate/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/estate/controllers/main.py b/estate/controllers/main.py new file mode 100644 index 00000000000..1ee0fc92dba --- /dev/null +++ b/estate/controllers/main.py @@ -0,0 +1,47 @@ +from odoo.http import Controller, request, route + + +class EstatePropertyController(Controller): + _references_per_page = 3 + # Route For all properties + @route(['/properties', '/properties/page/'], type='http', auth="public", website=True) + def list_properties(self, page=1, **kwargs): + Property = request.env['estate.property'] + PropertyType = request.env['estate.property.type'] + + property_types = PropertyType.sudo().search([]) + selected_type = kwargs.get('property_type') + + domain = [('state', 'in', ['new', 'offer_received'])] + if selected_type: + domain.append(('property_type_id', '=', int(selected_type))) + + property_count = Property.sudo().search_count(domain) + + pager = request.website.pager( + url='/properties', + total=property_count, + page=page, + step=self._references_per_page, + ) + + properties = Property.search( + domain, + offset=pager['offset'], + limit=self._references_per_page + ) + + return request.render('estate.property_list_template', { + 'properties': properties, + 'pager': pager, + 'property_types': property_types, + 'selected_type': int(selected_type) if selected_type else None + }) + + # Route For Particular Property + @route(['/properties//'], type='http', auth="public", website=True) + def list_property_details(self, property_id, **kwargs): + property_details = request.env['estate.property'].sudo().browse(property_id) + return request.render('estate.property_detail_template', { + 'property_details': property_details + }) diff --git a/estate/data/estate_property_tag_demo.xml b/estate/data/estate_property_tag_demo.xml new file mode 100644 index 00000000000..2c02c3df7e8 --- /dev/null +++ b/estate/data/estate_property_tag_demo.xml @@ -0,0 +1,20 @@ + + + + + Rich + + + Cozy + + + Renovated + + + Seaside + + + Lifestyle + + + diff --git a/estate/data/estate_property_type_demo.xml b/estate/data/estate_property_type_demo.xml new file mode 100644 index 00000000000..e603e1d0acb --- /dev/null +++ b/estate/data/estate_property_type_demo.xml @@ -0,0 +1,20 @@ + + + + + House + + + Villa + + + Farm + + + Office + + + Industry + + + diff --git a/estate/data/website_estate_menu.xml b/estate/data/website_estate_menu.xml new file mode 100644 index 00000000000..1cd2fd1f524 --- /dev/null +++ b/estate/data/website_estate_menu.xml @@ -0,0 +1,9 @@ + + + + + Properties + /properties + + + diff --git a/estate/demo/demo_data.xml b/estate/demo/demo_data.xml new file mode 100644 index 00000000000..d66758f5428 --- /dev/null +++ b/estate/demo/demo_data.xml @@ -0,0 +1,89 @@ + + + + + Residential + + + + + Big Villa + + new + A nice and big villa + 12345 + 2020-02-02 + 1600000 + 6 + 100 + 4 + True + True + 100000 + south + + + Trailer home + + cancelled + Home in a trailer park + 54321 + 1970-01-01 + 100000 + 120000 + 1 + 10 + 4 + False + + + + + Azure Interior + + + Deco Addict + + + + + Modern Apartment + new + A stylish and modern apartment + 800000 + 85 + 3 + + + + + + + + 10000 + 14 + + + + + 1500000 + 14 + + + + + 1500001 + 14 + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..a5ee6f30efb --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,6 @@ +from . import property +from . import property_offer +from . import property_tag +from . import property_type +from . import res_config_settings +from . import res_users diff --git a/estate/models/property.py b/estate/models/property.py new file mode 100644 index 00000000000..d63334c6de5 --- /dev/null +++ b/estate/models/property.py @@ -0,0 +1,148 @@ +from odoo import _, api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class Property(models.Model): + # Model Attributes + _name = 'estate.property' + _inherit = ['mail.thread', 'mail.activity.mixin'] + _description = 'Estate Model' + _order = 'id desc' + + # SQL Constraints + _sql_constraints = [ + ('check_expected_price', 'CHECK(expected_price > 0.00)', "The expected price must be strictly positive"), + ('check_selling_price', 'CHECK(selling_price > 0.00)', "The selling price must be strictly positive") + ] + + # Basic Fields + name = fields.Char(string="Property Name", required=True, tracking=True) + description = fields.Text(string="Description") + image_1920 = fields.Image(string="Property Image") + company_id = fields.Many2one( + 'res.company', + string="Company", + default=lambda self: self.env.user.company_id, + required=True + ) + + # Relational Fields + property_type_id = fields.Many2one( + 'estate.property.type', + default=lambda self: self.env.ref('estate.property_type_1'), + string="Property Type" + ) + tag_ids = fields.Many2many('estate.property.tag', string="Tags") + salesperson_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user, tracking=True) + buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False, tracking=True) + offer_ids = fields.One2many('estate.property.offer', 'property_id') + + # Basic Fields + postcode = fields.Char(string="Postcode") + date_availability = fields.Date( + string="Availability", + copy=False, + default=fields.Date.add(fields.Date.today(), months=3) + ) + expected_price = fields.Float(string="Expected Price", required=True) + selling_price = fields.Float(string="Selling Price", readonly=True, copy=False, tracking=True) + bedrooms = fields.Integer(string="No of Bedrooms", default=2) + living_area = fields.Integer(string="Living Area") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area") + garden_orientation = fields.Selection( + string = "Garden Orientation", + selection = [ + ('north', "North"), + ('south', "South"), + ('east', "East"), + ('west', "West") + ] + ) + active = fields.Boolean(string="Active", default=True) + state = fields.Selection( + readonly=True, + string="Status", + selection = [ + ('new', "New"), + ('offer_received', "Offer Received"), + ('offer_accepted', "Offer Accepted"), + ('sold', "Sold"), + ('cancelled', "Cancelled") + ], + default='new', + tracking=True + ) + + # Computed Fields + total_area = fields.Integer(compute='_compute_total', string="Total Area") + best_price = fields.Float(compute='_compute_best_price', string="Best Price") + + # Computed Methods + @api.depends('living_area', 'garden_area') + def _compute_total(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 record in self: + record.best_price = max(record.offer_ids.mapped('price'), default=0) + + # Python Constraints + @api.constrains('selling_price') + def _check_selling_price_constrains(self): + for record in self: + if record.selling_price and record.selling_price < (record.expected_price * 0.9): + raise ValidationError(_(f"Selling price cannot be lower than {record.expected_price * 0.9} (90% of the expected price).")) + + # Onchange Methods + @api.onchange('garden') + def _onchange_garden(self): + self.write({ + 'garden_area' : 10 if self.garden else 0, + 'garden_orientation' : 'north' if self.garden else False + }) + + # Actions + def action_sold(self): + self.ensure_one() + for property in self: + if property.state == 'cancelled': + raise UserError(_("Cancelled property can not be sold.")) + elif property.state == 'sold': + raise UserError(_("Property already sold.")) + accepted_offer = self.env['estate.property.offer'].search([ + ('property_id', '=', self.id), + ('status', '=', 'accepted') + ], limit=1) + if not accepted_offer: + raise UserError(_("You cannot sell a property without an accepted offer.")) + property.state = 'sold' + + def action_cancel(self): + self.ensure_one() + for property in self: + if property.state == 'sold': + raise UserError(_("Sold property can not be cancelled.")) + elif property.state == 'cancelled': + raise UserError(_("Property already Cancelled.")) + property.state = 'cancelled' + + @api.ondelete(at_uninstall=False) + def _unlink_prevent_if_state_new_or_cancelled(self): + if any(record.state not in ['new', 'cancelled'] for record in self): + raise UserError(_("You cannot delete a property whose state is not 'new' or 'cancelled'")) + + def _track_subtype(self, init_values): + self.ensure_one() + if 'state' in init_values and self.state == 'sold': + message = ( + f"Property sold by {self.salesperson_id.name} to {self.buyer_id.name} " + f"for a price of {self.selling_price}." + ) + self.message_post(body=message) + return self.env.ref('estate.estate_property_mt_state_change') + return super(Property, self)._track_subtype(init_values) diff --git a/estate/models/property_offer.py b/estate/models/property_offer.py new file mode 100644 index 00000000000..54a0b0e1887 --- /dev/null +++ b/estate/models/property_offer.py @@ -0,0 +1,94 @@ +from datetime import timedelta + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class PropertyOffer(models.Model): + # Model Attributes + _name = 'estate.property.offer' + _description = 'Property Offer Model' + _order = 'price desc' + + # SQL Constraints + _sql_constraints = [ + ('check_offer_price', 'CHECK(price > 0.00)', "The offer price must be strictly positive") + ] + + # Basic Fields + price = fields.Float(string="Price", required=True) + status = fields.Selection( + string="Status", + copy=False, + selection = [ + ('accepted', "Accepted"), + ('refused', "Refused"), + ] + ) + validity = fields.Integer(string="Validity", default=7) + + # Relational Fields + 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) + + # Computed Fields + date_deadline = fields.Date(string="Date Deadline", compute='_compute_validity', inverse='_inverse_validity') + + # Computed Methods + @api.depends('create_date', 'validity') + def _compute_validity(self): + for record in self: + create_date = record.create_date.date() if record.create_date else fields.Date.today() + record.date_deadline = create_date + timedelta(days=record.validity) + + def _inverse_validity(self): + for record in self: + if record.date_deadline: + create_date = record.create_date.date() if record.create_date else fields.Date.today() + record.validity = (record.date_deadline - create_date).days + + # CRUD + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property_id = vals.get('property_id') + property = self.env['estate.property'].browse(property_id) + if property.state == 'offer_accepted': + raise UserError(_("You cannot place an offer on a offer accepted property.")) + elif property.state == 'sold': + raise UserError(_("You cannot place an offer on a sold property.")) + elif property.best_price >= vals.get('price'): + raise UserError(_(f"A higher or equal offer already exists, increase your offer price.\n(It should be more than {property.best_price})")) + property.state = 'offer_received' + return super(PropertyOffer, self).create(vals_list) + + # Actions + def action_accepted(self): + self.ensure_one() + if self.property_id.state == 'sold': + raise UserError(_("Property already sold")) + elif self.property_id.state == 'cancelled': + raise UserError(_("Cancelled property's offer can not be accepted")) + elif self.status == 'accepted': + raise UserError(_("Buyer of property is already accepted")) + for offer in self.property_id.offer_ids: + if offer.id != self.id: + offer.status = 'refused' + else: + self.write({'status': 'accepted'}) + self.property_id.write({ + 'state': 'offer_accepted', + 'selling_price': self.price, + 'buyer_id': self.partner_id + }) + + def action_refused(self): + self.ensure_one() + if self.property_id.state == 'sold': + raise UserError(_("Property already sold")) + elif self.property_id.state == 'cancelled': + raise UserError(_("Cancelled property's offer can not be accepted")) + elif self.status == 'refused': + raise UserError(_("Buyer of property is already refused")) + self.status = 'refused' diff --git a/estate/models/property_tag.py b/estate/models/property_tag.py new file mode 100644 index 00000000000..1c6a10fd049 --- /dev/null +++ b/estate/models/property_tag.py @@ -0,0 +1,17 @@ +from odoo import fields, models + + +class PropertyTag(models.Model): + # Model Attributes + _name = 'estate.property.tag' + _description = 'Property Tag Model' + _order = 'name asc' + + # SQL Constraints + _sql_constraints = [ + ('check_unique_tag', 'UNIQUE(name)', "Property tag name must be unique.") + ] + + # Basic Fields + name = fields.Char(string="Property Tag", required=True) + color = fields.Integer(string="Color") diff --git a/estate/models/property_type.py b/estate/models/property_type.py new file mode 100644 index 00000000000..401190de870 --- /dev/null +++ b/estate/models/property_type.py @@ -0,0 +1,29 @@ +from odoo import api, fields, models + + +class PropertyType(models.Model): + # Model Attributes + _name = 'estate.property.type' + _description = 'Property Type Model' + _order = 'sequence, name asc' + + # SQL Constraints + _sql_constraints = [ + ('check_unique_type', 'UNIQUE(name)', "Property type name must be unique.") + ] + + # Basic Fields + name = fields.Char(string="Property Type", required=True) + sequence = fields.Integer(string="Sequence", default=1, help="Used to order property types") + + # Relatinal Fields + property_ids = fields.One2many('estate.property', 'property_type_id') + + # Computed Fields + offer_count = fields.Integer(compute='_compute_offer_count') + + # Compute Methods + @api.depends('property_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.property_ids.offer_ids) diff --git a/estate/models/res_config_settings.py b/estate/models/res_config_settings.py new file mode 100644 index 00000000000..37500c33951 --- /dev/null +++ b/estate/models/res_config_settings.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + module_estate_account = fields.Boolean(string="Invoice") diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..e62e2688803 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many('estate.property', 'salesperson_id') diff --git a/estate/report/estate_property_reports.xml b/estate/report/estate_property_reports.xml new file mode 100644 index 00000000000..2dc92c04d77 --- /dev/null +++ b/estate/report/estate_property_reports.xml @@ -0,0 +1,26 @@ + + + + + Property Offers Report + estate.property + qweb-pdf + estate.estate_property_report_template + estate.estate_property_report_template + 'Estate Property - %s' % (object.name or 'Property').replace('/','') + + report + + + + + Salesperson Property Report + res.users + qweb-pdf + estate.estate_property_res_users_properties + estate.estate_property_res_users_properties + 'Estate Property - %s' % (object.name or 'Person').replace('/','') + + report + + diff --git a/estate/report/estate_property_templates.xml b/estate/report/estate_property_templates.xml new file mode 100644 index 00000000000..d348476cd1c --- /dev/null +++ b/estate/report/estate_property_templates.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + diff --git a/estate/security/estate_rules.xml b/estate/security/estate_rules.xml new file mode 100644 index 00000000000..c75f02ab125 --- /dev/null +++ b/estate/security/estate_rules.xml @@ -0,0 +1,24 @@ + + + + + Property Manager Restricted Access + + + [ + ('state', 'in', ['offer_received', 'offer_accepted', 'sold']), + '|', ('company_id', '=', False), ('company_id', 'in', company_ids) + ] + + + + + Property Agent Restricted Access + + + [ + '|', ('salesperson_id', '=', user.id), ('salesperson_id', '=', False), + '|', ('company_id', '=', False), ('company_id', 'in', company_ids) + ] + + diff --git a/estate/security/estate_security.xml b/estate/security/estate_security.xml new file mode 100644 index 00000000000..17095add0a4 --- /dev/null +++ b/estate/security/estate_security.xml @@ -0,0 +1,19 @@ + + + + + Real Estate Category. + + + + + Property Agent + + + + + + Property Manager + + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..2497628e2cc --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,12 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_estate_property_base","Base Access","model_estate_property","base.group_user","1","0","0","0" +"access_estate_property_agent","Agent Access","model_estate_property","estate_group_user","1","1","1","0" +"access_estate_property_manager","Manager Access","model_estate_property","estate_group_manager","1","1","1","1" +"access_estate_property_type_base","Base access Type","model_estate_property_type","base.group_user","1","0","0","0" +"access_estate_property_type_agent","Agent Access Type","model_estate_property_type","estate_group_user","1","0","0","0" +"access_estate_property_type_manager","Manager Access Type","model_estate_property_type","estate_group_manager","1","1","1","1" +"access_estate_property_tag_base","Base access Tag","model_estate_property_tag","base.group_user","1","0","0","0" +"access_estate_property_tag_agent","Agent Access Tag","model_estate_property_tag","estate_group_user","1","0","0","0" +"access_estate_property_tag_manager","Manager Access Tag","model_estate_property_tag","estate_group_manager","1","1","1","1" +"access_estate_property_offer_base","base access","model_estate_property_offer","base.group_user","1","1","1","1" +"access_estate_property_offer_wizard_base","base access for wizard","model_estate_property_offer_wizard","base.group_user","1","1","1","1" diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..dfd37f0be11 --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_estate diff --git a/estate/tests/test_estate.py b/estate/tests/test_estate.py new file mode 100644 index 00000000000..41c3b4cac64 --- /dev/null +++ b/estate/tests/test_estate.py @@ -0,0 +1,75 @@ +from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase +from odoo.tests import Form, tagged + + +@tagged('post_install', '-at_install') +class EstateTestCase(TransactionCase): + @classmethod + def setUpClass(cls): + super(EstateTestCase, cls).setUpClass() + + cls.test_property_type = cls.env['estate.property.type'].create({ + 'name': 'apartment' + }) + + cls.test_property_tag = cls.env['estate.property.tag'].create({ + 'name': 'MetroCity' + }) + + cls.test_property = cls.env['estate.property'].create({ + 'name': 'Karsandas Bungalow', + 'description': 'Huge Bungalow', + 'property_type_id': cls.test_property_type.id, + 'tag_ids': [(6,0,[cls.test_property_tag.id])], + 'expected_price': 500000, + 'garden': True, + 'garden_area': 100, + 'garden_orientation': 'north' + }) + + cls.test_property_offer = cls.env['estate.property.offer'].create({ + 'price': 40000, + 'partner_id': 2, + 'property_id': cls.test_property.id + }) + + def test_create_property(self): + """Test property creation""" + property = self.env['estate.property'].create({ + 'name': 'Another Test Property', + 'description': 'Another test property description', + 'expected_price': 1, + 'property_type_id': self.test_property_type.id + }) + self.assertEqual(property.name, 'Another Test Property') + self.assertEqual(property.property_type_id.name, 'apartment') + + def test_creation_area(self): + """Test that the total_area is computed like it should.""" + self.test_property.living_area = 20 + self.test_property.garden_area = 20 + self.assertRecordValues(self.test_property, [ + {'name': 'Karsandas Bungalow', 'total_area': 40}, + ]) + + def test_create_offer_on_sold(self): + """Test that offer is created after property sold raises error.""" + self.test_property.state = 'sold' + with self.assertRaises(UserError): + self.env['estate.property.offer'].create({ + 'property_id': self.test_property.id, + 'price': 105000, + }) + + def test_sell_property_with_no_accepted_offer(self): + """Test that property is not being sold without accepting offer.""" + with self.assertRaises(UserError): + self.test_property.action_sold() + + def test_breaking_reset_garden(self): + """Test that onchange only apply to form views.""" + with Form(self.test_property) as f: + f.garden = False + self.assertEqual(self.test_property.garden_area, 0) + self.assertEqual(self.test_property.garden_orientation, False) diff --git a/estate/views/estate_menu.xml b/estate/views/estate_menu.xml new file mode 100644 index 00000000000..80a39b7bc0a --- /dev/null +++ b/estate/views/estate_menu.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..c6ecf4edf08 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,49 @@ + + + + + Property Offers + estate.property.offer + list,form + + + + + estate.property.offer.list + estate.property.offer + + + + + + + + + + + + + + + + + + + + + + + + + + + estate.property.type.search + estate.property.type + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..17d3358f8f8 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,258 @@ + + + + + Properties + estate.property + list,form,kanban,graph,pivot + {'search_default_availability': True} + + + + + estate.property.list + estate.property + + +
+
+ + + + + + + +
+
+
+ + + + estate.property.form + estate.property + +
+
+
+ + + +

+ +

+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + +
+ + + +
+ +
+
+ Expected Price: + +
+ +
+ Best Price: + +
+
+ +
+ Selling Price: + +
+
+
+ +
+
+
+
+
+
+
+ + + + estate.property.pivot + estate.property + + + + + + + + + + + + + estate.property.graph + estate.property + + + + + + + + + + Property State Changed + State Change + estate.property + True + +
diff --git a/estate/views/property_templates.xml b/estate/views/property_templates.xml new file mode 100644 index 00000000000..355d8ecc533 --- /dev/null +++ b/estate/views/property_templates.xml @@ -0,0 +1,141 @@ + + + + + diff --git a/estate/views/res_config_settings_views.xml b/estate/views/res_config_settings_views.xml new file mode 100644 index 00000000000..064a3ed8ff1 --- /dev/null +++ b/estate/views/res_config_settings_views.xml @@ -0,0 +1,29 @@ + + + + + Settings + res.config.settings + form + inline + {'module' : 'estate', 'bin_size': False} + + + + + res.config.settings.view.form.inherit.estate + res.config.settings + + + + + + + + + + + + + + diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..f3f96278a8a --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,16 @@ + + + + + res.users.form.inherit.property + res.users + + + + + + + + + + diff --git a/estate/wizard/__init__.py b/estate/wizard/__init__.py new file mode 100644 index 00000000000..e9926bcd3ec --- /dev/null +++ b/estate/wizard/__init__.py @@ -0,0 +1 @@ +from . import estate_property_offer_wizard diff --git a/estate/wizard/estate_property_offer_wizard.py b/estate/wizard/estate_property_offer_wizard.py new file mode 100644 index 00000000000..83fdc043ea7 --- /dev/null +++ b/estate/wizard/estate_property_offer_wizard.py @@ -0,0 +1,20 @@ +from odoo import api, fields, models + + +class PropertyOfferWizard(models.TransientModel): + _name = 'estate.property.offer.wizard' + _description = 'To create offer for multiple properties' + + price = fields.Float(string="Price", required=True) + validity = fields.Integer(string="Validity", default=7) + buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False) + + def action_add_offer(self): + active_ids = self._context.get('active_ids') + property_offer_vals = [{ + 'price': self.price, + 'partner_id': self.buyer_id.id, + 'validity': self.validity, + 'property_id': property_id + } for property_id in active_ids] + self.env['estate.property.offer'].create(property_offer_vals) diff --git a/estate/wizard/estate_property_offer_wizard_views.xml b/estate/wizard/estate_property_offer_wizard_views.xml new file mode 100644 index 00000000000..73d8a1ced86 --- /dev/null +++ b/estate/wizard/estate_property_offer_wizard_views.xml @@ -0,0 +1,29 @@ + + + + + estate.property.offer.wizard.form + estate.property.offer.wizard + +
+ + + + + +
+
+
+
+
+ + + + Create Offer + estate.property.offer.wizard + form + new + +
diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..9cedc0e7a9a --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': "Estate Account", + 'version': '1.0', + 'depends': ['estate', 'account'], + 'author': "ppch", + 'category': 'Real Estate/Account', + 'description': """ + Estate Account Module + """, + 'license': "LGPL-3", + 'data': [ + 'report/estate_account_estate_property_templates.xml', + ], + 'installable': True, +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..5e1963c9d2f --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..d0219d8d3d3 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,30 @@ +from odoo import _, Command, fields, models +from odoo.exceptions import UserError + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_sold(self): + self.check_access('write') + for record in self: + if not record.buyer_id: + raise UserError(_("Buyer is not set for this property")) + invoice_vals = { + 'partner_id': record.buyer_id.id, + 'move_type': 'out_invoice', + 'invoice_line_ids': [ + Command.create({ + 'name': "Service Fee(6%)", + 'quantity': 1, + 'price_unit': record.selling_price * 0.06, + }), + Command.create({ + 'name': "Administrative Fee", + 'quantity': 1, + 'price_unit': 100.00, + }), + ] + } + invoice = self.env['account.move'].sudo().create(invoice_vals) + return super().action_sold() diff --git a/estate_account/report/estate_account_estate_property_templates.xml b/estate_account/report/estate_account_estate_property_templates.xml new file mode 100644 index 00000000000..84a4c738c08 --- /dev/null +++ b/estate_account/report/estate_account_estate_property_templates.xml @@ -0,0 +1,10 @@ + + + + From 37b923edddab3b66254601dc74a2151457b62168 Mon Sep 17 00:00:00 2001 From: ppch-odoo Date: Mon, 24 Feb 2025 19:07:11 +0530 Subject: [PATCH 02/10] [ADD] Awesome owl - all task done of awesome owl --- .../static/src/dasboard_action.js | 12 +++++ awesome_dashboard/static/src/dashboard.js | 10 ---- awesome_dashboard/static/src/dashboard.xml | 8 --- .../static/src/dashboard/dashboard.js | 34 +++++++++++++ .../static/src/dashboard/dashboard.scss | 4 ++ .../static/src/dashboard/dashboard.xml | 36 +++++++++++++ .../static/src/dashboard/statisticsService.js | 26 ++++++++++ .../static/src/dashboardItem/dashboardItem.js | 13 +++++ .../src/dashboardItem/dashboardItem.xml | 11 ++++ .../static/src/pieChart/pieChart.js | 51 +++++++++++++++++++ .../static/src/pieChart/pieChart.xml | 8 +++ awesome_owl/static/src/card/card.js | 19 +++++++ awesome_owl/static/src/card/card.xml | 23 +++++++++ awesome_owl/static/src/counter/counter.js | 20 ++++++++ awesome_owl/static/src/counter/counter.xml | 11 ++++ awesome_owl/static/src/playground.js | 18 ++++++- awesome_owl/static/src/playground.xml | 23 ++++++++- awesome_owl/static/src/todo/todoitem.js | 21 ++++++++ awesome_owl/static/src/todo/todoitem.xml | 11 ++++ awesome_owl/static/src/todo/todolist.js | 36 +++++++++++++ awesome_owl/static/src/todo/todolist.xml | 15 ++++++ awesome_owl/static/src/util.js | 13 +++++ awesome_owl/views/templates.xml | 1 + 23 files changed, 403 insertions(+), 21 deletions(-) create mode 100644 awesome_dashboard/static/src/dasboard_action.js delete mode 100644 awesome_dashboard/static/src/dashboard.js delete mode 100644 awesome_dashboard/static/src/dashboard.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.js create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.scss create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.xml create mode 100644 awesome_dashboard/static/src/dashboard/statisticsService.js create mode 100644 awesome_dashboard/static/src/dashboardItem/dashboardItem.js create mode 100644 awesome_dashboard/static/src/dashboardItem/dashboardItem.xml create mode 100644 awesome_dashboard/static/src/pieChart/pieChart.js create mode 100644 awesome_dashboard/static/src/pieChart/pieChart.xml create mode 100644 awesome_owl/static/src/card/card.js create mode 100644 awesome_owl/static/src/card/card.xml create mode 100644 awesome_owl/static/src/counter/counter.js create mode 100644 awesome_owl/static/src/counter/counter.xml create mode 100644 awesome_owl/static/src/todo/todoitem.js create mode 100644 awesome_owl/static/src/todo/todoitem.xml create mode 100644 awesome_owl/static/src/todo/todolist.js create mode 100644 awesome_owl/static/src/todo/todolist.xml create mode 100644 awesome_owl/static/src/util.js diff --git a/awesome_dashboard/static/src/dasboard_action.js b/awesome_dashboard/static/src/dasboard_action.js new file mode 100644 index 00000000000..94665fecc7f --- /dev/null +++ b/awesome_dashboard/static/src/dasboard_action.js @@ -0,0 +1,12 @@ +import { Component, xml } from "@odoo/owl"; +import { LazyComponent } from "@web/core/assets"; +import { registry } from "@web/core/registry"; + +export class DashboardComponentLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; +} + +registry.category("actions").add("awesome_dashboard.dashboard_action", DashboardComponentLoader); diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index 637fa4bb972..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,10 +0,0 @@ -/** @odoo-module **/ - -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..466e9fcb608 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,34 @@ +/** @odoo-module **/ + +import { Component, useState, onWillStart } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { Layout } from "@web/search/layout"; +import { useService } from "@web/core/utils/hooks"; +import { DashboardItem } from "../dashboardItem/dashboardItem"; +import { PieChart } from "../pieChart/pieChart"; + +class AwesomeDashboard extends Component { + setup() { + this.action = useService("action"); + this.statistics = useState(useService("awesome_dashboard.statistics")) + } + + static template = "awesome_dashboard.AwesomeDashboard"; + + openCustomers() { + this.action.doAction("base.action_partner_form"); + } + + openLeads() { + this.action.doAction({ + type: 'ir.actions.act_window', + target: 'current', + res_model: 'crm.lead', + views: [[false, 'list'], [false, 'form']], + }); + } + + static components = { Layout, DashboardItem, PieChart } +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..a90acab3f9a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,4 @@ +.o_dashboard { + background-color: white; + min-height: 100vh; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..4b11b5115d7 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,36 @@ + + + + +
+ +
+ + +

Dashboard

+
+
+ +
+ + +
+ + +
+ + +
+ + +
+ + + + +
+
+
+
+ +
diff --git a/awesome_dashboard/static/src/dashboard/statisticsService.js b/awesome_dashboard/static/src/dashboard/statisticsService.js new file mode 100644 index 00000000000..7603502ce75 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statisticsService.js @@ -0,0 +1,26 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +const StatisticsService = { + start() { + const statistics = reactive({ data: {} }); + + async function fetchStatistics() { + try { + const result = await rpc("/awesome_dashboard/statistics", {}); + Object.assign(statistics.data, result); + } catch (error) { + console.error("Error fetching statistics:", error); + } + } + + fetchStatistics(); + + setInterval(fetchStatistics, 5000); + + return statistics; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", StatisticsService); diff --git a/awesome_dashboard/static/src/dashboardItem/dashboardItem.js b/awesome_dashboard/static/src/dashboardItem/dashboardItem.js new file mode 100644 index 00000000000..4ab92d97087 --- /dev/null +++ b/awesome_dashboard/static/src/dashboardItem/dashboardItem.js @@ -0,0 +1,13 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + static props = { + size: { type: Number, optional: true}, + title: { type: String, optional: true}, + slots: { type: Object, optional: true } + }; + static defaultProps = { + size: 1, + }; +} diff --git a/awesome_dashboard/static/src/dashboardItem/dashboardItem.xml b/awesome_dashboard/static/src/dashboardItem/dashboardItem.xml new file mode 100644 index 00000000000..2bf169310c2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboardItem/dashboardItem.xml @@ -0,0 +1,11 @@ + + + + +
+

+ +

+
+ +
\ No newline at end of file diff --git a/awesome_dashboard/static/src/pieChart/pieChart.js b/awesome_dashboard/static/src/pieChart/pieChart.js new file mode 100644 index 00000000000..83fa532e145 --- /dev/null +++ b/awesome_dashboard/static/src/pieChart/pieChart.js @@ -0,0 +1,51 @@ + +import { Component, onWillStart, useRef, useEffect, onWillUnmount, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; +import { loadJS } from "@web/core/assets"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChartTemplate"; + static props = { + label: { type: String } + } + setup(){ + this.chartRef = useRef("chartCanvas"); + this.chart = null; + this.statistics = useState(useService("awesome_dashboard.statistics")); + + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + }); + + useEffect(() => { + this.renderChart(); + }, () => [this.statistics.data.orders_by_size]); + + onWillUnmount(this.onWillUnmount); + } + + onWillUnmount() { + if (this.chart) { + this.chart.destroy(); + } + } + + renderChart() { + if (!this.statistics.data.orders_by_size || !this.chartRef.el) return; + + const ctx = this.chartRef.el.getContext("2d"); + if (this.chart) this.chart.destroy(); + + this.chart = new Chart(ctx, { + type: "pie", + data: { + labels: Object.keys(this.statistics.data.orders_by_size), + datasets: [{ + label: this.props.label, + data: Object.values(this.statistics.data.orders_by_size), + backgroundColor: ["#FF6384", "#36A2EB", "#FFCE56", "#4BC0C0", "#9966FF"], + }], + }, + }); + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/pieChart/pieChart.xml b/awesome_dashboard/static/src/pieChart/pieChart.xml new file mode 100644 index 00000000000..27476160d04 --- /dev/null +++ b/awesome_dashboard/static/src/pieChart/pieChart.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..b4783ba0427 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,19 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static props = { + title: {type: String}, + content: {type: String, optional: true}, + slots: { type: Object, optional: true } + } + + setup() { + this.state = useState({ isOpen: true }); + } + + toggleContent() { + this.state.isOpen = !this.state.isOpen; + } + + static template = "awesome_owl.card.card"; +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..e302c0d1115 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,23 @@ + + + + +
+
+
+
+ +
+ +

+ +

+ + +
+
+
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..37828eb9770 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,20 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static props = { + callback: {type: Function, optional: true} + } + + static template = "awesome_owl.counter.counter"; + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + if(this.props.callback){ + this.props.callback(1) + } + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..e6f8d102746 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,11 @@ + + + + +
+ Counter: + +
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..c56c95c7f6f 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,23 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./todo/todolist"; export class Playground extends Component { static template = "awesome_owl.playground"; + + setup() { + this.state = useState({ sum: 0 }); + } + + do_sum(value){ + this.state.sum += value; + } + + content1 = "
some content
"; + content2 = markup("
some content
"); + + static components = {Counter, Card, TodoList}; } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..e7894983aed 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,8 +2,27 @@ -
- hello world +
+
+ Hello World + + + The sum is : +
+
+
+
+ + + + + +
+
+
+
+ +
diff --git a/awesome_owl/static/src/todo/todoitem.js b/awesome_owl/static/src/todo/todoitem.js new file mode 100644 index 00000000000..ef9b386439c --- /dev/null +++ b/awesome_owl/static/src/todo/todoitem.js @@ -0,0 +1,21 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static props = { + todo: { + type: Object, + shape: { + id: {type: Number}, + description: {type: String}, + isCompleted: {type: Boolean} + } + }, + removeTodo: {type: Function} + } + + toggleState() { + this.props.todo.isCompleted = !this.props.todo.isCompleted; + } + + static template = "awesome_owl.todo.item"; +} diff --git a/awesome_owl/static/src/todo/todoitem.xml b/awesome_owl/static/src/todo/todoitem.xml new file mode 100644 index 00000000000..39b7abc093a --- /dev/null +++ b/awesome_owl/static/src/todo/todoitem.xml @@ -0,0 +1,11 @@ + + + + + + . + + + + + diff --git a/awesome_owl/static/src/todo/todolist.js b/awesome_owl/static/src/todo/todolist.js new file mode 100644 index 00000000000..904c551b336 --- /dev/null +++ b/awesome_owl/static/src/todo/todolist.js @@ -0,0 +1,36 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todoitem"; +import { useAutofocus } from "../util"; + +export class TodoList extends Component { + static template = "awesome_owl.todo.list"; + + setup(){ + this.state = useState({ + num: 0, + todos:[] + }); + this.todoInputRef = useAutofocus("todoInput"); + } + + addTodo(ev){ + if (ev.keyCode == 13){ + const newTodo = ev.target.value.trim(); + if(newTodo){ + this.state.num++; + this.state.todos.push({ + id: this.state.num, + description: newTodo, + isCompleted: false + }) + } + ev.target.value = ""; + } + } + + removeTodo(id) { + this.state.todos = this.state.todos.filter(todo => todo.id !== id); + } + + static components = {TodoItem}; +} diff --git a/awesome_owl/static/src/todo/todolist.xml b/awesome_owl/static/src/todo/todolist.xml new file mode 100644 index 00000000000..126a71953ea --- /dev/null +++ b/awesome_owl/static/src/todo/todolist.xml @@ -0,0 +1,15 @@ + + + + +
+ + +
+ +
+
+
+
+ +
diff --git a/awesome_owl/static/src/util.js b/awesome_owl/static/src/util.js new file mode 100644 index 00000000000..031b1093d33 --- /dev/null +++ b/awesome_owl/static/src/util.js @@ -0,0 +1,13 @@ +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutofocus(refName) { + const elementRef = useRef(refName); + + onMounted(() => { + if (elementRef.el) { + elementRef.el.focus(); + } + }); + + return elementRef; +} diff --git a/awesome_owl/views/templates.xml b/awesome_owl/views/templates.xml index aa54c1a7241..c94fd13d150 100644 --- a/awesome_owl/views/templates.xml +++ b/awesome_owl/views/templates.xml @@ -4,6 +4,7 @@ + From 0ad257832d07abc86da0e7d47ed2eebd37d09eaa Mon Sep 17 00:00:00 2001 From: ppch-odoo Date: Tue, 25 Feb 2025 10:03:39 +0530 Subject: [PATCH 03/10] [ADD] awesome_owl, awesome_dashboard: Implemented learning exercises awesome_owl: - Displayed a counter and extracted it into a sub-component - Implemented sum of two counters using state management - Created a simple Card component with slots and minimizable content - Used markup for dynamic HTML rendering and added props validation - Implemented core component concepts and a functional todo app - Developed a todo list with adding and deleting functionality awesome_dashboard: - Built an interactive dashboard with real data and services - Designed a new layout with quick navigation buttons - Added dashboard items and integrated statistics from the server - Cached network calls using a service for better performance - Displayed statistics using a pie chart and enabled real-time updates - Implemented lazy loading and made the dashboard generic and extensible - Allowed dynamic addition and removal of dashboard items --- awesome_dashboard/__manifest__.py | 3 + .../static/src/dashboard/dashboard.js | 68 +++++++++++++++++-- .../static/src/dashboard/dashboard.xml | 44 +++++++----- .../dashboardItem/dashboardItem.js | 5 +- .../dashboardItem/dashboardItem.xml | 5 +- .../static/src/dashboard/dashboard_items.js | 67 ++++++++++++++++++ .../src/dashboard/numberCard/number_card.js | 9 +++ .../src/dashboard/numberCard/number_card.xml | 9 +++ .../src/{ => dashboard}/pieChart/pieChart.js | 26 +++---- .../src/{ => dashboard}/pieChart/pieChart.xml | 2 - .../pie_chart_card/pie_chart_card.js | 11 +++ .../pie_chart_card/pie_chart_card.xml | 7 ++ .../static/src/dashboard/statisticsService.js | 6 +- ...dasboard_action.js => dashboard_action.js} | 8 ++- awesome_owl/static/src/card/card.xml | 2 +- awesome_owl/static/src/playground.js | 6 +- awesome_owl/static/src/playground.xml | 2 +- awesome_owl/static/src/todo/todolist.js | 2 +- 18 files changed, 219 insertions(+), 63 deletions(-) rename awesome_dashboard/static/src/{ => dashboard}/dashboardItem/dashboardItem.js (71%) rename awesome_dashboard/static/src/{ => dashboard}/dashboardItem/dashboardItem.xml (84%) create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_items.js create mode 100644 awesome_dashboard/static/src/dashboard/numberCard/number_card.js create mode 100644 awesome_dashboard/static/src/dashboard/numberCard/number_card.xml rename awesome_dashboard/static/src/{ => dashboard}/pieChart/pieChart.js (76%) rename awesome_dashboard/static/src/{ => dashboard}/pieChart/pieChart.xml (98%) create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml rename awesome_dashboard/static/src/{dasboard_action.js => dashboard_action.js} (62%) diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..7105d960c13 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -25,6 +25,9 @@ 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*' + ] }, 'license': 'AGPL-3' } diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js index 466e9fcb608..f700f9ce251 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -1,19 +1,42 @@ /** @odoo-module **/ -import { Component, useState, onWillStart } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; -import { DashboardItem } from "../dashboardItem/dashboardItem"; -import { PieChart } from "../pieChart/pieChart"; +import { DashboardItem } from "./dashboardItem/dashboardItem"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem } + setup() { + this.display = { + controlPanel: {}, + }; + this.items = registry.category("awesome_dashboard").getAll(); this.action = useService("action"); - this.statistics = useState(useService("awesome_dashboard.statistics")) + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dialog = useService("dialog"); + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] + }); } - static template = "awesome_dashboard.AwesomeDashboard"; + openConfiguration() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this), + }) + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } openCustomers() { this.action.doAction("base.action_partner_form"); @@ -27,8 +50,39 @@ class AwesomeDashboard extends Component { views: [[false, 'list'], [false, 'form']], }); } +} + +class ConfigurationDialog extends Component { + static template = "awesome_dashboard.ConfigurationDialog"; + static components = { Dialog, CheckBox }; + static props = ["close", "items", "disabledItems", "onUpdateConfiguration"]; + + setup() { + this.items = useState(this.props.items.map((item) => { + return { + ...item, + enabled: !this.props.disabledItems.includes(item.id), + } + })); + } + + done() { + this.props.close(); + } + + onChange(checked, changedItem) { + changedItem.enabled = checked; + const newDisabledItems = Object.values(this.items).filter( + (item) => !item.enabled + ).map((item) => item.id) - static components = { Layout, DashboardItem, PieChart } + browser.localStorage.setItem( + "disabledDashboardItems", + newDisabledItems, + ); + + this.props.onUpdateConfiguration(newDisabledItems); + } } -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml index 4b11b5115d7..264bcf91097 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -8,29 +8,37 @@

Dashboard

+ + +
- -
- - -
- - -
- - -
- - -
- - - - + + + + + +
+ + + Which cards do you whish to see ? + + + + + + + + + +
diff --git a/awesome_dashboard/static/src/dashboardItem/dashboardItem.js b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.js similarity index 71% rename from awesome_dashboard/static/src/dashboardItem/dashboardItem.js rename to awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.js index 4ab92d97087..bc4e610533b 100644 --- a/awesome_dashboard/static/src/dashboardItem/dashboardItem.js +++ b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.js @@ -3,11 +3,10 @@ import { Component } from "@odoo/owl"; export class DashboardItem extends Component { static template = "awesome_dashboard.DashboardItem"; static props = { - size: { type: Number, optional: true}, - title: { type: String, optional: true}, + size: { type: Number, optional: true }, slots: { type: Object, optional: true } }; static defaultProps = { size: 1, - }; + }; } diff --git a/awesome_dashboard/static/src/dashboardItem/dashboardItem.xml b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.xml similarity index 84% rename from awesome_dashboard/static/src/dashboardItem/dashboardItem.xml rename to awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.xml index 2bf169310c2..189df810a87 100644 --- a/awesome_dashboard/static/src/dashboardItem/dashboardItem.xml +++ b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.xml @@ -1,11 +1,8 @@ -
-

- -
\ No newline at end of file + diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js new file mode 100644 index 00000000000..ad5cca98e69 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,67 @@ +import { NumberCard } from "./numberCard/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; +import { _t } from "@web/core/l10n/translation"; + +const items = [ + { + id: "average_quantity", + description: _t("Average amount of t-shirt"), + Component: NumberCard, + props: (stat) => ({ + title: _t("Average amount of t-shirt by order this month"), + value: stat.data.average_quantity, + }) + }, + { + id: "average_time", + description: _t("Average time for an order"), + Component: NumberCard, + size: 2, + props: (stat) => ({ + title: _t("Average time for an order to go from 'new' to 'sent' or 'cancelled'"), + value: stat.data.average_time, + }) + }, + { + id: "number_new_orders", + description: _t("New orders this month"), + Component: NumberCard, + props: (stat) => ({ + title: _t("Number of new orders this month"), + value: stat.data.nb_new_orders, + }) + }, + { + id: "cancelled_orders", + description: _t("Cancelled orders this month"), + Component: NumberCard, + props: (stat) => ({ + title: _t("Number of cancelled orders this month"), + value: stat.data.nb_cancelled_orders, + }) + }, + { + id: "amount_new_orders", + description: _t("amount orders this month"), + Component: NumberCard, + props: (stat) => ({ + title: _t("Total amount of new orders this month"), + value: stat.data.total_amount, + }) + }, + { + id: "pie_chart", + description: _t("Shirt orders by size"), + Component: PieChartCard, + size: 2, + props: (stat) => ({ + title: _t("Shirt orders by size"), + values: stat.data.orders_by_size, + }) + } +] + +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); diff --git a/awesome_dashboard/static/src/dashboard/numberCard/number_card.js b/awesome_dashboard/static/src/dashboard/numberCard/number_card.js new file mode 100644 index 00000000000..79ba3679919 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/numberCard/number_card.js @@ -0,0 +1,9 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { type: String }, + value: { type: Number }, + } +} diff --git a/awesome_dashboard/static/src/dashboard/numberCard/number_card.xml b/awesome_dashboard/static/src/dashboard/numberCard/number_card.xml new file mode 100644 index 00000000000..3a0713623fa --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/numberCard/number_card.xml @@ -0,0 +1,9 @@ + + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/pieChart/pieChart.js b/awesome_dashboard/static/src/dashboard/pieChart/pieChart.js similarity index 76% rename from awesome_dashboard/static/src/pieChart/pieChart.js rename to awesome_dashboard/static/src/dashboard/pieChart/pieChart.js index 83fa532e145..677eccd392b 100644 --- a/awesome_dashboard/static/src/pieChart/pieChart.js +++ b/awesome_dashboard/static/src/dashboard/pieChart/pieChart.js @@ -1,4 +1,3 @@ - import { Component, onWillStart, useRef, useEffect, onWillUnmount, useState } from "@odoo/owl"; import { useService } from "@web/core/utils/hooks"; import { loadJS } from "@web/core/assets"; @@ -6,7 +5,8 @@ import { loadJS } from "@web/core/assets"; export class PieChart extends Component { static template = "awesome_dashboard.PieChartTemplate"; static props = { - label: { type: String } + label: { type: String }, + data: { type: Object } } setup(){ this.chartRef = useRef("chartCanvas"); @@ -16,27 +16,19 @@ export class PieChart extends Component { onWillStart(async () => { await loadJS("/web/static/lib/Chart/Chart.js"); }); - + useEffect(() => { this.renderChart(); - }, () => [this.statistics.data.orders_by_size]); - - onWillUnmount(this.onWillUnmount); - } - - onWillUnmount() { - if (this.chart) { + }); + + onWillUnmount(() => { this.chart.destroy(); - } + }); } renderChart() { - if (!this.statistics.data.orders_by_size || !this.chartRef.el) return; - - const ctx = this.chartRef.el.getContext("2d"); if (this.chart) this.chart.destroy(); - - this.chart = new Chart(ctx, { + this.chart = new Chart(this.chartRef.el, { type: "pie", data: { labels: Object.keys(this.statistics.data.orders_by_size), @@ -48,4 +40,4 @@ export class PieChart extends Component { }, }); } -} \ No newline at end of file +} diff --git a/awesome_dashboard/static/src/pieChart/pieChart.xml b/awesome_dashboard/static/src/dashboard/pieChart/pieChart.xml similarity index 98% rename from awesome_dashboard/static/src/pieChart/pieChart.xml rename to awesome_dashboard/static/src/dashboard/pieChart/pieChart.xml index 27476160d04..d7081142baf 100644 --- a/awesome_dashboard/static/src/pieChart/pieChart.xml +++ b/awesome_dashboard/static/src/dashboard/pieChart/pieChart.xml @@ -1,8 +1,6 @@ - - diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..4930dd4a966 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,11 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "../pieChart/pieChart"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = { PieChart } + static props = { + title: { type: String }, + values: { type: Object }, + } +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..58a6811c83a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/statisticsService.js b/awesome_dashboard/static/src/dashboard/statisticsService.js index 7603502ce75..fd424350366 100644 --- a/awesome_dashboard/static/src/dashboard/statisticsService.js +++ b/awesome_dashboard/static/src/dashboard/statisticsService.js @@ -14,11 +14,11 @@ const StatisticsService = { console.error("Error fetching statistics:", error); } } - + fetchStatistics(); - setInterval(fetchStatistics, 5000); - + setInterval(fetchStatistics, 600000); + return statistics; }, }; diff --git a/awesome_dashboard/static/src/dasboard_action.js b/awesome_dashboard/static/src/dashboard_action.js similarity index 62% rename from awesome_dashboard/static/src/dasboard_action.js rename to awesome_dashboard/static/src/dashboard_action.js index 94665fecc7f..95244e38916 100644 --- a/awesome_dashboard/static/src/dasboard_action.js +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -3,10 +3,12 @@ import { LazyComponent } from "@web/core/assets"; import { registry } from "@web/core/registry"; export class DashboardComponentLoader extends Component { - static components = { LazyComponent }; + static components = { + LazyComponent + }; static template = xml` - + `; } -registry.category("actions").add("awesome_dashboard.dashboard_action", DashboardComponentLoader); +registry.category("actions").add("awesome_dashboard.dashboard", DashboardComponentLoader); diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml index e302c0d1115..4e1c4613463 100644 --- a/awesome_owl/static/src/card/card.xml +++ b/awesome_owl/static/src/card/card.xml @@ -15,7 +15,7 @@

- +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index c56c95c7f6f..e5c1fe9174d 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -7,15 +7,15 @@ import { TodoList } from "./todo/todolist"; export class Playground extends Component { static template = "awesome_owl.playground"; - + setup() { this.state = useState({ sum: 0 }); } - + do_sum(value){ this.state.sum += value; } - + content1 = "
some content
"; content2 = markup("
some content
"); diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index e7894983aed..1e4be406398 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -21,7 +21,7 @@
- +
diff --git a/awesome_owl/static/src/todo/todolist.js b/awesome_owl/static/src/todo/todolist.js index 904c551b336..bb0757687a3 100644 --- a/awesome_owl/static/src/todo/todolist.js +++ b/awesome_owl/static/src/todo/todolist.js @@ -4,7 +4,7 @@ import { useAutofocus } from "../util"; export class TodoList extends Component { static template = "awesome_owl.todo.list"; - + setup(){ this.state = useState({ num: 0, From 14035f06902101e5e9b36af510fddb3d1594abe6 Mon Sep 17 00:00:00 2001 From: ppch-odoo Date: Tue, 25 Feb 2025 15:17:14 +0530 Subject: [PATCH 04/10] [IMP] awesome*, estate*: code formatting and code changes done --- awesome_dashboard/static/src/dashboard/dashboard.js | 2 +- .../dashboardItem.js => dashboard_item/dashboard_item.js} | 0 .../dashboard_item.xml} | 0 awesome_dashboard/static/src/dashboard/dashboard_items.js | 2 +- .../dashboard/{numberCard => number_card}/number_card.js | 0 .../dashboard/{numberCard => number_card}/number_card.xml | 0 .../{pieChart/pieChart.js => pie_chart/pie_chart.js} | 2 +- .../{pieChart/pieChart.xml => pie_chart/pie_chart.xml} | 0 .../static/src/dashboard/pie_chart_card/pie_chart_card.js | 2 +- .../{statisticsService.js => statistics_service.js} | 0 awesome_owl/static/src/card/card.js | 4 ++-- awesome_owl/static/src/counter/counter.js | 2 +- awesome_owl/static/src/playground.js | 4 ++-- awesome_owl/static/src/todo/todoitem.js | 8 ++++---- awesome_owl/static/src/todo/todolist.js | 6 +++--- estate/models/property.py | 6 +----- 16 files changed, 17 insertions(+), 21 deletions(-) rename awesome_dashboard/static/src/dashboard/{dashboardItem/dashboardItem.js => dashboard_item/dashboard_item.js} (100%) rename awesome_dashboard/static/src/dashboard/{dashboardItem/dashboardItem.xml => dashboard_item/dashboard_item.xml} (100%) rename awesome_dashboard/static/src/dashboard/{numberCard => number_card}/number_card.js (100%) rename awesome_dashboard/static/src/dashboard/{numberCard => number_card}/number_card.xml (100%) rename awesome_dashboard/static/src/dashboard/{pieChart/pieChart.js => pie_chart/pie_chart.js} (98%) rename awesome_dashboard/static/src/dashboard/{pieChart/pieChart.xml => pie_chart/pie_chart.xml} (100%) rename awesome_dashboard/static/src/dashboard/{statisticsService.js => statistics_service.js} (100%) diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js index f700f9ce251..e6fb54c915e 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -4,7 +4,7 @@ import { Component, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; -import { DashboardItem } from "./dashboardItem/dashboardItem"; +import { DashboardItem } from "./dashboard_item/dashboard_item"; import { Dialog } from "@web/core/dialog/dialog"; import { CheckBox } from "@web/core/checkbox/checkbox"; import { browser } from "@web/core/browser/browser"; diff --git a/awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js similarity index 100% rename from awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.js rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js diff --git a/awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml similarity index 100% rename from awesome_dashboard/static/src/dashboard/dashboardItem/dashboardItem.xml rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js index ad5cca98e69..b427e18f29d 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard_items.js +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -1,4 +1,4 @@ -import { NumberCard } from "./numberCard/number_card"; +import { NumberCard } from "./number_card/number_card"; import { PieChartCard } from "./pie_chart_card/pie_chart_card"; import { registry } from "@web/core/registry"; import { _t } from "@web/core/l10n/translation"; diff --git a/awesome_dashboard/static/src/dashboard/numberCard/number_card.js b/awesome_dashboard/static/src/dashboard/number_card/number_card.js similarity index 100% rename from awesome_dashboard/static/src/dashboard/numberCard/number_card.js rename to awesome_dashboard/static/src/dashboard/number_card/number_card.js diff --git a/awesome_dashboard/static/src/dashboard/numberCard/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml similarity index 100% rename from awesome_dashboard/static/src/dashboard/numberCard/number_card.xml rename to awesome_dashboard/static/src/dashboard/number_card/number_card.xml diff --git a/awesome_dashboard/static/src/dashboard/pieChart/pieChart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js similarity index 98% rename from awesome_dashboard/static/src/dashboard/pieChart/pieChart.js rename to awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js index 677eccd392b..60dc3241122 100644 --- a/awesome_dashboard/static/src/dashboard/pieChart/pieChart.js +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -8,7 +8,7 @@ export class PieChart extends Component { label: { type: String }, data: { type: Object } } - setup(){ + setup() { this.chartRef = useRef("chartCanvas"); this.chart = null; this.statistics = useState(useService("awesome_dashboard.statistics")); diff --git a/awesome_dashboard/static/src/dashboard/pieChart/pieChart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml similarity index 100% rename from awesome_dashboard/static/src/dashboard/pieChart/pieChart.xml rename to awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js index 4930dd4a966..91bf45c34c9 100644 --- a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -1,5 +1,5 @@ import { Component } from "@odoo/owl"; -import { PieChart } from "../pieChart/pieChart"; +import { PieChart } from "../pie_chart/pie_chart"; export class PieChartCard extends Component { static template = "awesome_dashboard.PieChartCard"; diff --git a/awesome_dashboard/static/src/dashboard/statisticsService.js b/awesome_dashboard/static/src/dashboard/statistics_service.js similarity index 100% rename from awesome_dashboard/static/src/dashboard/statisticsService.js rename to awesome_dashboard/static/src/dashboard/statistics_service.js diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js index b4783ba0427..be088170105 100644 --- a/awesome_owl/static/src/card/card.js +++ b/awesome_owl/static/src/card/card.js @@ -2,8 +2,8 @@ import { Component, useState } from "@odoo/owl"; export class Card extends Component { static props = { - title: {type: String}, - content: {type: String, optional: true}, + title: { type: String }, + content: { type: String, optional: true }, slots: { type: Object, optional: true } } diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js index 37828eb9770..5f06c282b00 100644 --- a/awesome_owl/static/src/counter/counter.js +++ b/awesome_owl/static/src/counter/counter.js @@ -2,7 +2,7 @@ import { Component, useState } from "@odoo/owl"; export class Counter extends Component { static props = { - callback: {type: Function, optional: true} + callback: { type: Function, optional: true } } static template = "awesome_owl.counter.counter"; diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index e5c1fe9174d..ae5c7935b84 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -12,12 +12,12 @@ export class Playground extends Component { this.state = useState({ sum: 0 }); } - do_sum(value){ + do_sum(value) { this.state.sum += value; } content1 = "
some content
"; content2 = markup("
some content
"); - static components = {Counter, Card, TodoList}; + static components = { Counter, Card, TodoList }; } diff --git a/awesome_owl/static/src/todo/todoitem.js b/awesome_owl/static/src/todo/todoitem.js index ef9b386439c..43b0d0603bc 100644 --- a/awesome_owl/static/src/todo/todoitem.js +++ b/awesome_owl/static/src/todo/todoitem.js @@ -5,12 +5,12 @@ export class TodoItem extends Component { todo: { type: Object, shape: { - id: {type: Number}, - description: {type: String}, - isCompleted: {type: Boolean} + id: { type: Number } , + description: { type: String }, + isCompleted: { type: Boolean } } }, - removeTodo: {type: Function} + removeTodo: { type: Function } } toggleState() { diff --git a/awesome_owl/static/src/todo/todolist.js b/awesome_owl/static/src/todo/todolist.js index bb0757687a3..dd443e66a19 100644 --- a/awesome_owl/static/src/todo/todolist.js +++ b/awesome_owl/static/src/todo/todolist.js @@ -5,7 +5,7 @@ import { useAutofocus } from "../util"; export class TodoList extends Component { static template = "awesome_owl.todo.list"; - setup(){ + setup() { this.state = useState({ num: 0, todos:[] @@ -13,7 +13,7 @@ export class TodoList extends Component { this.todoInputRef = useAutofocus("todoInput"); } - addTodo(ev){ + addTodo(ev) { if (ev.keyCode == 13){ const newTodo = ev.target.value.trim(); if(newTodo){ @@ -32,5 +32,5 @@ export class TodoList extends Component { this.state.todos = this.state.todos.filter(todo => todo.id !== id); } - static components = {TodoItem}; + static components = { TodoItem }; } diff --git a/estate/models/property.py b/estate/models/property.py index d63334c6de5..3b8d88f7365 100644 --- a/estate/models/property.py +++ b/estate/models/property.py @@ -114,11 +114,7 @@ def action_sold(self): raise UserError(_("Cancelled property can not be sold.")) elif property.state == 'sold': raise UserError(_("Property already sold.")) - accepted_offer = self.env['estate.property.offer'].search([ - ('property_id', '=', self.id), - ('status', '=', 'accepted') - ], limit=1) - if not accepted_offer: + if not (property.state == 'offer_accepted'): raise UserError(_("You cannot sell a property without an accepted offer.")) property.state = 'sold' From 86f69827dac15d001650465d906da71a111924fe Mon Sep 17 00:00:00 2001 From: ppch-odoo Date: Mon, 3 Mar 2025 19:07:00 +0530 Subject: [PATCH 05/10] [IMP] automated_auction: improved estate by adding auction feature - Automated auction option added in config settings - Inherited estate.property and added some extra fields required for automated auction functionality - Inherited estate_property_from_view to display all fields of automated auction such as start auction button, auction details section - Added automated auction functionality such as create offer button, property offer form to add offer in selected property --- automated_auction/__init__.py | 2 ++ automated_auction/__manifest__.py | 19 ++++++++++++ automated_auction/controllers/__init__.py | 2 ++ .../controllers/property_list.py | 8 +++++ .../controllers/property_offer.py | 31 +++++++++++++++++++ automated_auction/models/__init__.py | 1 + automated_auction/models/property.py | 21 +++++++++++++ .../views/estate_property_views.xml | 23 ++++++++++++++ .../views/property_add_offer_template.xml | 31 +++++++++++++++++++ .../views/property_templates.xml | 23 ++++++++++++++ estate/controllers/__init__.py | 2 +- .../controllers/{main.py => property_list.py} | 0 estate/models/res_config_settings.py | 1 + estate/views/estate_property_views.xml | 11 ++----- estate/views/property_templates.xml | 4 +-- estate/views/res_config_settings_views.xml | 5 +++ 16 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 automated_auction/__init__.py create mode 100644 automated_auction/__manifest__.py create mode 100644 automated_auction/controllers/__init__.py create mode 100644 automated_auction/controllers/property_list.py create mode 100644 automated_auction/controllers/property_offer.py create mode 100644 automated_auction/models/__init__.py create mode 100644 automated_auction/models/property.py create mode 100644 automated_auction/views/estate_property_views.xml create mode 100644 automated_auction/views/property_add_offer_template.xml create mode 100644 automated_auction/views/property_templates.xml rename estate/controllers/{main.py => property_list.py} (100%) diff --git a/automated_auction/__init__.py b/automated_auction/__init__.py new file mode 100644 index 00000000000..91c5580fed3 --- /dev/null +++ b/automated_auction/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/automated_auction/__manifest__.py b/automated_auction/__manifest__.py new file mode 100644 index 00000000000..57f0a92f302 --- /dev/null +++ b/automated_auction/__manifest__.py @@ -0,0 +1,19 @@ +{ + 'name': "Automated Auction", + 'version': '1.0', + 'depends': ['estate'], + 'author': "ppch", + 'category': '', + 'description': """ + Automated Auction module for Estate properties + """, + 'license': "LGPL-3", + 'data': [ + 'views/estate_property_views.xml', + 'views/property_add_offer_template.xml', + 'views/property_templates.xml', + ], + 'demo': [ + ], + 'installable': True, +} diff --git a/automated_auction/controllers/__init__.py b/automated_auction/controllers/__init__.py new file mode 100644 index 00000000000..1925339230e --- /dev/null +++ b/automated_auction/controllers/__init__.py @@ -0,0 +1,2 @@ +from . import property_offer +from . import property_list diff --git a/automated_auction/controllers/property_list.py b/automated_auction/controllers/property_list.py new file mode 100644 index 00000000000..9d976e5b398 --- /dev/null +++ b/automated_auction/controllers/property_list.py @@ -0,0 +1,8 @@ +from odoo.http import request, route +from odoo.addons.estate.controllers.property_list import EstatePropertyController + + +class EstatePropertyOfferContoller(EstatePropertyController): + @route(['/properties', '/properties/page/'], type='http', auth="public", website=True) + def list_properties(self, page=1, **kwargs): + #define diff --git a/automated_auction/controllers/property_offer.py b/automated_auction/controllers/property_offer.py new file mode 100644 index 00000000000..21a883eb7dc --- /dev/null +++ b/automated_auction/controllers/property_offer.py @@ -0,0 +1,31 @@ +from odoo import _ +from odoo.http import Controller, request, route +from odoo.exceptions import UserError + + +class EstatePropertyOfferContoller(Controller): + # Route For Add Offer in Particular Property + @route(['/properties//add_offer'], type='http', auth="user", website=True) + def add_offer_form(self, property_id, **kwargs): + property_details = request.env['estate.property'].sudo().browse(property_id) + + return request.render('automated_auction.property_add_offer_template', { + 'property_details': property_details, + }) + + @route(['/properties//submit_offer'], type='http', auth="user", website=True) + def add_offer_submit_form(self, property_id, **post): + property_details = request.env['estate.property'].sudo().browse(property_id) + + offer_amount = float(post.get('offer_amount')) + if offer_amount <= property_details.expected_price: + raise UserError(_("Price must be greater than expected price")) + + # Create the offer in the estate.property.offer model + request.env['estate.property.offer'].sudo().create({ + 'property_id': property_id, + 'partner_id': request.env.user.partner_id.id, + 'price': offer_amount + }) + + return request.render('automated_auction.property_offer_added') diff --git a/automated_auction/models/__init__.py b/automated_auction/models/__init__.py new file mode 100644 index 00000000000..8120b005bb6 --- /dev/null +++ b/automated_auction/models/__init__.py @@ -0,0 +1 @@ +from . import property diff --git a/automated_auction/models/property.py b/automated_auction/models/property.py new file mode 100644 index 00000000000..0ee663ff441 --- /dev/null +++ b/automated_auction/models/property.py @@ -0,0 +1,21 @@ +from odoo import api, fields, models + + +class Property(models.Model): + _inherit = 'estate.property' + + property_auction_type = fields.Selection( + string="Auction Type", + help="Automated auction\n" + "Regular auction", + selection=[ + ('auction', "Auction"), + ('regular', "Regular"), + ], + required=True, + default='auction', + ) + start_time = fields.Datetime() + end_time = fields.Datetime() + highest_offer_amount = fields.Float(readonly=True) + highest_offer_bidder = fields.Char(readonly=True) diff --git a/automated_auction/views/estate_property_views.xml b/automated_auction/views/estate_property_views.xml new file mode 100644 index 00000000000..c2acbc537f1 --- /dev/null +++ b/automated_auction/views/estate_property_views.xml @@ -0,0 +1,23 @@ + + + + estate.property.views.auction.inherit.form + estate.property + + + + + + + + + + + + + + + + - + -