diff --git a/.gitignore b/.gitignore index b6e47617de1..fbc0c865e38 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# Not functionnal +estate/security/security.xml diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..cb9e4e5da40 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,12 @@ +import { Component } from "@odoo/owl"; + + +export class Card extends Component { + static template = "awesome_owl.card"; + + static props = { + title: {type: String,}, + content: {type: String,}, + }; + +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..8c780989abb --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,13 @@ + + + + +
+
+
+

+
+
+
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..8a5fbe88497 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,20 @@ +import { Component, useState } from "@odoo/owl"; + + +export class Counter extends Component { + static template = "awesome_owl.counter"; + + static props = { + onChange: {type: Function, optional: true,}, + }; + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + if (typeof this.props.onChange === "function") + 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..6c7b5ceeb2c --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,12 @@ + + + + +
+ hello world +

Counter:

+ +
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..d004616a5d0 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,27 @@ -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 "./todo/todo_list"; +import { TodoItem } from "./todo/todo_item"; + + +const exampleHtml = "
some content
"; export class Playground extends Component { static template = "awesome_owl.playground"; + + static components = { Counter, Card, TodoItem, TodoList }; + // static components = {Counter, Card}; + + html = exampleHtml; + markupHtml = markup(exampleHtml); + + setup() { + this.state = useState({ sum: 0 }); + } + + onChange(){ + this.state.sum ++; + } + } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..e5817774175 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,9 +2,24 @@ -
- hello world + + + + + + + + + +
+ + +

The sum is:

+ + + + diff --git a/awesome_owl/static/src/todo/todo_item.js b/awesome_owl/static/src/todo/todo_item.js new file mode 100644 index 00000000000..603b1ab4ac2 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,17 @@ +import { Component } from "@odoo/owl"; + + +export class TodoItem extends Component { + + static template = "awesome_owl.todo_item"; + + static props = { + todo: {type: Object, + shape: { + id: Number, + description: String, + isCompleted: Boolean, + }, + }, + }; +} diff --git a/awesome_owl/static/src/todo/todo_item.xml b/awesome_owl/static/src/todo/todo_item.xml new file mode 100644 index 00000000000..89cedde61c2 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,10 @@ + + + + +
+ . +
+
+ +
diff --git a/awesome_owl/static/src/todo/todo_list.js b/awesome_owl/static/src/todo/todo_list.js new file mode 100644 index 00000000000..67d5b45798e --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -0,0 +1,25 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todo_item" + + +export class TodoList extends Component { + static template = "awesome_owl.todo_list"; + + static components = { TodoItem }; + + todos = useState([]); + + setup() { + this.state = useState({ id_counter: 0 }); + } + + + addTodo(ev){ + if (ev.keyCode === 13 && ev.target.value !== ""){ + this.todos.push({ id: this.state.id_counter, description: ev.target.value, isCompleted: false }); + this.state.id_counter++; + ev.target.value = ""; + } + } + +} diff --git a/awesome_owl/static/src/todo/todo_list.xml b/awesome_owl/static/src/todo/todo_list.xml new file mode 100644 index 00000000000..ab89be87a52 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,20 @@ + + + + +
+
+ +
+ + + +
+
+ +
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..fffad6b4e40 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': 'Real estate', + 'author': 'anden', + 'license': 'LGPL-3', + 'depends': ['base'], + 'category': 'Real Estate/Brokerage', + 'application': True, + 'data': [ + # 'security/security.xml', + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + ] +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..d7ceb496724 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import property +from . import property_type +from . import property_tag +from . import property_offer +from . import res_users diff --git a/estate/models/property.py b/estate/models/property.py new file mode 100644 index 00000000000..1768ee6cfdf --- /dev/null +++ b/estate/models/property.py @@ -0,0 +1,106 @@ +from odoo import api, fields, models, exceptions +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = 'estate_property' + _description = 'estate property' + _order = "id desc" + + name = fields.Char(string='Title', required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date(string='Available From', copy=False, default=fields.Date.add(fields.Date.today(), months=3)) + expected_price = fields.Float(required=True) + + _check_expected_price = models.Constraint( + 'CHECK(0 < expected_price)', + 'A property expected price must be strictly positive') + + selling_price = fields.Float(readonly=True, copy=False) + + _check_selling_price = models.Constraint( + 'CHECK(0 <= selling_price)', + 'A property selling price must be positive') + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + if not float_is_zero(record.selling_price, 2): + if float_compare(record.selling_price, 0.9 * record.expected_price, 2) == -1: + raise exceptions.ValidationError("The selling price cannot be lower than 90% of the expected price.") + + bedrooms = fields.Integer(default=2) + living_area = fields.Integer(string='Living Area (sqm)') + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer(string='Garden Area (sqm)') + garden_orientation = fields.Selection(selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')]) + active = fields.Boolean(default=True) + state = fields.Selection( + string='Status', + selection=[ + ('new', 'New'), + ('offer received', 'Offer Received'), + ('offer accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled') + ], + required=True, + copy=False, + default='new', + ) + property_type_id = fields.Many2one('estate_property_type', string='Property Type') + salesperson = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user) + buyer = fields.Many2one('res.partner', copy=False) + property_tag_id = fields.Many2many('estate_property_tag', string='Property Tag') + property_offer_id = fields.One2many('estate_property_offer', 'property_id', string='Property Offer') + total_area = fields.Float(string='Total Area (sqm)', compute='_compute_area') + best_price = fields.Float(string='Best offer', compute='_compute_best_price') + + @api.depends('living_area', 'garden_area') + def _compute_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends('property_offer_id.price') + def _compute_best_price(self): + for record in self: + record.best_price = max(record.property_offer_id.mapped('price'), default=False) + + @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 = False + + def action_property_sold(self): + if self.state == 'cancelled': + raise exceptions.UserError('Cancelled properties cannot be sold') + else: + self.state = 'sold' + + def action_property_cancel(self): + if self.state == 'sold': + raise exceptions.UserError('Sold properties cannot be cancelled') + else: + self.state = 'cancelled' + + @api.onchange('property_offer_id') + def _onchange_property_offer_id(self): + for record in self: + if len(record.property_offer_id) > 0: + if record.state == 'new': + record.state = 'offer received' + elif record.state != 'cancelled': + record.state = 'new' + + @api.ondelete(at_uninstall=False) + def _unlink_for_specific_state(self): + if any(record.state not in ('new', 'cancelled') for record in self): + raise exceptions.UserError('Can\'t delete a property if its state is not \'New\' or \'Cancelled\'') diff --git a/estate/models/property_offer.py b/estate/models/property_offer.py new file mode 100644 index 00000000000..a91dd8ba190 --- /dev/null +++ b/estate/models/property_offer.py @@ -0,0 +1,65 @@ +from odoo import api, fields, models, exceptions + + +class EstatePropertyOffer(models.Model): + _name = 'estate_property_offer' + _description = 'estate property offer' + _order = "price desc" + + price = fields.Float() + status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refused')], copy=False, readonly=True) + partner_id = fields.Many2one('res.partner', required=True, string='Partner') + property_id = fields.Many2one('estate_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("estate_property_type", related="property_id.property_type_id", store=True, string="Property Type") + + @api.depends('create_date', 'validity') + def _compute_deadline(self): + for record in self: + if record.create_date: + record.date_deadline = fields.Date.add(record.create_date.date(), days=record.validity) + else: + record.date_deadline = fields.Date.add(fields.Date.today(), days=record.validity) # If no create_date we take the date of today + + def _inverse_deadline(self): + for record in self: + if record.create_date: + record.validity = (record.date_deadline - record.create_date.date()).days + else: + record.validity = (record.date_deadline - fields.Date.today()).days # If no create_date we take the date of today + + def action_status_accepted(self): + + if len(self) > 1: + raise exceptions.UserError('Only one offer can be accepted') + + if self.status != 'accepted' and 'accepted' in self.mapped('property_id.property_offer_id.status'): + raise exceptions.UserError('Another offer is already accepted') + + self.status = 'accepted' + self.property_id.selling_price = self.price + self.property_id.buyer = self.partner_id + self.property_id.state = 'offer accepted' + + def action_status_refused(self): + for record in self: + if record.status == 'accepted': + record.property_id.selling_price = False + record.property_id.buyer = False + record.property_id.state = 'offer received' + record.status = 'refused' + + _check_offer_price = models.Constraint( + 'CHECK(0 < price)', + 'An offer price must be strictly positive') + + @api.model + def create(self, vals_list): + + for vals in vals_list: + max_existing_price = max((offer.price for offer in self.env['estate_property'].browse(vals_list[0]['property_id']).property_offer_id), default=0) + if vals['price'] < max_existing_price: + raise exceptions.UserError('The offer must be higher than ' + str(max_existing_price)) + + return super().create(vals_list) diff --git a/estate/models/property_tag.py b/estate/models/property_tag.py new file mode 100644 index 00000000000..1574df8ecb3 --- /dev/null +++ b/estate/models/property_tag.py @@ -0,0 +1,15 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate_property_tag' + _description = 'estate property tag' + _order = "name" + + name = fields.Char(required=True) + color = fields.Integer("Color Index") + + _name_uniq = models.Constraint( + 'unique (name)', + "A property tag name must be unique", + ) diff --git a/estate/models/property_type.py b/estate/models/property_type.py new file mode 100644 index 00000000000..314c4758009 --- /dev/null +++ b/estate/models/property_type.py @@ -0,0 +1,22 @@ +from odoo import fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate_property_type' + _description = 'estate property type' + _order = "sequence, name" + + name = fields.Char(string='Type', required=True) + sequence = fields.Integer('Sequence', default=1) + property_ids = fields.One2many('estate_property', 'property_type_id') + offer_ids = fields.One2many('estate_property_offer', 'property_type_id') + offer_count = fields.Integer(compute='_compute_offer_count') + + _name_uniq = models.Constraint( + 'unique (name)', + "A property type name must be unique", + ) + + 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..bf36b7e9eb4 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _name = 'res.users' + _inherit = ["res.users"] + + property_ids = fields.One2many('estate_property', 'salesperson', domain=[('state', 'in', ('new', 'offer received'))]) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..ca416c8057c --- /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_ir_group_user,ir_group_user,model_estate_property,base.group_user,1,1,1,1 +access_ir_group_user_type,ir_group_user_type,model_estate_property_type,base.group_user,1,1,1,1 +access_ir_group_user_tag,ir_group_user_tag,model_estate_property_tag,base.group_user,1,1,1,1 +access_ir_group_user_offer,ir_group_user_offer,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..28b1018038b --- /dev/null +++ b/estate/views/estate_menus.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..9d868248db3 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,44 @@ + + + + + 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..90b797c73ee --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,137 @@ + + + + + Property action + estate_property + list,kanban,form + {'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_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..8643245b69c --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,19 @@ + + + + + + res_users_view_form_inherit_estate_property + 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..b6c9b519c92 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,9 @@ +{ + "name": "Real estate accounting", + 'author': 'anden', + 'license': 'LGPL-3', + 'depends': ['account', 'estate'], + # 'category': 'Real Estate/Brokerage', + 'data': [ + ] +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..8120b005bb6 --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import property diff --git a/estate_account/models/property.py b/estate_account/models/property.py new file mode 100644 index 00000000000..7023e4b9c14 --- /dev/null +++ b/estate_account/models/property.py @@ -0,0 +1,30 @@ +from odoo import models, exceptions, Command + + +class EstateProperty(models.Model): + _name = 'estate_property' + _inherit = ['estate_property'] + + def action_property_sold(self): + + if self.state != 'offer accepted': + raise exceptions.UserError('An offer should be accepted') + + self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.buyer.id, + 'invoice_line_ids': [ + Command.create({ + 'name': 'Proportionnal fees', + 'quantity': 0.06, + 'price_unit': self.selling_price, + }), + Command.create({ + 'name': 'Administrative fees', + 'quantity': 1.0, + 'price_unit': 100.0, + }) + ], + }) + + return super().action_property_sold()