Merge lp:~vauxoo/addons-vauxoo/7.0_debit-credit-yml_dev-sabrina into lp:addons-vauxoo/7.0

Proposed by Sabrina Romero - http://www.vauxoo.com
Status: Needs review
Proposed branch: lp:~vauxoo/addons-vauxoo/7.0_debit-credit-yml_dev-sabrina
Merge into: lp:addons-vauxoo/7.0
Diff against target: 1592 lines (+1380/-105)
4 files modified
debit_credit_note/__openerp__.py (+9/-2)
debit_credit_note/test/account_customer_refund.yml (+602/-0)
debit_credit_note/test/account_supplier_refund.yml (+616/-0)
debit_credit_note/wizard/account_invoice_refund.py (+153/-103)
To merge this branch: bzr merge lp:~vauxoo/addons-vauxoo/7.0_debit-credit-yml_dev-sabrina
Reviewer Review Type Date Requested Status
Sabrina Romero - http://www.vauxoo.com Needs Resubmitting
hbto [Vauxoo] http://www.vauxoo.com Needs Fixing
Review via email: mp+202786@code.launchpad.net

Description of the change

[FIX] Bug #918961 solved without l10n_ve_fiscal_requirements and test added.

The bug was happening in the module debit_credit_note, but not with l10n_ve_fiscal_requirements module installed.

To post a comment you must log in.
Revision history for this message
hbto [Vauxoo] http://www.vauxoo.com (humbertoarocha) :
review: Needs Fixing
961. By Sabrina Romero - http://www.vauxoo.com

[ADD] Supplier refund test added.

Revision history for this message
Sabrina Romero - http://www.vauxoo.com (sabrina) wrote :

[ADD] Supplier refund test added and fields belonging to OVL were removed with their respective methods.

review: Needs Resubmitting
962. By Sabrina Romero - http://www.vauxoo.com

[ADD] Some dependencies added.

Revision history for this message
Sabrina Romero - http://www.vauxoo.com (sabrina) wrote :

[ADD] Some dependencies added.

review: Needs Resubmitting
963. By Sabrina Romero - http://www.vauxoo.com

[FIX] The total amount of the invoice is assigned to the payment.

964. By Sabrina Romero - http://www.vauxoo.com

[FIX] id correct assignment.

965. By Sabrina Romero - http://www.vauxoo.com

[FIX] amount_total correct assignment.

Revision history for this message
Sabrina Romero - http://www.vauxoo.com (sabrina) wrote :

corrected error in the allocation of payment amount.
Tested to review 965, working!

review: Approve
Revision history for this message
Sabrina Romero - http://www.vauxoo.com (sabrina) :
review: Needs Resubmitting
966. By hbto [Vauxoo] http://www.vauxoo.com

[CC][debit_credit_note] Getting Rid of Commented Code

Revision history for this message
hbto [Vauxoo] http://www.vauxoo.com (humbertoarocha) wrote :

In general It Looks Ok,

Some issues,

*) Why did you have to change the browse for a read method in this iteration:

  for form in self.read(cr, uid, ids, context=context):

  for form in self.browse(cr, uid, ids, context=context):

Which resulted in you to change a bit of code downstream.

browse is one method recommended by openerp to use within the code

*) When accessing the date field you made a split and after
that you try to look for periods following the code which you
assume will _always_ be dash (-) separated,

date = wzr_brw.date and wzr_brw.date.split('-')
        period = wzr_brw and wzr_brw.period and wzr_brw.period.id
        period_ids = date and len(date) == 3 and period_obj.search(cr,uid,[('code','=','%s/%s'%(date[1],date[0]))],context=context)

please use instead the same date without splitting it, and
when look for the periods use the date though this time instead
of the code use date_start>= date and date_end <= date and special=False

this way it will be Period Code independent

Best Regards

review: Needs Fixing
967. By Sabrina Romero - http://www.vauxoo.com

[FIX] Using browse method instead read and splitting date removed.

Revision history for this message
Sabrina Romero - http://www.vauxoo.com (sabrina) wrote :

[FIX] Using browse method instead read and splitting date removed.
Tested to review 967, working!

review: Needs Resubmitting
Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

7 Month it stoped....

We should delete or merge or test + merge, what is the task related?

Revision history for this message
hbto [Vauxoo] http://www.vauxoo.com (humbertoarocha) wrote :

My fault, I have been delaying it.
On Sep 23, 2014 1:54 AM, "Nhomar - Vauxoo" <email address hidden> wrote:

> 7 Month it stoped....
>
> We should delete or merge or test + merge, what is the task related?
> --
>
> https://code.launchpad.net/~vauxoo/addons-vauxoo/7.0_debit-credit-yml_dev-sabrina/+merge/202786
> You are reviewing the proposed merge of
> lp:~vauxoo/addons-vauxoo/7.0_debit-credit-yml_dev-sabrina into
> lp:addons-vauxoo/7.0.
>

Unmerged revisions

967. By Sabrina Romero - http://www.vauxoo.com

[FIX] Using browse method instead read and splitting date removed.

966. By hbto [Vauxoo] http://www.vauxoo.com

[CC][debit_credit_note] Getting Rid of Commented Code

965. By Sabrina Romero - http://www.vauxoo.com

[FIX] amount_total correct assignment.

964. By Sabrina Romero - http://www.vauxoo.com

[FIX] id correct assignment.

963. By Sabrina Romero - http://www.vauxoo.com

[FIX] The total amount of the invoice is assigned to the payment.

962. By Sabrina Romero - http://www.vauxoo.com

[ADD] Some dependencies added.

961. By Sabrina Romero - http://www.vauxoo.com

[ADD] Supplier refund test added.

960. By Sabrina Romero - http://www.vauxoo.com

