Chapter 13

This commit is contained in:
Matt Marcha 2024-07-31 14:17:09 -10:00 committed by Matt Marcha
parent fccc44bb2e
commit 8684a4e87e
6 changed files with 59 additions and 4 deletions

View file

@ -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

View file

@ -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:

View file

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View file

@ -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',
}

View file

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import estate_property

View file

@ -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