Skip to content

Commit 63f21b7

Browse files
committed
[IMP] estate: Added restriction to agent
Given some permission to the managers and given some restriction to the agents.
1 parent 8d01b45 commit 63f21b7

13 files changed

+230
-33
lines changed

estate/__manifest__.py

+29-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
{
2-
'name': 'estate',
3-
'category': 'real estate',
4-
'summary': 'create a estate property',
5-
'website': 'https://www.odoo.com',
6-
'depends': ['base'],
7-
'installable': True,
8-
'application': True,
9-
'license': 'LGPL-3',
10-
'data': [
11-
'security/ir.model.access.csv',
12-
'views/estate_property_views.xml',
13-
'views/estate_property_offer_views.xml',
14-
'views/estate_property_type_views.xml',
15-
'views/estate_property_tags_views.xml',
16-
'views/estate_property_resusers_views.xml',
17-
'views/estate_menus.xml',
18-
'data/estate_property_type_data.xml',
19-
'report/ estate_property_reports.xml',
20-
'report/ estate_property_templates.xml'
2+
"name": "estate",
3+
"category": "real estate",
4+
"category": "Estate/Brokerage",
5+
"summary": "create a estate property",
6+
"website": "https://www.odoo.com",
7+
"depends": ["base"],
8+
"installable": True,
9+
"application": True,
10+
"license": "LGPL-3",
11+
"data": [
12+
"security/security.xml",
13+
"security/ir.model.access.csv",
14+
"views/estate_property_views.xml",
15+
"views/estate_property_offer_views.xml",
16+
"views/estate_property_type_views.xml",
17+
"views/estate_property_tags_views.xml",
18+
"views/estate_property_resusers_views.xml",
19+
"views/estate_menus.xml",
20+
"data/estate_property_type_data.xml",
21+
"report/ estate_property_reports.xml",
22+
"report/ estate_property_templates.xml",
23+
"report/estate_property_offer_templates.xml",
24+
"report/estate_property_resusers_report.xml",
25+
"report/estate_property_resusers_templates.xml",
26+
# "report/estate_property_company_info.xml"
2127
],
22-
'demo':[
23-
'demo/estate_demo_data.xml',
24-
'demo/estate_offer_demo_data.xml',
28+
"demo": [
29+
"demo/estate_demo_data.xml",
30+
"demo/estate_offer_demo_data.xml",
2531
],
26-
}
32+
}

estate/models/estate_property.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class EstateProperty(models.Model):
6767
best_price = fields.Float(string="Best Price", compute="_compute_best_price", store=True)
6868
offer_received = fields.Boolean(string="Offer Received", compute="_compute_offer_received", store=True)
6969
offer_accepted = fields.Boolean(string="Offer Accepted", compute="_compute_offer_accepted", store=True)
70+
user_id = fields.Many2one('res.users', string="Salesperson")
71+
company_id = fields.Many2one(
72+
"res.company",
73+
string="Company",
74+
required=True,
75+
default=lambda self: self.env.company,
76+
)
7077

7178

7279

@@ -123,10 +130,10 @@ def _check_selling_price(self):
123130
if float_is_zero(record.selling_price, precision_rounding=0.01):
124131
continue
125132
min_price = record.expected_price * 0.9
126-
if float_compare(record.selling_price, min_price, precision_rounding=0.01) < 0:
127-
raise ValidationError(
128-
"The selling price cannot be lower than 90% of the expected price."
129-
)
133+
# if float_compare(record.selling_price, min_price, precision_rounding=0.01) < 0:
134+
# raise ValidationError(
135+
# "The selling price cannot be lower than 90% of the expected price."
136+
# )
130137

131138
@api.depends('state')
132139
def _compute_offer_received(self):

estate/report/ estate_property_templates.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<h2>Property Offers Report</h2>
88
<p><strong>Property Name:</strong> <t t-esc="doc.name"/></p>
99
<p><strong>Expected Price:</strong> <t t-esc="doc.expected_price"/></p>
10+
<div id="status"></div>
1011

1112
<t t-if="doc.offer_ids">
1213
<table class="table table-sm">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<odoo>
2+
<template id="report_company_information">
3+
<t t-set="company" t-value="company" />
4+
<div class="company-info" style="margin-bottom:50px;">
5+
<div>
6+
<img
7+
t-if="company.logo"
8+
class="o_company_logo_big"
9+
t-att-src="image_data_uri(company.logo)"
10+
alt="Company Logo"
11+
/>
12+
</div>
13+
<hr />
14+
<div>
15+
<strong t-field="company.name" />
16+
</div>
17+
<div>
18+
<span t-field="company.street" />
19+
</div>
20+
<div>
21+
<span t-field="company.city" />
22+
<span t-field="company.state_id.code" />
23+
<span t-field="company.zip" />
24+
</div>
25+
<div>
26+
<span t-field="company.country_id.name" />
27+
</div>
28+
</div>
29+
</template>
30+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<odoo>
2+
<template id="report_property_offers_table">
3+
<t t-set="offers" t-value="offers" />
4+
<t t-if="offers">
5+
<table class="table">
6+
<thead>
7+
<tr>
8+
<th style="font-weight: bold;">Price</th>
9+
<th style="font-weight: bold;">Partner</th>
10+
<th style="font-weight: bold;">Validity (days)</th>
11+
<th style="font-weight: bold;">Deadline</th>
12+
<th style="font-weight: bold;">Status</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<t t-foreach="offers" t-as="offer">
17+
<tr>
18+
<td>
19+
<span t-field="offer.price" />
20+
</td>
21+
<td>
22+
<span t-field="offer.partner_id" />
23+
</td>
24+
<td>
25+
<span t-field="offer.validity" />
26+
</td>
27+
<td>
28+
<span t-field="offer.date_deadline" />
29+
</td>
30+
<td>
31+
<span t-field="offer.status" />
32+
</td>
33+
</tr>
34+
</t>
35+
</tbody>
36+
</table>
37+
</t>
38+
<t t-else="">
39+
<tr>
40+
<td colspan="5" style="text-align: center; font-style: italic;">
41+
No offers has been made yet :(
42+
</td>
43+
</tr>
44+
</t>
45+
</template>
46+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<odoo>
2+
<record id="action_print_report_by_salesman" model="ir.actions.report">
3+
<field name="name">Real Estate Property List</field>
4+
<field name="model">res.users</field>
5+
<field name="report_type">qweb-pdf</field>
6+
<field name="report_name">estate.report_property_by_salesman</field>
7+
<field name="report_file">estate.report_property_by_salesman</field>
8+
<field name="print_report_name">'Property Report By Salesman'</field>
9+
<field name="binding_model_id" ref="base.model_res_users" />
10+
</record>
11+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
<odoo>
3+
<template id="report_property_by_salesman">
4+
<t t-foreach="docs" t-as="salesman">
5+
<t t-call="web.html_container">
6+
<t t-call="web.external_layout">
7+
<div class="page">
8+
<t t-call="estate.report_company_information">
9+
<t t-set="company" t-value="salesman.company_id" />
10+
</t>
11+
<h1>
12+
<strong>Salesman:</strong>
13+
<span t-field="salesman.display_name" />
14+
</h1>
15+
<div>
16+
<t t-foreach="salesman.property_ids" t-as="property">
17+
<h1>
18+
<span t-field="property.name" />
19+
</h1>
20+
<div>
21+
<strong>Expected Price: </strong>
22+
<span t-field="property.expected_price" />
23+
</div>
24+
<div>
25+
<strong>Status: </strong>
26+
<span t-field="property.state" />
27+
</div>
28+
<t t-call="estate.report_property_offers_table">
29+
<t t-set="offers" t-value="property.mapped('offer_ids')" />
30+
</t>
31+
</t>
32+
</div>
33+
</div>
34+
</t>
35+
</t>
36+
</t>
37+
</template>
38+
</odoo>

estate/security/ir.model.access.csv

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
22
estate.access_property_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1
33
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
44
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1
5-
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
5+
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
6+
access_real_estate_manager,access_real_estate_manager,model_estate_property,estate_group_manager,1,1,1,0
7+
access_real_estate_agent,access_real_estate_agent,model_estate_property,estate_group_user,1,0,0,0
8+
access_type_read_only,access_type_read_only,model_estate_property_type,estate_group_user,1,0,0,0
9+
access_tag_read_only,access_tag_read_only,model_estate_property_tag,estate_group_user,1,0,0,0
10+
access_property_tag_manager,Property Tag - Manager,model_estate_property_tag,estate_group_manager,1,1,1,1
11+
access_property_type_manager,Property Type - Manager,model_estate_property_type,estate_group_manager,1,1,1,1

estate/security/security.xml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="base.module_category_estate_brokerage" model="ir.module.category">
4+
<field name="name"> Estate/Brokerage</field>
5+
</record>
6+
7+
<record id="estate_group_user" model="res.groups">
8+
<field name="name">Real Estate Agent</field>
9+
<field name="category_id" ref="base.module_category_estate_brokerage"/>
10+
</record>
11+
12+
13+
<record id="estate_group_manager" model="res.groups">
14+
<field name="name">Manager</field>
15+
<field name="category_id" ref="base.module_category_estate_brokerage"/>
16+
</record>
17+
<!-- Rule for Real Estate Agents -->
18+
<record id="rule_estate_agent_properties" model="ir.rule">
19+
<field name="name">Agent: Access Own or Unassigned Properties</field>
20+
<field name="model_id" ref="model_estate_property"/>
21+
<field name="groups" eval="[(4, ref('estate_group_user'))]"/>
22+
<field name="domain_force">[
23+
'|', ('user_id', '=', user.id),
24+
('user_id', '=', False),
25+
('company_id', '=', user.company_id.id)
26+
]</field>
27+
28+
</record>
29+
30+
<!-- Rule for Real Estate Managers -->
31+
<record id="rule_estate_manager_access" model="ir.rule">
32+
<field name="name">Manager: Access All Properties</field>
33+
<field name="model_id" ref="model_estate_property"/>
34+
<field name="groups" eval="[(4, ref('estate_group_manager'))]"/>
35+
<field name="domain_force">[(1, '=', 1)]</field>
36+
</record>
37+
38+
</odoo>

estate/views/estate_menus.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<odoo>
33
<menuitem id="estate_menu_root" name="Estate"/>
44
<menuitem id="estate_properties_menu" name="Advertisements" parent="estate_menu_root" action="estate_property_action"/>
5-
<menuitem id="estate_properties_menu_two" name="Settings" parent="estate_menu_root"/>
5+
<menuitem id="estate_properties_menu_two" name="Settings" parent="estate_menu_root" groups="estate.estate_group_manager"/>
66
<menuitem id="estate_property_type_menu" name="Property Types" parent="estate_properties_menu_two" action="estate_property_type_action"/>
77
<menuitem id="estate_property_tag_menu" name="Property Tags" parent="estate_properties_menu_two" action="estate_property_tag_action"/>
88
</odoo>

estate_account/__manifest__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
'name': 'Estate Account',
33
'version': '1.0',
4-
'category': 'Accounting',
4+
'category': 'Estate/Brokerage',
55
'summary': 'Link module between Estate and Account',
66
'description': 'This module links the Estate and Account modules for financial integration.',
7-
'depends': ['estate', 'account'],
8-
'data': [],
7+
'depends': ['estate', 'account' ,'mail',
8+
'spreadsheet_edition',],
9+
'data': [
10+
'report/estate_account_templates.xml'
11+
],
912
'installable': True,
1013
'application': True,
1114
'license': 'LGPL-3',

estate_account/models/estate_property.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class EstateProperty(models.Model):
55

66
def action_sold(self):
77
for record in self:
8-
self.env['account.move'].create({
8+
record.user_id.check_access("create")
9+
self.env['account.move'].sudo().create({
910
'partner_id': record.partner_id.id,
1011
'move_type': 'out_invoice',
1112
'invoice_line_ids': [
@@ -21,3 +22,4 @@ def action_sold(self):
2122
})
2223
]})
2324
return super(EstateProperty, self).action_sold()
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<odoo>
2+
<template id="report_estate_property_invoice" inherit_id="estate.report_property_offers">
3+
<xpath expr="//div[@id='status']" position="inside">
4+
<t t-if="doc.state=='sold'">
5+
<strong>!!! Invoice has already been created !!!</strong>
6+
</t>
7+
</xpath>
8+
</template>
9+
</odoo>

0 commit comments

Comments
 (0)