diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..e1c6a9461bc --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,24 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + + static props = { + title: {type: String}, + slots: { + type: Object, + shape: { + default: true + }, + } + }; + + setup() { + this.state = useState({open: true}); + this.toggleOpen = this.toggleOpen.bind(this); + } + + toggleOpen() { + this.state.open = !this.state.open; + } +} \ 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..fa037b9aa84 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,14 @@ + + + +
+
+
+ + +
+ +
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..2769a397124 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,20 @@ +import { Component, xml, 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/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..c92f1bfe9c9 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + +
+

Counter:

+ +
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..fb44c90f9f5 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,18 @@ -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 "./todo/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { Card, Counter, TodoList }; + + setup() { + this.state = useState({value: 2}); + this.onChange = this.onChange.bind(this); + } + + onChange() { + this.state.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..0883a56d6e9 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,18 @@ -
- hello world +

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..f4ca7cfd734 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,28 @@ +import { Component, xml, useState } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.todo_item"; + static props = { + item: {type: Object, shape: { + id: {type: Number}, + description: {type: String}, + isCompleted: {type: Boolean, optional: true} + }}, + toggleState: {type: Function}, + removeTodo: {type: Function}, + }; + + setup() { + this.markCompleted = this.markCompleted.bind(this); + this.deleteTask = this.deleteTask.bind(this); + } + + markCompleted() { + this.props.toggleState(this.props.item.id); + } + + deleteTask() { + this.props.removeTodo(this.props.item.id); + } +} + 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..aaf97c057e8 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,15 @@ + + + +
+ +

+ . +

+ +
+
+
\ No newline at end of file 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..f9c1633a397 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -0,0 +1,47 @@ +import {Component, onMounted, toRaw, useRef, useState} from "@odoo/owl"; +import { TodoItem } from "./todo_item"; +import { useAutoFocus } from "../utils"; + +export class TodoList extends Component { + static template = "awesome_owl.todo_list"; + static components = { TodoItem }; + numOfItems = 1; + + setup() { + this.todos = useState([]); + this.state = useState({description: ""}); + + this.addItem = this.addItem.bind(this); + this.toggleState = this.toggleState.bind(this); + this.removeTodo = this.removeTodo.bind(this); + + useAutoFocus("input"); + } + + addItem(ev) { + if (ev.keyCode === 13 && ev.target.value != "") { + this.todos.push( + { + id: this.numOfItems++, + description: ev.target.value, + isCompleted: false, + } + ); + ev.target.value = ""; + } + } + + toggleState(id) { + const index = this.todos.findIndex((todo) => todo.id === id); + if (index >= 0) { + this.todos[index].isCompleted = !this.todos[index].isCompleted; + } + } + + removeTodo(id) { + const index = this.todos.findIndex((todo) => todo.id === id); + if (index >= 0) { + this.todos.splice(index, 1); + } + } +} 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..5d18970ee17 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,23 @@ + + + +
+ +
    +
  • + +
  • +
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..5ce2840f4fe --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { onMounted, useRef } from "@odoo/owl" + +export function useAutoFocus(focusItem) { + const ref = useRef(focusItem); + onMounted(() => { + ref.el.focus() + }) +} \ 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..57b7f13c1af --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,28 @@ +{ + 'name': 'Real Estate', + 'depends': [ + 'base', + ], + 'application': True, + 'installable': True, + 'author': 'Odoo S.A.', + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_view_kanban.xml', + 'views/estate_property_views.xml', + 'views/estate_property_view_list.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_tag_view_list.xml', + 'views/estate_menus.xml', + 'views/estate_property_view_form.xml', + 'views/estate_property_view_search.xml', + 'views/estate_property_type_view_form.xml', + 'views/estate_property_type_view_list.xml', + 'views/estate_property_tag_view_form.xml', + 'views/estate_property_offer_view_list.xml', + 'views/estate_property_offer_view_form.xml', + 'views/estate_res_users_view_form.xml', + ], + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..9fbf2a95ded --- /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 estate_inherited_user diff --git a/estate/models/estate_inherited_user.py b/estate/models/estate_inherited_user.py new file mode 100644 index 00000000000..8096e7e074e --- /dev/null +++ b/estate/models/estate_inherited_user.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class User(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + "estate.property", + "salesperson_id", + string="Related Property", + domain=["|", ("state", "=", "new"), ("state", "=", "received")], + ) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..357aadbde9e --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,137 @@ +from dateutil.relativedelta import relativedelta +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class Property(models.Model): + _name = "estate.property" + _description = "Properties of the real estate" + _order = "id desc" + + name = fields.Char("Title", required=True) + description = fields.Text() + postcode = fields.Char() + + date_availability = fields.Date( + "Available From", copy=False, default=fields.Date.today() + relativedelta(months=3) + ) + + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer("Living Area (sqm)") + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer("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"), + ("received", "Offer Received"), + ("accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled"), + ], + default="new", + required=True, + copy=False, + ) + + property_type_id = fields.Many2one( + "estate.property.type", string="Property Type" + ) + buyer_id = fields.Many2one( + "res.partner", string="Buyer", copy=False + ) + salesperson_id = fields.Many2one( + "res.users", string="Salesperson", default=lambda self: self.env.user + ) + property_tag_ids = fields.Many2many( + "estate.property.tag", string="Property tags" + ) + property_offer_ids = fields.One2many( + "estate.property.offer", "property_id", string="Offers" + ) + + total_area = fields.Integer("Total area", compute="_compute_total_area") + best_price = fields.Float("Best offer", compute="_compute_best_price") + + # constraints + + # Make sure that expected price is positive + _check_expected_price = models.Constraint( + "CHECK(expected_price > 0)", + "Expected price must be positive" + ) + + # Make sure that selling price is positive or equal to zero + _check_selling_price = models.Constraint( + "CHECK(selling_price >= 0)", + "Selling price must be positive or equal to zero" + ) + + @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("property_offer_ids.price") + def _compute_best_price(self): + for record in self: + record.best_price = max(record.property_offer_ids.mapped( + "price")) if record.property_offer_ids else 0 + + @api.onchange("garden") + def _onchange_garden(self): + if not self.garden: + self.garden_orientation = None + self.garden_area = 0 + else: + self.garden_orientation = "north" + self.garden_area = 10 + + def action_cancel_property(self): + for record in self: + if record.state == "sold": + raise UserError("You cannot cancel a sold property") + record.state = "cancelled" + return True + + def action_sell_property(self): + for record in self: + if record.state == "cancelled": + raise UserError("You cannot sell a cancelled property") + record.state = "sold" + return True + + @api.constrains("selling_price", "expected_price") + def _check_expected_to_selling(self): + for record in self: + # if no offer is accepted, then selling price is zero + if float_is_zero(record.selling_price, precision_digits=2): + continue + + if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1: + raise ValidationError( + "The selling price is too low, it has to be at least 90% of expected price") + + # allow to delete only when states are new and cancelled + @api.ondelete(at_uninstall=False) + def _unlink_if_new_or_cancelled(self): + for record in self: + if record.state != "new" and record.state != "cancelled": + raise UserError("Can delete only new or cancelled properties") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..6ffdd721a1c --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,114 @@ +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class PropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Offer for the property" + _order = "price desc" + + price = fields.Float() + status = fields.Selection( + selection=[ + ("accepted", "Accepted"), + ("refused", "Refused"), + ], + copy=False + ) + + partner_id = fields.Many2one( + "res.partner", string="Partner", required=True + ) + property_id = fields.Many2one( + "estate.property", string="Property", required=True + ) + + validity = fields.Integer(default=7) + date_deadline = fields.Date( + "Deadline date", + compute="_compute_deadline_date", + inverse="_inverse_deadline_date", + ) + + property_type_id = fields.Many2one( + related="property_id.property_type_id", + store=True, + ) + + @api.depends("validity", "create_date") + def _compute_deadline_date(self): + for record in self: + valifity_offset = relativedelta(days=record.validity) + creation_date = record.create_date.date() \ + if record.create_date else fields.Date.today() + record.date_deadline = creation_date + valifity_offset + + def _inverse_deadline_date(self): + for record in self: + creation_date = record.create_date.date() \ + if record.create_date else fields.Date.today() + record.validity = (record.date_deadline - creation_date).days + + def action_accept_offer(self): + for record in self: + # check if there is already an accepted offer + exists_accepted_offer = record.search_count( + [ + ("property_id.id", "=", record.property_id.id), + ("status", "=", "accepted") + ], + 1 + ) + if exists_accepted_offer: + raise UserError("You cannot accept multiple offers") + + # Ensure offers for estates with south-facing gardens can only be accepted if above expected price. + if record.property_id.garden_orientation == 'south' and \ + record.price <= record.property_id.expected_price: + raise ValidationError( + "If garden orientation is south, price must be higher than expected one") + + # accept the offer + record.status = "accepted" + record.property_id.state = "accepted" + record.property_id.selling_price = record.price + record.property_id.buyer_id = record.partner_id + return True + + def action_refuse_offer(self): + for record in self: + if record.status == "accepted": + record.property_id.state = "received" + record.property_id.selling_price = 0 + record.property_id.buyer_id = None + record.status = "refused" + return True + + # Make sure that price is positive + _check_price = models.Constraint( + "CHECK(price > 0)", + "Expected price must be positive" + ) + + @api.model + def create(self, vals_list): + for vals in vals_list: + # raise error if creating offer with lower price + exists_higher_offer = self.search_count( + [ + ("property_id.id", "=", vals["property_id"]), + ("price", ">", vals["price"]) + ], + 1 + ) + if exists_higher_offer: + raise UserError("Can't create an offer with a lower price") + + # change status to received + current_property = self.env["estate.property"].browse( + vals["property_id"]) + current_property.state = "received" + + 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..6318382fc55 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,14 @@ +from odoo import fields, models + + +class PropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Property tags (f.e. cozy)" + _order = "name" + + name = fields.Char("Name", required=True) + color = fields.Integer() + + _check_unique = models.Constraint( + "UNIQUE(name)" + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..b7ac9da7977 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,49 @@ +from odoo import api, fields, models + + +class PropertyType(models.Model): + _name = "estate.property.type" + _description = "Type of properties (f.e. house)" + _order = "name" + + name = fields.Char("Name", required=True) + sequence = fields.Integer( + "Sequence", + default=1, + help="Used to order property types." + ) + + _check_unique = models.Constraint( + "UNIQUE(name)" + ) + + property_ids = fields.One2many( + "estate.property", "property_type_id", string="Properties" + ) + + offer_ids = fields.One2many( + "estate.property.offer", + "property_type_id", + string="Offers for this property type", + ) + + offer_count = fields.Integer( + string="Offers", + compute="_compute_total_offers" + ) + + @api.depends("offer_ids") + def _compute_total_offers(self): + for record in self: + record.offer_count = len(self.offer_ids) + + def action_view_offers(self): + action = { + "name": "Offers", + "type": "ir.actions.act_window", + "res_model": "estate.property.offer", + "target": "current", + "view_mode": "list", + "domain": [["property_type_id", "=", self.id]] + } + return action diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..78458c1cb61 --- /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/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..a23ffc3d8ea --- /dev/null +++ b/estate/tests/test_estate_property.py @@ -0,0 +1,46 @@ +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.property_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.property_offer_ids = [Command.create({ + 'price': 475000.0, + 'partner_id': self.test_partner.id, + })] + self.estate.garden = True + self.estate.garden_orientation = 'south' + + with self.assertRaises(ValidationError): + self.estate.property_offer_ids.action_accept_offer() diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..79b0dee3ca7 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_view_form.xml b/estate/views/estate_property_offer_view_form.xml new file mode 100644 index 00000000000..2372c5e7934 --- /dev/null +++ b/estate/views/estate_property_offer_view_form.xml @@ -0,0 +1,21 @@ + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + + + +
+
+
+
\ No newline at end of file diff --git a/estate/views/estate_property_offer_view_list.xml b/estate/views/estate_property_offer_view_list.xml new file mode 100644 index 00000000000..78283731280 --- /dev/null +++ b/estate/views/estate_property_offer_view_list.xml @@ -0,0 +1,23 @@ + + + + estate.property.offer.list + estate.property.offer + + + + + + + + + +

+ +

+ + + + + + + + + + + +
+ +
+
+
\ No newline at end of file diff --git a/estate/views/estate_property_type_view_list.xml b/estate/views/estate_property_type_view_list.xml new file mode 100644 index 00000000000..806ea92c2e5 --- /dev/null +++ b/estate/views/estate_property_type_view_list.xml @@ -0,0 +1,13 @@ + + + + estate.property.type.list + estate.property.type + + + + + + + + \ No newline at end of file diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..8d8012a78aa --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,8 @@ + + + + Property Types + estate.property.type + list,form + + \ No newline at end of file diff --git a/estate/views/estate_property_view_form.xml b/estate/views/estate_property_view_form.xml new file mode 100644 index 00000000000..2cdd9ecb82e --- /dev/null +++ b/estate/views/estate_property_view_form.xml @@ -0,0 +1,59 @@ + + + + estate.property.form + estate.property + +
+
+
+ +

+ +

+ +

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

+
+
+
\ No newline at end of file diff --git a/estate/views/estate_property_view_kanban.xml b/estate/views/estate_property_view_kanban.xml new file mode 100644 index 00000000000..9a87552f659 --- /dev/null +++ b/estate/views/estate_property_view_kanban.xml @@ -0,0 +1,30 @@ + + + + estate.property.kanban + estate.property + + + + + + +
+ +

+ Expected Price: +

+

+ Best Offer: +

+

+ Selling Price: +

+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/estate/views/estate_property_view_list.xml b/estate/views/estate_property_view_list.xml new file mode 100644 index 00000000000..c2f88be852e --- /dev/null +++ b/estate/views/estate_property_view_list.xml @@ -0,0 +1,25 @@ + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/estate/views/estate_property_view_search.xml b/estate/views/estate_property_view_search.xml new file mode 100644 index 00000000000..7918ca110ea --- /dev/null +++ b/estate/views/estate_property_view_search.xml @@ -0,0 +1,26 @@ + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + \ 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..47c63151453 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,9 @@ + + + + Properties + estate.property + list,kanban,form + {'search_default_available': True} + + diff --git a/estate/views/estate_res_users_view_form.xml b/estate/views/estate_res_users_view_form.xml new file mode 100644 index 00000000000..a05153ea3d0 --- /dev/null +++ b/estate/views/estate_res_users_view_form.xml @@ -0,0 +1,15 @@ + + + + inherited.res.users.view.form.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..fd08b37a68a --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,11 @@ +{ + 'name': 'Real Estate Accounting', + 'depends': [ + 'estate', + 'account', + ], + 'application': True, + 'installable': True, + '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..6d3726a0835 --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_account_inherited_property diff --git a/estate_account/models/estate_account_inherited_property.py b/estate_account/models/estate_account_inherited_property.py new file mode 100644 index 00000000000..51f2bfabd52 --- /dev/null +++ b/estate_account/models/estate_account_inherited_property.py @@ -0,0 +1,57 @@ +from odoo import Command, models +from odoo.exceptions import AccessError, UserError + + +class Property(models.Model): + _inherit = "estate.property" + + def _get_default_journal(self): + journal_type = self.env.context.get('journal_type', 'sale') + return self.env['account.journal'].search([ + *self.env['account.journal']._check_company_domain(self.env.company), + ('type', '=', journal_type), + ], limit=1) + + def action_sell_property(self): + # check for permissions + try: + self.env["account.move"].check_access('create') + except AccessError: + raise UserError("You do not have the correct rights") + + # if no buyer, do not invoice + if self.buyer_id is None: + return super().action_sell_property() + + MOVE_TYPE = "out_invoice" + # get journal + journal = self._get_default_journal() + + # create invoice lines + invoice_line_ids = [ + Command.create({ + "name": "Selling price percentage", + "quantity": 1, + "price_unit": self.selling_price * 0.06, + }), + Command.create({ + "name": "Administrative fees", + "quantity": 1, + "price_unit": 100.00, + }), + ] + + # create the invoice values object + invoice_vals = { + "move_type": MOVE_TYPE, + "journal_id": journal.id, + "partner_id": self.buyer_id.id, + "invoice_line_ids": invoice_line_ids, + } + + # make the invoice + self.env["account.move"].sudo().with_context( + default_move_type=MOVE_TYPE).create(invoice_vals) + + # invoke the parent functionality + return super().action_sell_property()