Skip to content

Commit

Permalink
[ADD] estate: Created new module and added a link with existing module
Browse files Browse the repository at this point in the history
Chapter 13: Interact With Other Modules

- Created the 'estate_account' module as a link between the 'estate' and
  'account' modules.
- Added logic to generate an invoice when a property is marked as 'Sold'.
- Overrode the 'action_sold' method in the 'estate.property' model to initiate
  the invoice creation process.
- Implemented the creation of an empty 'account.move' (invoice) with the
  necessary details (partner_id, move_type, and journal_id).
- Added functionality to include two invoice lines during the invoice creation:
  6% of the selling price and an additional 100 INR for administrative fees.
  • Loading branch information
pach-odoo committed Aug 14, 2024
1 parent 3368de9 commit 3f9092f
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from odoo import api, models, fields, _
from odoo import _, api, fields, models
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError, ValidationError
from odoo.exceptions import ValidationError, UserError
from odoo.tools.float_utils import float_compare, float_is_zero


Expand Down
4 changes: 2 additions & 2 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from odoo import api, fields, models, _
from datetime import timedelta, date
from odoo import _, api, fields, models
from datetime import date, timedelta
from odoo.exceptions import UserError


Expand Down
2 changes: 1 addition & 1 deletion estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import fields, models, api
from odoo import api, fields, models


class EstatePropertyType(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion estate/models/res_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields
from odoo import fields, models


class ResUser(models.Model):
Expand Down
2 changes: 0 additions & 2 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>

<field name="status"/>
</group>
</sheet>
</form>
</field>
</record>

</odoo>
3 changes: 0 additions & 3 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<field name="name">Property Tag</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">tree,form</field>

<field name="help" type="html">
<p class="o_view_nocontent_smiling_face"> Create a property type</p>
</field>
Expand Down Expand Up @@ -33,6 +32,4 @@
</form>
</field>
</record>


</odoo>
5 changes: 0 additions & 5 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<field name="arch" type="xml">
<form string="Properties Form">
<sheet>

<div style="text-align: right;">
<button name="%(estate.estate_property_offer_actions)d" type="action" string="Offers" icon="fa-money fa-2x" class="oe_stat_button">
<div class="o_stat_info">
Expand All @@ -39,11 +38,9 @@
</div>
</button>
</div>

<h1>
<field name="name" />
</h1>

<notebook>
<page string="Properties">
<field name="property_ids">
Expand All @@ -59,6 +56,4 @@
</form>
</field>
</record>


</odoo>
2 changes: 0 additions & 2 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,5 @@
<filter string="Postcode" name="postcode" context="{'group_by':'postcode'}"/>
</search>
</field>

</record>

</odoo>
1 change: 1 addition & 0 deletions estate_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Real Estate Account",
"version": "1.1",
"license": "LGPL-3",
"category": "Tutorials",
"sequence": 15,
"summary": "Accounting informatin about real estate properties",
"description": "",
"installable": True,
"application": True,
"depends": ["estate", "account"],
}
1 change: 1 addition & 0 deletions estate_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property
18 changes: 18 additions & 0 deletions estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import Command, models


class EstateProperty(models.Model):
_inherit = "estate.property"

def action_sold_property(self):
self.env["account.move"].create(
{
"move_type": "out_invoice",
"partner_id": self.buyer_id.id,
"invoice_line_ids": [
Command.create({'name': '6% of the selling price', 'quantity': 1, 'price_unit': 0.06 * self.selling_price}),
Command.create({'name': 'Administrative Fees', 'quantity': 1, 'price_unit': 100.00}),
],
}
)
return super().action_sold_property()

0 comments on commit 3f9092f

Please sign in to comment.