diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..7a4001509e7 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,20 @@ +import { Component, useState } from "@odoo/owl"; + + +export class Card extends Component { + static template = "awesome_owl.card.card"; + static props = { + title: {type: String}, + slots: { + type: Object, + shape: { + default: {} + } + } + } + + setup() { + this.state = useState({visible: true}) + } + +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..54c5dad547a --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,17 @@ + + + + + +
+ +
+

+ +
+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..199d80ac1d6 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,17 @@ +import { Component, useState } from "@odoo/owl" + + +export class Counter extends Component { + static template = "awesome_owl.counter.counter" + static props = ['onchange?'] + + setup() { + this.counter = useState({ value: 0 }); + } + + increment() { + this.counter.value++; + if(this.props.onchange != null && this.props.onchange != undefined) + this.props.onchange() + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..4e8f007ad01 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,17 @@ + + + +
+ +

Counter:

+ + + +
+
+
diff --git a/awesome_owl/static/src/main.js b/awesome_owl/static/src/main.js index 1aaea902b55..686037c08ec 100644 --- a/awesome_owl/static/src/main.js +++ b/awesome_owl/static/src/main.js @@ -1,12 +1,12 @@ -import { whenReady } from "@odoo/owl"; -import { mountComponent } from "@web/env"; -import { Playground } from "./playground"; +import { whenReady } from "@odoo/owl" +import { mountComponent } from "@web/env" +import { Playground } from "./playground" + const config = { dev: true, name: "Owl Tutorial" -}; +} // Mount the Playground component when the document.body is ready -whenReady(() => mountComponent(Playground, document.body, config)); - +whenReady(() => mountComponent(Playground, document.body, config)) diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..8c25b264355 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,17 @@ -import { Component } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; +import { Counter } from "./counter/counter" +import { Card } from "./card/card" +import { TodoList } from "./todo/list"; + export class Playground extends Component { static template = "awesome_owl.playground"; + static components = {Counter, Card, TodoList} + + setup() { + this.sum = useState({value: 2}) + } + incrementSum() { + this.sum.value += 1 + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..a49b6947032 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,9 +1,26 @@ -
- hello world +
+ + +

SUM is

+
+ +
+ + + + +

hello

+
+
+ +
+

My todo list for this week

+ +
diff --git a/awesome_owl/static/src/todo/item.js b/awesome_owl/static/src/todo/item.js new file mode 100644 index 00000000000..951687b43a3 --- /dev/null +++ b/awesome_owl/static/src/todo/item.js @@ -0,0 +1,7 @@ +import { Component } from "@odoo/owl" + + +export class TodoItem extends Component { + static template = "awesome_owl.todo.item" + static props = ['todo', 'toggleState', 'deleteTodo'] +} diff --git a/awesome_owl/static/src/todo/item.xml b/awesome_owl/static/src/todo/item.xml new file mode 100644 index 00000000000..38f50ae7f23 --- /dev/null +++ b/awesome_owl/static/src/todo/item.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/awesome_owl/static/src/todo/list.js b/awesome_owl/static/src/todo/list.js new file mode 100644 index 00000000000..9848cbd2d6c --- /dev/null +++ b/awesome_owl/static/src/todo/list.js @@ -0,0 +1,33 @@ +import { Component, useState, useRef, onMounted } from "@odoo/owl" +import { TodoItem } from "./item" +import { useAutofocus } from './../utils' + + +export class TodoList extends Component { + static template = "awesome_owl.todo.list" + static components = {TodoItem} + + setup() { + this.todos = useState([]) + useAutofocus('todoInputRef') + } + addTodo(ev) { + if(ev.keyCode == '13' && ev.target.value != '') { + this.todos.push({ + id: this.todos.length + 1, + description: ev.target.value, + isCompleted: false + }) + ev.target.value = '' + } + } + toggleState(id) { + const [res] = this.todos.filter(todo => todo.id == id) + res.isCompleted = !res.isCompleted + + } + deleteTodo(id) { + const [res] = this.todos.filter(todo => todo.id == id) + this.todos.splice(this.todos.indexOf(res), 1) + } +} diff --git a/awesome_owl/static/src/todo/list.xml b/awesome_owl/static/src/todo/list.xml new file mode 100644 index 00000000000..aeaf3e0e71c --- /dev/null +++ b/awesome_owl/static/src/todo/list.xml @@ -0,0 +1,20 @@ + + + + + +
    +
  1. + +
  2. +
+

+ You have tasks to do +

+
+ +
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..9ae78255305 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,12 @@ +import { useRef, onMounted } from "@odoo/owl"; + + +const useAutofocus = (refName) => { + const ref = useRef(refName) + onMounted(() => ref.el.focus()) +} + + +export { + useAutofocus +} \ No newline at end of file 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..53897e50bde --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,17 @@ +{ + 'name': "Estate", + 'version': '1.0', + 'depends': ['base'], + 'author': "GACI Jugurtha (jugac)", + 'application': True, + 'license': 'LGPL-3', + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_menus.xml', + 'views/res_users_views.xml', + ] +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..9a2189b6382 --- /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_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..e01bcab6ca7 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,116 @@ +from odoo import models, api +from odoo.fields import Char, Text, Html, Float, Integer, Date, Boolean, Selection, Many2many, Many2one, One2many +from odoo.tools import float_compare, float_is_zero +from odoo.exceptions import UserError, ValidationError + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate Property" + _order = "id desc" + + name = Char(required=True) + description = Text() + notes = Html() + postcode = Char() + date_availability = Date( + string="Available From", + copy=False, + default=lambda self: Date.add(Date.today(), months=3) + ) + + expected_price = Float(required=True) + selling_price = Float(copy=False) + best_offer = Float(copy=False, compute="_compute_best_offer") + + bedrooms = Integer(default=2) + living_area = Integer(string="Living Area (sqm)") + total_area = Integer( + compute="_compute_total_area", + store=True, + string="Total Area (sqm)", + ) + facades = Integer() + garage = Boolean() + + garden = Boolean() + garden_area = Integer() + garden_orientation = Selection( + selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West') + ] + ) + + active = Boolean(default=True) + state = Selection( + selection=[ + ('new', 'New'), + ('received', 'Offer Received'), + ('accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('canceled', 'Canceled') + ], + default="new" + ) + + # relations + property_type_id = Many2one("estate.property.type") + buyer_id = Many2one("res.partner") + salesman_id = Many2one("res.users", default=lambda self: self.env.user) + tag_ids = Many2many("estate.property.tag") + offer_ids = One2many("estate.property.offer", "property_id") + + @api.depends("living_area", "garden_area") + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends("offer_ids.price") + def _compute_best_offer(self): + for record in self: + record.best_offer = max((offer.price for offer in record.offer_ids), default=0) + + @api.onchange("garden") + def _onchange_garden(self): + if self.garden: + self.garden_area = 10 + self.garden_orientation = "north" + + def action_set_sold(self): + for record in self: + if record.state == 'canceled': + raise UserError('A canceled property cannot be sold') + record.state = 'sold' + return True + + def action_set_canceled(self): + for record in self: + if record.state == 'sold': + raise UserError('A sold property cannot be canceled') + record.state = 'canceled' + return True + + _check_expected_price = models.Constraint( + 'CHECK(expected_price >= 0)', + 'The expected price of the property should be strictly postitive', + ) + + @api.constrains('selling_price') + def _check_selling_price(self): + for record in self.filtered(lambda p: p.state not in ("new", "received")): + + if float_compare(record.selling_price, (record.expected_price * 0.9), 2) < 0: + raise ValidationError("The selling price cannot be lower than 90%% of the expected price") + + if float_is_zero(record.selling_price, 2): + raise ValidationError("The selling price should be positive") + + @api.ondelete(at_uninstall=False) + def _unlink_property(self): + if self.state not in ('new', 'canceled'): + raise UserError("This property can't be deleted") + + return super().unlink() diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..8023c87f61a --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,74 @@ +from odoo import models, api +from odoo.fields import Float, Selection, Integer, Date, Many2one +from odoo.exceptions import UserError + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Estate offers" + _order = "price desc" + + price = Float(required=True) + status = Selection( + selection=[ + ('new', 'New'), + ('refused', 'Refused'), + ('accepted', 'Accepted') + ], + default="new", + copy=False + ) + validity = Integer(default=7) + create_date = Date(default=lambda self: Date.today(), readonly=True) + date_deadline = Date(compute="_compute_date_deadline", inverse="_inverse_validity") + + # relations + partner_id = Many2one("res.partner", required=True) + property_id = Many2one("estate.property", required=True, ondelete="cascade") + property_type_id = Many2one( + related="property_id.property_type_id", + store=True, + ) + + @api.depends("validity", "create_date") + def _compute_date_deadline(self): + for record in self: + record.date_deadline = Date.add(record.create_date, days=record.validity) + + @api.depends("date_deadline") + def _inverse_validity(self): + for record in self: + if record.date_deadline: + record.validity = (record.date_deadline - record.create_date).days + + def action_accept(self): + for record in self: + record.status = 'accepted' + record.property_id.buyer_id = record.partner_id + record.property_id.selling_price = record.price + record.property_id.state = 'accepted' + + return True + + def action_refuse(self): + self.status = 'refused' + return True + + @api.model_create_multi + def create(self, vals_list): + + for offer in self: + if offer.price > vals_list.price: + raise UserError('The offer price should be greater than those already received') + + res = super().create(vals_list) + + if res.property_id.state != 'received': + res.property_id.state = 'received' + + return res + + _check_selling_price = models.Constraint( + 'CHECK(price > 0)', + 'The offer price should be strictly postitive', + ) diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..727965f4b24 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,16 @@ +from odoo import models +from odoo.fields import Char, Integer + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Estate tags" + _order = "name" + + name = Char(required=True) + color = Integer() + + _check_name_is_unique = models.Constraint( + 'unique(name)', + 'The tag name should be unique', + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..d8d0cc9ca03 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,21 @@ +from odoo import models, api +from odoo.fields import Char, Integer, One2many + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate property types" + _order = "sequence, name" + + name = Char(required=True) + sequence = Integer('Sequence', default=1) + + # relations + property_ids = One2many("estate.property", "property_type_id") + offer_ids = One2many("estate.property.offer", "property_type_id") + offer_count = Integer(default=0, 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_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..8b747f48d76 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,12 @@ +from odoo import models +from odoo.fields import One2many + + +class InheritedUser(models.Model): + _inherit = "res.users" + + property_ids = One2many( + comodel_name='estate.property', + inverse_name='salesman_id', + domain="[('state', 'not in', ('sold', 'canceled'))]" + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..9eb29855a32 --- /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_group_user,estate.group.user,model_estate_property,base.group_user,1,1,1,1 +access_estate_type_group_user,estate.type.group.user,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_tag_group_user,estate.tag.group.user,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_offer_group_user,estate.offer.group.user,model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..a2c3b22357b --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..dad61d0126a --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,20 @@ + + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + +
+
+
+
+
diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml new file mode 100644 index 00000000000..e1e2c808b3c --- /dev/null +++ b/estate/views/estate_property_tag_views.xml @@ -0,0 +1,30 @@ + + + + + Property tags + estate.property.tag + list,form + + + + estate.property.tag.list + estate.property.tag + + + + + + + + + estate.property.tag.form + estate.property.tag + +
+ + +
+
+
+
diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..bb7dfba7bd3 --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,81 @@ + + + + + Offers + estate.property.offer + list + [('property_type_id', '=', active_id)] + + + + estate.property.type.offer.list + estate.property.offer + + + + + + + + + + + + Property types + estate.property.type + list,form + + + + estate.property.type.list + estate.property.type + + + + + + + + + + estate.property.type.form + 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..88e743e56c7 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,152 @@ + + + + Create new estate + estate.property + list,form,kanban + {'search_default_available': True} + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + +

+ +

+

+ Expected price : € +

+

+ Selling price : € +

+
+ Best offer so far : + € +
+
+ +
+
+
+
+
+
+ + + estate.property.form + estate.property + +
+
+
+ +

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