4
4
5
5
import logging
6
6
7
+ from odoo .tests .common import Form , tagged
8
+
7
9
from odoo .addons .l10n_es_aeat .tests .test_l10n_es_aeat_mod_base import (
8
10
TestL10nEsAeatModBase ,
9
11
)
10
12
11
13
_logger = logging .getLogger ("aeat.349" )
12
14
13
15
16
+ @tagged ("post_install" , "-at_install" )
14
17
class TestL10nEsAeatMod349Base (TestL10nEsAeatModBase ):
15
18
# Set 'debug' attribute to True to easy debug this test
16
19
# Do not forget to include '--log-handler aeat:DEBUG' in Odoo command line
@@ -23,6 +26,32 @@ class TestL10nEsAeatMod349Base(TestL10nEsAeatModBase):
23
26
"P_IVA21_IC_BC//2" : (150 , 0 ),
24
27
}
25
28
29
+ @classmethod
30
+ def _invoice_refund (cls , invoice , dt , price_unit = None ):
31
+ _logger .debug (
32
+ "Refund {} invoice: date = {}: price_unit = {}" .format (
33
+ invoice .move_type , dt , price_unit or 150.0
34
+ )
35
+ )
36
+ default_values_list = [
37
+ {
38
+ "date" : dt ,
39
+ "invoice_date" : dt ,
40
+ "invoice_payment_term_id" : None ,
41
+ }
42
+ ]
43
+ inv = invoice .with_user (cls .billing_user )._reverse_moves (default_values_list )
44
+ if price_unit is not None :
45
+ inv_lines = inv .invoice_line_ids
46
+ with Form (inv ) as inv_form :
47
+ for i in range (len (inv_lines )):
48
+ with inv_form .invoice_line_ids .edit (i ) as line :
49
+ line .price_unit = price_unit or 150.0
50
+ inv .action_post ()
51
+ if cls .debug :
52
+ cls ._print_move_lines (inv .line_ids )
53
+ return inv
54
+
26
55
def test_model_349 (self ):
27
56
# Add some test data
28
57
self .customer .write (
@@ -210,3 +239,79 @@ def test_model_349(self):
210
239
self .env .ref ("l10n_es_aeat_mod349.act_report_aeat_mod349_pdf" )._render (
211
240
model349 .ids
212
241
)
242
+
243
+ def test_model_349_with_intermediate_periods (self ):
244
+ # Create vendor bill and 2 refunds in different periods
245
+ inv = self ._invoice_purchase_create ("2017-01-01" )
246
+ self ._invoice_refund (inv , "2017-02-01" , price_unit = 50 )
247
+ self ._invoice_refund (inv , "2017-03-01" , price_unit = 50 )
248
+ # Create model
249
+ model349_model = self .env ["l10n.es.aeat.mod349.report" ].with_user (
250
+ self .account_manager
251
+ )
252
+ model349_1 = model349_model .create (
253
+ {
254
+ "name" : "3490000000001" ,
255
+ "company_id" : self .company .id ,
256
+ "company_vat" : "1234567890" ,
257
+ "contact_name" : "Test owner" ,
258
+ "statement_type" : "N" ,
259
+ "support_type" : "T" ,
260
+ "contact_phone" : "911234455" ,
261
+ "year" : 2017 ,
262
+ "period_type" : "01" ,
263
+ "date_start" : "2017-01-01" ,
264
+ "date_end" : "2017-01-31" ,
265
+ }
266
+ )
267
+ # Calculate
268
+ _logger .debug ("Calculate AEAT 349 January 2017" )
269
+ model349_1 .button_calculate ()
270
+ self .assertEqual (model349_1 .total_partner_records , 1 )
271
+ self .assertEqual (model349_1 .partner_record_ids .total_operation_amount , 300 )
272
+
273
+ model349_2 = model349_model .create (
274
+ {
275
+ "name" : "3490000000002" ,
276
+ "company_id" : self .company .id ,
277
+ "company_vat" : "1234567890" ,
278
+ "contact_name" : "Test owner" ,
279
+ "statement_type" : "N" ,
280
+ "support_type" : "T" ,
281
+ "contact_phone" : "911234455" ,
282
+ "year" : 2017 ,
283
+ "period_type" : "02" ,
284
+ "date_start" : "2017-02-01" ,
285
+ "date_end" : "2017-02-28" ,
286
+ }
287
+ )
288
+ # Calculate
289
+ _logger .debug ("Calculate AEAT 349 February 2017" )
290
+ model349_2 .button_calculate ()
291
+ self .assertEqual (model349_2 .total_partner_records , 0 )
292
+ self .assertEqual (model349_2 .total_partner_refunds , 1 )
293
+ self .assertEqual (model349_2 .partner_refund_ids .total_origin_amount , 300 )
294
+ self .assertEqual (model349_2 .partner_refund_ids .total_operation_amount , 200 )
295
+
296
+ model349_3 = model349_model .create (
297
+ {
298
+ "name" : "3490000000003" ,
299
+ "company_id" : self .company .id ,
300
+ "company_vat" : "1234567890" ,
301
+ "contact_name" : "Test owner" ,
302
+ "statement_type" : "N" ,
303
+ "support_type" : "T" ,
304
+ "contact_phone" : "911234455" ,
305
+ "year" : 2017 ,
306
+ "period_type" : "03" ,
307
+ "date_start" : "2017-03-01" ,
308
+ "date_end" : "2017-03-31" ,
309
+ }
310
+ )
311
+ # Calculate
312
+ _logger .debug ("Calculate AEAT 349 March 2017" )
313
+ model349_3 .button_calculate ()
314
+ self .assertEqual (model349_3 .total_partner_records , 0 )
315
+ self .assertEqual (model349_3 .total_partner_refunds , 1 )
316
+ self .assertEqual (model349_3 .partner_refund_ids .total_origin_amount , 200 )
317
+ self .assertEqual (model349_3 .partner_refund_ids .total_operation_amount , 100 )
0 commit comments