@@ -559,6 +559,7 @@ def _default_display_invoice_template_pdf_report_id(self):
559
559
ref_company_ids = fields .One2many ('res.company' , 'partner_id' ,
560
560
string = 'Companies that refers to partner' )
561
561
supplier_invoice_count = fields .Integer (compute = '_compute_supplier_invoice_count' , string = '# Vendor Bills' )
562
+ account_move_count = fields .Integer (compute = '_compute_account_move_count' , groups = 'account.group_account_invoice,account.group_account_readonly' )
562
563
invoice_ids = fields .One2many ('account.move' , 'partner_id' , string = 'Invoices' , readonly = True , copy = False )
563
564
contract_ids = fields .One2many ('account.analytic.account' , 'partner_id' , string = 'Partner Contracts' , readonly = True )
564
565
bank_account_count = fields .Integer (compute = '_compute_bank_count' , string = "Bank" )
@@ -1023,3 +1024,37 @@ def _compute_partner_company_registry_placeholder(self):
1023
1024
for partner in self :
1024
1025
country_code = partner .country_id .code or ''
1025
1026
partner .partner_company_registry_placeholder = _ref_company_registry .get (country_code .lower (), '' )
1027
+
1028
+ def _compute_account_move_count (self ):
1029
+ # retrieve all children partners and prefetch 'parent_id' on them
1030
+ all_partners = self .with_context (active_test = False ).search_fetch (
1031
+ [("id" , "child_of" , self .ids )],
1032
+ ["parent_id" ],
1033
+ )
1034
+ domain = [
1035
+ ("partner_id" , "in" , all_partners .ids ),
1036
+ ("move_type" , "in" , ("out_invoice" , "out_refund" )),
1037
+ ]
1038
+ account_move_groups = self .env ["account.move" ]._read_group (
1039
+ domain = domain , groupby = ["partner_id" ], aggregates = ["__count" ],
1040
+ )
1041
+ self_ids = set (self ._ids )
1042
+
1043
+ self .account_move_count = 0
1044
+ for partner , count in account_move_groups :
1045
+ while partner :
1046
+ if partner .id in self_ids :
1047
+ partner .account_move_count += count
1048
+ partner = partner .parent_id
1049
+
1050
+ def _get_stat_info (self ):
1051
+ data_list = super ()._get_stat_info ()
1052
+ if not self .env .user .has_group ('account.group_account_invoice' ):
1053
+ return data_list
1054
+ for partner in self .filtered (lambda p : p ._get_account_stat_count ()):
1055
+ stat_info = {'iconClass' : 'fa-pencil-square-o' , 'value' : partner ._get_account_stat_count (), 'label' : _ ('Invoices/Bills/Mandates' )}
1056
+ data_list [partner .id ].append (stat_info )
1057
+ return data_list
1058
+
1059
+ def _get_account_stat_count (self ):
1060
+ return self .account_move_count + self .supplier_invoice_count
0 commit comments