mirror of
https://github.com/SARL-PACIFIC-ERP/odoo-sh-test.git
synced 2025-06-25 17:42:22 +00:00
Chapter 13
This commit is contained in:
parent
fccc44bb2e
commit
8684a4e87e
|
@ -96,22 +96,18 @@ class EstateProperty(models.Model):
|
||||||
if self.exists():
|
if self.exists():
|
||||||
if self.state == 'cancelled':
|
if self.state == 'cancelled':
|
||||||
raise exceptions.UserError('A cancelled property cannot be sold')
|
raise exceptions.UserError('A cancelled property cannot be sold')
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
self.state = 'sold'
|
self.state = 'sold'
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise exceptions.MissingError('Property not found')
|
raise exceptions.MissingError('Property not found')
|
||||||
return False
|
|
||||||
|
|
||||||
def action_cancel(self):
|
def action_cancel(self):
|
||||||
if self.exists():
|
if self.exists():
|
||||||
if self.state == 'sold':
|
if self.state == 'sold':
|
||||||
raise exceptions.UserError('A sold property cannot be cancelled')
|
raise exceptions.UserError('A sold property cannot be cancelled')
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
self.state = 'cancelled'
|
self.state = 'cancelled'
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise exceptions.MissingError('Property not found')
|
raise exceptions.MissingError('Property not found')
|
||||||
return False
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ class EstatePropertyOffer(models.Model):
|
||||||
"state": "offer_accepted",
|
"state": "offer_accepted",
|
||||||
"selling_price": self.price,
|
"selling_price": self.price,
|
||||||
"buyer_id": self.partner_id.id,
|
"buyer_id": self.partner_id.id,
|
||||||
|
"salesman_id": self.create_uid.id
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
3
estate_account/__init__.py
Normal file
3
estate_account/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
14
estate_account/__manifest__.py
Normal file
14
estate_account/__manifest__.py
Normal 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',
|
||||||
|
}
|
3
estate_account/models/__init__.py
Normal file
3
estate_account/models/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import estate_property
|
38
estate_account/models/estate_property.py
Normal file
38
estate_account/models/estate_property.py
Normal 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
|
Loading…
Reference in a new issue