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
66class 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' )
0 commit comments