From bcda8b11b2695d053a7d4e3881a0e7c25403c392 Mon Sep 17 00:00:00 2001 From: Vincent Janssen Date: Wed, 10 Dec 2025 12:40:41 +0100 Subject: [PATCH 1/4] [IMP] estate: Server101 Finished [IMP] estate: Server101 Finished Chapter 3 [IMP] estate: Server101 Finished Chapter 4 [IMP] estate: Server101 Finished Chapter 5 [IMP] estate: Server101 Finished Chapter 6 [IMP] estate: Server101 Finished Chapter 7 [IMP] estate: Server101 Finished Chapter 8 [IMP] estate: Server101 Finished Chapter 9 [IMP] estate: Server101 Finished Chapter 10 [IMP] estate: Server101 Finished Chapter 10 [IMP] estate: Server101 WIP Chapter 11 [CLN] estate: code cleanup to match Ruff [CLN] estate: Server101 Cleanup [CLN] estate: Server101 Cleanup final [CLN] estate: Server101 Appling PR requested changes and cleanup of the code for readability [FIX] estate: Server101 Fixing bugs based on cleanup [IMP] estate: Server101 Finished Chapter 11 [IMP] estate : Server101 Finished Chapter 12 [FIX] estate: Fixed bug where the stat button from property type to property offer would crash on new install of the estate module [IMP] estate: Server101 Finished Chapter 13 [IMP] estate: Server101 Finshed Chapter 14 [FIX] estate: Added error message translation useing self.env._() and applied fix in the PR --- .gitignore | 1 - estate/__init__.py | 1 + estate/__manifest__.py | 21 + estate/i18n/estate.pot | 500 +++++++++++++++++++ estate/models/__init__.py | 5 + estate/models/estate_property.py | 100 ++++ estate/models/estate_property_offer.py | 60 +++ estate/models/estate_property_tag.py | 12 + estate/models/estate_property_type.py | 20 + estate/models/res_user.py | 6 + estate/security/ir.model.access.csv | 5 + estate/views/estate_menu_views.xml | 12 + estate/views/estate_property_offer_views.xml | 44 ++ estate/views/estate_property_tag_views.xml | 21 + estate/views/estate_property_type_views.xml | 56 +++ estate/views/estate_property_views.xml | 131 +++++ estate/views/res_user_views.xml | 17 + estate_account/__init__.py | 1 + estate_account/__manifest__.py | 14 + estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 27 + 21 files changed, 1054 insertions(+), 1 deletion(-) create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py create mode 100644 estate/i18n/estate.pot create mode 100644 estate/models/__init__.py create mode 100644 estate/models/estate_property.py create mode 100644 estate/models/estate_property_offer.py create mode 100644 estate/models/estate_property_tag.py create mode 100644 estate/models/estate_property_type.py create mode 100644 estate/models/res_user.py create mode 100644 estate/security/ir.model.access.csv create mode 100644 estate/views/estate_menu_views.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/res_user_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 diff --git a/.gitignore b/.gitignore index b6e47617de1..63a8dfbb408 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,6 @@ coverage.xml # Translations *.mo -*.pot # Django stuff: *.log diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..be6e30605f5 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,21 @@ +{ + 'name': "estate", + 'description': "test", + 'depends': [ + 'base_setup' + ], + 'category': "Tutorials", + 'installable': True, + 'application': True, + 'data': [ + '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_menu_views.xml', + 'views/res_user_views.xml', + 'security/ir.model.access.csv'], + 'author': 'Odoo S.A.', + 'license': 'LGPL-3' + +} diff --git a/estate/i18n/estate.pot b/estate/i18n/estate.pot new file mode 100644 index 00000000000..4e95f72c03b --- /dev/null +++ b/estate/i18n/estate.pot @@ -0,0 +1,500 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * estate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-18 09:47+0000\n" +"PO-Revision-Date: 2025-12-18 09:47+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_type_model_form +msgid "" +"\n" +" Offers\n" +" " +msgstr "" + +#. module: estate +#: model:ir.model.constraint,message:estate.constraint_estate_property_offer_postif_price +#: model:ir.model.constraint,message:estate.constraint_estate_property_positif_expected_price +#: model:ir.model.constraint,message:estate.constraint_estate_property_positif_selling_price +msgid "A price can't be negatif" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Accept" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property_offer__status__accepted +msgid "Accepted" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__active +msgid "Active" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_search +msgid "Available" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__date_availability +msgid "Available From" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__best_price +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_kanban +msgid "Best Price" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__buyer_id +msgid "Buyer" +msgstr "" + +#. module: estate +#. odoo-python +#: code:addons/estate/models/estate_property.py:0 +msgid "Can't cancel sold property." +msgstr "" + +#. module: estate +#. odoo-python +#: code:addons/estate/models/estate_property.py:0 +msgid "Can't delete non-new and non-cancelled property" +msgstr "" + +#. module: estate +#. odoo-python +#: code:addons/estate/models/estate_property.py:0 +msgid "Can't sell cancelled property." +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_form +msgid "Cancel" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__state__cancelled +msgid "Cancelled" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__color +msgid "Color" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__garage +msgid "Contains a Garage ?" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__garden +msgid "Contains a Garden ?" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__create_uid +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__create_uid +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__create_uid +#: model:ir.model.fields,field_description:estate.field_estate_property_type__create_uid +msgid "Created by" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__create_date +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__create_date +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__create_date +#: model:ir.model.fields,field_description:estate.field_estate_property_type__create_date +msgid "Created on" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__date_deadline +msgid "Deadline" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_form +msgid "Description" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__display_name +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__display_name +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__display_name +#: model:ir.model.fields,field_description:estate.field_estate_property_type__display_name +#: model:ir.model.fields,field_description:estate.field_res_users__display_name +msgid "Display Name" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__garden_orientation__east +msgid "East" +msgstr "" + +#. module: estate +#: model:ir.ui.menu,name:estate.estate_menu_root +msgid "Estate" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__expected_price +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_kanban +msgid "Expected Price" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__garden_area +msgid "Garden Area Size m^2" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__garden_orientation +msgid "Garden orientation" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__id +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__id +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__id +#: model:ir.model.fields,field_description:estate.field_estate_property_type__id +#: model:ir.model.fields,field_description:estate.field_res_users__id +msgid "ID" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__last_seen +msgid "Last Seen" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__write_uid +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__write_uid +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__write_uid +#: model:ir.model.fields,field_description:estate.field_estate_property_type__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__write_date +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__write_date +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__write_date +#: model:ir.model.fields,field_description:estate.field_estate_property_type__write_date +msgid "Last Updated on" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__living_area +msgid "Living Area Size m^2" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__name +#: model:ir.model.fields,field_description:estate.field_estate_property_tag__name +#: model:ir.model.fields,field_description:estate.field_estate_property_type__name +msgid "Name" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__state__new +msgid "New" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__garden_orientation__north +msgid "North" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__facades +msgid "Number of Facades" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_type__offer_count +msgid "Number of Offers" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__bedrooms +msgid "Number of bedrooms" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_type__offer_ids +msgid "Offer" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__state__offer_accepted +msgid "Offer Accepted" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__state__offer_received +msgid "Offer Received" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Offer Sender" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Offer deadline" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Offer validity time (days)" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__offer_ids +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_form +#: model_terms:ir.ui.view,arch_db:estate.estate_property_type_model_form +msgid "Offers" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_form +msgid "Other Info" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__partner_id +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_model_form +msgid "Partner" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__postcode +msgid "Postcode" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_search +msgid "Postcodes" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__price +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_model_form +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Price" +msgstr "" + +#. module: estate +#: model:ir.actions.act_window,name:estate.estate_property_model_action +#: model:ir.model,name:estate.model_estate_property +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__property_id +#: model:ir.model.fields,field_description:estate.field_estate_property_type__property_ids +#: model:ir.model.fields,field_description:estate.field_res_users__property_ids +#: model:ir.ui.menu,name:estate.estate_property_menu +#: model:ir.ui.menu,name:estate.estate_property_menu_action +msgid "Property" +msgstr "" + +#. module: estate +#: model:ir.actions.act_window,name:estate.estate_property_offer_model_action +#: model:ir.model,name:estate.model_estate_property_offer +msgid "Property Offer" +msgstr "" + +#. module: estate +#: model:ir.actions.act_window,name:estate.estate_property_tag_model_action +#: model:ir.model,name:estate.model_estate_property_tag +#: model:ir.ui.menu,name:estate.estate_property_tag_menu_acion +msgid "Property Tag" +msgstr "" + +#. module: estate +#: model:ir.actions.act_window,name:estate.estate_property_type_model_action +#: model:ir.model,name:estate.model_estate_property_type +#: model:ir.ui.menu,name:estate.estate_property_type_menu_acion +msgid "Property Type" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_form +#: model_terms:ir.ui.view,arch_db:estate.estate_property_tag_model_form +#: model_terms:ir.ui.view,arch_db:estate.estate_property_view_list +msgid "Property list" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_model_form +msgid "Property offer form" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Property offer list" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_search +msgid "Property search" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_tag_model_list +msgid "Property tag list" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Property type" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_type_model_form +msgid "Property type Form" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_type_model_list +msgid "Property type list" +msgstr "" + +#. module: estate +#: model:ir.model.constraint,message:estate.constraint_estate_property_type_unique_type +msgid "Property type name must be unique in database" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.res_users_view_form +msgid "Real Estate Properties" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_offer_view_list +msgid "Refuse" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property_offer__status__refused +msgid "Refused" +msgstr "" + +#. module: estate +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_form +msgid "Sell" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__seller_id +msgid "Seller" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__selling_price +#: model_terms:ir.ui.view,arch_db:estate.estate_property_model_kanban +msgid "Selling Price" +msgstr "" + +#. module: estate +#. odoo-python +#: code:addons/estate/models/estate_property.py:0 +msgid "Selling price is too low %(price)s" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_type__sequence +msgid "Sequence" +msgstr "" + +#. module: estate +#: model:ir.ui.menu,name:estate.estate_settings_menu +msgid "Settings" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__state__sold +msgid "Sold" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__garden_orientation__south +msgid "South" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__state +msgid "State" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__status +msgid "Status" +msgstr "" + +#. module: estate +#: model:ir.model.constraint,message:estate.constraint_estate_property_tag_unique_tag +msgid "Tag name must be unique in database" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__tag_ids +msgid "Tags" +msgstr "" + +#. module: estate +#. odoo-python +#: code:addons/estate/models/estate_property_offer.py:0 +msgid "This offer is lower than what has already been offered." +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__total_area +msgid "Total Area m^2" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__property_type_id +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__property_type_id +msgid "Type" +msgstr "" + +#. module: estate +#: model:ir.model,name:estate.model_res_users +msgid "User" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property_offer__validity +msgid "Validity Duration" +msgstr "" + +#. module: estate +#: model:ir.model.fields.selection,name:estate.selection__estate_property__garden_orientation__west +msgid "West" +msgstr "" + +#. module: estate +#: model:ir.model.fields,field_description:estate.field_estate_property__description +msgid "description" +msgstr "" + +#. module: estate +#: model:ir.model.fields,help:estate.field_estate_property_type__sequence +msgid "use to order the list inside the type view" +msgstr "" diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..8f914bbb526 --- /dev/null +++ b/estate/models/__init__.py @@ -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 res_user diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..6515699f95e --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,100 @@ +from dateutil.relativedelta import relativedelta +from odoo import fields, models, api +from odoo.tools.float_utils import float_compare, float_is_zero +from odoo.exceptions import ValidationError, UserError + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Property" + _order = "id desc" + + _positif_expected_price = models.Constraint("CHECK (expected_price >= 0)", "A price can't be negatif") + _positif_selling_price = models.Constraint("CHECK (selling_price >= 0)", "A price can't be negatif") + + state = fields.Selection(selection=[ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled") + ], default='new') + + active = fields.Boolean('Active', default=True) + name = fields.Char(required=True, default="Unknown", string="Name") + description = fields.Text(string="description") + postcode = fields.Char(string="Postcode") + date_availability = fields.Date(string="Available From", copy=False, default=lambda self: fields.Datetime.today() + relativedelta(months=3)) + last_seen = fields.Date(string="Last Seen", default=lambda self: fields.Datetime.now()) + expected_price = fields.Float(required=True, string="Expected Price") + selling_price = fields.Float(readonly=True, copy=False, string="Selling Price") + best_price = fields.Float(string="Best Price", compute="_compute_best_price") + bedrooms = fields.Integer(default=2, string="Number of bedrooms") + living_area = fields.Integer(string="Living Area Size m^2") + facades = fields.Integer(string="Number of Facades") + garage = fields.Boolean(string="Contains a Garage ?") + garden = fields.Boolean(string="Contains a Garden ?") + garden_area = fields.Integer(string="Garden Area Size m^2") + garden_orientation = fields.Selection(string="Garden orientation", selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West')]) + + total_area = fields.Float(string="Total Area m^2", compute="_compute_total_area") + property_type_id = fields.Many2one("estate.property.type", string="Type") + buyer_id = fields.Many2one("res.partner", string="Buyer") + seller_id = fields.Many2one("res.users", default=lambda self: self.env.user, string="Seller") + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + + def sell_property(self): + for record in self: + if (record.state == "cancelled"): + raise UserError(self.env._("Can't sell cancelled property.")) + record.state = "sold" + return True + + def cancel_property(self): + for record in self: + if (record.state == "sold"): + raise UserError(self.env._("Can't cancel sold property.")) + record.state = "cancelled" + return True + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.garden_area + record.living_area + + @api.depends('offer_ids') + def _compute_best_price(self): + for record in self: + if (not record.offer_ids): + record.best_price = 0 + continue + record.best_price = max(record.offer_ids.mapped('price')) + + @api.onchange("offer_ids") + def _on_change_offer_ids(self): + if (self.state == 'new' and len(self.offer_ids) != 0): + self.state = 'offer_received' + + @api.onchange("garden") + def _on_change_garden(self): + self.garden_area = 10 if self.garden else 0 + self.garden_orientation = 'north' if self.garden else '' + + @api.constrains('selling_price', 'expected_price') + def _constrain_prices(self): + for record in self: + if float_is_zero(record.selling_price, 2): + continue + if (float_compare(record.selling_price, record.expected_price * 0.8, 2) == -1): + raise ValidationError(self.env._("Selling price is too low %(price)s", price=record.selling_price)) + + @api.ondelete(at_uninstall=False) + def _unlink_excpet_cancel_new(self): + for record in self: + if (record.state != 'new' and record.state != 'cancelled'): + raise UserError(self.env._("Can't delete non-new and non-cancelled property")) diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..2725617a495 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,60 @@ +from datetime import datetime, time +from dateutil.relativedelta import relativedelta +from odoo import fields, models, api +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_compare + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Property Offer" + _order = "price desc" + + _postif_price = models.Constraint("CHECK (price > 0)", "A price can't be negatif") + + price = fields.Float(string="Price") + status = fields.Selection(copy=False, selection=[ + ("accepted", "Accepted"), + ("refused", "Refused")]) + + partner_id = fields.Many2one('res.partner', required=True) + property_id = fields.Many2one('estate.property', ondelete='cascade', required=True) + property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) + validity = fields.Integer(string="Validity Duration", default=7) + date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline") + + def accept_offer(self): + for record in self: + if (record.property_id.selling_price == 0): + record.status = "accepted" + record.property_id.buyer_id = record.partner_id + record.property_id.selling_price = record.price + record.property_id.state = 'offer_accepted' + return True + + def refused_offer(self): + for record in self: + record.status = "refused" + return True + + @api.depends("validity") + def _compute_date_deadline(self): + for record in self: + if (isinstance(record.create_date, bool)): + record.date_deadline = fields.Datetime.now() + relativedelta(days=record.validity) + return + record.date_deadline = record.create_date + relativedelta(days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + record.validity = (datetime.combine(record.date_deadline, time()) - record.create_date).days + + @api.model + def create(self, vals_list): + property_ids = (val['property_id'] for val in vals_list) + property = self.env['estate.property'].browse(property_ids) + + for i, record in enumerate(vals_list): + if (float_compare(record['price'], property[i].best_price, 2) == -1): + raise UserError(self.env._("This offer is lower than what has already been offered.")) + return super().create(vals_list) diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..93b5a4f5606 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Property Tag" + _order = "name asc" + + _unique_tag = models.UniqueIndex("(name)", "Tag name must be unique in database") + + name = fields.Char(string="Name", required=True) + color = fields.Integer() diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..5b25ae43da9 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,20 @@ +from odoo import fields, models, api + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Property Type" + _order = "sequence, name asc" + + _unique_type = models.UniqueIndex("(name)", "Property type name must be unique in database") + + name = fields.Char(string="Name", required=True) + property_ids = fields.One2many("estate.property", "property_type_id") + sequence = fields.Integer('Sequence', default=1, help="use to order the list inside the type view") + offer_ids = fields.One2many('estate.property.offer', 'property_type_id') + offer_count = fields.Integer(string="Number of Offers", compute='_compute_offer_count') + + @api.depends("offer_ids") + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/res_user.py b/estate/models/res_user.py new file mode 100644 index 00000000000..718699c6cb4 --- /dev/null +++ b/estate/models/res_user.py @@ -0,0 +1,6 @@ +from odoo import models, fields + + +class ResUsers(models.Model): + _inherit = 'res.users' + property_ids = fields.One2many("estate.property", "seller_id", domain="['|',('state','=','Offer_Received'),('state','=','New')]") diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..4073dc03078 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property_model,access_estate_property_model,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type_model,access_estate_property_type_model,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag_model,access_estate_property_tag_model,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer_model,access_estate_property_offer_model,model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/views/estate_menu_views.xml b/estate/views/estate_menu_views.xml new file mode 100644 index 00000000000..20051185c6e --- /dev/null +++ b/estate/views/estate_menu_views.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..f0f32300bcc --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,44 @@ + + + + + Property Offer + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + +
+
+
+ + + estate.property.offer.list + estate.property.offer + + + + + + + + + + +

