@@ -146,92 +146,6 @@ def _action_confirm(self):
146
146
self .order_line ._field_service_generation ()
147
147
return result
148
148
149
- def _create_invoices (self , grouped = False , final = False ):
150
- Invoices = self .env ["account.move" ]
151
- InvoiceLines = self .env ["account.move.line" ]
152
- invoice_ids = super ()._create_invoices (grouped , final )
153
- result = invoice_ids or Invoices
154
-
155
- for invoice in invoice_ids :
156
- # check for invoice lines with product
157
- # field_service_tracking = line
158
- lines_by_line = InvoiceLines .search (
159
- [
160
- ("move_id" , "=" , invoice .id ),
161
- ("product_id.field_service_tracking" , "=" , "line" ),
162
- ("exclude_from_invoice_tab" , "=" , False ),
163
- ]
164
- )
165
- if len (lines_by_line ) > 0 :
166
- # Create a new invoice for each "line" product
167
- line_count = len (invoice .invoice_line_ids )
168
- for i in range (len (lines_by_line )):
169
- duplicate = True
170
- if ((i + 1 ) == len (lines_by_line )) and ((i + 1 ) == line_count ):
171
- # Don't create a new invoice if there's only 1 product
172
- duplicate = False
173
- inv = invoice
174
- if duplicate :
175
- inv = invoice .copy ()
176
- inv .with_context (check_move_validity = False ).write (
177
- {"invoice_line_ids" : [(6 , 0 , [])]}
178
- )
179
- lines_by_line [i ].with_context (
180
- check_move_validity = False
181
- ).move_id = inv .id
182
- inv .with_context (
183
- check_move_validity = False
184
- )._recompute_dynamic_lines (
185
- recompute_all_taxes = True , recompute_tax_base_amount = True
186
- )
187
- invoice .with_context (
188
- check_move_validity = False
189
- )._recompute_dynamic_lines (
190
- recompute_all_taxes = True , recompute_tax_base_amount = True
191
- )
192
- result |= inv
193
- inv .fsm_order_ids = [(4 , lines_by_line [i ].fsm_order_id .id )]
194
- # check for invoice lines with product
195
- # field_service_tracking = sale
196
- lines_by_sale = InvoiceLines .search (
197
- [
198
- ("move_id" , "=" , invoice .id ),
199
- ("product_id.field_service_tracking" , "=" , "sale" ),
200
- ("exclude_from_invoice_tab" , "=" , False ),
201
- ]
202
- )
203
- if len (lines_by_sale ) > 0 :
204
- # Create a new invoice for "sale" products
205
- fsm_orders = self .env ["fsm.order" ].search (
206
- [("sale_id" , "in" , self .ids ), ("sale_line_id" , "=" , False )]
207
- )
208
- if len (lines_by_sale ) == len (invoice .invoice_line_ids ):
209
- # Don't create a new invoice if all products are "sale"
210
- invoice .fsm_order_ids = [
211
- (4 , fsm_order .id ) for fsm_order in fsm_orders
212
- ]
213
- elif len (invoice .invoice_line_ids ) > len (lines_by_sale ):
214
- new = invoice .copy ()
215
- new .fsm_order_ids = [(4 , fsm_order .id ) for fsm_order in fsm_orders ]
216
- new .with_context (check_move_validity = False ).write (
217
- {"invoice_line_ids" : [(6 , 0 , [])]}
218
- )
219
- lines_by_sale .with_context (check_move_validity = False ).write (
220
- {"move_id" : new .id }
221
- )
222
- new .with_context (
223
- check_move_validity = False
224
- )._recompute_dynamic_lines (
225
- recompute_all_taxes = True , recompute_tax_base_amount = True
226
- )
227
- invoice .with_context (
228
- check_move_validity = False
229
- )._recompute_dynamic_lines (
230
- recompute_all_taxes = True , recompute_tax_base_amount = True
231
- )
232
- result |= new
233
- return result
234
-
235
149
def action_view_fsm_order (self ):
236
150
fsm_orders = self .mapped ("fsm_order_ids" )
237
151
action = self .env .ref ("fieldservice.action_fsm_dash_order" ).read ()[0 ]
0 commit comments