From 48c6042e6c87889efa1cee4498d4cedecfcada02 Mon Sep 17 00:00:00 2001 From: Matt Marcha Date: Wed, 31 Jul 2024 14:17:09 -1000 Subject: [PATCH] Chapter 13 --- estate/models/estate_property.py | 4 --- estate/models/estate_property_offer.py | 1 + estate_account/__init__.py | 3 ++ estate_account/__manifest__.py | 14 +++++++++ estate_account/models/__init__.py | 3 ++ estate_account/models/estate_property.py | 38 ++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py create mode 100644 estate_account/models/__init__.py create mode 100644 estate_account/models/estate_property.py diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index e9aa90d..f56e904 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -96,22 +96,18 @@ class EstateProperty(models.Model): if self.exists(): if self.state == 'cancelled': raise exceptions.UserError('A cancelled property cannot be sold') - return False else: self.state = 'sold' return True else: raise exceptions.MissingError('Property not found') - return False def action_cancel(self): if self.exists(): if self.state == 'sold': raise exceptions.UserError('A sold property cannot be cancelled') - return False else: self.state = 'cancelled' return True else: raise exceptions.MissingError('Property not found') - return False diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 45f822e..65f81aa 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -60,6 +60,7 @@ class EstatePropertyOffer(models.Model): "state": "offer_accepted", "selling_price": self.price, "buyer_id": self.partner_id.id, + "salesman_id": self.create_uid.id } ) else: diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 0000000..5305644 --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models \ No newline at end of file diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 0000000..963e626 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Real Estate Invoicing', + 'category': 'Accounting', + 'application': True, + 'installable': True, + 'author': 'Matt Marcha', + 'depends': [ + 'estate','account', + ], + 'data': [ + ], + 'license': 'AGPL-3', +} \ No newline at end of file diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 0000000..f2db223 --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import estate_property \ No newline at end of file diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 0000000..01ffa08 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +from odoo import Command, api, models + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_sold(self): + """ + Create an invoice when a property is sold + """ + # Run the parent method first so that nothing is + # invoiced if an error is raised + parent = super().action_sold() + + # If ever this is called on several records + for property in self: + # Prepare the values + vals = { + 'partner_id' : property.buyer_id.id, + 'move_type' : 'out_invoice', + 'invoice_line_ids' : [ + Command.create({ + 'name' : property.name, + 'quantity' : 1.0, + 'price_unit': property.selling_price * 0.6 + }), + Command.create({ + 'name' : "Administrative fees", + 'quantity' : 1.0, + 'price_unit': 100.00 + }), + ], + } + # Create the invoice + self.env['account.move'].create(vals) + + return parent \ No newline at end of file