Skip to content

Commit

Permalink
[ADD] estate_account: override action_sold to create invoices
Browse files Browse the repository at this point in the history
- Created estate_account module to link estate and account modules.
- In estate_property.py, inherited estate.property model.
- Overrode action_sold method to return the super call.
  • Loading branch information
yasp-odoo committed Aug 22, 2024
1 parent 7de8e7d commit 576fb56
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 27 deletions.
2 changes: 1 addition & 1 deletion estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
76 changes: 50 additions & 26 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@
<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">tree,form,kanban</field>
<field name="context">{'search_default_available_properties':1}</field>
</record>

<record id="estate_property_kanban" model="ir.ui.view">
<field name="name">estate.property.kanban</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<field name="name" />
</div>
</t>
</templates>
</kanban>
</field>
</record>
<record id="estate_property_list" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<tree string="Estate Property List"
decoration-success="state in ['offer_accepted', 'offer_received']"
decoration-muted="state == 'sold'"
decoration-bf="state == 'offer_accepted'">
decoration-success="state in ['offer_accepted', 'offer_received']"
decoration-muted="state == 'sold'"
decoration-bf="state == 'offer_accepted'">
<field name="name" />
<field name="bedrooms" />
<field name="postcode" />
<field name="living_area" />
<field name="expected_price" />
<field name="selling_price" />
<field name="date_availability" optional="hidden"/>
<field name="date_availability" optional="hidden" />
<field name="buyer_id" />
<field name="seller_id" />
<field name="state" column_invisible="1"/>
<field name="state" column_invisible="1" />
<field name="property_type_id" />
<field name="tag_ids" widget="many2many_tags" />
</tree>
Expand All @@ -36,23 +50,27 @@
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form string="Estate Property Form">

<header>
<button name="action_sold" type="object" string="Set as Sold" invisible="state in ['sold', 'canceled']"/>
<button name="action_cancel" type="object" string="Cancel" invisible="state in ['sold', 'canceled']"/>
<button name="action_sold" type="object" string="Set as Sold"
invisible="state in ['sold', 'canceled']" />
<button name="action_cancel" type="object" string="Cancel"
invisible="state in ['sold', 'canceled']" />
<field name="state" widget="statusbar" />
</header>
<sheet>
<group>
<group>
<field name="name" />
<field name="tag_ids" widget="many2many_tags" options="{'color_field':'color'}"/>
<field name="description" widget="textarea"/>
<field name="state"/>

<field name="tag_ids" widget="many2many_tags"
options="{'color_field':'color'}" />
<field name="description" widget="textarea" />
<field name="state" />

</group>
<group>
<field name="property_type_id" options="{'no_create': True, 'no_open': True}"/>
<field name="property_type_id"
options="{'no_create': True, 'no_open': True}" />
<field name="postcode" />
<field name="date_availability" />
</group>
Expand All @@ -62,36 +80,42 @@
<field name="best_price" />
</group>
</group>
<notebook>x`x`
<page string="Description">
<notebook>x`x` <page string="Description">
<field name="description" />
<group>
<field name="bedrooms" />
<field name="living_area" />
<field name="facades" />
<field name="garage" />
<field name="garden" />
<field name="garden_area" invisible="garden == False"/>
<field name="garden_orientation" invisible="garden == False"/>
<field name="garden_area" invisible="garden == False" />
<field name="garden_orientation" invisible="garden == False" />
<field name="total_area" />
</group>
</page>
<page string="Offers">
<field name="offer_ids" readonly="state in ['offer_accepted','sold', 'canceled']">
<tree string="Offers" editable="bottom" decoration-danger="status == 'refused'" decoration-success="status == 'accepted'">
<page
string="Offers">
<field name="offer_ids"
readonly="state in ['offer_accepted','sold', 'canceled']">
<tree string="Offers" editable="bottom"
decoration-danger="status == 'refused'"
decoration-success="status == 'accepted'">
<field name="price" />
<field name="partner_id" />
<button name="action_accept" type="object" string="Accept"
class="btn-primary" invisible="status in ['accepted','refused']"/>
class="btn-primary"
invisible="status in ['accepted','refused']" />
<button name="action_refuse" type="object" string="Refuse"
class="btn-secondary" invisible="status in ['refused','accepted']"/>
class="btn-secondary"
invisible="status in ['refused','accepted']" />
<field name="status" column_invisible="1" />
<field name="validity" />
<field name="date_deadline" />
</tree>
</field>
</page>
<page string="Other Info">
<page
string="Other Info">
<group>
<field name="buyer_id" />
<field name="seller_id" />
Expand All @@ -112,7 +136,7 @@
<field name="postcode" />
<field name="bedrooms" />
<field name="living_area" string="Living Area"
filter_domain="[('living_area', '>=', self)]"/>
filter_domain="[('living_area', '>=', self)]" />
<field name="expected_price" />
<field name="selling_price" />
<field name="date_availability" />
Expand Down
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
13 changes: 13 additions & 0 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
'name': 'Estate Account Integration',
'version': '1.0',
'summary': 'Integration between Estate and Accounting modules',
'description': 'This module creates invoices for sold properties.',
'category': 'Accounting',
'author': 'yasp',
'depends': ['estate', 'account'],
'license': 'LGPL-3',
'data': [],
'installable': True,
'application': False,
}
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
27 changes: 27 additions & 0 deletions estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import models, api, Command

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

@api.model
def action_sold(self):
# Create an invoice with two lines
self.env['account.move'].create({
'partner_id': self.buyer_id.id, # Assuming 'buyer_id' is the field holding the customer
'move_type': 'out_invoice', # 'Customer Invoice'
'invoice_line_ids': [
Command.create({
'name': 'Property Sale Commission',
'quantity': 1,
'price_unit': self.selling_price * 0.06, # 6% of the selling price
}),
Command.create({
'name': 'Administrative Fees',
'quantity': 1,
'price_unit': 100.00, # Fixed administrative fee
})
],
})

# Call the original action_sold method
return super().action_sold()

0 comments on commit 576fb56

Please sign in to comment.