diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..a84972ac27e --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,21 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + + static props = { + title: { type: String }, + slots: { type: Object }, + // content: { type: String }, removed following 13. Generic Card with slots + } + + setup() { + this.opened = useState({ value: true }); + } + + toggleOpened() { + this.opened.value = !this.opened.value; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..aa2afa46d56 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,19 @@ + + + + +
+
+
+

+ +
+

+ + +

+
+
+
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..fb59480f999 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,23 @@ +/** @odoo-module **/ + +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: 0 }); + } + + increment() { + this.state.value++; + + if (this.props.onChange) { + 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..d3737ead14c --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,13 @@ + + + + +
+
+

Counter:

+ +
+
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..675875be754 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,25 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; +import { Card } from "./card/card"; +import { Counter } from "./counter/counter"; +import { TodoList } from "./todolist/todolist"; export class Playground extends Component { + static components = { Counter, Card, TodoList }; + static template = "awesome_owl.playground"; + + static props = {}; + + html1 = "
some content
"; + html2 = markup("
some content
"); + + 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..5b474706a6f 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,9 +1,23 @@ - +
- hello world + hello world, The sum is +
+
+ + +
+
+ some content + + + + +
+
+
diff --git a/awesome_owl/static/src/todolist/todoitem.js b/awesome_owl/static/src/todolist/todoitem.js new file mode 100644 index 00000000000..64bc072ce0a --- /dev/null +++ b/awesome_owl/static/src/todolist/todoitem.js @@ -0,0 +1,25 @@ +/** @odoo-module **/ + +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, + }, + }, + removeTodo: { type: Function }, + } + + toggleState(ev) { + if (!ev.target) return; + + this.props.todo.isCompleted = ev.target.checked; + } +} diff --git a/awesome_owl/static/src/todolist/todoitem.xml b/awesome_owl/static/src/todolist/todoitem.xml new file mode 100644 index 00000000000..b869f931824 --- /dev/null +++ b/awesome_owl/static/src/todolist/todoitem.xml @@ -0,0 +1,24 @@ + + + + + +
+ . +
+ +
+ +
diff --git a/awesome_owl/static/src/todolist/todolist.js b/awesome_owl/static/src/todolist/todolist.js new file mode 100644 index 00000000000..61c3fff5a1e --- /dev/null +++ b/awesome_owl/static/src/todolist/todolist.js @@ -0,0 +1,56 @@ +/** @odoo-module **/ + +import { Component, useRef, useState } from "@odoo/owl"; +import { useAutofocus } from "../utils"; +import { TodoItem } from "./todoitem"; + +export class TodoList extends Component { + static components = { TodoItem }; + + static template = "awesome_owl.todolist"; + + static props = {}; + + setup() { + this.id = 1; // could be calculated every iteration but would get very slow with a lot of todos + this.todos = useState([ + // removed following 9. Adding a todo + // { id: 2, description: "write tutorial", isCompleted: true }, + // { id: 3, description: "buy milk", isCompleted: false }, + ]); + this.inputRef = useRef("add_task"); + useAutofocus("add_task"); + } + + addTodo(ev) { + if (ev.keyCode != 13) return; + + if (!this.inputRef.el) return; + + const desc = this.inputRef.el.value; + + if (desc === "") return; + + this.todos.push({ + id: this.id, + description: desc, + isCompleted: false, + }); + + this.inputRef.el.value = ""; + this.id++; + } + + removeTodo(ev) { + // is there not a better way ??? this doesn't feel good + const elemId = parseInt(ev.target.parentNode.childNodes[1].childNodes[0].textContent); + + if (elemId < 0 || elemId >= this.id) return; + + const index = this.todos.findIndex((elem) => elem.id === elemId); + if (index >= 0) { + // remove the element at index from list + this.todos.splice(index, 1); + } + } +} diff --git a/awesome_owl/static/src/todolist/todolist.xml b/awesome_owl/static/src/todolist/todolist.xml new file mode 100644 index 00000000000..f3df4b49c7d --- /dev/null +++ b/awesome_owl/static/src/todolist/todolist.xml @@ -0,0 +1,15 @@ + + + + +
+
+ +
+ +
+
+
+
+ +
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..6fc44dbca94 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,11 @@ +/** @odoo-module **/ + +import { useEffect, useRef } from "@odoo/owl"; + +export function useAutofocus(name) { + let ref = useRef(name); + useEffect( + (el) => el && el.focus(), + () => [ref.el] + ); +} 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..09c14ecb8e2 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,26 @@ +{ + 'name': 'Real Estate', + 'summary': """ + Starting module for "Server framework 101" + """, + 'description': """ + Starting module for "Server framework 101" + """, + 'author': 'Odoo', + 'website': 'https://www.odoo.com', + 'license': 'LGPL-3', + 'category': 'Tutorials/Real Estate', + 'version': '0.1', + 'application': True, + 'installable': True, + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_menus.xml', + 'views/res_users_views.xml', + ], + 'depends': ['base'], +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..fea9f441d6d --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_offer +from . import estate_property_tag +from . import estate_property_type +from . import res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..86e8f8192a2 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,104 @@ +from dateutil import relativedelta + +from odoo import _, api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_utils + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate property' + _order = 'id desc' + + name = fields.Char(string='Name of the Property', required=True) + description = fields.Text(string='Description') + postcode = fields.Char(string='Postcode') + date_availability = fields.Date( + string='Available From', + copy=False, + default=fields.Date.today() + relativedelta.relativedelta(months=3), + ) + expected_price = fields.Float(string='Expected Price', required=True) + selling_price = fields.Float(string='Selling Price', readonly=True, copy=False) + bedrooms = fields.Integer(string='Number Bedrooms', default=2) + living_area = fields.Integer(string='Living Area (sqm)') + facades = fields.Integer(string='Facades') + garage = fields.Boolean(string='Garage') + garden = fields.Boolean(string='Garden') + garden_area = fields.Integer(string='Garden Area (sqm)') + garden_orientation = fields.Selection( + string='Garden Orientation', + selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], + ) + active = fields.Boolean(default=True) + state = fields.Selection( + string='State', + selection=[ + ('new', 'New'), + ('received', 'Offer Received'), + ('accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], + required=True, + copy=False, + default='new', + ) + property_type_id = fields.Many2one('estate.property.type', string='Property Type') + users_id = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user) + partner_id = fields.Many2one('res.partner', string='Buyer', readonly=True) + tag_ids = fields.Many2many('estate.property.tag', string='Property Tags') + offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers') + total_area = fields.Integer(string='Total Area (sqm)', compute='_compute_total_area') + best_price = fields.Float(string='Best Offer', compute='_compute_price') + + _sql_constraints = [ + ('check_expected_price', 'CHECK(expected_price > 0)', 'The expected price must strictly be positive.'), + ('check_selling_price', 'CHECK(selling_price >= 0)', 'The selling price must be positive.'), + ] + + @api.ondelete(at_uninstall=False) + def prevent_delete_based_on_state(self): + if any(record.state in {'new', 'cancelled'} for record in self): + raise UserError(_('A new or cancelled property cannot be deleted.')) + + @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_price(self): + for record in self: + record.write({'best_price': max(record.offer_ids.mapped('price'), default=0)}) + + @api.onchange('garden') + def _onchange_garden(self): + if not self.garden: + self.write({'garden_orientation': False, 'garden_area': 0}) + return + + self.write({'garden_area': 10, 'garden_orientation': self.garden_orientation or 'north'}) + + def action_sell(self): + if 'cancelled' in self.mapped('state'): + raise UserError(_('A property cancelled cannot be set as sold.')) + + self.write({'state': 'sold'}) + return True + + def action_cancel(self): + if 'sold' in self.mapped('state'): + raise UserError(_('A property sold cannot be set as cancelled.')) + + self.write({'state': 'cancelled'}) + return True + + @api.constrains('selling_price') + def _check_price(self): + for record in self: + if not record.selling_price: + continue + + if float_utils.float_compare(record.selling_price, record.expected_price * 0.9, precision_rounding=3) == -1: + raise ValidationError(_('The selling cannot be lower than 90% of the expected price.')) diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..bd0ba0227e9 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,78 @@ +from dateutil import relativedelta + +from odoo import _, api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Estate property Offer' + _order = 'price desc' + + price = fields.Float(string='Price', required=True) + status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refused')], copy=False) + partner_id = fields.Many2one('res.partner', string='Buyer', required=True) + property_id = fields.Many2one('estate.property', string='Property', required=True) + validity = fields.Integer(string='Validity (days)', default=7) + date_deadline = fields.Date(string='Deadline', compute='_compute_deadline', inverse='_inverse_deadline') + property_type_id = fields.Many2one( + string='Property Type', + related='property_id.property_type_id', + store=True, + ) + + _sql_constraints = [ + ('check_price', 'CHECK(price > 0)', 'The price must be strictly positive.'), + ] + + @api.model_create_multi + def create(self, vals_list): + properties = { + p.id: p + for p in self.env['estate.property'].browse([e['property_id'] for e in vals_list if e.get('property_id')]) + } + + for vals in vals_list: + property = properties.get(vals.get('property_id'), '') + + if not property: + raise ValidationError(_('Creating an offer without a property is not possible.')) + + if (price := vals.get('price')) and price < property.best_price: + raise UserError(_('An offer cannot have a lower price then an existing offer.')) + + if property.state == 'new': + property.write({'state': 'received'}) + + return super().create(vals_list) + + @api.depends('validity') + def _compute_deadline(self): + for record in self: + create_date = record.create_date or fields.Date.today() + record.write({'date_deadline': create_date + relativedelta.relativedelta(days=record.validity)}) + + def _inverse_deadline(self): + for record in self: + create_date = record.create_date or fields.Date.today() + record.write({'validity': (record.date_deadline - create_date.date()).days}) + + def action_refuse_offer(self): + for record in self: + record.write({'status': 'refused'}) + return True + + def action_accept_offer(self): + for record in self: + if record.property_id.state in {'accepted', 'sold'}: + raise UserError(_('An offer as already been accepted.')) + + record.write({'status': 'accepted'}) + + record.property_id.write({ + 'selling_price': record.price, + 'state': 'accepted', + 'partner_id': record.partner_id, + }) + + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..22d72983627 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,14 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Estate property Tag' + _order = 'name' + + name = fields.Char(string='Name') + color = fields.Integer(string='Color') + + _sql_constraints = [ + ('check_name', 'UNIQUE(name)', 'A tag must be unique.'), + ] diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..aa35238944f --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,22 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Estate property Type' + _order = 'name' + + name = fields.Char(string='Name') + property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties') + sequence = fields.Integer('Sequence', default=1, help='Used to order stages. Lower is better.') + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers') + offer_count = fields.Integer(string='Number of offers', compute='_compute_offer_count') + + _sql_constraints = [ + ('check_name', 'UNIQUE(name)', 'A type must be unique.'), + ] + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.write({'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..bd5d4f5fadd --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class Users(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many( + 'estate.property', + 'users_id', + string='Seller of', + domain=[('state', 'in', ('new', 'received'))], + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..1ea64ff88f9 --- /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_offer,access_estate_property_offer,estate.model_estate_property_offer,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_type,access_estate_property_type,estate.model_estate_property_type,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..d547815f684 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..9e86162fafa --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,34 @@ + + + + Property Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + + estate_property_offer_list + estate.property.offer + + + + + + + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..ade7ecd7cc5 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,149 @@ + + + + Property + estate.property + list,form,kanban + {'search_default_available': True} + + + + estate_property_list + estate.property + + + + + + + + + + + + + + + estate_property_kaban + estate.property + + + + + + + + + +
+ +
Expected Price: +
+
Best Offer: +
+
Selling Price: +
+ +
+
+
+
+ +
+
+ + + estate_property_form + estate.property + +
+
+
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate_property_view_search + estate.property + + + + + + + + + + + + + + + + +
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..637badea298 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + estate.inherited.model.form.inherit + res.users + + + + + + + + + + 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..4ff2c52e17f --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,8 @@ +{ + 'name': 'Real Estate Account', + 'license': 'LGPL-3', + 'category': 'Tutorials/Real Eastate Invoicing', + 'version': '0.1', + 'auto_install': True, + 'depends': ['estate', 'account'], +} 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..7826c9520d9 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,23 @@ +from odoo import Command, models + + +class InheritedEstateProperty(models.Model): + _inherit = 'estate.property' + + def action_sell(self): + res = super().action_sell() + + self.env['account.move'].create({ + 'partner_id': self.partner_id.id, + 'move_type': 'out_invoice', + 'line_ids': [ + Command.create({ + 'name': '6% of the selling price', + 'quantity': 1, + 'price_unit': 0.06 * self.selling_price, + }), + Command.create({'name': 'Administrative fees', 'quantity': 1, 'price_unit': 100.0}), + ], + }) + + return res