77
88
99class AccountInvoice (models .Model ):
10- _inherit = ' account.invoice'
10+ _inherit = " account.invoice"
1111
1212 asset_accounting_info_ids = fields .One2many (
13- 'asset.accounting.info' ,
14- 'invoice_id' ,
15- string = "Assets Accounting Info"
13+ "asset.accounting.info" , "invoice_id" , string = "Assets Accounting Info"
1614 )
1715
1816 asset_ids = fields .Many2many (
19- 'asset.asset' ,
20- compute = '_compute_asset_data' ,
21- store = True ,
22- string = "Assets"
17+ "asset.asset" , compute = "_compute_asset_data" , store = True , string = "Assets"
2318 )
2419
2520 dep_line_ids = fields .Many2many (
26- ' asset.depreciation.line' ,
27- compute = ' _compute_asset_data' ,
21+ " asset.depreciation.line" ,
22+ compute = " _compute_asset_data" ,
2823 store = True ,
29- string = "Depreciation Lines"
24+ string = "Depreciation Lines" ,
3025 )
3126
3227 hide_link_asset_button = fields .Boolean (
33- compute = ' _compute_hide_link_asset_button' ,
28+ compute = " _compute_hide_link_asset_button" ,
3429 default = True ,
3530 string = "Hide Asset Button" ,
3631 )
3732
38- @api .constrains (' company_id' )
33+ @api .constrains (" company_id" )
3934 def check_company (self ):
4035 for inv in self :
41- comp = inv .get_linked_aa_info_records ().mapped (' company_id' )
36+ comp = inv .get_linked_aa_info_records ().mapped (" company_id" )
4237 if len (comp ) > 1 or (comp and comp != inv .company_id ):
4338 raise ValidationError (
44- _ ("`{}`: cannot change invoice's company once it's already"
45- " related to an asset." )
46- .format (inv .name_get ()[0 ][- 1 ])
39+ _ (
40+ "`{}`: cannot change invoice's company once it's already"
41+ " related to an asset."
42+ ).format (inv .name_get ()[0 ][- 1 ])
4743 )
4844
4945 @api .multi
@@ -53,43 +49,45 @@ def action_invoice_cancel(self):
5349 # Remove every a.a.info related to current invoices, and delete
5450 # related depreciation lines
5551 aa_infos = self .mapped (lambda i : i .get_linked_aa_info_records ())
56- dep_lines = aa_infos .mapped (' dep_line_id' )
52+ dep_lines = aa_infos .mapped (" dep_line_id" )
5753 aa_infos .unlink ()
5854 # Filtering needed: cannot delete dep lines with a.a.info
59- dep_lines .filtered (
60- lambda l : not l .asset_accounting_info_ids
61- ).unlink ()
55+ dep_lines .filtered (lambda l : not l .asset_accounting_info_ids ).unlink ()
6256 return res
6357
6458 @api .multi
6559 @api .depends (
66- ' asset_accounting_info_ids' ,
67- ' asset_accounting_info_ids.asset_id' ,
68- ' asset_accounting_info_ids.dep_line_id' ,
60+ " asset_accounting_info_ids" ,
61+ " asset_accounting_info_ids.asset_id" ,
62+ " asset_accounting_info_ids.dep_line_id" ,
6963 )
7064 def _compute_asset_data (self ):
7165 for inv in self :
7266 aa_info = inv .get_linked_aa_info_records ()
73- assets = aa_info .mapped (' asset_id' )
74- dep_lines = aa_info .mapped (' dep_line_id' )
67+ assets = aa_info .mapped (" asset_id" )
68+ dep_lines = aa_info .mapped (" dep_line_id" )
7569 if dep_lines :
76- assets += dep_lines .mapped ('asset_id' )
77- inv .update ({
78- 'asset_ids' : [(6 , 0 , assets .ids )],
79- 'dep_line_ids' : [(6 , 0 , dep_lines .ids )]
80- })
70+ assets += dep_lines .mapped ("asset_id" )
71+ inv .update (
72+ {
73+ "asset_ids" : [(6 , 0 , assets .ids )],
74+ "dep_line_ids" : [(6 , 0 , dep_lines .ids )],
75+ }
76+ )
8177
8278 @api .multi
8379 def _compute_hide_link_asset_button (self ):
8480 valid_account_ids = self .get_valid_accounts ()
8581 if not valid_account_ids :
86- self .update ({' hide_link_asset_button' : True })
82+ self .update ({" hide_link_asset_button" : True })
8783 else :
8884 for inv in self :
89- inv .hide_link_asset_button = not any ([
90- l .account_id .id in valid_account_ids .ids
91- for l in inv .invoice_line_ids
92- ]) or inv .state in ('draft' , 'cancel' )
85+ inv .hide_link_asset_button = not any (
86+ [
87+ l .account_id .id in valid_account_ids .ids
88+ for l in inv .invoice_line_ids
89+ ]
90+ ) or inv .state in ("draft" , "cancel" )
9391
9492 @api .multi
9593 def open_wizard_manage_asset (self ):
@@ -98,31 +96,33 @@ def open_wizard_manage_asset(self):
9896 lambda l : not l .asset_accounting_info_ids
9997 )
10098 if not lines :
101- raise ValidationError (
102- _ ("Every line is already linked to an asset." )
103- )
99+ raise ValidationError (_ ("Every line is already linked to an asset." ))
104100
105- xmlid = ' assets_management.action_wizard_invoice_manage_asset'
101+ xmlid = " assets_management.action_wizard_invoice_manage_asset"
106102 act = self .env .ref (xmlid ).read ()[0 ]
107103 ctx = dict (self ._context )
108- ctx .update ({
109- 'default_company_id' : self .company_id .id ,
110- 'default_dismiss_date' : self .date_invoice or self .date_due ,
111- 'default_invoice_ids' : [(6 , 0 , self .ids )],
112- 'default_invoice_line_ids' : [(6 , 0 , lines .ids )],
113- 'default_purchase_date' : self .date_invoice or self .date_due ,
114- 'invoice_ids' : self .ids ,
115- })
116- act .update ({'context' : ctx })
104+ ctx .update (
105+ {
106+ "default_company_id" : self .company_id .id ,
107+ "default_dismiss_date" : self .date_invoice or self .date_due ,
108+ "default_invoice_ids" : [(6 , 0 , self .ids )],
109+ "default_invoice_line_ids" : [(6 , 0 , lines .ids )],
110+ "default_purchase_date" : self .date_invoice or self .date_due ,
111+ "invoice_ids" : self .ids ,
112+ }
113+ )
114+ act .update ({"context" : ctx })
117115 return act
118116
119117 def get_linked_aa_info_records (self ):
120118 self .ensure_one ()
121- return self .env ['asset.accounting.info' ].search ([
122- '|' ,
123- ('invoice_id' , '=' , self .id ),
124- ('invoice_line_id.invoice_id' , '=' , self .id ),
125- ])
119+ return self .env ["asset.accounting.info" ].search (
120+ [
121+ "|" ,
122+ ("invoice_id" , "=" , self .id ),
123+ ("invoice_line_id.invoice_id" , "=" , self .id ),
124+ ]
125+ )
126126
127127 def get_valid_accounts (self ):
128- return self .env [' asset.category' ].search ([]).mapped (' asset_account_id' )
128+ return self .env [" asset.category" ].search ([]).mapped (" asset_account_id" )
0 commit comments