Skip to content

Commit 86c1fa8

Browse files
committed
[IMP] estate: Adding a button to link the property to the invoice
1 parent 626e597 commit 86c1fa8

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

estate/views/estate_form_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<field name="arch" type="xml">
77
<form string="Property Form">
88
<header>
9-
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold" options="{'clickable': '1'}"/>
9+
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold" readonly="1"/>
1010
<button name="action_sold" type="object" string="Sold" invisible="state == 'sold' or state == 'canceled'"/>
1111
<button name="action_cancel" type="object" string="Cancel" invisible="state == 'sold' or state == 'canceled'"/>
1212
</header>

estate_account/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
A app for real estate invoices.
1010
""",
1111
'data': [
12+
'views/estate_account_form_views.xml',
1213
],
1314
}

estate_account/models/estate_property.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
11
# Part of Odoo. See LICENSE file for full copyright and licensing details.
22

3-
from odoo import models
3+
from odoo import fields, models
44

55

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

9+
invoice_count = fields.Integer(compute='_compute_invoice_count', string='Invoice Count')
10+
11+
def _compute_invoice_count(self):
12+
for property_record in self:
13+
property_record.invoice_count = self.env['account.move'].search_count([
14+
('estate_property_id', 'in', property_record.ids),
15+
('move_type', '=', 'out_invoice'),
16+
])
17+
18+
def action_view_invoices(self):
19+
self.ensure_one()
20+
invoices = self.env['account.move'].search([
21+
('estate_property_id', '=', self.id),
22+
('move_type', '=', 'out_invoice'),
23+
])
24+
action = self.env.ref('account.action_move_out_invoice_type').read()[0]
25+
action['domain'] = [
26+
('estate_property_id', '=', self.id),
27+
('move_type', '=', 'out_invoice'),
28+
]
29+
action['context'] = {
30+
'default_move_type': 'out_invoice',
31+
'default_partner_id': self.buyer_id.id,
32+
'default_estate_property_id': self.id,
33+
}
34+
if len(invoices) == 1:
35+
form_view = [(self.env.ref('account.view_move_form').id, 'form')]
36+
if 'views' in action:
37+
action['views'] = form_view + [(state, view) for state, view in action['views'] if view != 'form']
38+
else:
39+
action['views'] = form_view
40+
action['res_id'] = invoices.id
41+
return action
42+
943
def action_sold(self):
1044

1145
self.env['account.move'].create({
1246
'partner_id': self.buyer_id.id,
1347
'move_type': 'out_invoice',
48+
'estate_property_id': self.id,
1449
'journal_id': self.env['account.journal'].search([('type', '=', 'sale')], limit=1).id,
1550
'line_ids': [
1651
# 6% of the selling price
@@ -30,3 +65,9 @@ def action_sold(self):
3065
})
3166

3267
return super().action_sold()
68+
69+
70+
class AccountMove(models.Model):
71+
_inherit = 'account.move'
72+
73+
estate_property_id = fields.Many2one('estate.property', string='Property')
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="estate_property_view_form_inherit_account" model="ir.ui.view">
4+
<field name="name">estate.property.form.inherit.account</field>
5+
<field name="model">estate.property</field>
6+
<field name="inherit_id" ref="estate.estate_view_form"/>
7+
<field name="arch" type="xml">
8+
<sheet position="inside">
9+
<div class="oe_button_box" name="button_box">
10+
<button name="action_view_invoices" type="object" class="oe_stat_button" invisible="state != 'sold'">
11+
<field name="invoice_count" widget="statinfo" string="Invoices"/>
12+
</button>
13+
</div>
14+
</sheet>
15+
</field>
16+
</record>
17+
</odoo>

0 commit comments

Comments
 (0)