+ +

+
+ + + + + + + + + +
+
+ + + estate.property.type.list + estate.property.type + + + + + + + + +
\ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..740575c80fe --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,131 @@ + + + + + Property + estate.property + list,form,kanban + {'search_default_available':True} + + + + estate.property.list + estate.property + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ + +

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.search + estate.property + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + +
+ +

+ +
+ +
+ +
+
+ +
+
+
+
+
+
+ +
diff --git a/estate/views/res_user_views.xml b/estate/views/res_user_views.xml new file mode 100644 index 00000000000..aa4b825a8c5 --- /dev/null +++ b/estate/views/res_user_views.xml @@ -0,0 +1,17 @@ + + + + + res.users.view.form.inherit.estate + res.users + + + + + + + + + + + \ No newline at end of file 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..341b8a7db19 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,14 @@ +{ + 'name': "estate_account", + 'description': "link the estate module to the invoiceing module", + 'depends': [ + 'base_setup', 'estate', 'account' + ], + 'category': "Tutorials", + 'installable': True, + 'application': False, + 'data': [], + 'author': 'Odoo S.A.', + 'license': 'LGPL-3' + +} 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..b37e980a120 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,27 @@ +from odoo import models, Command + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def sell_property(self): + for record in self: + invoice_val = { + 'state': 'draft', + 'move_type': 'out_invoice', + 'partner_id': int(record.buyer_id), + 'line_ids': [ + Command.create({ + "name": "First Payment", + "quantity": 1, + "price_unit": record.selling_price * 0.06 + }), + Command.create({ + "name": "Administrative Fees", + "quantity": 1, + "price_unit": 100.00 + }) + ] + } + self.env['account.move'].sudo().with_context(default_move_type='out_invoice').create(invoice_val) + return super().sell_property() From 7d734c468b6adacf48030cdb3f9ede64e82d6bc4 Mon Sep 17 00:00:00 2001 From: VincentJanssen-Code Date: Fri, 19 Dec 2025 09:42:09 +0100 Subject: [PATCH 2/4] [IMP] awesome_owl: Web Framework Finished Chapter 1 [IMP] awesome_owl: Web Framework Finished Chapter 1 Part 9-14 --- awesome_owl/controllers/controllers.py | 1 + awesome_owl/static/src/TodoItem/TodoItem.js | 33 ++++++++++++++ awesome_owl/static/src/TodoItem/TodoItem.xml | 13 ++++++ awesome_owl/static/src/TodoList/TodoList.js | 46 ++++++++++++++++++++ awesome_owl/static/src/TodoList/TodoList.xml | 10 +++++ awesome_owl/static/src/card/card.js | 26 +++++++++++ awesome_owl/static/src/card/card.xml | 15 +++++++ awesome_owl/static/src/counter/counter.js | 22 ++++++++++ awesome_owl/static/src/counter/counter.xml | 12 +++++ awesome_owl/static/src/playground.js | 20 ++++++++- awesome_owl/static/src/playground.xml | 12 +++-- awesome_owl/static/src/utils.js | 10 +++++ 12 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 awesome_owl/static/src/TodoItem/TodoItem.js create mode 100644 awesome_owl/static/src/TodoItem/TodoItem.xml create mode 100644 awesome_owl/static/src/TodoList/TodoList.js create mode 100644 awesome_owl/static/src/TodoList/TodoList.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/utils.js diff --git a/awesome_owl/controllers/controllers.py b/awesome_owl/controllers/controllers.py index bccfd6fe283..2dc0e769e1d 100644 --- a/awesome_owl/controllers/controllers.py +++ b/awesome_owl/controllers/controllers.py @@ -1,6 +1,7 @@ from odoo import http from odoo.http import request, route + class OwlPlayground(http.Controller): @http.route(['/awesome_owl'], type='http', auth='public') def show_playground(self): diff --git a/awesome_owl/static/src/TodoItem/TodoItem.js b/awesome_owl/static/src/TodoItem/TodoItem.js new file mode 100644 index 00000000000..40608fc3b78 --- /dev/null +++ b/awesome_owl/static/src/TodoItem/TodoItem.js @@ -0,0 +1,33 @@ +import { Component, useState } from "@odoo/owl"; + +export class TodoItem extends Component +{ + static template = 'awesome_owl.TodoItem'; + static props = { + todo : { + type: Object, + shape:{ + id: {type : Number}, + description: {type : String}, + isCompleted: {type: Boolean}} + }, + + updateState : { + type: Function, + }, + + deleteTodo : { + type : Function, + optional: true + } + }; + + updateState(event) + { + this.props.updateState(this.props.todo.id); + } + deleteTodo(event) + { + this.props.deleteTodo(this.props.todo.id); + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/TodoItem/TodoItem.xml b/awesome_owl/static/src/TodoItem/TodoItem.xml new file mode 100644 index 00000000000..ab7dfeca8ad --- /dev/null +++ b/awesome_owl/static/src/TodoItem/TodoItem.xml @@ -0,0 +1,13 @@ + + + + +
+ +

ID :

+

Desc :

+ + +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/TodoList/TodoList.js b/awesome_owl/static/src/TodoList/TodoList.js new file mode 100644 index 00000000000..aed43ffe258 --- /dev/null +++ b/awesome_owl/static/src/TodoList/TodoList.js @@ -0,0 +1,46 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "../TodoItem/TodoItem"; +import { useAutoFocus } from "../utils"; + +export class TodoList extends Component +{ + static template = 'awesome_owl.TodoList'; + static components = { TodoItem }; + static props = {}; + setup() + { + this.todos = useState([]); + this.ids = 0; + useAutoFocus('todo_input'); + } + addTodo(event) + { + if (event.type !== 'keyup' || event.keyCode !== 13 || event.target.value == "" ) + { + return; + } + this.todos.push({id:this.ids++,description:event.target.value,isCompleted:false}); + event.target.value = ""; + + } + updateTodo(id) + { + let selectedTodo = this.todos.find(todo => todo.id == id); + if(selectedTodo) + { + selectedTodo.isCompleted = !selectedTodo.isCompleted; + } + + } + deleteTodo(id) + { + const selectedTodo = this.todos.findIndex(todo => todo.id == id); + if(selectedTodo >= 0) + { + this.todos.splice(selectedTodo, 1); + } + + + } + +} \ No newline at end of file diff --git a/awesome_owl/static/src/TodoList/TodoList.xml b/awesome_owl/static/src/TodoList/TodoList.xml new file mode 100644 index 00000000000..60757443795 --- /dev/null +++ b/awesome_owl/static/src/TodoList/TodoList.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..6eb07494ab9 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,26 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + static props = { + title: String, + slots: { + type: Object, + shape: { + default:true + } + }, + html: {type:String} + }; + + setup() + { + this.hide = useState({value:false}); + } + + hideToggle() + { + this.hide.value = ! this.hide.value; + } + +} \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..7ed3570412a --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,15 @@ + + + +
+ +
+
+

+ + +

+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..edbad216204 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,22 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component +{ + static template = 'awesome_owl.counter'; + static props = { + onChange: {type : Function} + }; + setup() + { + this.state = useState({value: 0}); + } + + increment() + { + this.state.value++; + if(this.props.onChange) + { + this.props.onChange(); + } + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..d3315e59de5 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,12 @@ + + + + +
+

Counter :

+ +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..fdd7d6d576e 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,23 @@ -import { Component } from "@odoo/owl"; +import { Component, useState, markup } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./TodoList/TodoList" export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoList }; + static props = {}; + todo = {id: 3, description: "buy milk", isCompleted: false }; + html = markup("

Hi

"); + + setup() + { + this.sum = useState({value: 0}); + } + incrementSum() + { + this.sum.value ++; + } + + } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..e00dc86b594 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,14 @@ - -
- hello world + + + + + + +
+
- diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..78625e52f2e --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,10 @@ +import { useRef, onMounted } from "@odoo/owl"; + + +export function useAutoFocus(ref_name) +{ + const inputRef = useRef(ref_name); + onMounted(() => { + inputRef.el.focus(); + }); +} \ No newline at end of file From 9981db353b7f5d74f612f9c27bbb1a794e8aa412 Mon Sep 17 00:00:00 2001 From: VincentJanssen-Code Date: Fri, 19 Dec 2025 17:26:08 +0100 Subject: [PATCH 3/4] [IMP] awesome_owl: Web Framework Finished Chapter 2 [FIX] awesome_owl: Invisible dialog box [FIX] awesome_owl: Dummy push [IMP] awsome_owl: Framework Finished Chapter 7-12 --- awesome_dashboard/__manifest__.py | 4 + awesome_dashboard/static/src/dashboard.js | 8 -- awesome_dashboard/static/src/dashboard.xml | 8 -- .../src/dashboard/ChartCard/ChartCard.js | 13 +++ .../src/dashboard/ChartCard/ChartCard.xml | 7 ++ .../dashboard/DashboardItem/DashboardItem.js | 18 ++++ .../dashboard/DashboardItem/DashboardItem.xml | 8 ++ .../src/dashboard/NumberCard/NumberCard.js | 9 ++ .../src/dashboard/NumberCard/NumberCard.xml | 9 ++ .../static/src/dashboard/PieChart/PieChart.js | 89 +++++++++++++++++++ .../src/dashboard/PieChart/PieChart.xml | 6 ++ .../SettingsDialog/SettingsDialog.js | 38 ++++++++ .../SettingsDialog/SettingsDialog.xml | 18 ++++ .../static/src/dashboard/dashboard.js | 55 ++++++++++++ .../static/src/dashboard/dashboard.scss | 11 +++ .../static/src/dashboard/dashboard.xml | 29 ++++++ .../static/src/dashboard/dashboard_items.js | 74 +++++++++++++++ .../static/src/dashboard/statistics.js | 20 +++++ .../static/src/dashboard_acion.js | 12 +++ awesome_owl/static/src/playground.js | 2 +- 20 files changed, 421 insertions(+), 17 deletions(-) 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/ChartCard/ChartCard.js create mode 100644 awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.xml create mode 100644 awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.js create mode 100644 awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.xml create mode 100644 awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.js create mode 100644 awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.xml create mode 100644 awesome_dashboard/static/src/dashboard/PieChart/PieChart.js create mode 100644 awesome_dashboard/static/src/dashboard/PieChart/PieChart.xml create mode 100644 awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.js create mode 100644 awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.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/dashboard_items.js create mode 100644 awesome_dashboard/static/src/dashboard/statistics.js create mode 100644 awesome_dashboard/static/src/dashboard_acion.js diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index a1cd72893d7..1063a9ad6d4 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,7 +24,11 @@ 'assets': { 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', + ('remove', 'awesome_dashboard/static/src/dashboard/**/**'), ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/**' + ] }, 'license': 'AGPL-3' } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index c4fb245621b..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,8 +0,0 @@ -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/ChartCard/ChartCard.js b/awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.js new file mode 100644 index 00000000000..6639fb59b7f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.js @@ -0,0 +1,13 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "../PieChart/PieChart"; + + +export class ChartCard extends Component { + static template = "awesome_dashboard.ChartCard"; + static components = { PieChart}; + static props = { + title: String, + label : String, + data : {type : Object, optional: true}, + } +} diff --git a/awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.xml b/awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.xml new file mode 100644 index 00000000000..1920e7d6d89 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.xml @@ -0,0 +1,7 @@ + + + +

+ +
+
diff --git a/awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.js b/awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.js new file mode 100644 index 00000000000..25264cdbc9b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.js @@ -0,0 +1,18 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + static props = { + slots: { + type :Object, + shape:{ + default:Object + } + }, + size: { + type: Number, + default: 1, + optional: true + } + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.xml b/awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.xml new file mode 100644 index 00000000000..fbd5b91d8ee --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/DashboardItem/DashboardItem.xml @@ -0,0 +1,8 @@ + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.js b/awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.js new file mode 100644 index 00000000000..141834ad87b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.js @@ -0,0 +1,9 @@ +import { Component, onWillStart, useState} from "@odoo/owl"; +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static components = { }; + static props = { + title: {type : String, optional: true}, + value: { type: Number, optional: true} + }; +} diff --git a/awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.xml b/awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.xml new file mode 100644 index 00000000000..7f07c6158c3 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.xml @@ -0,0 +1,9 @@ + + + +
+

+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/PieChart/PieChart.js b/awesome_dashboard/static/src/dashboard/PieChart/PieChart.js new file mode 100644 index 00000000000..6f5fa67f325 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/PieChart/PieChart.js @@ -0,0 +1,89 @@ +import { loadJS } from "@web/core/assets"; +import { useService } from "@web/core/utils/hooks"; +import { Component, onWillStart, useRef,onMounted,onPatched,onWillUnmount} from "@odoo/owl"; + +export class PieChart extends Component +{ + static template = "awesome_dashboard.PieChart" + static props = { + label : String, + data : {type : Object, optional: true}, + } + setup() + { + this.canvasRef = useRef("canvas"); + this.action = useService("action"); + onWillStart(()=> loadJS("/web/static/lib/Chart/Chart.js")) + + onMounted(()=> {this.renderChart();}); + + onPatched(() =>{ + this.chart.destroy(); + this.renderChart(); + }); + + onWillUnmount(()=> {this.chart.destroy();}); + } + + renderChart() + { + this.chart = new Chart(this.canvasRef.el, + { + type: 'doughnut', + data:{ + labels:Object.keys(this.props.data), + datasets: [ + { + data: Object.values(this.props.data), + label: this.props.label + } + ] + }, + options: { + responsive: true, + onClick: (e) =>{ + const activePoints = this.chart.getElementsAtEventForMode(e, 'nearest', { + intersect: true + }, false); + if (activePoints.length > 0) { + const index = activePoints[0].index; + const label = this.chart.data.labels[index]; + const value = this.chart.data.datasets[0].data[index]; + this.onClick(label) + } + } + // events: ['click'], + }, + // plugins: [{ + // id: 'custome_plugin', + // afterEvent(chart, args, pluginOptions) + // { + // // this.onClick(chart.tooltip.title) + // console.log(args); + // import { useService } from "@web/core/utils/hooks"; + // this.action = useService("action"); + // // this.action.doAction(({ + // // type: 'ir.actions.act_window', + // // name: "All leads", + // // res_model: 'account.move', + // // views: [[0,'list'],[1,'form']] + // // })); + // } + // }] + + }); + + } + onClick(title) + { + this.action.doAction(({ + type: 'ir.actions.act_window', + name: "Sales Order", + res_model: 'sale.order', + //domain: [["order_line.product_id.name", "=", "Shirt"]], + domain: [["order_line.product_id.product_template_variant_value_ids.product_attribute_value_id.display_name", "=", title]], + views: [[0,'list'],[1,'form']] + })); + } + +} diff --git a/awesome_dashboard/static/src/dashboard/PieChart/PieChart.xml b/awesome_dashboard/static/src/dashboard/PieChart/PieChart.xml new file mode 100644 index 00000000000..b7ce5002417 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/PieChart/PieChart.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.js b/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.js new file mode 100644 index 00000000000..ad51eb0a2f1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.js @@ -0,0 +1,38 @@ +import { Component, useState} from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { registry } from "@web/core/registry"; +import { browser } from "@web/core/browser/browser"; +import {CheckBox} from "@web/core/checkbox/checkbox"; + +export class SettingsDialog extends Component +{ + static template = "awesome_dashboard.SettingsDialog"; + static components = {Dialog, CheckBox} + static props = ['close','disabled','items','OnChange']; + + setup() + { + console.log(this.props.disabled); + this.items = useState(this.props.items.map((item) => + { + return { + ...item, + enabled: !this.props.disabled.includes(item.id), + } + })) + } + done() + { + this.props.close(); + } + onChange(state, item) + { + item.enabled = state; + const updateDisabled = Object.values(this.items).filter( + (item) => !item.enabled + ).map((item) => item.id) + + browser.localStorage.setItem("disabledDashboardItems",updateDisabled); + this.props.OnChange(updateDisabled); + } +} diff --git a/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml b/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml new file mode 100644 index 00000000000..4c08bedbf6e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml @@ -0,0 +1,18 @@ + + + + + + +
+ + + +
+
+ + + +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..5ef0315908c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,55 @@ +import {_t } from "@web/core/l10n/translation"; +import { Component, onWillStart, 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 { SettingsDialog } from "./SettingsDialog/SettingsDialog"; +import { browser } from "@web/core/browser/browser"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout , DashboardItem, PieChart}; + + setup() + { + this.action = useService("action"); + this.result = useState(useService("awesome_dashboard.statistics")); + this.items = registry.category("awesome_dashboard").getAll(); + this.dialog = useService("dialog"); + this.state = useState({disabledItems : browser.localStorage.getItem("disabledDashboardItems")?.split(",")||[]}); + this.Customer = _t("Customer"); + this.Leads = _t("Leads"); + + } + openCustomers() + { + this.action.doAction("base.action_partner_form") + } + openLeads() + { + this.action.doAction(({ + type: 'ir.actions.act_window', + name: "All leads", + res_model: 'account.move', + views: [[0,'list'],[1,'form']] + })); + } + openSettings() + { + this.dialog.add(SettingsDialog, { + disabled:this.state.disabledItems, + items:this.items, + OnChange:this.updateSettings.bind(this), + }) + } + updateSettings(disabledItems) + { + this.state.disabledItems = disabledItems; + } +} + + +registry.category("lazy_components").add("AwesomeDashboard", 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..e4b262386de --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,11 @@ +.o_dashboard{ + background-color: rgb(255, 209, 122); + +} +.o_text{ + align-self: center; +} +.o_settings_text +{ + padding-left: 15px; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..e01b2d53972 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,29 @@ + + + + + +
+ + +
+
+ + + +
+ + + + + + +
+ +
+ +
+ +
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..6ef037b79bf --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,74 @@ +import { _t } from "@web/core/l10n/translation"; +import { ChartCard } from "./ChartCard/ChartCard"; +import { NumberCard } from "./NumberCard/NumberCard"; +import { registry } from "@web/core/registry"; + +const items = [ + { + id:"avg_amount", + description: _t("Average amount of t-shirt by order this month"), + Component : NumberCard, + size: 35, + props: (data) => ({ + title: _t("Average amount of t-shirt by order this month"), + value: data.average_quantity, + }) + }, + { + id:"avg_time", + description: _t("Average time for an order"), + Component : NumberCard, + size: 35, + props: (data) => ({ + title: _t("Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’"), + value: data.average_time + }) + }, + { + id:"nb_cancelled_orders", + description: _t("Number of cancelled orders this month"), + Component : NumberCard, + size: 25, + props: (data) => ({ + title: _t("Number of cancelled orders this month"), + value: data.nb_cancelled_orders + }) + }, + { + id:"nb_new_orders", + description: _t("Number of new orders this month"), + Component : NumberCard, + props: (data) => ({ + title: _t("Number of new orders this month"), + value: data.nb_new_orders + }) + }, + { + id:"total_amount", + description: _t("Total amount of new orders this month"), + Component : NumberCard, + size: 45, + props: (data) => ({ + title: _t("Total amount of new orders this month"), + value: data.total_amount + }) + }, + { + id:"orders_by_size", + description: _t("Shirt by size"), + Component : ChartCard, + size: 25, + props: (data) => ({ + title: _t("Shirt by size"), + label : _t("Shirt by size"), + data : data.orders_by_size, + }) + }, +] +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); + + + + diff --git a/awesome_dashboard/static/src/dashboard/statistics.js b/awesome_dashboard/static/src/dashboard/statistics.js new file mode 100644 index 00000000000..25d2fe89ba0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics.js @@ -0,0 +1,20 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +const statistics = { + dependencies: [], + start(env) { + + const ret = reactive({isReady:false}) + async function loadStatistics() + { + Object.assign(ret, await rpc("/awesome_dashboard/statistics"), {isReady:true}); + } + setInterval(loadStatistics,1000*60*10); + + loadStatistics(); + return ret; + } + }; + registry.category("services").add("awesome_dashboard.statistics",statistics) diff --git a/awesome_dashboard/static/src/dashboard_acion.js b/awesome_dashboard/static/src/dashboard_acion.js new file mode 100644 index 00000000000..08177a7f50c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_acion.js @@ -0,0 +1,12 @@ +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +export class DashboardLoader extends Component { + static components = { LazyComponent}; + static template = xml` + + `; +} + +registry.category("actions").add("awesome_dashboard.dashboard", DashboardLoader); diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index fdd7d6d576e..1e27b46156b 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,7 @@ import { Component, useState, markup } from "@odoo/owl"; import { Counter } from "./counter/counter"; import { Card } from "./card/card"; -import { TodoList } from "./TodoList/TodoList" +import { TodoList } from "./TodoList/TodoList"; export class Playground extends Component { static template = "awesome_owl.playground"; From 23c251901b4b79a6339450ab02dbbbee223cb94d Mon Sep 17 00:00:00 2001 From: VincentJanssen-Code Date: Tue, 23 Dec 2025 13:18:33 +0100 Subject: [PATCH 4/4] [IMP] awesome_clicker: Web Framework Master Chapter 1 Finish Part 1-10 --- awesome_clicker/__init__.py | 1 - .../static/src/click_value/click_value.js | 18 +++++++++ .../static/src/click_value/click_value.xml | 6 +++ .../static/src/clicker_hook/clicker_hook.js | 6 +++ .../static/src/clicker_model/clicker_model.js | 40 +++++++++++++++++++ .../src/clicker_service/clicker_service.js | 29 ++++++++++++++ .../clicker_systray_item.js | 30 ++++++++++++++ .../clicker_systray_item.xml | 11 +++++ .../static/src/client_action/client_action.js | 25 ++++++++++++ .../src/client_action/client_action.xml | 17 ++++++++ .../SettingsDialog/SettingsDialog.xml | 2 +- 11 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 awesome_clicker/static/src/click_value/click_value.js create mode 100644 awesome_clicker/static/src/click_value/click_value.xml create mode 100644 awesome_clicker/static/src/clicker_hook/clicker_hook.js create mode 100644 awesome_clicker/static/src/clicker_model/clicker_model.js create mode 100644 awesome_clicker/static/src/clicker_service/clicker_service.js create mode 100644 awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js create mode 100644 awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml create mode 100644 awesome_clicker/static/src/client_action/client_action.js create mode 100644 awesome_clicker/static/src/client_action/client_action.xml diff --git a/awesome_clicker/__init__.py b/awesome_clicker/__init__.py index 40a96afc6ff..e69de29bb2d 100644 --- a/awesome_clicker/__init__.py +++ b/awesome_clicker/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/awesome_clicker/static/src/click_value/click_value.js b/awesome_clicker/static/src/click_value/click_value.js new file mode 100644 index 00000000000..1b61e9345b7 --- /dev/null +++ b/awesome_clicker/static/src/click_value/click_value.js @@ -0,0 +1,18 @@ +import { humanNumber } from "@web/core/utils/numbers"; +import { Component} from "@odoo/owl"; +import { useClicker } from "../clicker_hook/clicker_hook"; + +export class ClickValue extends Component { + static template = "awesome_clicker.click_value"; + static components = { }; + + setup() + { + this.clicker = useClicker(); + console.log(this.clicker.clicks); + } + get humanClicks(){ + return humanNumber(this.clicker.clicks, {decimals: 1,}) + } + +} diff --git a/awesome_clicker/static/src/click_value/click_value.xml b/awesome_clicker/static/src/click_value/click_value.xml new file mode 100644 index 00000000000..64063e31181 --- /dev/null +++ b/awesome_clicker/static/src/click_value/click_value.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/awesome_clicker/static/src/clicker_hook/clicker_hook.js b/awesome_clicker/static/src/clicker_hook/clicker_hook.js new file mode 100644 index 00000000000..231d86736a1 --- /dev/null +++ b/awesome_clicker/static/src/clicker_hook/clicker_hook.js @@ -0,0 +1,6 @@ +import { useService } from "@web/core/utils/hooks"; +import { useState } from "@odoo/owl"; + +export function useClicker() { + return useState(useService("awesome_clicker.clicker_service")); +} diff --git a/awesome_clicker/static/src/clicker_model/clicker_model.js b/awesome_clicker/static/src/clicker_model/clicker_model.js new file mode 100644 index 00000000000..189efa4fa26 --- /dev/null +++ b/awesome_clicker/static/src/clicker_model/clicker_model.js @@ -0,0 +1,40 @@ +import { Reactive } from "@web/core/utils/reactive"; +import {EventBus} from "@odoo/owl"; + + +export class ClickerModel extends Reactive{ + constructor() + { + super(); + this.clicks = 0; + this.level = 0; + this.clickBots = 0; + this.levelupEvent = new EventBus(); + } + + tick(){ + this.addClicks(this.clickBots * 10); + } + + addClicks(val) + { + if(this.clicks >= 100 && this.level == 0) + { + this.level = 1; + this.levelupEvent.trigger("MILESTONE1K"); + } + this.clicks+= val; + } + + buyClickerBot() + { + const botPrice = 100; + if (this.clicks < botPrice) + { + return false; + } + this.clicks -= botPrice; + this.clickBots ++; + + } +} diff --git a/awesome_clicker/static/src/clicker_service/clicker_service.js b/awesome_clicker/static/src/clicker_service/clicker_service.js new file mode 100644 index 00000000000..949aa8e1bc0 --- /dev/null +++ b/awesome_clicker/static/src/clicker_service/clicker_service.js @@ -0,0 +1,29 @@ +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; +import { reactive } from "@odoo/owl"; +import { ClickerModel } from "../clicker_model/clicker_model"; + +const clicker_service = { + dependencies: ["effect"], + start(env, services) + { + const model = new ClickerModel(); + + setInterval(() => + { + model.tick(); + }, + 10000); + + document.addEventListener("click",() => model.addClicks(1),true); + model.levelupEvent.addEventListener("MILESTONE1K",()=>{ + services.effect.add({type: "rainbow_man",message:"You just leveled up your clicker level"}); + }) + + return model; + + }, + +}; + +registry.category("services").add("awesome_clicker.clicker_service",clicker_service) diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js new file mode 100644 index 00000000000..b655720ed3b --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js @@ -0,0 +1,30 @@ +import { Component, onWillStart, useState, useExternalListener} from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; +import { useClicker } from "../clicker_hook/clicker_hook"; +import { ClickValue } from "../click_value/click_value"; + +class ClickerSystrayItem extends Component { + static template = "awesome_clicker.clicker_systray_item"; + static components = {ClickValue }; + + setup() + { + this.action = useService("action"); + } + onOpen() + { + this.action.doAction({ + type: "ir.actions.client", + tag: "awesome_clicker.client_action", + target: "new", + name: "Clicker" + }) + } + + +} +export const sysItem = { + Component: ClickerSystrayItem +} +registry.category("systray").add("awesome_clicker.clickerSystrayItem",sysItem, {sequence:10000}) diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml new file mode 100644 index 00000000000..1095c9b11e2 --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml @@ -0,0 +1,11 @@ + + + +
+ Clicks: + +
+
+
diff --git a/awesome_clicker/static/src/client_action/client_action.js b/awesome_clicker/static/src/client_action/client_action.js new file mode 100644 index 00000000000..ee99e78a45a --- /dev/null +++ b/awesome_clicker/static/src/client_action/client_action.js @@ -0,0 +1,25 @@ +import { Component, useState } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; +import { ClickValue } from "../click_value/click_value"; + +class ClientAction extends Component { + static template = "awesome_clicker.client_action"; + static components = { ClickValue}; + + setup() + { + this.clicker = useService("awesome_clicker.clicker_service"); + } + + onClick() + { + this.clicker.addClicks(9); + } + + buyBot() + { + this.clicker.buyClickerBot(); + } +} +registry.category("actions").add("awesome_clicker.client_action",ClientAction) diff --git a/awesome_clicker/static/src/client_action/client_action.xml b/awesome_clicker/static/src/client_action/client_action.xml new file mode 100644 index 00000000000..99c72594755 --- /dev/null +++ b/awesome_clicker/static/src/client_action/client_action.xml @@ -0,0 +1,17 @@ + + + +
+ Clicks : + +
+ +
+

BOTS :

+
x ClickBots (10clicks/10 second)
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml b/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml index 4c08bedbf6e..05db77169a4 100644 --- a/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml +++ b/awesome_dashboard/static/src/dashboard/SettingsDialog/SettingsDialog.xml @@ -10,7 +10,7 @@
- +