Skip to content

Commit

Permalink
[ADD] estate: Add report for the property, salesman, invoice
Browse files Browse the repository at this point in the history
- Implemented a property offers PDF report using QWeb templates.
- Created estate_property_templates.xml to define the report template for
- displaying property offers.
- Added estate_property_reports.xml for the ir.actions.report to include the
  report in the module's business logic.
- Enhanced the report by adding logic to conditionally handle cases with no
  offers using t-if and t-else.
- Introduced a sub-template to separate the table portion of the offers,
  promoting code reuse.
- Created a new report for res.users to list all the Real Estate Properties
  for a salesperson, including property offers.
- Extended the property report in the estate_account module to include
  invoice information for sold properties using QWeb inheritance.
  • Loading branch information
amya-odoo committed Aug 21, 2024
1 parent b189355 commit 27fc6ce
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 35 deletions.
25 changes: 13 additions & 12 deletions estate/demo/estate_property_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,29 @@
<field name="description">Home in a Ocean park</field>
<field name="postcode">0001</field>
<field name="date_availability">2030-01-01</field>
<field name="expected_price">80</field>
<field name="expected_price">50.0</field>
<field name="selling_price">0.0</field>
<field name="bedrooms">1</field>
<field name="living_area">10</field>
<field name="facades">4</field>
<field name="garage">False</field>
<field name="property_type_id" ref="1"></field>
<field name="garage">false</field>
<field name="property_type_id" ref="1"/>
<field name="offer_ids" eval="[
Command.create({
'price': 100,
'status': 'accepted',
'partner_id':ref('base.res_partner_2'),
}) ]"/>
Command.create({
'price': 10000900.0,
'status': 'accepted',
'partner_id': ref('base.res_partner_2'),
})]"/>
</record>

<record id="id3" model="estate.property">

<record id="id4" model="estate.property">
<field name="name">Small Villa</field>
<field name="state">new</field>
<field name="description">A nice and big villa</field>
<field name="postcode">12345</field>
<field name="date_availability">2020-02-02</field>
<field name="expected_price">1600000</field>
<field name="expected_price">1600</field>
<field name="selling_price">0.0</field>
<field name="bedrooms">6</field>
<field name="living_area">100</field>
Expand All @@ -79,13 +80,13 @@
<field name="property_id" ref="id2"/>
</record>
<record id="offer2" model="estate.property.offer">
<field name="price">1500000</field>
<field name="price">150000000</field>
<field name="validity">14</field>
<field name="partner_id" ref="base.res_partner_12"/>
<field name="property_id" ref="id2"/>
</record>
<record id="offer3" model="estate.property.offer">
<field name="price">1500001</field>
<field name="price">10001000.0</field>
<field name="validity">14</field>
<field name="partner_id" ref="base.res_partner_2"/>
<field name="property_id" ref="id3"/>
Expand Down
13 changes: 7 additions & 6 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import date, timedelta
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
Expand Down Expand Up @@ -33,7 +34,9 @@ def _compute_deadline(self):
for record in self:
created_date = record.create_date or date.today()
record.deadline = (
created_date + timedelta(days=record.validity) if record.validity else created_date
created_date + timedelta(days=record.validity)
if record.validity
else created_date
)

def _inverse_deadline(self):
Expand All @@ -56,16 +59,14 @@ def action_status_accept(self):
self.property_id.state = "offer_accepted"
property_id = self.property_id
try:
existing_offer = self.search([('property_id', '=', int(property_id))])
existing_offer = self.search([("property_id", "=", int(property_id))])
for record in existing_offer:
if record.id == self.id:
print("Found the matching recode offer for this")
continue
else:
print(record.status)
record.status = "refused"
except Exception:
pass
except (UserError, ValidationError):
logging.exception("Error while updating offer status accepted")
else:
raise ValidationError("The selling price must be at least 90%")

Expand Down
22 changes: 22 additions & 0 deletions estate/report/estate_property_report.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
<odoo>
<record id="report_estate_property" model="ir.actions.report">
<field name="name">Real Estate Property</field>
<field name="model">estate.property</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">estate.report_property_template</field>
<field name="report_file">estate.report_property_template</field>
<field name="print_report_name">'Estate Property- %s' % (object.name or 'Attendee').replace('/','')</field>
<field name="binding_model_id" ref="model_estate_property"/>
<field name="binding_type">report</field>
</record>

