Skip to content

Commit 3e72a2c

Browse files
committed
[ADD] estate: add module for invoicing customers after purchase
Server framework 101: Chapter 13 This will add an `estate_account` module which will automatically create the invoice for the buyer of a property when it is marked as sold [ADD] estate: add module for invoicing customers after purchase Server framework 101: Chapter 13 This will add an `estate_account` module which will automatically create the invoice for the buyer of a property when it is marked as sold
1 parent 085797c commit 3e72a2c

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

estate_account/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

estate_account/__manifest__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'name': 'Estate Account',
3+
'summary': 'Invoice property buyers',
4+
'description': """
5+
Link between real estate management and accounting by invoicing property buyers as part of the "Sever framework 101" tutorial
6+
""",
7+
'author': 'Odoo',
8+
'website': 'https://www.odoo.com',
9+
'version': '0.1',
10+
'application': True,
11+
'installable': True,
12+
'depends': ['estate', 'account'],
13+
'data': [
14+
'security/ir.model.access.csv',
15+
],
16+
'license': 'AGPL-3',
17+
}

estate_account/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import estate_property
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from odoo import Command, fields, models
2+
from odoo.exceptions import AccessError
3+
4+
5+
class EstateProperty(models.Model):
6+
_inherit = 'estate.property'
7+
8+
def action_set_sold(self):
9+
self.ensure_one()
10+
11+
if not self.env['account.move'].check_access_rights('create', False):
12+
try:
13+
self.check_access_rights('write')
14+
self.check_access_rule('write')
15+
except AccessError:
16+
return self.env['account.move']
17+
18+
self.env['account.move'].create(
19+
{
20+
'name': f'INV/PROP/{fields.Date.today().year}/{self.id:05d}',
21+
'move_type': 'out_invoice',
22+
'partner_id': self.buyer_id.id,
23+
'invoice_line_ids': [
24+
Command.create(
25+
{
26+
'name': self.name,
27+
'quantity': 1,
28+
'price_unit': self.selling_price,
29+
}
30+
),
31+
Command.create(
32+
{
33+
'name': '6% Fees',
34+
'quantity': 1,
35+
'price_unit': self.selling_price * 0.06,
36+
}
37+
),
38+
Command.create(
39+
{
40+
'name': 'Adminstrative Fees',
41+
'quantity': 1,
42+
'price_unit': 100.0,
43+
}
44+
),
45+
],
46+
}
47+
)
48+
49+
return super().action_set_sold()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1

0 commit comments

Comments
 (0)