mirror of
https://github.com/SARL-PACIFIC-ERP/odoo-sh-test.git
synced 2025-06-25 09:32:22 +00:00
Chapter 13
This commit is contained in:
parent
cb8f699eb1
commit
71c7573902
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
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