diff --git a/awesome_owl/static/src/components/card/card.js b/awesome_owl/static/src/components/card/card.js new file mode 100644 index 00000000000..c2d8b0caeba --- /dev/null +++ b/awesome_owl/static/src/components/card/card.js @@ -0,0 +1,11 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + + static props = { + title: String, + content : { type: String, optional: true }, + slots: { type: Object, optional: true }, + }; +} diff --git a/awesome_owl/static/src/components/card/card.xml b/awesome_owl/static/src/components/card/card.xml new file mode 100644 index 00000000000..a90461f296a --- /dev/null +++ b/awesome_owl/static/src/components/card/card.xml @@ -0,0 +1,15 @@ + + + +
+
+
+ +
+

+ +

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

Counter Value:

+ +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/components/todo/todo_item.js b/awesome_owl/static/src/components/todo/todo_item.js new file mode 100644 index 00000000000..c218473d1fb --- /dev/null +++ b/awesome_owl/static/src/components/todo/todo_item.js @@ -0,0 +1,12 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + + static props = { + todo: { + type: Object, + shape: { id: Number, description: String, isCompleted: Boolean }, + }, + }; +} \ No newline at end of file diff --git a/awesome_owl/static/src/components/todo/todo_item.xml b/awesome_owl/static/src/components/todo/todo_item.xml new file mode 100644 index 00000000000..2e1badc803f --- /dev/null +++ b/awesome_owl/static/src/components/todo/todo_item.xml @@ -0,0 +1,9 @@ + + + +
+ . +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/components/todo/todo_list.js b/awesome_owl/static/src/components/todo/todo_list.js new file mode 100644 index 00000000000..91467e9d4a8 --- /dev/null +++ b/awesome_owl/static/src/components/todo/todo_list.js @@ -0,0 +1,38 @@ +import { Component, useState, onMounted, useRef} from "@odoo/owl" +import { TodoItem } from "./todo_item"; + +export class TodoList extends Component { + static template = "awesome_owl.todo_list" + static components = { TodoItem }; + + setup() { + // in TodoList + this.todos = useState([ + // { id: 2, description: "write tutorial", isCompleted: true }, + // { id: 3, description: "buy milk", isCompleted: false }, + ]); + this.nextId = 1; + + this.inputRef = useRef("todo-input"); + + onMounted(() => { + this.inputRef.el.focus(); + }) + } + + addTodo(ev) { + if (ev.keyCode == 13) { + const description = ev.target.value.trim(); + + if (description !== "") { + this.todos.push({ + id:this.nextId++, + description: description, + isCompleted: false, + }); + + ev.target.value = ""; + } + } + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/components/todo/todo_list.xml b/awesome_owl/static/src/components/todo/todo_list.xml new file mode 100644 index 00000000000..3dba6336ab1 --- /dev/null +++ b/awesome_owl/static/src/components/todo/todo_list.xml @@ -0,0 +1,22 @@ + + + +
+

My Tasks

+ +
+ +
+ +
+ + + +
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..c542ee41e4a 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,21 @@ -import { Component } from "@odoo/owl"; +import { Component, useState, markup } from "@odoo/owl"; +import { Counter } from "./components/counter/counter" +import { Card } from "./components/card/card"; +import { TodoList } from "./components/todo/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; + + static components = { Counter, Card, TodoList }; + + setup() { + this.html = markup("
some content
"); + + this.state = useState({sum: 2}) + this.incrementSum = this.incrementSum.bind(this); + } + + incrementSum(){ + this.state.sum++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..83c6b084f95 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,9 +2,25 @@ -
- hello world +
+
+ hello world +
+ +
+ + + + + The sum is: +
+ + + + + +
- + 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..d5570b13b92 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,28 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Real Estate', + 'version': '19.0.0.1.0', + 'category': 'Real Estate/Properties', + 'sequence': 15, + 'summary': 'Track leads and close opportunities', + 'website': 'https://www.odoo.com/app/estate', + 'depends': [ + 'base', + ], + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_type_views.xml', + 'views/estate_property_tags_views.xml', + 'views/estate_property_users_views.xml', + 'views/estate_property_offers_views.xml', + 'views/estate_property_views.xml', + 'views/estate_property_menu.xml', + ], + 'demo': [], + 'installable': True, + 'application': True, + 'assets': {}, + 'author': 'Odoo S.A.', + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..d16f45eccd6 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_propery_type +from . import estate_propery_tag +from . import estate_propery_offer +from . import res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..508f9ca895b --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,112 @@ +from odoo import fields, models, api +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + _order = "id desc" + + name = fields.Char(required=True) + description = fields.Text() + postcode = fields.Char() + date_avaibility = fields.Date(string="Date Avaibility") + expected_price = fields.Float() + selling_price = fields.Float() + bedrooms = fields.Integer() + living_area = fields.Integer() + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection( + selection=[ + ("north", "North"), + ("south", "South"), + ("east", "East"), + ("west", "West") + ], + ) + active = fields.Boolean(default=True) + state = fields.Selection( + selection=[ + ("new", "New"), + ("offer received", "Offer Received"), + ("offer accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled") + ], + default="new" + ) + + partner_id = fields.Many2one("res.partner", string="Partner") + user_id = fields.Many2one("res.users", string="Users") + property_type_id = fields.Many2one("estate.property.type", + string="PropType") + property_tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many( + "estate.property.offer", "property_id", string="offers") + total_area = fields.Float(compute="_compute_total") + best_price = fields.Float(compute="_compute_best_price") + + # define constrain + _check_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + 'The expected price must be strictly positive', + ) + + @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", "expected_price") + def _compute_best_price(self): + for record in self: + if record.offer_ids: + record.best_price = max(record.offer_ids.mapped("price")) + else: + record.best_price = 0 + + @api.onchange("garden") + def _onchange_garden(self): + for record in self: + if record.garden: + record.garden_area = 10 + record.garden_orientation = "north" + else: + record.garden_area = 0 + record.garden_orientation = "" + + @api.constrains("expected_price", "selling_price") + def _check_price_offer(self): + for record in self: + if record.selling_price > 0: + if float_is_zero(record.selling_price, precision_rounding=2): + continue + min_price = 0.9 * record.expected_price + # if offer percentage lower then 90% + if float_compare(record.selling_price, min_price, precision_digits=2) == -1: + raise ValidationError( + "The selling price cannot be lower than 90% of the expected price\n" + "You must reduce the expected price if you want to accept this offer" + ) + + def action_sold(self): + for record in self: + if record.state == "cancelled": + raise UserError("Cancelled properties cannot be sold") + record.state = "sold" + + def action_cancel(self): + for record in self: + if record.state == "sold": + raise UserError("Sold properties cannot be cancelled") + record.state = "cancelled" + + @api.ondelete(at_uninstall=False) + def _unlink_if_new_or_canceled(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError("You can only delete new or canceled properties.") diff --git a/estate/models/estate_propery_offer.py b/estate/models/estate_propery_offer.py new file mode 100644 index 00000000000..a3ab31c87b3 --- /dev/null +++ b/estate/models/estate_propery_offer.py @@ -0,0 +1,90 @@ +from odoo import fields, models, api +from odoo.exceptions import UserError, ValidationError +from datetime import datetime, timedelta + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Real Estate Property Offer" + _order = "price desc" + + price = fields.Float() + status = fields.Selection( + selection=[ + ("accepted", "Accepted"), + ("refused", "Refused") + ], + ) + partner_id = fields.Many2one( + "res.partner", string="Partner", required=True) + property_id = fields.Many2one( + "estate.property", required=True) + property_type_id = fields.Many2one("estate.property.type") + deadline = fields.Date( + string="Deadline", + default=datetime.today(), + compute="_compute_validity_days", + inverse="_inverse_deadline", + store=True + ) + validity_days = fields.Integer(default=7) + + _check_expected_price = models.Constraint( + 'CHECK(price > 0)', + 'The price must be strictly positive', + ) + + @api.depends("validity_days") + def _compute_validity_days(self): + for record in self: + if record.deadline and record.validity_days > 0: + record.deadline = record.deadline + timedelta( + days=record.validity_days) + else: + record.deadline = fields.Date.today() + + @api.depends("deadline") + def _inverse_deadline(self): + for record in self: + if record.deadline: + diff = record.deadline - fields.Date.today() + record.validity_days = diff.days + + def accept_offer(self): + for record in self: + if record.status == "accepted": + raise ValidationError("the offer already accepted") + + if record.property_id.garden_orientation == "south" and record.property_id.expected_price > record.price: + raise ValidationError("The south-facing garden can only be accepted if above expected price") + + if record.property_id.selling_price == 0: + record.status = "accepted" + record.property_id.selling_price = record.price + record.property_id.partner_id = record.partner_id + record.property_id.state = "offer accepted" + + def action_refuse_offer(self): + for record in self: + if record.status == "accepted": + raise ValidationError( + "You're not eligible to refused an accepted offer" + ) + record.status = "refused" + + @api.model + def create(self, val_list): + for vals in val_list: + property_id = vals.get('property_id') + + existing_offers = self.search([ + ('property_id', '=', property_id)], + order='price desc', limit=1) + + if existing_offers and vals.get('price', 0) < existing_offers.price: + raise UserError(f"You cannot create an offer lower than {existing_offers.price}.") + + property_record = self.env['estate.property'].browse(property_id) + property_record.state = 'offer received' + + return super().create(val_list) diff --git a/estate/models/estate_propery_tag.py b/estate/models/estate_propery_tag.py new file mode 100644 index 00000000000..e78e66125aa --- /dev/null +++ b/estate/models/estate_propery_tag.py @@ -0,0 +1,15 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Real Estate Property Tag" + _order = "name asc" + + name = fields.Char(required=True) + + color = fields.Integer() + + _check_unique_property_tags = models.Constraint( + 'unique(name)' + ) diff --git a/estate/models/estate_propery_type.py b/estate/models/estate_propery_type.py new file mode 100644 index 00000000000..a2ec0c12e6e --- /dev/null +++ b/estate/models/estate_propery_type.py @@ -0,0 +1,31 @@ +from odoo import fields, models, api + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Real Estate Property Type" + _order = "name asc" + + sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.") + name = fields.Char(required=True) + + property_ids = fields.One2many("estate.property", "property_type_id") + offer_ids = fields.One2many("estate.property.offer", "property_id") + expected_price = fields.Float() + state = fields.Char() + offer_count = fields.Char(compute="_compute_offer") + + @api.depends("offer_ids") + def _compute_offer(self): + for record in self: + record.offer_count = len(record.offer_ids) + + def action_offer(self): + return { + "type": "ir.actions.act_window", + "name": "Propery Offers", + "res_model": "estate.property.offer", + "domain": [("property_id", "=", self.id)], + "view_mode": "list,form", + "context": {"default_property_id": self.id}, + } diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..a387e729ad4 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,6 @@ +from odoo import fields, models + + +class Users(models.Model): + _inherit = "res.users" + property_ids = fields.One2many("estate.property", 'user_id') diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..0c0b62b7fee --- /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 +estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 +estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 +estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 +estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/static/description/icon.png b/estate/static/description/icon.png new file mode 100644 index 00000000000..a02a465d8cc Binary files /dev/null and b/estate/static/description/icon.png differ diff --git a/estate/static/description/icon.svg b/estate/static/description/icon.svg new file mode 100644 index 00000000000..12e8ec084cc --- /dev/null +++ b/estate/static/description/icon.svg @@ -0,0 +1 @@ + diff --git a/estate/static/description/icon_hi.png b/estate/static/description/icon_hi.png new file mode 100644 index 00000000000..7a3f54851c9 Binary files /dev/null and b/estate/static/description/icon_hi.png differ diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..576617cccff --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_estate_property diff --git a/estate/tests/test_estate_property.py b/estate/tests/test_estate_property.py new file mode 100644 index 00000000000..6f6b1d6724b --- /dev/null +++ b/estate/tests/test_estate_property.py @@ -0,0 +1,45 @@ +from odoo.exceptions import ValidationError +from odoo.tests import TransactionCase, tagged +from odoo import Command + + +@tagged('post_install', '-at_install') +class TestEstateProperty(TransactionCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.estate = cls.env['estate.property'].create({ + 'name': 'Super test estate', + 'expected_price': 100000.0, + 'state': 'new', + }) + cls.test_partner = cls.env['res.partner'].create({ + 'name': 'Maman ours', + }) + + def test_estate_best_price(self): + ''' + Ensure best price is correctly updated when an offer is received. + ''' + self.assertEqual(self.estate.best_price, 0.0) + self.estate.offer_ids = [Command.create({ + 'price': 125000.0, + 'partner_id': self.test_partner.id, + })] + self.assertEqual(self.estate.best_price, 125000.0) + + def test_accept_offer_south_facing_garden(self): + ''' + Ensure offers for estates with south-facing gardens can only be accepted if above expected + price. + ''' + self.estate.expected_price = 500000 + self.estate.garden = True + self.estate.garden_orientation = 'south' + self.estate.offer_ids = [Command.create({ + 'price': 475000.0, + 'partner_id': self.test_partner.id, + })] + with self.assertRaises(ValidationError): + self.estate.offer_ids.accept_offer() diff --git a/estate/views/estate_property_menu.xml b/estate/views/estate_property_menu.xml new file mode 100644 index 00000000000..ebb2cd358c3 --- /dev/null +++ b/estate/views/estate_property_menu.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offers_views.xml b/estate/views/estate_property_offers_views.xml new file mode 100644 index 00000000000..eae2502042a --- /dev/null +++ b/estate/views/estate_property_offers_views.xml @@ -0,0 +1,19 @@ + + + + + estate.property_offer.list + estate.property.offer + + + + + + + +
+ + +
+ +

+ +

+ +
+
+ + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_users_views.xml b/estate/views/estate_property_users_views.xml new file mode 100644 index 00000000000..5cc378bd95a --- /dev/null +++ b/estate/views/estate_property_users_views.xml @@ -0,0 +1,17 @@ + + + + + inherited.res.users.view.form.estate + res.users + + + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..c5e52b27903 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,166 @@ + + + + + Property + estate.property + list,kanban,form + {'search_default_active': 1} + +

+ If you need help, ask yourself +

+

+ You need to be strong, go working out +

+

+ don't skip working out +

+
+
+ + estate.properties.list + estate.property + + + + + + + + + + + + + + + + + estate.property.form + estate.property + + +
+
+
+ +
+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +