4
4
5
5
from dateutil .relativedelta import relativedelta
6
6
7
- from odoo import _ , api , exceptions , fields , models
7
+ from odoo import api , exceptions , fields , models
8
8
from odoo .exceptions import ValidationError
9
9
from odoo .tools import float_is_zero
10
10
@@ -32,28 +32,22 @@ def _default_company_id(self):
32
32
33
33
name = fields .Char (
34
34
readonly = True ,
35
- states = {"draft" : [("readonly" , False )]},
36
35
)
37
36
check_draft_moves = fields .Boolean (
38
37
readonly = True ,
39
- states = {"draft" : [("readonly" , False )]},
40
38
)
41
39
year = fields .Integer (
42
40
help = "Introduce here the year to close. If the fiscal year is between "
43
41
"several natural years, you have to put here the last one." ,
44
42
default = lambda self : self ._default_year (),
45
43
readonly = True ,
46
- states = {"draft" : [("readonly" , False )]},
47
44
)
48
45
company_id = fields .Many2one (
49
46
default = lambda self : self ._default_company_id (),
50
47
readonly = True ,
51
- states = {"draft" : [("readonly" , False )]},
52
48
)
53
- chart_template_id = fields .Many2one (
54
- comodel_name = "account.chart.template" ,
55
- string = "Chart template" ,
56
- related = "company_id.chart_template_id" ,
49
+ chart_template = fields .Selection (
50
+ related = "company_id.chart_template" ,
57
51
readonly = True ,
58
52
)
59
53
state = fields .Selection (
@@ -74,33 +68,28 @@ def _default_company_id(self):
74
68
string = "From date" ,
75
69
required = True ,
76
70
readonly = True ,
77
- states = {"draft" : [("readonly" , False )]},
78
71
)
79
72
date_end = fields .Date (
80
73
string = "To date" ,
81
74
required = True ,
82
75
readonly = True ,
83
- states = {"draft" : [("readonly" , False )]},
84
76
)
85
77
date_opening = fields .Date (
86
78
string = "Opening date" ,
87
79
required = True ,
88
80
readonly = True ,
89
- states = {"draft" : [("readonly" , False )]},
90
81
)
91
82
closing_template_id = fields .Many2one (
92
83
comodel_name = "account.fiscalyear.closing.template" ,
93
84
string = "Closing template" ,
94
- domain = "[('chart_template_ids ', '=', chart_template_id )]" ,
85
+ domain = "[('chart_template ', '=', chart_template )]" ,
95
86
readonly = True ,
96
- states = {"draft" : [("readonly" , False )]},
97
87
)
98
88
move_config_ids = fields .One2many (
99
89
comodel_name = "account.fiscalyear.closing.config" ,
100
90
inverse_name = "fyc_id" ,
101
91
string = "Moves configuration" ,
102
92
readonly = True ,
103
- states = {"draft" : [("readonly" , False )]},
104
93
)
105
94
move_ids = fields .One2many (
106
95
comodel_name = "account.move" ,
@@ -113,7 +102,7 @@ def _default_company_id(self):
113
102
(
114
103
"year_company_uniq" ,
115
104
"unique(year, company_id)" ,
116
- _ (
105
+ (
117
106
"There should be only one fiscal year closing for that year and "
118
107
"company!"
119
108
),
@@ -135,7 +124,7 @@ def _prepare_mapping(self, tmpl_mapping):
135
124
)
136
125
# Use an error name if no destination account found
137
126
if not dest_account :
138
- name = _ ("No destination account '%s' found." ) % (
127
+ name = self . env . _ ("No destination account '%s' found." ) % (
139
128
tmpl_mapping .dest_account ,
140
129
)
141
130
return {
@@ -233,9 +222,12 @@ def draft_moves_check(self):
233
222
]
234
223
)
235
224
if draft_moves :
236
- msg = _ ("One or more draft moves found: \n " )
225
+ msg = closing . env . _ ("One or more draft moves found: \n " )
237
226
for move in draft_moves :
238
- msg += f"ID: { move .id } , Date: { move .date } , Number: { move .name } , Ref: { move .ref } \n "
227
+ msg += (
228
+ f"ID: { move .id } , Date: { move .date } "
229
+ f", Number: { move .name } , Ref: { move .ref } \n "
230
+ )
239
231
raise ValidationError (msg )
240
232
return True
241
233
@@ -252,7 +244,7 @@ def _show_unbalanced_move_wizard(self, data):
252
244
wizard = self .env ["account.fiscalyear.closing.unbalanced.move" ].create (data )
253
245
return {
254
246
"type" : "ir.actions.act_window" ,
255
- "name" : _ ("Unbalanced journal entry found" ),
247
+ "name" : self . env . _ ("Unbalanced journal entry found" ),
256
248
"view_type" : "form" ,
257
249
"view_mode" : "form" ,
258
250
"res_model" : "account.fiscalyear.closing.unbalanced.move" ,
@@ -311,20 +303,20 @@ def button_post(self):
311
303
def button_open_moves (self ):
312
304
# Return an action for showing moves
313
305
return {
314
- "name" : _ ("Fiscal closing moves" ),
306
+ "name" : self . env . _ ("Fiscal closing moves" ),
315
307
"type" : "ir.actions.act_window" ,
316
308
"view_type" : "form" ,
317
- "view_mode" : "tree ,form" ,
309
+ "view_mode" : "list ,form" ,
318
310
"res_model" : "account.move" ,
319
311
"domain" : [("fyc_id" , "in" , self .ids )],
320
312
}
321
313
322
314
def button_open_move_lines (self ):
323
315
return {
324
- "name" : _ ("Fiscal closing move lines" ),
316
+ "name" : self . env . _ ("Fiscal closing move lines" ),
325
317
"type" : "ir.actions.act_window" ,
326
318
"view_type" : "form" ,
327
- "view_mode" : "tree ,form" ,
319
+ "view_mode" : "list ,form" ,
328
320
"res_model" : "account.move.line" ,
329
321
"domain" : [("move_id.fyc_id" , "in" , self .ids )],
330
322
}
@@ -346,12 +338,12 @@ def button_recover(self):
346
338
def unlink (self ):
347
339
if any (x .state not in ("draft" , "cancelled" ) for x in self ):
348
340
raise exceptions .UserError (
349
- _ (
341
+ self . env . _ (
350
342
"You can't remove any closing that is not in draft or "
351
343
"cancelled state."
352
344
)
353
345
)
354
- return super (AccountFiscalyearClosing , self ).unlink ()
346
+ return super ().unlink ()
355
347
356
348
357
349
class AccountFiscalyearClosingConfig (models .Model ):
@@ -387,7 +379,7 @@ class AccountFiscalyearClosingConfig(models.Model):
387
379
(
388
380
"code_uniq" ,
389
381
"unique(code, fyc_id)" ,
390
- _ ( "Code must be unique per fiscal year closing!" ) ,
382
+ "Code must be unique per fiscal year closing!" ,
391
383
),
392
384
]
393
385
@@ -436,7 +428,7 @@ def _mapping_move_lines_get(self):
436
428
dest_totals .setdefault (dest , 0 )
437
429
src_accounts = self .env ["account.account" ].search (
438
430
[
439
- ("company_id " , "= " , self .fyc_id .company_id .id ),
431
+ ("company_ids " , "in " , self .fyc_id .company_id .ids ),
440
432
("code" , "=ilike" , account_map .src_accounts ),
441
433
],
442
434
order = "code ASC" ,
@@ -550,15 +542,15 @@ def create(self, vals_list):
550
542
vals ["dest_account_id" ], list
551
543
):
552
544
vals ["dest_account_id" ] = vals ["dest_account_id" ][0 ]
553
- res = super (AccountFiscalyearClosingMapping , self ).create (vals_list )
545
+ res = super ().create (vals_list )
554
546
return res
555
547
556
548
def write (self , vals ):
557
549
if vals .get ("dest_account_id" , False ) and isinstance (
558
550
vals ["dest_account_id" ], list
559
551
):
560
552
vals ["dest_account_id" ] = vals ["dest_account_id" ][0 ]
561
- res = super (AccountFiscalyearClosingMapping , self ).write (vals )
553
+ res = super ().write (vals )
562
554
return res
563
555
564
556
def dest_move_line_prepare (self , dest , balance , partner_id = False ):
@@ -573,7 +565,7 @@ def dest_move_line_prepare(self, dest, balance, partner_id=False):
573
565
"account_id" : dest .id ,
574
566
"debit" : balance < 0 and - balance ,
575
567
"credit" : balance > 0 and balance ,
576
- "name" : _ ("Result" ),
568
+ "name" : self . env . _ ("Result" ),
577
569
"date" : date ,
578
570
"partner_id" : partner_id ,
579
571
}
0 commit comments