<record id="report_salesmen_estate_property" model="ir.actions.report">
<field name="name">Salesman Property</field>
<field name="model">res.users</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">estate.report_salesmen_property_template</field>
<field name="report_file">estate.report_salesmen_property_template</field>
<field name="print_report_name">'Properties - %s' % (object.name or 'Attendee').replace('/','')</field>
<field name="binding_model_id" ref="base.model_res_users"/>
<field name="binding_type">report</field>
</record>

</odoo>
102 changes: 85 additions & 17 deletions estate/report/estate_property_templates.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,99 @@
<odoo>
<template id="report_property_offers">
<template id="report_property_template">
<t t-foreach="docs" t-as="property">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<h2>
<span t-field="property.name"/>
</h2>
<div>
<div class="x">
<strong>Salesman: </strong>
<span t-field="property.salesman_id"/>
<br />
<strong>Expected Price: </strong>
<span t-field="property.expected_price"/>
<br/>
<strong>State: </strong>
<span t-field="property.state"/>
</div>
<table class="table">
<thead>
<tr>
<th>Price</th>
</tr>
</thead>
<tbody>
<t t-set="offers" t-value="property.mapped('offer_ids')"/>
<tr t-foreach="offers" t-as="offer">
<td>
<span t-field="offer.price"/>
</td>
</tr>
</tbody>
</table>
<t t-if="property.offer_ids">
<t t-call="estate.estate_property_offer_template"/>
</t>
<t t-else="">
<div>
<strong>No offer has been accepted</strong>
</div>
</t>
</div>
</t>
</t>
</t>
</template>

<template id="estate_property_offer_template">
<table class="table">
<thead class="display: table-row-group">
<tr>
<th>Price</th>
<th>Partner</th>
<th>Validity(days)</th>
<th>Deadline</th>
<th>State</th>
</tr>
</thead>
<tbody>
<t t-set="offers" t-value="property.mapped('offer_ids')"/>
<tr t-foreach="offers" t-as="offer">
<td>
<span t-field="offer.price"/>
</td>
<td>
<span t-field="offer.partner_id"/>
</td>
<td>
<span t-field="offer.validity"/>
</td>
<td>
<span t-field="offer.deadline"/>
</td>
<td>
<span t-field="offer.status"/>
</td>
</tr>
</tbody>
</table>
</template>

<template id="report_salesmen_property_template">
<t t-foreach="docs" t-as="user">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<h2>
<strong>Salesman: </strong>
<span t-field="user.name"/>
</h2>
<tr t-foreach="user.property_ids" t-as="property">
<div>
<h3 style="margin: 10px 0px 0px 0px;">
<span t-field="property.name"/>
</h3>
<strong>Expected Price: </strong>
<span t-field="property.expected_price"/>
<br/>
<strong>State: </strong>
<span t-field="property.state"/>
</div>
<t t-if="property.offer_ids">
<t t-call="estate.estate_property_offer_template"/>
</t>
<t t-else="">
<div>
<strong>No offer has been accepted</strong>
</div>
</t>
</tr>
</div>
</t>
</t>
Expand Down
3 changes: 3 additions & 0 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
'version': '0.1',
'depends': ['base', 'account', 'estate'],
'description': "Technical practice",
'data': [
"report/estate_account_invoice_templates.xml",
],
'installable': True,
'application': True,
'license': 'LGPL-3',
Expand Down
11 changes: 11 additions & 0 deletions estate_account/report/estate_account_invoice_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<odoo>
<template id="estate_property_invoice_template_x" inherit_id="estate.report_property_template">
<xpath expr="//div[@class='x']" position="after">
<t t-if="property.state == 'sold'">
<div class="page">
<span>!!!Invoice has been already created!!!</span>
</div>
</t>
</xpath>
</template>
</odoo>

0 comments on commit 27fc6ce

Please sign in to comment.