[FIX] Bug #918961 solved without l10n_ve_fiscal_requirements and test added.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debit_credit_note/__openerp__.py'
2--- debit_credit_note/__openerp__.py 2014-01-17 21:53:54 +0000
3+++ debit_credit_note/__openerp__.py 2014-02-03 16:27:19 +0000
4@@ -44,11 +44,16 @@
5
6 ''',
7 "init_xml": [],
8- "depends": ["base", "account"],
9+ "depends": [
10+ "base",
11+ "account",
12+ "account_voucher",
13+ "account_cancel",
14+ ],
15 'data': [
16 'wizard/account_invoice_debit_view.xml',
17 'wizard/account_invoice_parent_view.xml',
18- 'account_invoice_view.xml',
19+ "account_invoice_view.xml",
20 ],
21 'js': [
22 ],
23@@ -59,6 +64,8 @@
24 'demo': [
25 ],
26 'test': [
27+ 'test/account_supplier_refund.yml',
28+ 'test/account_customer_refund.yml',
29 ],
30 "installable": True,
31 "active": False,
32
33=== added directory 'debit_credit_note/test'
34=== added file 'debit_credit_note/test/account_customer_refund.yml'
35--- debit_credit_note/test/account_customer_refund.yml 1970-01-01 00:00:00 +0000
36+++ debit_credit_note/test/account_customer_refund.yml 2014-02-03 16:27:19 +0000
37@@ -0,0 +1,602 @@
38+-
39+ I set the context that will be used for the encoding of all the invoices of this file
40+-
41+ !context
42+ 'type': 'out_invoice'
43+-
44+ 1.- In order to test account refund with "Create a draft refund" method
45+-
46+ 1.1.- I create a customer invoice
47+-
48+ !record {model: account.invoice, id: account_invoice_customer0, view: account.invoice_form}: &customer_invoice
49+ payment_term: account.account_payment_term_advance
50+ journal_id: account.sales_journal
51+ partner_id: base.res_partner_3
52+ reference_type: none
53+ name: 'Test Customer Invoice - debit_credit_note'
54+ invoice_line:
55+ - product_id: product.product_product_5
56+ price_unit: 850.0
57+ quantity: 1.0
58+-
59+ 1.2.- I check that Initially customer invoice state is "Draft"
60+-
61+ !assert {model: account.invoice, id: account_invoice_customer0}:
62+ - state == 'draft'
63+-
64+ 1.3.- I check that the customer invoice is a "Customer Invoice"
65+-
66+ !assert {model: account.invoice, id: account_invoice_customer0, string: This is not a customer invoice}:
67+ - type == 'out_invoice'
68+-
69+ 1.4.- I change the state of invoice to open by clicking Validate button
70+-
71+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer0}
72+-
73+ 1.5.- I check that the invoice state is now "Open"
74+-
75+ !assert {model: account.invoice, id: account_invoice_customer0}:
76+ - state == 'open'
77+-
78+ 1.6.- I create a customer refund using the method "Create a draft refund" and
79+ check the state of the account invoice refund resulting
80+-
81+ !python {model: account.invoice.refund}: |
82+ import time
83+ values = {
84+ 'date': time.strftime('%Y-%m-%d'),
85+ 'period': self.pool.get('account.period').find(
86+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
87+ 'journal_id': ref('account.refund_expenses_journal'),
88+ 'description': 'Desde el test',
89+ 'filter_refund': 'refund',
90+ }
91+ wzr_id = self.create(cr, uid, values)
92+ assert wzr_id, 'The wizard instance was not created.'
93+ context['wzr_id'] = wzr_id
94+ context['active_ids'] = [ref('account_invoice_customer0')]
95+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
96+ assert rfnd_id, 'The refund was not created.'
97+ context['rfnd_id'] = rfnd_id
98+ obj_inv = self.pool.get('account.invoice')
99+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
100+ assert rfnd_customer_inv_brw[0].state == 'draft', 'The customer refund was not properly created, the state must be Draft.'
101+-
102+ 1.7.- I check the correct asigning of parent_id in the customer refund created, for that
103+ the customer refund must have the customer invoice id in the fiel parent_id
104+-
105+ !python {model: account.invoice.refund}: |
106+ obj_inv = self.pool.get('account.invoice')
107+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
108+ customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer0'))
109+ assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
110+-
111+ 2.- In order to test account refund with "Create refund and reconcile" method
112+-
113+ 2.1.- I create a new customer invoice
114+-
115+ !record {model: account.invoice, id: account_invoice_customer1, view: account.invoice_form }:
116+ <<: *customer_invoice
117+-
118+ 2.2.- I check that Initially customer invoice state is "Draft"
119+-
120+ !assert {model: account.invoice, id: account_invoice_customer1}:
121+ - state == 'draft'
122+-
123+ 2.3.- I check that the customer invoice is a "Customer Invoice"
124+-
125+ !assert {model: account.invoice, id: account_invoice_customer1, string: This is not a customer invoice}:
126+ - type == 'out_invoice'
127+-
128+ 2.4.- I change the state of invoice to open by clicking Validate button
129+-
130+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer1}
131+-
132+ 2.5.- I check that the invoice state is now "Open"
133+-
134+ !assert {model: account.invoice, id: account_invoice_customer1}:
135+ - state == 'open'
136+-
137+ 2.6.- I create a customer refund using the method "Create refund and reconcile" and
138+ check the state of the account invoice refund resulting
139+-
140+ !python {model: account.invoice.refund}: |
141+ import time
142+ values = {
143+ 'date': time.strftime('%Y-%m-%d'),
144+ 'period': self.pool.get('account.period').find(
145+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
146+ 'journal_id': ref('account.refund_expenses_journal'),
147+ 'description': 'Desde el test',
148+ 'filter_refund': 'cancel',
149+ }
150+ wzr_id = self.create(cr, uid, values)
151+ assert wzr_id, 'The wizard instance was not created.'
152+ context['wzr_id'] = wzr_id
153+ context['active_ids'] = [ref('account_invoice_customer1')]
154+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
155+ assert rfnd_id, 'The refund was not created.'
156+ context['rfnd_id'] = rfnd_id
157+ obj_inv = self.pool.get('account.invoice')
158+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
159+ assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
160+-
161+ 2.7.- I check the correct asigning of parent_id in the customer refund created, for that
162+ the customer refund must have the customer invoice id in the fiel parent_id
163+-
164+ !python {model: account.invoice.refund}: |
165+ obj_inv = self.pool.get('account.invoice')
166+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
167+ customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer1'))
168+ assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
169+-
170+ 3.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
171+ method
172+-
173+ 3.1.- I create a new customer invoice
174+-
175+ !record {model: account.invoice, id: account_invoice_customer2, view: account.invoice_form }:
176+ <<: *customer_invoice
177+-
178+ 3.2.- I check that Initially customer invoice state is "Draft"
179+-
180+ !assert {model: account.invoice, id: account_invoice_customer2}:
181+ - state == 'draft'
182+-
183+ 3.3.- I check that the customer invoice is a "Customer Invoice"
184+-
185+ !assert {model: account.invoice, id: account_invoice_customer2, string: This is not a customer invoice}:
186+ - type == 'out_invoice'
187+-
188+ 3.4.- I change the state of invoice to open by clicking Validate button
189+-
190+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer2}
191+-
192+ 3.5.- I check that the invoice state is now "Open"
193+-
194+ !assert {model: account.invoice, id: account_invoice_customer2}:
195+ - state == 'open'
196+-
197+ 3.6.- I create a customer refund using the method "Create refund, reconcile and create a new draft invoice" and
198+ check the state of the account invoice refund resulting
199+-
200+ !python {model: account.invoice.refund}: |
201+ import time
202+ values = {
203+ 'date': time.strftime('%Y-%m-%d'),
204+ 'period': self.pool.get('account.period').find(
205+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
206+ 'journal_id': ref('account.refund_expenses_journal'),
207+ 'description': 'Desde el test',
208+ 'filter_refund': 'modify',
209+ }
210+ wzr_id = self.create(cr, uid, values)
211+ assert wzr_id, 'The wizard instance was not created.'
212+ context['wzr_id'] = wzr_id
213+ context['active_ids'] = [ref('account_invoice_customer2')]
214+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
215+ assert rfnd_id, 'The refund was not created.'
216+ context['rfnd_id'] = rfnd_id
217+ obj_inv = self.pool.get('account.invoice')
218+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
219+ assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
220+-
221+ 3.7.- I check the correct asigning of parent_id in the customer refund created, for that
222+ the customer refund must have the customer invoice id in the fiel parent_id
223+-
224+ !python {model: account.invoice.refund}: |
225+ obj_inv = self.pool.get('account.invoice')
226+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
227+ customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer2'))
228+ assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
229+-
230+ 3.8.- I check that the new customer invoice was created in Draft state
231+-
232+ !python {model: account.invoice.refund}: |
233+ obj_inv = self.pool.get('account.invoice')
234+ inv_src = obj_inv.search(cr, uid, [], order='id')
235+ customer_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
236+ assert customer_inv_brw.state == 'draft', 'The new customer invoice was not properly created, the state must be Draft.'
237+-
238+ 4.- In order to test account refund with "Create a draft refund" method in a "Paid" invoice
239+-
240+ 4.1.- I create a new partner
241+-
242+ !record {model: 'res.partner', id: res_partner8}:
243+ name: Juan Perez
244+ use_parent_address: True
245+ function: Tests
246+ email: juan@perez.com
247+-
248+ 4.2.- I create a Sale Journal.
249+-
250+ !record {model: account.journal, id: sale_journal_debit}:
251+ code: sjou_test
252+ company_id: base.main_company
253+ name: Sale Journal For Debit Credit Note Tests
254+ sequence_id: account.sequence_sale_journal
255+ type: sale
256+-
257+ 4.3.- I create a new customer invoice
258+-
259+ !record {model: account.invoice, id: account_invoice_customer3}:
260+ account_id: account.a_recv
261+ company_id: base.main_company
262+ currency_id: base.EUR
263+ invoice_line:
264+ - account_id: account.a_sale
265+ name: '[PCSC234] PC Assemble SC234'
266+ price_unit: 450.0
267+ quantity: 1.0
268+ product_id: product.product_product_3
269+ uos_id: product.product_uom_unit
270+ journal_id: sale_journal_debit
271+ partner_id: res_partner8
272+-
273+ 4.4.- I check that Initially customer invoice state is "Draft"
274+-
275+ !assert {model: account.invoice, id: account_invoice_customer3}:
276+ - state == 'draft'
277+-
278+ 4.5.- I check that the customer invoice is a "Customer Invoice"
279+-
280+ !assert {model: account.invoice, id: account_invoice_customer3, string: This is not a customer invoice}:
281+ - type == 'out_invoice'
282+-
283+ 4.6.- I change the state of invoice to open by clicking Validate button
284+-
285+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer3}
286+-
287+ 4.7.- I check that the invoice state is now "Open"
288+-
289+ !assert {model: account.invoice, id: account_invoice_customer3}:
290+ - state == 'open'
291+-
292+ 4.8.- I check that a payment entry gets created in the account.move.line
293+-
294+ !python {model: account.invoice}: |
295+ acc_id=self.browse(cr, uid, ref("account_invoice_customer3"))
296+ assert(acc_id.move_id)
297+-
298+ 4.9.- I create a Cash Journal.
299+-
300+ !record {model: account.journal, id: cash_journal_debit}:
301+ code: cjou_test
302+ company_id: base.main_company
303+ name: Cash Journal For Debit Credit Note Tests
304+ sequence_id: account.sequence_cash_journal
305+ type: cash
306+-
307+ 4.10.- I will create and post an account voucher with the amount total
308+ of the customer invoice created for the partner Juan Perez.
309+-
310+ !python {model: account.voucher}: |
311+ import netsvc
312+ import time
313+ vals = {}
314+ amount_total = self.pool.get('account.invoice').browse(cr, uid, [ref('account_invoice_customer3')], context=None)[0].amount_total
315+ journal_id = self.default_get(cr, uid, ['journal_id']).get('journal_id',None)
316+ res = self.onchange_partner_id(cr, uid, [], ref("res_partner8"), journal_id, 0.0, 1, ttype='receipt', date=False)
317+ vals = {
318+ 'account_id': ref('account.cash'),
319+ 'amount': amount_total,
320+ 'company_id': ref('base.main_company'),
321+ 'journal_id': ref('cash_journal_debit'),
322+ 'partner_id': ref('res_partner8'),
323+ 'period_id': self.pool.get('account.period').find(
324+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
325+ 'type': 'receipt',
326+ }
327+ if not res['value']['line_cr_ids']:
328+ res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
329+ res['value']['line_cr_ids'][0]['amount'] = amount_total
330+ vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
331+ id = self.create(cr, uid, vals)
332+ voucher_id = self.browse(cr, uid, id)
333+ assert (voucher_id.state=='draft'), "Voucher is not in draft state"
334+ wf_service = netsvc.LocalService("workflow")
335+ wf_service.trg_validate(uid, 'account.voucher', voucher_id.id, 'proforma_voucher', cr)
336+-
337+ 4.11.- I check if the state of the invoice is "Paid"
338+-
339+ !assert {model: account.invoice, id: account_invoice_customer3}:
340+ - state == 'paid'
341+-
342+ 4.12.- I modified the sale journal record so it can cancel invoice
343+-
344+ !record {model: account.journal, id: sale_journal_debit}:
345+ update_posted: 1
346+-
347+ 4.13.- I modified the cash journal record so it can cancel invoice
348+-
349+ !record {model: account.journal, id: cash_journal_debit}:
350+ update_posted: 1
351+-
352+ 4.14.- I create a Sale Refund Journal.
353+-
354+ !record {model: account.journal, id: sale_refund_journal_debit}:
355+ code: csrjou_test
356+ company_id: base.main_company
357+ name: Sale Refund Journal For Debit Credit Note Tests
358+ sequence_id: account.sequence_refund_sales_journal
359+ type: sale_refund
360+-
361+ 4.15.- I create a customer refund using the method "Create a draft refund" and
362+ check the state of the account invoice refund resulting
363+-
364+ !python {model: account.invoice.refund}: |
365+ import time
366+ values = {
367+ 'date': time.strftime('%Y-%m-%d'),
368+ 'period': self.pool.get('account.period').find(
369+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
370+ 'journal_id': ref('sale_refund_journal_debit'),
371+ 'description': 'Desde el test',
372+ 'filter_refund': 'refund',
373+ }
374+ wzr_id = self.create(cr, uid, values)
375+ assert wzr_id, 'The wizard instance was not created.'
376+ context['wzr_id'] = wzr_id
377+ context['active_ids'] = [ref('account_invoice_customer3')]
378+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
379+ assert rfnd_id, 'The refund was not created.'
380+ context['rfnd_id'] = rfnd_id
381+ obj_inv = self.pool.get('account.invoice')
382+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
383+ assert rfnd_customer_inv_brw[0].state == 'draft', 'The customer refund was not properly created, the state must be Draft.'
384+-
385+ 4.16.- I check the correct asigning of parent_id in the customer refund created, for that
386+ the customer refund must have the customer invoice id in the fiel parent_id
387+-
388+ !python {model: account.invoice.refund}: |
389+ obj_inv = self.pool.get('account.invoice')
390+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
391+ customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer3'))
392+ assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
393+-
394+ 5.- In order to test account refund with "Create refund and reconcile" method in a "Paid" invoice
395+-
396+ 5.1.- I create a new partner
397+-
398+ !record {model: 'res.partner', id: res_partner7}:
399+ name: Pedro Perez
400+ use_parent_address: True
401+ function: Tests
402+ email: pedro@perez.com
403+-
404+ 5.2.- I create a new customer invoice
405+-
406+ !record {model: account.invoice, id: account_invoice_customer4}:
407+ account_id: account.a_recv
408+ company_id: base.main_company
409+ currency_id: base.EUR
410+ invoice_line:
411+ - account_id: account.a_sale
412+ name: '[PCSC234] PC Assemble SC234'
413+ price_unit: 450.0
414+ quantity: 1.0
415+ product_id: product.product_product_3
416+ uos_id: product.product_uom_unit
417+ journal_id: sale_journal_debit
418+ partner_id: res_partner7
419+-
420+ 5.3.- I check that Initially customer invoice state is "Draft"
421+-
422+ !assert {model: account.invoice, id: account_invoice_customer4}:
423+ - state == 'draft'
424+-
425+ 5.4.- I check that the customer invoice is a "Customer Invoice"
426+-
427+ !assert {model: account.invoice, id: account_invoice_customer4, string: This is not a customer invoice}:
428+ - type == 'out_invoice'
429+-
430+ 5.5.- I change the state of invoice to open by clicking Validate button
431+-
432+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer4}
433+-
434+ 5.6.- I check that the invoice state is now "Open"
435+-
436+ !assert {model: account.invoice, id: account_invoice_customer4}:
437+ - state == 'open'
438+-
439+ 5.7.- I check that a payment entry gets created in the account.move.line
440+-
441+ !python {model: account.invoice}: |
442+ acc_id=self.browse(cr, uid, ref("account_invoice_customer4"))
443+ assert(acc_id.move_id)
444+-
445+ 5.8.- I will create and post an account voucher with the amount total
446+ of the customer invoice created for the partner Pedro Perez.
447+-
448+ !python {model: account.voucher}: |
449+ import netsvc
450+ import time
451+ vals = {}
452+ amount_total = self.pool.get('account.invoice').browse(cr, uid, [ref('account_invoice_customer4')], context=None)[0].amount_total
453+ journal_id = self.default_get(cr, uid, ['journal_id']).get('journal_id',None)
454+ res = self.onchange_partner_id(cr, uid, [], ref("res_partner7"), journal_id, 0.0, 1, ttype='receipt', date=False)
455+ vals = {
456+ 'account_id': ref('account.cash'),
457+ 'amount': amount_total,
458+ 'company_id': ref('base.main_company'),
459+ 'journal_id': ref('cash_journal_debit'),
460+ 'partner_id': ref('res_partner7'),
461+ 'period_id': self.pool.get('account.period').find(
462+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
463+ 'type': 'receipt',
464+ }
465+ if not res['value']['line_cr_ids']:
466+ res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
467+ res['value']['line_cr_ids'][0]['amount'] = amount_total
468+ vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
469+ id = self.create(cr, uid, vals)
470+ voucher_id = self.browse(cr, uid, id)
471+ assert (voucher_id.state=='draft'), "Voucher is not in draft state"
472+ wf_service = netsvc.LocalService("workflow")
473+ wf_service.trg_validate(uid, 'account.voucher', voucher_id.id, 'proforma_voucher', cr)
474+-
475+ 5.9.- I check if the state of the invoice is "Paid"
476+-
477+ !assert {model: account.invoice, id: account_invoice_customer4}:
478+ - state == 'paid'
479+-
480+ 5.10.- I create a customer refund using the method "Create refund and reconcile" and
481+ check the state of the account invoice refund resulting
482+-
483+ !python {model: account.invoice.refund}: |
484+ import time
485+ values = {
486+ 'date': time.strftime('%Y-%m-%d'),
487+ 'period': self.pool.get('account.period').find(
488+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
489+ 'journal_id': ref('sale_refund_journal_debit'),
490+ 'description': 'Desde el test',
491+ 'filter_refund': 'cancel',
492+ }
493+ wzr_id = self.create(cr, uid, values)
494+ assert wzr_id, 'The wizard instance was not created.'
495+ context['wzr_id'] = wzr_id
496+ context['active_ids'] = [ref('account_invoice_customer4')]
497+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
498+ assert rfnd_id, 'The refund was not created.'
499+ context['rfnd_id'] = rfnd_id
500+ obj_inv = self.pool.get('account.invoice')
501+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
502+ assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
503+-
504+ 5.11.- I check the correct asigning of parent_id in the customer refund created, for that
505+ the customer refund must have the customer invoice id in the fiel parent_id
506+-
507+ !python {model: account.invoice.refund}: |
508+ obj_inv = self.pool.get('account.invoice')
509+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
510+ customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer4'))
511+ assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
512+-
513+ 6.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
514+ method in a "Paid" invoice
515+-
516+ 6.1.- I create a new partner
517+-
518+ !record {model: 'res.partner', id: res_partner9}:
519+ name: Maria Perez
520+ use_parent_address: True
521+ function: Tests
522+ email: maria@perez.com
523+-
524+ 6.2.- I create a new customer invoice
525+-
526+ !record {model: account.invoice, id: account_invoice_customer5}:
527+ account_id: account.a_recv
528+ company_id: base.main_company
529+ currency_id: base.EUR
530+ invoice_line:
531+ - account_id: account.a_sale
532+ name: '[PCSC234] PC Assemble SC234'
533+ price_unit: 450.0
534+ quantity: 1.0
535+ product_id: product.product_product_3
536+ uos_id: product.product_uom_unit
537+ journal_id: sale_journal_debit
538+ partner_id: res_partner9
539+-
540+ 6.3.- I check that Initially customer invoice state is "Draft"
541+-
542+ !assert {model: account.invoice, id: account_invoice_customer5}:
543+ - state == 'draft'
544+-
545+ 6.4.- I check that the customer invoice is a "Customer Invoice"
546+-
547+ !assert {model: account.invoice, id: account_invoice_customer5, string: This is not a customer invoice}:
548+ - type == 'out_invoice'
549+-
550+ 6.5.- I change the state of invoice to open by clicking Validate button
551+-
552+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer5}
553+-
554+ 6.6.- I check that the invoice state is now "Open"
555+-
556+ !assert {model: account.invoice, id: account_invoice_customer5}:
557+ - state == 'open'
558+-
559+ 6.7.- I check that a payment entry gets created in the account.move.line
560+-
561+ !python {model: account.invoice}: |
562+ acc_id=self.browse(cr, uid, ref("account_invoice_customer5"))
563+ assert(acc_id.move_id)
564+-
565+ 6.8.- I will create and post an account voucher with the amount total
566+ of the customer invoice created for the partner Maria Perez.
567+-
568+ !python {model: account.voucher}: |
569+ import netsvc
570+ import time
571+ vals = {}
572+ amount_total = self.pool.get('account.invoice').browse(cr, uid, [ref('account_invoice_customer5')], context=None)[0].amount_total
573+ journal_id = self.default_get(cr, uid, ['journal_id']).get('journal_id',None)
574+ res = self.onchange_partner_id(cr, uid, [], ref("res_partner9"), journal_id, 0.0, 1, ttype='receipt', date=False)
575+ vals = {
576+ 'account_id': ref('account.cash'),
577+ 'amount': amount_total,
578+ 'company_id': ref('base.main_company'),
579+ 'journal_id': ref('cash_journal_debit'),
580+ 'partner_id': ref('res_partner9'),
581+ 'period_id': self.pool.get('account.period').find(
582+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
583+ 'type': 'receipt',
584+ }
585+ if not res['value']['line_cr_ids']:
586+ res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
587+ res['value']['line_cr_ids'][0]['amount'] = amount_total
588+ vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
589+ id = self.create(cr, uid, vals)
590+ voucher_id = self.browse(cr, uid, id)
591+ assert (voucher_id.state=='draft'), "Voucher is not in draft state"
592+ wf_service = netsvc.LocalService("workflow")
593+ wf_service.trg_validate(uid, 'account.voucher', voucher_id.id, 'proforma_voucher', cr)
594+-
595+ 6.9.- I check if the state of the invoice is "Paid"
596+-
597+ !assert {model: account.invoice, id: account_invoice_customer5}:
598+ - state == 'paid'
599+-
600+ 6.10.- I create a customer refund using the method "Create refund, reconcile and create a new draft invoice" and
601+ check the state of the account invoice refund resulting
602+-
603+ !python {model: account.invoice.refund}: |
604+ import time
605+ values = {
606+ 'date': time.strftime('%Y-%m-%d'),
607+ 'period': self.pool.get('account.period').find(
608+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
609+ 'journal_id': ref('sale_refund_journal_debit'),
610+ 'description': 'Desde el test',
611+ 'filter_refund': 'modify',
612+ }
613+ wzr_id = self.create(cr, uid, values)
614+ assert wzr_id, 'The wizard instance was not created.'
615+ context['wzr_id'] = wzr_id
616+ context['active_ids'] = [ref('account_invoice_customer5')]
617+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
618+ assert rfnd_id, 'The refund was not created.'
619+ context['rfnd_id'] = rfnd_id
620+ obj_inv = self.pool.get('account.invoice')
621+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
622+ assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
623+-
624+ 6.11.- I check the correct asigning of parent_id in the customer refund created, for that
625+ the customer refund must have the customer invoice id in the fiel parent_id
626+-
627+ !python {model: account.invoice.refund}: |
628+ obj_inv = self.pool.get('account.invoice')
629+ rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
630+ customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer5'))
631+ assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
632+-
633+ 6.12.- I check that the new customer invoice was created in Draft state
634+-
635+ !python {model: account.invoice.refund}: |
636+ obj_inv = self.pool.get('account.invoice')
637+ inv_src = obj_inv.search(cr, uid, [], order='id')
638+ customer_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
639+ assert customer_inv_brw.state == 'draft', 'The new customer invoice was not properly created, the state must be Draft.'
640
641=== added file 'debit_credit_note/test/account_supplier_refund.yml'
642--- debit_credit_note/test/account_supplier_refund.yml 1970-01-01 00:00:00 +0000
643+++ debit_credit_note/test/account_supplier_refund.yml 2014-02-03 16:27:19 +0000
644@@ -0,0 +1,616 @@
645+-
646+ I set the context that will be used for the encoding of all the invoices of this file
647+-
648+ !context
649+ 'type': 'in_invoice'
650+-
651+ 1.- In order to test account refund with "Create a draft refund" method
652+-
653+ 1.1.- I create a supplier invoice
654+-
655+ !record {model: account.invoice, id: account_invoice_supplier0, view: account.invoice_supplier_form }: &supplier_invoice
656+ account_id: account.a_pay
657+ company_id: base.main_company
658+ currency_id: base.EUR
659+ invoice_line:
660+ - account_id: account.a_expense
661+ name: '[PCSC234] PC Assemble SC234'
662+ price_unit: 300.0
663+ product_id: product.product_product_3
664+ quantity: 10.0
665+ uos_id: product.product_uom_unit
666+ journal_id: account.expenses_journal
667+ partner_id: base.res_partner_12
668+ reference_type: none
669+ type: 'in_invoice'
670+-
671+ 1.2.- I check that Initially supplier invoice state is "Draft"
672+-
673+ !assert {model: account.invoice, id: account_invoice_supplier0}:
674+ - state == 'draft'
675+-
676+ 1.3.- I check that the supplier invoice is a "Supplier Invoice"
677+-
678+ !assert {model: account.invoice, id: account_invoice_supplier0, string: This is not a supplier invoice}:
679+ - type == 'in_invoice'
680+-
681+ 1.4.- I change the state of invoice to open by clicking Validate button
682+-
683+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier0}
684+-
685+ 1.5.- I check that the invoice state is now "Open"
686+-
687+ !assert {model: account.invoice, id: account_invoice_supplier0}:
688+ - state == 'open'
689+-
690+ 1.6.- I create a supplier refund using the method "Create a draft refund" and
691+ check the state of the account invoice refund resulting
692+-
693+ !python {model: account.invoice.refund}: |
694+ import time
695+ values = {
696+ 'date': time.strftime('%Y-%m-%d'),
697+ 'period': self.pool.get('account.period').find(
698+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
699+ 'journal_id': ref('account.refund_expenses_journal'),
700+ 'description': 'Desde el test',
701+ 'filter_refund': 'refund',
702+ }
703+ wzr_id = self.create(cr, uid, values)
704+ context['wzr_id'] = wzr_id
705+ context['active_ids'] = [ref('account_invoice_supplier0')]
706+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
707+ context['rfnd_id'] = rfnd_id
708+ obj_inv = self.pool.get('account.invoice')
709+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
710+ assert rfnd_supplier_inv_brw[0].state == 'draft', 'The supplier refund was not properly created, the state must be Draft.'
711+-
712+ 1.7.- I check the correct asigning of parent_id in the supplier refund created, for that
713+ the supplier refund must have the supplier invoice id in the fiel parent_id
714+-
715+ !python {model: account.invoice.refund}: |
716+ obj_inv = self.pool.get('account.invoice')
717+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
718+ supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier0'))
719+ assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
720+-
721+ 2.- In order to test account refund with "Create refund and reconcile" method
722+-
723+ 2.1.- I create a new supplier invoice
724+-
725+ !record {model: account.invoice, id: account_invoice_supplier1, view: account.invoice_supplier_form }:
726+ <<: *supplier_invoice
727+-
728+ 2.2.- I check that Initially supplier invoice state is "Draft"
729+-
730+ !assert {model: account.invoice, id: account_invoice_supplier1}:
731+ - state == 'draft'
732+-
733+ 2.3.- I check that the supplier invoice is a "Supplier Invoice"
734+-
735+ !assert {model: account.invoice, id: account_invoice_supplier1, string: This is not a supplier invoice}:
736+ - type == 'in_invoice'
737+-
738+ 2.4.- I change the state of invoice to open by clicking Validate button
739+-
740+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier1}
741+-
742+ 2.5.- I check that the invoice state is now "Open"
743+-
744+ !assert {model: account.invoice, id: account_invoice_supplier1}:
745+ - state == 'open'
746+-
747+ 2.6.- I create a supplier refund using the method "Create refund and reconcile" and
748+ check the state of the account invoice refund resulting
749+-
750+ !python {model: account.invoice.refund}: |
751+ import time
752+ values = {
753+ 'date': time.strftime('%Y-%m-%d'),
754+ 'period': self.pool.get('account.period').find(
755+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
756+ 'journal_id': ref('account.refund_expenses_journal'),
757+ 'description': 'Desde el test',
758+ 'filter_refund': 'cancel',
759+ }
760+ wzr_id = self.create(cr, uid, values)
761+ context['wzr_id'] = wzr_id
762+ context['active_ids'] = [ref('account_invoice_supplier1')]
763+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
764+ context['rfnd_id'] = rfnd_id
765+ obj_inv = self.pool.get('account.invoice')
766+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
767+ assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
768+-
769+ 2.7.- I check the correct asigning of parent_id in the supplier refund created, for that
770+ the supplier refund must have the supplier invoice id in the fiel parent_id
771+-
772+ !python {model: account.invoice.refund}: |
773+ obj_inv = self.pool.get('account.invoice')
774+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
775+ supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier1'))
776+ assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
777+-
778+ 3.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
779+ method
780+-
781+ 3.1.- I create a new supplier invoice
782+-
783+ !record {model: account.invoice, id: account_invoice_supplier2, view: account.invoice_supplier_form }:
784+ <<: *supplier_invoice
785+-
786+ 3.2.- I check that Initially supplier invoice state is "Draft"
787+-
788+ !assert {model: account.invoice, id: account_invoice_supplier2}:
789+ - state == 'draft'
790+-
791+ 3.3.- I check that the supplier invoice is a "Supplier Invoice"
792+-
793+ !assert {model: account.invoice, id: account_invoice_supplier2, string: This is not a supplier invoice}:
794+ - type == 'in_invoice'
795+-
796+ 3.4.- I change the state of invoice to open by clicking Validate button
797+-
798+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier2}
799+-
800+ 3.5.- I check that the invoice state is now "Open"
801+-
802+ !assert {model: account.invoice, id: account_invoice_supplier2}:
803+ - state == 'open'
804+-
805+ 3.6.- I create a supplier refund using the method "Create refund, reconcile and create a new draft invoice" and
806+ check the state of the account invoice refund resulting
807+-
808+ !python {model: account.invoice.refund}: |
809+ import time
810+ values = {
811+ 'date': time.strftime('%Y-%m-%d'),
812+ 'period': self.pool.get('account.period').find(
813+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
814+ 'journal_id': ref('account.refund_expenses_journal'),
815+ 'description': 'Desde el test',
816+ 'filter_refund': 'modify',
817+ }
818+ wzr_id = self.create(cr, uid, values)
819+ context['wzr_id'] = wzr_id
820+ context['active_ids'] = [ref('account_invoice_supplier2')]
821+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
822+ context['rfnd_id'] = rfnd_id
823+ obj_inv = self.pool.get('account.invoice')
824+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
825+ assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
826+-
827+ 3.7.- I check the correct asigning of parent_id in the supplier refund created, for that
828+ the supplier refund must have the supplier invoice id in the fiel parent_id
829+-
830+ !python {model: account.invoice.refund}: |
831+ obj_inv = self.pool.get('account.invoice')
832+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
833+ supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier2'))
834+ assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
835+-
836+ 3.8.- I check that the new supplier invoice was created in Draft state
837+-
838+ !python {model: account.invoice.refund}: |
839+ obj_inv = self.pool.get('account.invoice')
840+ inv_src = obj_inv.search(cr, uid, [], order='id')
841+ supplier_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
842+ assert supplier_inv_brw.state == 'draft', 'The new supplier invoice was not properly created, the state must be Draft.'
843+-
844+ 4.- In order to test account refund with "Create a draft refund" method in a "Paid" invoice
845+-
846+ 4.1.- I create a new partner
847+-
848+ !record {model: 'res.partner', id: res_partner10}:
849+ name: Juan Garcia
850+ use_parent_address: True
851+ function: Tests
852+ email: juan@garcia.com
853+ supplier: True
854+-
855+ 4.2.- I create a Purchase Journal.
856+-
857+ !record {model: account.journal, id: purchase_journal_debit}:
858+ code: pjou_test
859+ company_id: base.main_company
860+ name: Purchase Journal For Debit Credit Note Tests
861+ sequence_id: account.sequence_purchase_journal
862+ type: purchase
863+-
864+ 4.3.- I create a new supplier invoice
865+-
866+ !record {model: account.invoice, id: account_invoice_supplier3, view: account.invoice_supplier_form }:
867+ account_id: account.a_pay
868+ company_id: base.main_company
869+ currency_id: base.EUR
870+ invoice_line:
871+ - account_id: account.a_expense
872+ name: '[PCSC234] PC Assemble SC234'
873+ price_unit: 300.0
874+ product_id: product.product_product_3
875+ quantity: 10.0
876+ uos_id: product.product_uom_unit
877+ journal_id: purchase_journal_debit
878+ partner_id: res_partner10
879+ reference_type: none
880+ type: 'in_invoice'
881+-
882+ 4.4.- I check that initially supplier invoice state is "Draft"
883+-
884+ !assert {model: account.invoice, id: account_invoice_supplier3}:
885+ - state == 'draft'
886+-
887+ 4.5.- I check that the supplier invoice is a "Supplier Invoice"
888+-
889+ !assert {model: account.invoice, id: account_invoice_supplier3, string: This is not a supplier invoice}:
890+ - type == 'in_invoice'
891+-
892+ 4.6.- I change the state of invoice to open by clicking Validate button
893+-
894+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier3}
895+-
896+ 4.7.- I check that the invoice state is now "Open"
897+-
898+ !assert {model: account.invoice, id: account_invoice_supplier3}:
899+ - state == 'open'
900+-
901+ 4.8.- I check that a payment entry gets created in the account.move.line
902+-
903+ !python {model: account.invoice}: |
904+ acc_id=self.browse(cr, uid, ref("account_invoice_supplier3"))
905+ assert(acc_id.move_id)
906+-
907+ 4.9.- I create a Bank Journal.
908+-
909+ !record {model: account.journal, id: bank_journal_debit}:
910+ name: Bank Journal For Debit Credit Note Tests
911+ code: bjou_test
912+ type: bank
913+ analytic_journal_id: account.sit
914+ sequence_id: account.sequence_bank_journal
915+ default_debit_account_id: account.cash
916+ default_credit_account_id: account.cash
917+ company_id: base.main_company
918+-
919+ 4.10.- I will create and post an account voucher of amount 3450.00 for the partner Juan Garcia.
920+-
921+ !record {model: account.voucher, id: account_voucher0, view: account_voucher.view_vendor_payment_form}:
922+ type: payment
923+ account_id: account.cash
924+ amount: 3450.00
925+ company_id: base.main_company
926+ journal_id: bank_journal_debit
927+ name: Voucher x
928+ narration: PC Assemble SC234
929+ line_dr_ids:
930+ - account_id: account.cash
931+ amount: 3450.00
932+ name: Voucher x
933+ partner_id: res_partner10
934+ reference: none
935+-
936+ 4.11.- I check that initially vendor voucher is in the "Draft" state
937+-
938+ !assert {model: account.voucher, id: account_voucher0}:
939+ - state == 'draft'
940+-
941+ 4.12.- I create voucher by clicking on create button
942+-
943+ !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher0}
944+-
945+ 4.13.- I check that the voucher state is "Posted"
946+-
947+ !assert {model: account.voucher, id: account_voucher0}:
948+ - state == 'posted'
949+-
950+ 4.14.- I check if the state of the invoice is "Paid"
951+-
952+ !assert {model: account.invoice, id: account_invoice_supplier3}:
953+ - state == 'paid'
954+-
955+ 4.15.- I modified the sale journal record so it can cancel invoice
956+-
957+ !record {model: account.journal, id: purchase_journal_debit}:
958+ update_posted: 1
959+-
960+ 4.16.- I modified the cash journal record so it can cancel invoice
961+-
962+ !record {model: account.journal, id: bank_journal_debit}:
963+ update_posted: 1
964+-
965+ 4.17.- I create a Purchase Refund Journal.
966+-
967+ !record {model: account.journal, id: purchase_refund_journal_debit}:
968+ code: sprjou_test
969+ company_id: base.main_company
970+ name: Purchase Refund Journal For Debit Credit Note Tests
971+ sequence_id: account.sequence_refund_purchase_journal
972+ type: purchase_refund
973+-
974+ 4.18.- I create a supplier refund using the method "Create a draft refund" and
975+ check the state of the account invoice refund resulting
976+-
977+ !python {model: account.invoice.refund}: |
978+ import time
979+ values = {
980+ 'date': time.strftime('%Y-%m-%d'),
981+ 'period': self.pool.get('account.period').find(
982+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
983+ 'journal_id': ref('purchase_refund_journal_debit'),
984+ 'description': 'Desde el test',
985+ 'filter_refund': 'refund',
986+ }
987+ wzr_id = self.create(cr, uid, values)
988+ assert wzr_id, 'The wizard instance was not created.'
989+ context['wzr_id'] = wzr_id
990+ context['active_ids'] = [ref('account_invoice_supplier3')]
991+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
992+ assert rfnd_id, 'The refund was not created.'
993+ context['rfnd_id'] = rfnd_id
994+ obj_inv = self.pool.get('account.invoice')
995+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
996+ assert rfnd_supplier_inv_brw[0].state == 'draft', 'The supplier refund was not properly created, the state must be Draft.'
997+-
998+ 4.19.- I check the correct asigning of parent_id in the supplier refund created, for that
999+ the supplier refund must have the supplier invoice id in the fiel parent_id
1000+-
1001+ !python {model: account.invoice.refund}: |
1002+ obj_inv = self.pool.get('account.invoice')
1003+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
1004+ supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier3'))
1005+ assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
1006+-
1007+ 5.- In order to test account refund with "Create refund and reconcile" method in a "Paid" invoice
1008+-
1009+ 5.1.- I create a new partner
1010+-
1011+ !record {model: 'res.partner', id: res_partner11}:
1012+ name: Maria Garcia
1013+ use_parent_address: True
1014+ function: Tests
1015+ email: maria@garcia.com
1016+ supplier: True
1017+-
1018+ 5.2.- I create a new supplier invoice
1019+-
1020+ !record {model: account.invoice, id: account_invoice_supplier4, view: account.invoice_supplier_form }:
1021+ account_id: account.a_pay
1022+ company_id: base.main_company
1023+ currency_id: base.EUR
1024+ invoice_line:
1025+ - account_id: account.a_expense
1026+ name: '[PCSC234] PC Assemble SC234'
1027+ price_unit: 300.0
1028+ product_id: product.product_product_3
1029+ quantity: 10.0
1030+ uos_id: product.product_uom_unit
1031+ journal_id: purchase_journal_debit
1032+ partner_id: res_partner11
1033+ reference_type: none
1034+ type: 'in_invoice'
1035+-
1036+ 5.3.- I check that initially supplier invoice state is "Draft"
1037+-
1038+ !assert {model: account.invoice, id: account_invoice_supplier4}:
1039+ - state == 'draft'
1040+-
1041+ 5.4.- I check that the supplier invoice is a "Supplier Invoice"
1042+-
1043+ !assert {model: account.invoice, id: account_invoice_supplier4, string: This is not a supplier invoice}:
1044+ - type == 'in_invoice'
1045+-
1046+ 5.5.- I change the state of invoice to open by clicking Validate button
1047+-
1048+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier4}
1049+-
1050+ 5.6.- I check that the invoice state is now "Open"
1051+-
1052+ !assert {model: account.invoice, id: account_invoice_supplier4}:
1053+ - state == 'open'
1054+-
1055+ 5.7.- I check that a payment entry gets created in the account.move.line
1056+-
1057+ !python {model: account.invoice}: |
1058+ acc_id=self.browse(cr, uid, ref("account_invoice_supplier4"))
1059+ assert(acc_id.move_id)
1060+-
1061+ 5.8.- I will create and post an account voucher of amount 3450.00 for the partner Maria Garcia.
1062+-
1063+ !record {model: account.voucher, id: account_voucher1, view: account_voucher.view_vendor_payment_form}:
1064+ type: payment
1065+ account_id: account.cash
1066+ amount: 3450.00
1067+ company_id: base.main_company
1068+ journal_id: bank_journal_debit
1069+ name: Voucher x
1070+ narration: PC Assemble SC234
1071+ line_dr_ids:
1072+ - account_id: account.cash
1073+ amount: 3450.00
1074+ name: Voucher x
1075+ partner_id: res_partner11
1076+ reference: none
1077+-
1078+ 5.9.- I check that initially vendor voucher is in the "Draft" state
1079+-
1080+ !assert {model: account.voucher, id: account_voucher1}:
1081+ - state == 'draft'
1082+-
1083+ 5.10.- I create voucher by clicking on create button
1084+-
1085+ !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher1}
1086+-
1087+ 5.11.- I check that the voucher state is "Posted"
1088+-
1089+ !assert {model: account.voucher, id: account_voucher1}:
1090+ - state == 'posted'
1091+-
1092+ 5.12.- I check if the state of the invoice is "Paid"
1093+-
1094+ !assert {model: account.invoice, id: account_invoice_supplier4}:
1095+ - state == 'paid'
1096+-
1097+ 5.13.- I create a supplier refund using the method "Create refund and reconcile" and
1098+ check the state of the account invoice refund resulting
1099+-
1100+ !python {model: account.invoice.refund}: |
1101+ import time
1102+ values = {
1103+ 'date': time.strftime('%Y-%m-%d'),
1104+ 'period': self.pool.get('account.period').find(
1105+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
1106+ 'journal_id': ref('purchase_refund_journal_debit'),
1107+ 'description': 'Desde el test',
1108+ 'filter_refund': 'cancel',
1109+ }
1110+ wzr_id = self.create(cr, uid, values)
1111+ assert wzr_id, 'The wizard instance was not created.'
1112+ context['wzr_id'] = wzr_id
1113+ context['active_ids'] = [ref('account_invoice_supplier4')]
1114+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
1115+ assert rfnd_id, 'The refund was not created.'
1116+ context['rfnd_id'] = rfnd_id
1117+ obj_inv = self.pool.get('account.invoice')
1118+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
1119+ assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
1120+-
1121+ 5.14.- I check the correct asigning of parent_id in the supplier refund created, for that
1122+ the supplier refund must have the supplier invoice id in the fiel parent_id
1123+-
1124+ !python {model: account.invoice.refund}: |
1125+ obj_inv = self.pool.get('account.invoice')
1126+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
1127+ supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier4'))
1128+ assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
1129+-
1130+ 6.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
1131+ method in a "Paid" invoice
1132+-
1133+ 6.1.- I create a new partner
1134+-
1135+ !record {model: 'res.partner', id: res_partner12}:
1136+ name: Pablo Garcia
1137+ use_parent_address: True
1138+ function: Tests
1139+ email: pablo@garcia.com
1140+ supplier: True
1141+-
1142+ 6.2.- I create a new supplier invoice
1143+-
1144+ !record {model: account.invoice, id: account_invoice_supplier5, view: account.invoice_supplier_form }:
1145+ account_id: account.a_pay
1146+ company_id: base.main_company
1147+ currency_id: base.EUR
1148+ invoice_line:
1149+ - account_id: account.a_expense
1150+ name: '[PCSC234] PC Assemble SC234'
1151+ price_unit: 300.0
1152+ product_id: product.product_product_3
1153+ quantity: 10.0
1154+ uos_id: product.product_uom_unit
1155+ journal_id: purchase_journal_debit
1156+ partner_id: res_partner12
1157+ reference_type: none
1158+ type: 'in_invoice'
1159+-
1160+ 6.3.- I check that initially supplier invoice state is "Draft"
1161+-
1162+ !assert {model: account.invoice, id: account_invoice_supplier5}:
1163+ - state == 'draft'
1164+-
1165+ 6.4.- I check that the supplier invoice is a "Supplier Invoice"
1166+-
1167+ !assert {model: account.invoice, id: account_invoice_supplier5, string: This is not a supplier invoice}:
1168+ - type == 'in_invoice'
1169+-
1170+ 6.5.- I change the state of invoice to open by clicking Validate button
1171+-
1172+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier5}
1173+-
1174+ 5.6.- I check that the invoice state is now "Open"
1175+-
1176+ !assert {model: account.invoice, id: account_invoice_supplier5}:
1177+ - state == 'open'
1178+-
1179+ 6.7.- I check that a payment entry gets created in the account.move.line
1180+-
1181+ !python {model: account.invoice}: |
1182+ acc_id=self.browse(cr, uid, ref("account_invoice_supplier5"))
1183+ assert(acc_id.move_id)
1184+-
1185+ 6.8.- I will create and post an account voucher of amount 3450.00 for the partner Maria Garcia.
1186+-
1187+ !record {model: account.voucher, id: account_voucher2, view: account_voucher.view_vendor_payment_form}:
1188+ type: payment
1189+ account_id: account.cash
1190+ amount: 3450.00
1191+ company_id: base.main_company
1192+ journal_id: bank_journal_debit
1193+ name: Voucher x
1194+ narration: PC Assemble SC234
1195+ line_dr_ids:
1196+ - account_id: account.cash
1197+ amount: 3450.00
1198+ name: Voucher x
1199+ partner_id: res_partner12
1200+ reference: none
1201+-
1202+ 6.9.- I check that initially vendor voucher is in the "Draft" state
1203+-
1204+ !assert {model: account.voucher, id: account_voucher2}:
1205+ - state == 'draft'
1206+-
1207+ 6.10.- I create voucher by clicking on create button
1208+-
1209+ !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher2}
1210+-
1211+ 6.11.- I check that the voucher state is "Posted"
1212+-
1213+ !assert {model: account.voucher, id: account_voucher2}:
1214+ - state == 'posted'
1215+-
1216+ 6.12.- I check if the state of the invoice is "Paid"
1217+-
1218+ !assert {model: account.invoice, id: account_invoice_supplier5}:
1219+ - state == 'paid'
1220+-
1221+ 6.13.- I create a supplier refund using the method "Create refund, reconcile and create a new draft invoice" and
1222+ check the state of the account invoice refund resulting
1223+-
1224+ !python {model: account.invoice.refund}: |
1225+ import time
1226+ values = {
1227+ 'date': time.strftime('%Y-%m-%d'),
1228+ 'period': self.pool.get('account.period').find(
1229+ cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
1230+ 'journal_id': ref('purchase_refund_journal_debit'),
1231+ 'description': 'Desde el test',
1232+ 'filter_refund': 'modify',
1233+ }
1234+ wzr_id = self.create(cr, uid, values)
1235+ assert wzr_id, 'The wizard instance was not created.'
1236+ context['wzr_id'] = wzr_id
1237+ context['active_ids'] = [ref('account_invoice_supplier5')]
1238+ rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
1239+ assert rfnd_id, 'The refund was not created.'
1240+ context['rfnd_id'] = rfnd_id
1241+ obj_inv = self.pool.get('account.invoice')
1242+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
1243+ assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
1244+-
1245+ 6.14.- I check the correct asigning of parent_id in the supplier refund created, for that
1246+ the supplier refund must have the supplier invoice id in the fiel parent_id
1247+-
1248+ !python {model: account.invoice.refund}: |
1249+ obj_inv = self.pool.get('account.invoice')
1250+ rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
1251+ supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier5'))
1252+ assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
1253+-
1254+ 6.15.- I check that the new supplier invoice was created in Draft state
1255+-
1256+ !python {model: account.invoice.refund}: |
1257+ obj_inv = self.pool.get('account.invoice')
1258+ inv_src = obj_inv.search(cr, uid, [], order='id')
1259+ supplier_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
1260+ assert supplier_inv_brw.state == 'draft', 'The new supplier invoice was not properly created, the state must be Draft.'
1261
1262=== modified file 'debit_credit_note/wizard/account_invoice_refund.py'
1263--- debit_credit_note/wizard/account_invoice_refund.py 2014-01-17 21:53:54 +0000
1264+++ debit_credit_note/wizard/account_invoice_refund.py 2014-02-03 16:27:19 +0000
1265@@ -92,24 +92,21 @@
1266 period_id = ids[0]
1267 return period_id
1268
1269- def _get_orig(self, cr, uid, inv, context={}):
1270- """
1271- Return default origin value
1272- """
1273- nro_ref = ''
1274+ def _get_orig(self, cr, uid, inv, ref, context={}):
1275+ """ Return default origin value
1276+ """
1277+ nro_ref = ref
1278 if inv.type == 'out_invoice':
1279 nro_ref = inv.number
1280- orig = _('INV REFUND:') + (nro_ref or '') + _('- DATE:') + (
1281- inv.date_invoice or '') + (' TOTAL:' + str(inv.amount_total) or '')
1282+ orig = 'Devolucion FACT:' +(nro_ref or '') + '- DE FECHA:' + (inv.date_invoice or '') + (' TOTAL:' + str(inv.amount_total) or '')
1283 return orig
1284-
1285+
1286 def compute_refund(self, cr, uid, ids, mode='refund', context=None):
1287- """
1288- @param cr: the current row, from the database cursor,
1289- @param uid: the current user’s ID for security checks,
1290+ """
1291 @param ids: the account invoice refund’s ID or list of IDs
1292-
1293 """
1294+ wzd_brw = self.browse(cr,uid,ids[0],context=context)
1295+ brw = self.browse(cr,uid,ids[0],context=context)
1296 inv_obj = self.pool.get('account.invoice')
1297 reconcile_obj = self.pool.get('account.move.reconcile')
1298 account_m_line_obj = self.pool.get('account.move.line')
1299@@ -121,70 +118,66 @@
1300 res_users_obj = self.pool.get('res.users')
1301 if context is None:
1302 context = {}
1303-
1304 for form in self.browse(cr, uid, ids, context=context):
1305 created_inv = []
1306 date = False
1307 period = False
1308 description = False
1309- company = res_users_obj.browse(
1310- cr, uid, uid, context=context).company_id
1311- journal_id = form.journal_id.id
1312- for inv in inv_obj.browse(cr, uid, context.get('active_ids'),
1313- context=context):
1314+ company = res_users_obj.browse(cr, uid, uid, context=context).company_id
1315+ journal_brw = form.journal_id or False
1316+ for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
1317 if inv.state in ['draft', 'proforma2', 'cancel']:
1318- raise osv.except_osv(_('Error!'), _(
1319- 'Cannot %s draft/proforma/cancel invoice.') % (mode))
1320+ raise osv.except_osv(_('Error !'), _('Can not %s draft/proforma/cancel invoice.') % (mode))
1321 if inv.reconciled and mode in ('cancel', 'modify'):
1322- raise osv.except_osv(_('Error!'), _(
1323- 'Cannot %s invoice which is already reconciled, '
1324- 'invoice should be unreconciled first. You can only '
1325- 'refund this invoice.') % (mode))
1326- if form.period.id:
1327- period = form.period.id
1328- else:
1329- period = inv.period_id and inv.period_id.id or False
1330+ raise osv.except_osv(_('Error !'), _('Can not %s invoice which is already reconciled, invoice should be unreconciled first. You can only Refund this invoice') % (mode))
1331+ period = form.period.id or False
1332+ if not period:
1333+ #Take period from the current date
1334+ period = self.pool.get('account.period').find(cr, uid, context=context)
1335+ period = period and period[0] or False
1336+ if not period:
1337+ raise osv.except_osv(_('No Period Defined'), \
1338+ _('You have been left empty the period field that automatically fill with the current period. However there is not period defined for the current company. Please check in Accounting/Configuration/Periods'))
1339+ self.write(cr, uid, ids, {'period': period }, context=context)
1340
1341- if not journal_id:
1342+ if not journal_brw:
1343 journal_id = inv.journal_id.id
1344+ else:
1345+ journal_id=journal_brw.id
1346
1347 if form.date:
1348 date = form.date
1349- if not form.period.id:
1350- cr.execute("select name from ir_model_fields \
1351- where model = 'account.period' \
1352- and name = 'company_id'")
1353- result_query = cr.fetchone()
1354- if result_query:
1355- cr.execute("""select p.id from account_fiscalyear y
1356- , account_period p
1357- where y.id=p.fiscalyear_id \
1358- and date(%s) between p.date_start AND
1359- p.date_stop and y.company_id = %s limit 1""",
1360- (date, company.id,))
1361- else:
1362- cr.execute("""SELECT id
1363- from account_period where date(%s)
1364- between date_start AND date_stop \
1365- limit 1 """, (date,))
1366- res = cr.fetchone()
1367- if res:
1368- period = res[0]
1369+ if not form.period:
1370+ cr.execute("select name from ir_model_fields \
1371+ where model = 'account.period' \
1372+ and name = 'company_id'")
1373+ result_query = cr.fetchone()
1374+ if result_query:
1375+ cr.execute("""select p.id from account_fiscalyear y, account_period p where y.id=p.fiscalyear_id \
1376+ and date(%s) between p.date_start AND p.date_stop and y.company_id = %s limit 1""", (date, company.id,))
1377+ else:
1378+ cr.execute("""SELECT id
1379+ from account_period where date(%s)
1380+ between date_start AND date_stop \
1381+ limit 1 """, (date,))
1382+ res = cr.fetchone()
1383+ if res:
1384+ period = res[0]
1385 else:
1386- date = inv.date_invoice
1387+ #Take current date
1388+ #date = inv.date_invoice
1389+ date = time.strftime('%Y-%m-%d')
1390 if form.description:
1391 description = form.description
1392 else:
1393 description = inv.name
1394
1395 if not period:
1396- raise osv.except_osv(_('Insufficient Data!'),
1397- _('No period found on the invoice.'))
1398-
1399- refund_id = inv_obj.refund(cr, uid, [
1400- inv.id], date, period,
1401- description, journal_id,
1402- context=context)
1403+ raise osv.except_osv(_('Data Insufficient !'), \
1404+ _('No Period found on Invoice!'))
1405+
1406+ refund_id = inv_obj.refund(cr, uid, [inv.id], date, period, description, journal_id)
1407+
1408 refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
1409 # Add parent invoice
1410 inv_obj.write(cr, uid, [refund.id],
1411@@ -202,43 +195,37 @@
1412 to_reconcile_ids[line.account_id.id] = [line.id]
1413 if type(line.reconcile_id) != osv.orm.browse_null:
1414 reconcile_obj.unlink(cr, uid, line.reconcile_id.id)
1415- wf_service.trg_validate(uid, 'account.invoice',
1416- refund.id, 'invoice_open', cr)
1417- refund = inv_obj.browse(
1418- cr, uid, refund_id[0], context=context)
1419- for tmpline in refund.move_id.line_id:
1420+ wf_service.trg_validate(uid, 'account.invoice', \
1421+ refund.id, 'invoice_open', cr)
1422+
1423+ refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
1424+
1425+ for tmpline in refund.move_id.line_id:
1426 if tmpline.account_id.id == inv.account_id.id:
1427- to_reconcile_ids[
1428- tmpline.account_id.id].append(tmpline.id)
1429+ to_reconcile_ids[tmpline.account_id.id].append(tmpline.id)
1430 for account in to_reconcile_ids:
1431- account_m_line_obj.reconcile(
1432- cr, uid, to_reconcile_ids[account],
1433- writeoff_period_id=period,
1434- writeoff_journal_id=inv.journal_id.id,
1435- writeoff_acc_id=inv.account_id.id
1436- )
1437+ account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account],
1438+ writeoff_period_id=period,
1439+ writeoff_journal_id = inv.journal_id.id,
1440+ writeoff_acc_id=inv.account_id.id
1441+ )
1442 if mode == 'modify':
1443 invoice = inv_obj.read(cr, uid, [inv.id],
1444- ['name', 'type', 'number',
1445- 'reference', 'comment',
1446- 'date_due', 'partner_id',
1447- 'partner_insite',
1448- 'partner_contact',
1449- 'partner_ref', 'payment_term',
1450- 'account_id', 'currency_id',
1451- 'invoice_line', 'tax_line',
1452- 'journal_id', 'period_id'],
1453- context=context)
1454+ ['name', 'type', 'number', 'supplier_invoice_number',
1455+ 'comment', 'date_due', 'partner_id',
1456+ 'partner_insite', 'partner_contact',
1457+ 'partner_ref', 'payment_term', 'account_id',
1458+ 'currency_id', 'invoice_line', 'tax_line',
1459+ 'journal_id', 'period_id'], context=context)
1460 invoice = invoice[0]
1461 del invoice['id']
1462- invoice_lines = inv_line_obj.browse(
1463- cr, uid, invoice['invoice_line'], context=context)
1464- invoice_lines = inv_obj._refund_cleanup_lines(
1465- cr, uid, invoice_lines, context=context)
1466- tax_lines = inv_tax_obj.browse(
1467- cr, uid, invoice['tax_line'], context=context)
1468- tax_lines = inv_obj._refund_cleanup_lines(
1469- cr, uid, tax_lines, context=context)
1470+ invoice_lines = inv_line_obj.browse(cr, uid, invoice['invoice_line'], context=context)
1471+
1472+ invoice_lines = inv_obj._refund_cleanup_lines(cr, uid, invoice_lines)
1473+ tax_lines = inv_tax_obj.browse(cr, uid, invoice['tax_line'], context=context)
1474+ tax_lines = inv_obj._refund_cleanup_lines(cr, uid, tax_lines)
1475+ #Add origin value
1476+ orig = self._get_orig(cr, uid, inv, invoice['supplier_invoice_number'], context)
1477 invoice.update({
1478 'type': inv.type,
1479 'date_invoice': date,
1480@@ -248,36 +235,99 @@
1481 'tax_line': tax_lines,
1482 'period_id': period,
1483 'name': description,
1484- 'origin': self._get_orig(cr, uid, inv, context={}),
1485+ 'origin': orig,
1486 })
1487- for field in (
1488- 'partner_id', 'account_id', 'currency_id',
1489- 'payment_term', 'journal_id'):
1490- invoice[field] = invoice[
1491- field] and invoice[field][0]
1492+ for field in ( 'partner_id',
1493+ 'account_id', 'currency_id', 'payment_term', 'journal_id'):
1494+ invoice[field] = invoice[field] and invoice[field][0]
1495 inv_id = inv_obj.create(cr, uid, invoice, {})
1496 if inv.payment_term.id:
1497- data = inv_obj.onchange_payment_term_date_invoice(
1498- cr, uid, [inv_id], inv.payment_term.id, date)
1499+ data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
1500 if 'value' in data and data['value']:
1501 inv_obj.write(cr, uid, [inv_id], data['value'])
1502 created_inv.append(inv_id)
1503- xml_id = (inv.type == 'out_refund') and 'action_invoice_tree1' or \
1504- (inv.type == 'in_refund') and 'action_invoice_tree2' or \
1505- (inv.type == 'out_invoice') and 'action_invoice_tree3' or \
1506- (inv.type == 'in_invoice') and 'action_invoice_tree4'
1507+
1508+ new_inv_brw = inv_obj.browse(cr,uid,created_inv[1],context=context)
1509+ inv_obj.write(cr,uid,created_inv[0],{'name':wzd_brw.description,'origin':new_inv_brw.origin},context=context)
1510+ inv_obj.write(cr,uid,created_inv[1],{'origin':inv.origin,'name':wzd_brw.description},context=context)
1511+ if inv.type in ('out_invoice', 'out_refund'):
1512+ xml_id = 'action_invoice_tree3'
1513+ else:
1514+ xml_id = 'action_invoice_tree4'
1515 result = mod_obj.get_object_reference(cr, uid, 'account', xml_id)
1516 id = result and result[1] or False
1517 result = act_obj.read(cr, uid, id, context=context)
1518 invoice_domain = eval(result['domain'])
1519 invoice_domain.append(('id', 'in', created_inv))
1520 result['domain'] = invoice_domain
1521+
1522+ if wzd_brw.filter_refund == 'cancel':
1523+ orig = self._get_orig(cr, uid, inv, inv.supplier_invoice_number, context)
1524+ inv_obj.write(cr,uid,created_inv[0],{'origin':orig,'name':wzd_brw.description},context=context)
1525+
1526+ if wzd_brw.filter_refund == 'refund':
1527+ orig = self._get_orig(cr, uid, inv, inv.supplier_invoice_number, context)
1528+ inv_obj.write(cr,uid,created_inv[0],{'origin':inv.origin,'name':wzd_brw.description},context=context)
1529 return result
1530+
1531+ def validate_total_payment_inv(self, cr, uid, ids, context=None):
1532+ """ Method that validate if invoice is totally paid.
1533+ @param ids: list of invoices.
1534+ return: True: if invoice is paid.
1535+ False: if invoice is not paid.
1536+ """
1537+ res = False
1538+ inv_obj = self.pool.get('account.invoice')
1539+ for inv in inv_obj.browse(cr, uid, ids, context=context):
1540+ res = inv.reconciled
1541+ return res
1542+
1543+ def unreconcile_paid_invoices(self, cr, uid, invoiceids, context=None):
1544+ """ Method that unreconcile the payments of invoice.
1545+ @param invoiceids: list of invoices.
1546+ return: True: unreconcile successfully.
1547+ False: unreconcile unsuccessfully.
1548+ """
1549+ inv_obj = self.pool.get('account.invoice')
1550+ moveline_obj = self.pool.get('account.move.line')
1551+ voucher_pool = self.pool.get('account.voucher')
1552+ res = True
1553+ rec = []
1554+ mid = []
1555+ if self.validate_total_payment_inv(cr, uid, invoiceids, context=context):
1556+ for inv in inv_obj.browse(cr, uid, invoiceids, context=context):
1557+ movelineids = inv_obj.move_line_id_payment_get(cr, uid,[inv.id])
1558+ for moveline in moveline_obj.browse(cr, uid, movelineids,context=context):
1559+ if moveline.reconcile_id:
1560+ rec += [moveline.reconcile_id.id]
1561+ if moveline.reconcile_partial_id:
1562+ rec += [moveline.reconcile_partial_id.id]
1563+ movelines = moveline_obj.search(cr, uid, [('|'),('reconcile_id','in',rec),('reconcile_partial_id','in',rec)],context=context)
1564+ for mids in moveline_obj.browse(cr, uid, movelines, context=context):
1565+ mid +=[mids.move_id.id]
1566+ voucherids = voucher_pool.search(cr, uid,[('move_id','in',mid)])
1567+ if voucherids:
1568+ voucher_pool.cancel_voucher(cr, uid, voucherids, context=context)
1569+ else:
1570+ res = False
1571+ return res
1572
1573 def invoice_refund(self, cr, uid, ids, context=None):
1574- data_refund = self.read(cr, uid, ids, [
1575- 'filter_refund'],
1576- context=context)[0]['filter_refund']
1577+ """ Create a invoice refund
1578+ """
1579+ if context is None:
1580+ context = {}
1581+ inv_obj = self.pool.get('account.invoice')
1582+ period_obj = self.pool.get('account.period')
1583+ wzr_brw = self.browse(cr,uid,ids,context=context)[0]
1584+ date = wzr_brw.date
1585+ period = wzr_brw and wzr_brw.period and wzr_brw.period.id
1586+ period_ids = date and period_obj.search(cr,uid,[('date_start', '<=', date),('date_stop', '>=', date),('special', '=', False)],context=context)
1587+ if period not in period_ids:
1588+ raise osv.except_osv(_('Error !'), \
1589+ _('The date should be chosen to belong to the period'))
1590+ self.unreconcile_paid_invoices(cr, uid, context.get('active_ids'), context=context)
1591+ data_refund = self.browse(cr, uid, ids, context=context)[0].filter_refund
1592 return self.compute_refund(cr, uid, ids, data_refund, context=context)
1593
1594