6
6
7
7
8
8
class AccountMove (models .Model ):
9
- _inherit = ' account.move'
9
+ _inherit = " account.move"
10
10
11
11
has_discount_available = fields .Boolean (
12
- ' Has discount available' ,
13
- compute = ' _compute_financial_discount_data' ,
12
+ " Has discount available" ,
13
+ compute = " _compute_financial_discount_data" ,
14
14
# TODO implement read_group + search because we cannot store the field
15
15
# as it depends on actual date
16
16
)
17
17
display_force_financial_discount = fields .Boolean (
18
- compute = ' _compute_financial_discount_data'
18
+ compute = " _compute_financial_discount_data"
19
19
)
20
20
force_financial_discount = fields .Boolean (
21
- ' Force financial discount?' ,
21
+ " Force financial discount?" ,
22
22
default = False ,
23
23
help = "If marked, financial discount will be applied even if the "
24
24
"discount date is passed" ,
25
25
)
26
26
payment_blocked = fields .Boolean (
27
- ' Is payment blocked' ,
27
+ " Is payment blocked" ,
28
28
default = False ,
29
29
help = "Allows group-by but has no logic linked to it" ,
30
30
)
31
31
32
32
# TODO refactor the two functions below together
33
33
def _get_discount_available (self ):
34
34
self .ensure_one ()
35
- if self .state == ' draft' :
35
+ if self .state == " draft" :
36
36
if (
37
37
self .invoice_payment_term_id .days_discount
38
38
and self .invoice_payment_term_id .percent_discount
@@ -48,25 +48,21 @@ def _get_discount_available(self):
48
48
)
49
49
):
50
50
return True
51
- elif self .state == ' posted' :
51
+ elif self .state == " posted" :
52
52
disc_date = self ._get_first_payment_term_line ().date_discount
53
- if (
54
- disc_date
55
- and disc_date >= date .today ()
56
- or self .force_financial_discount
57
- ):
53
+ if disc_date and disc_date >= date .today () or self .force_financial_discount :
58
54
return True
59
55
return False
60
56
61
57
def _get_display_force_financial_discount (self ):
62
58
self .ensure_one ()
63
- if self .state == ' draft' :
59
+ if self .state == " draft" :
64
60
if (
65
61
self .invoice_payment_term_id .days_discount
66
62
and self .invoice_payment_term_id .percent_discount
67
63
):
68
64
return True
69
- elif self .state == ' posted' :
65
+ elif self .state == " posted" :
70
66
first_payment_term_line = self ._get_first_payment_term_line ()
71
67
if (
72
68
first_payment_term_line .date_discount
@@ -87,11 +83,11 @@ def _get_discount_amount(self, amount=None):
87
83
return discount_amount
88
84
89
85
@api .depends (
90
- ' invoice_date' ,
91
- ' invoice_payment_term_id' ,
92
- ' invoice_payment_term_id.days_discount' ,
93
- ' invoice_payment_term_id.percent_discount' ,
94
- ' force_financial_discount' ,
86
+ " invoice_date" ,
87
+ " invoice_payment_term_id" ,
88
+ " invoice_payment_term_id.days_discount" ,
89
+ " invoice_payment_term_id.percent_discount" ,
90
+ " force_financial_discount" ,
95
91
)
96
92
def _compute_financial_discount_data (self ):
97
93
"""Compute discount financial discount fields"""
@@ -109,14 +105,13 @@ def post(self):
109
105
def _get_first_payment_term_line (self ):
110
106
self .ensure_one ()
111
107
payment_term_lines = self .line_ids .filtered (
112
- lambda line : line .account_id .user_type_id .type
113
- in ('receivable' , 'payable' )
108
+ lambda line : line .account_id .user_type_id .type in ("receivable" , "payable" )
114
109
)
115
- return fields .first (payment_term_lines .sorted (' date_maturity' ))
110
+ return fields .first (payment_term_lines .sorted (" date_maturity" ))
116
111
117
112
def _get_taxes_lines (self ):
118
113
self .ensure_one ()
119
- taxes_applied = self .line_ids .mapped (' tax_ids' )
114
+ taxes_applied = self .line_ids .mapped (" tax_ids" )
120
115
taxes_lines = self .line_ids .filtered (
121
116
lambda line : line .tax_line_id in taxes_applied
122
117
)
@@ -134,21 +129,21 @@ def _store_financial_discount(self):
134
129
and payment_term .percent_discount
135
130
and len (tax_line ) <= 1
136
131
and (
137
- (move .type == ' out_invoice' and payment_term_line .debit )
138
- or (move .type == ' in_invoice' and payment_term_line .credit )
132
+ (move .type == " out_invoice" and payment_term_line .debit )
133
+ or (move .type == " in_invoice" and payment_term_line .credit )
139
134
)
140
135
):
141
136
pay_term_vals = move ._prepare_discount_vals (payment_term )
142
137
if tax_line :
143
138
tax_discount_amount = move ._get_discount_amount (
144
139
tax_line .debit or tax_line .credit
145
140
)
146
- if move .type == ' in_invoice' :
141
+ if move .type == " in_invoice" :
147
142
tax_discount_amount = - tax_discount_amount
148
143
pay_term_vals .update (
149
144
{
150
- ' discount_tax_line_id' : tax_line .id ,
151
- ' amount_discount_tax' : tax_discount_amount ,
145
+ " discount_tax_line_id" : tax_line .id ,
146
+ " amount_discount_tax" : tax_discount_amount ,
152
147
}
153
148
)
154
149
payment_term_line .write (pay_term_vals )
@@ -159,22 +154,20 @@ def _prepare_discount_vals(self, payment_term):
159
154
if not payment_term .days_discount or not payment_term .percent_discount :
160
155
vals .update (
161
156
{
162
- ' amount_discount' : 0 ,
163
- ' amount_discount_currency' : 0 ,
164
- ' date_discount' : False ,
157
+ " amount_discount" : 0 ,
158
+ " amount_discount_currency" : 0 ,
159
+ " date_discount" : False ,
165
160
}
166
161
)
167
162
else :
168
163
company_currency = self .company_id .currency_id
169
164
diff_currency = self .currency_id != company_currency
170
- date_invoice = (
171
- self .date or self .invoice_date or fields .Date .today ()
172
- )
165
+ date_invoice = self .date or self .invoice_date or fields .Date .today ()
173
166
date_discount = payment_term .calc_discount_date (date_invoice )
174
167
# if there is a discount defined we always want the amount
175
168
# the date is enough to lock it down.
176
169
amount_discount_invoice_currency = self ._get_discount_amount ()
177
- vals [' date_discount' ] = date_discount
170
+ vals [" date_discount" ] = date_discount
178
171
amount_discount_company_currency = False
179
172
if diff_currency :
180
173
amount_discount_company_currency = self .currency_id ._convert (
@@ -183,20 +176,16 @@ def _prepare_discount_vals(self, payment_term):
183
176
self .company_id ,
184
177
date_invoice ,
185
178
)
186
- if self .type == ' out_invoice' :
179
+ if self .type == " out_invoice" :
187
180
if diff_currency :
188
- vals ['amount_discount' ] = amount_discount_company_currency
189
- vals [
190
- 'amount_discount_currency'
191
- ] = amount_discount_invoice_currency
181
+ vals ["amount_discount" ] = amount_discount_company_currency
182
+ vals ["amount_discount_currency" ] = amount_discount_invoice_currency
192
183
else :
193
- vals [' amount_discount' ] = amount_discount_invoice_currency
194
- elif self .type == ' in_invoice' :
184
+ vals [" amount_discount" ] = amount_discount_invoice_currency
185
+ elif self .type == " in_invoice" :
195
186
if diff_currency :
196
- vals ['amount_discount' ] = - amount_discount_company_currency
197
- vals [
198
- 'amount_discount_currency'
199
- ] = - amount_discount_invoice_currency
187
+ vals ["amount_discount" ] = - amount_discount_company_currency
188
+ vals ["amount_discount_currency" ] = - amount_discount_invoice_currency
200
189
else :
201
- vals [' amount_discount' ] = - amount_discount_invoice_currency
190
+ vals [" amount_discount" ] = - amount_discount_invoice_currency
202
191
return vals
0 commit comments