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
=== modified file 'debit_credit_note/__openerp__.py'
--- debit_credit_note/__openerp__.py 2014-01-17 21:53:54 +0000
+++ debit_credit_note/__openerp__.py 2014-02-03 16:27:19 +0000
@@ -44,11 +44,16 @@
4444
45''',45''',
46 "init_xml": [],46 "init_xml": [],
47 "depends": ["base", "account"],47 "depends": [
48 "base",
49 "account",
50 "account_voucher",
51 "account_cancel",
52 ],
48 'data': [53 'data': [
49 'wizard/account_invoice_debit_view.xml',54 'wizard/account_invoice_debit_view.xml',
50 'wizard/account_invoice_parent_view.xml',55 'wizard/account_invoice_parent_view.xml',
51 'account_invoice_view.xml',56 "account_invoice_view.xml",
52 ],57 ],
53 'js': [58 'js': [
54 ],59 ],
@@ -59,6 +64,8 @@
59 'demo': [64 'demo': [
60 ],65 ],
61 'test': [66 'test': [
67 'test/account_supplier_refund.yml',
68 'test/account_customer_refund.yml',
62 ],69 ],
63 "installable": True,70 "installable": True,
64 "active": False,71 "active": False,
6572
=== added directory 'debit_credit_note/test'
=== added file 'debit_credit_note/test/account_customer_refund.yml'
--- debit_credit_note/test/account_customer_refund.yml 1970-01-01 00:00:00 +0000
+++ debit_credit_note/test/account_customer_refund.yml 2014-02-03 16:27:19 +0000
@@ -0,0 +1,602 @@
1-
2 I set the context that will be used for the encoding of all the invoices of this file
3-
4 !context
5 'type': 'out_invoice'
6-
7 1.- In order to test account refund with "Create a draft refund" method
8-
9 1.1.- I create a customer invoice
10-
11 !record {model: account.invoice, id: account_invoice_customer0, view: account.invoice_form}: &customer_invoice
12 payment_term: account.account_payment_term_advance
13 journal_id: account.sales_journal
14 partner_id: base.res_partner_3
15 reference_type: none
16 name: 'Test Customer Invoice - debit_credit_note'
17 invoice_line:
18 - product_id: product.product_product_5
19 price_unit: 850.0
20 quantity: 1.0
21-
22 1.2.- I check that Initially customer invoice state is "Draft"
23-
24 !assert {model: account.invoice, id: account_invoice_customer0}:
25 - state == 'draft'
26-
27 1.3.- I check that the customer invoice is a "Customer Invoice"
28-
29 !assert {model: account.invoice, id: account_invoice_customer0, string: This is not a customer invoice}:
30 - type == 'out_invoice'
31-
32 1.4.- I change the state of invoice to open by clicking Validate button
33-
34 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer0}
35-
36 1.5.- I check that the invoice state is now "Open"
37-
38 !assert {model: account.invoice, id: account_invoice_customer0}:
39 - state == 'open'
40-
41 1.6.- I create a customer refund using the method "Create a draft refund" and
42 check the state of the account invoice refund resulting
43-
44 !python {model: account.invoice.refund}: |
45 import time
46 values = {
47 'date': time.strftime('%Y-%m-%d'),
48 'period': self.pool.get('account.period').find(
49 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
50 'journal_id': ref('account.refund_expenses_journal'),
51 'description': 'Desde el test',
52 'filter_refund': 'refund',
53 }
54 wzr_id = self.create(cr, uid, values)
55 assert wzr_id, 'The wizard instance was not created.'
56 context['wzr_id'] = wzr_id
57 context['active_ids'] = [ref('account_invoice_customer0')]
58 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
59 assert rfnd_id, 'The refund was not created.'
60 context['rfnd_id'] = rfnd_id
61 obj_inv = self.pool.get('account.invoice')
62 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
63 assert rfnd_customer_inv_brw[0].state == 'draft', 'The customer refund was not properly created, the state must be Draft.'
64-
65 1.7.- I check the correct asigning of parent_id in the customer refund created, for that
66 the customer refund must have the customer invoice id in the fiel parent_id
67-
68 !python {model: account.invoice.refund}: |
69 obj_inv = self.pool.get('account.invoice')
70 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
71 customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer0'))
72 assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
73-
74 2.- In order to test account refund with "Create refund and reconcile" method
75-
76 2.1.- I create a new customer invoice
77-
78 !record {model: account.invoice, id: account_invoice_customer1, view: account.invoice_form }:
79 <<: *customer_invoice
80-
81 2.2.- I check that Initially customer invoice state is "Draft"
82-
83 !assert {model: account.invoice, id: account_invoice_customer1}:
84 - state == 'draft'
85-
86 2.3.- I check that the customer invoice is a "Customer Invoice"
87-
88 !assert {model: account.invoice, id: account_invoice_customer1, string: This is not a customer invoice}:
89 - type == 'out_invoice'
90-
91 2.4.- I change the state of invoice to open by clicking Validate button
92-
93 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer1}
94-
95 2.5.- I check that the invoice state is now "Open"
96-
97 !assert {model: account.invoice, id: account_invoice_customer1}:
98 - state == 'open'
99-
100 2.6.- I create a customer refund using the method "Create refund and reconcile" and
101 check the state of the account invoice refund resulting
102-
103 !python {model: account.invoice.refund}: |
104 import time
105 values = {
106 'date': time.strftime('%Y-%m-%d'),
107 'period': self.pool.get('account.period').find(
108 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
109 'journal_id': ref('account.refund_expenses_journal'),
110 'description': 'Desde el test',
111 'filter_refund': 'cancel',
112 }
113 wzr_id = self.create(cr, uid, values)
114 assert wzr_id, 'The wizard instance was not created.'
115 context['wzr_id'] = wzr_id
116 context['active_ids'] = [ref('account_invoice_customer1')]
117 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
118 assert rfnd_id, 'The refund was not created.'
119 context['rfnd_id'] = rfnd_id
120 obj_inv = self.pool.get('account.invoice')
121 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
122 assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
123-
124 2.7.- I check the correct asigning of parent_id in the customer refund created, for that
125 the customer refund must have the customer invoice id in the fiel parent_id
126-
127 !python {model: account.invoice.refund}: |
128 obj_inv = self.pool.get('account.invoice')
129 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
130 customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer1'))
131 assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
132-
133 3.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
134 method
135-
136 3.1.- I create a new customer invoice
137-
138 !record {model: account.invoice, id: account_invoice_customer2, view: account.invoice_form }:
139 <<: *customer_invoice
140-
141 3.2.- I check that Initially customer invoice state is "Draft"
142-
143 !assert {model: account.invoice, id: account_invoice_customer2}:
144 - state == 'draft'
145-
146 3.3.- I check that the customer invoice is a "Customer Invoice"
147-
148 !assert {model: account.invoice, id: account_invoice_customer2, string: This is not a customer invoice}:
149 - type == 'out_invoice'
150-
151 3.4.- I change the state of invoice to open by clicking Validate button
152-
153 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer2}
154-
155 3.5.- I check that the invoice state is now "Open"
156-
157 !assert {model: account.invoice, id: account_invoice_customer2}:
158 - state == 'open'
159-
160 3.6.- I create a customer refund using the method "Create refund, reconcile and create a new draft invoice" and
161 check the state of the account invoice refund resulting
162-
163 !python {model: account.invoice.refund}: |
164 import time
165 values = {
166 'date': time.strftime('%Y-%m-%d'),
167 'period': self.pool.get('account.period').find(
168 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
169 'journal_id': ref('account.refund_expenses_journal'),
170 'description': 'Desde el test',
171 'filter_refund': 'modify',
172 }
173 wzr_id = self.create(cr, uid, values)
174 assert wzr_id, 'The wizard instance was not created.'
175 context['wzr_id'] = wzr_id
176 context['active_ids'] = [ref('account_invoice_customer2')]
177 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
178 assert rfnd_id, 'The refund was not created.'
179 context['rfnd_id'] = rfnd_id
180 obj_inv = self.pool.get('account.invoice')
181 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
182 assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
183-
184 3.7.- I check the correct asigning of parent_id in the customer refund created, for that
185 the customer refund must have the customer invoice id in the fiel parent_id
186-
187 !python {model: account.invoice.refund}: |
188 obj_inv = self.pool.get('account.invoice')
189 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
190 customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer2'))
191 assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
192-
193 3.8.- I check that the new customer invoice was created in Draft state
194-
195 !python {model: account.invoice.refund}: |
196 obj_inv = self.pool.get('account.invoice')
197 inv_src = obj_inv.search(cr, uid, [], order='id')
198 customer_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
199 assert customer_inv_brw.state == 'draft', 'The new customer invoice was not properly created, the state must be Draft.'
200-
201 4.- In order to test account refund with "Create a draft refund" method in a "Paid" invoice
202-
203 4.1.- I create a new partner
204-
205 !record {model: 'res.partner', id: res_partner8}:
206 name: Juan Perez
207 use_parent_address: True
208 function: Tests
209 email: juan@perez.com
210-
211 4.2.- I create a Sale Journal.
212-
213 !record {model: account.journal, id: sale_journal_debit}:
214 code: sjou_test
215 company_id: base.main_company
216 name: Sale Journal For Debit Credit Note Tests
217 sequence_id: account.sequence_sale_journal
218 type: sale
219-
220 4.3.- I create a new customer invoice
221-
222 !record {model: account.invoice, id: account_invoice_customer3}:
223 account_id: account.a_recv
224 company_id: base.main_company
225 currency_id: base.EUR
226 invoice_line:
227 - account_id: account.a_sale
228 name: '[PCSC234] PC Assemble SC234'
229 price_unit: 450.0
230 quantity: 1.0
231 product_id: product.product_product_3
232 uos_id: product.product_uom_unit
233 journal_id: sale_journal_debit
234 partner_id: res_partner8
235-
236 4.4.- I check that Initially customer invoice state is "Draft"
237-
238 !assert {model: account.invoice, id: account_invoice_customer3}:
239 - state == 'draft'
240-
241 4.5.- I check that the customer invoice is a "Customer Invoice"
242-
243 !assert {model: account.invoice, id: account_invoice_customer3, string: This is not a customer invoice}:
244 - type == 'out_invoice'
245-
246 4.6.- I change the state of invoice to open by clicking Validate button
247-
248 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer3}
249-
250 4.7.- I check that the invoice state is now "Open"
251-
252 !assert {model: account.invoice, id: account_invoice_customer3}:
253 - state == 'open'
254-
255 4.8.- I check that a payment entry gets created in the account.move.line
256-
257 !python {model: account.invoice}: |
258 acc_id=self.browse(cr, uid, ref("account_invoice_customer3"))
259 assert(acc_id.move_id)
260-
261 4.9.- I create a Cash Journal.
262-
263 !record {model: account.journal, id: cash_journal_debit}:
264 code: cjou_test
265 company_id: base.main_company
266 name: Cash Journal For Debit Credit Note Tests
267 sequence_id: account.sequence_cash_journal
268 type: cash
269-
270 4.10.- I will create and post an account voucher with the amount total
271 of the customer invoice created for the partner Juan Perez.
272-
273 !python {model: account.voucher}: |
274 import netsvc
275 import time
276 vals = {}
277 amount_total = self.pool.get('account.invoice').browse(cr, uid, [ref('account_invoice_customer3')], context=None)[0].amount_total
278 journal_id = self.default_get(cr, uid, ['journal_id']).get('journal_id',None)
279 res = self.onchange_partner_id(cr, uid, [], ref("res_partner8"), journal_id, 0.0, 1, ttype='receipt', date=False)
280 vals = {
281 'account_id': ref('account.cash'),
282 'amount': amount_total,
283 'company_id': ref('base.main_company'),
284 'journal_id': ref('cash_journal_debit'),
285 'partner_id': ref('res_partner8'),
286 'period_id': self.pool.get('account.period').find(
287 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
288 'type': 'receipt',
289 }
290 if not res['value']['line_cr_ids']:
291 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
292 res['value']['line_cr_ids'][0]['amount'] = amount_total
293 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
294 id = self.create(cr, uid, vals)
295 voucher_id = self.browse(cr, uid, id)
296 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
297 wf_service = netsvc.LocalService("workflow")
298 wf_service.trg_validate(uid, 'account.voucher', voucher_id.id, 'proforma_voucher', cr)
299-
300 4.11.- I check if the state of the invoice is "Paid"
301-
302 !assert {model: account.invoice, id: account_invoice_customer3}:
303 - state == 'paid'
304-
305 4.12.- I modified the sale journal record so it can cancel invoice
306-
307 !record {model: account.journal, id: sale_journal_debit}:
308 update_posted: 1
309-
310 4.13.- I modified the cash journal record so it can cancel invoice
311-
312 !record {model: account.journal, id: cash_journal_debit}:
313 update_posted: 1
314-
315 4.14.- I create a Sale Refund Journal.
316-
317 !record {model: account.journal, id: sale_refund_journal_debit}:
318 code: csrjou_test
319 company_id: base.main_company
320 name: Sale Refund Journal For Debit Credit Note Tests
321 sequence_id: account.sequence_refund_sales_journal
322 type: sale_refund
323-
324 4.15.- I create a customer refund using the method "Create a draft refund" and
325 check the state of the account invoice refund resulting
326-
327 !python {model: account.invoice.refund}: |
328 import time
329 values = {
330 'date': time.strftime('%Y-%m-%d'),
331 'period': self.pool.get('account.period').find(
332 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
333 'journal_id': ref('sale_refund_journal_debit'),
334 'description': 'Desde el test',
335 'filter_refund': 'refund',
336 }
337 wzr_id = self.create(cr, uid, values)
338 assert wzr_id, 'The wizard instance was not created.'
339 context['wzr_id'] = wzr_id
340 context['active_ids'] = [ref('account_invoice_customer3')]
341 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
342 assert rfnd_id, 'The refund was not created.'
343 context['rfnd_id'] = rfnd_id
344 obj_inv = self.pool.get('account.invoice')
345 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
346 assert rfnd_customer_inv_brw[0].state == 'draft', 'The customer refund was not properly created, the state must be Draft.'
347-
348 4.16.- I check the correct asigning of parent_id in the customer refund created, for that
349 the customer refund must have the customer invoice id in the fiel parent_id
350-
351 !python {model: account.invoice.refund}: |
352 obj_inv = self.pool.get('account.invoice')
353 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
354 customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer3'))
355 assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
356-
357 5.- In order to test account refund with "Create refund and reconcile" method in a "Paid" invoice
358-
359 5.1.- I create a new partner
360-
361 !record {model: 'res.partner', id: res_partner7}:
362 name: Pedro Perez
363 use_parent_address: True
364 function: Tests
365 email: pedro@perez.com
366-
367 5.2.- I create a new customer invoice
368-
369 !record {model: account.invoice, id: account_invoice_customer4}:
370 account_id: account.a_recv
371 company_id: base.main_company
372 currency_id: base.EUR
373 invoice_line:
374 - account_id: account.a_sale
375 name: '[PCSC234] PC Assemble SC234'
376 price_unit: 450.0
377 quantity: 1.0
378 product_id: product.product_product_3
379 uos_id: product.product_uom_unit
380 journal_id: sale_journal_debit
381 partner_id: res_partner7
382-
383 5.3.- I check that Initially customer invoice state is "Draft"
384-
385 !assert {model: account.invoice, id: account_invoice_customer4}:
386 - state == 'draft'
387-
388 5.4.- I check that the customer invoice is a "Customer Invoice"
389-
390 !assert {model: account.invoice, id: account_invoice_customer4, string: This is not a customer invoice}:
391 - type == 'out_invoice'
392-
393 5.5.- I change the state of invoice to open by clicking Validate button
394-
395 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer4}
396-
397 5.6.- I check that the invoice state is now "Open"
398-
399 !assert {model: account.invoice, id: account_invoice_customer4}:
400 - state == 'open'
401-
402 5.7.- I check that a payment entry gets created in the account.move.line
403-
404 !python {model: account.invoice}: |
405 acc_id=self.browse(cr, uid, ref("account_invoice_customer4"))
406 assert(acc_id.move_id)
407-
408 5.8.- I will create and post an account voucher with the amount total
409 of the customer invoice created for the partner Pedro Perez.
410-
411 !python {model: account.voucher}: |
412 import netsvc
413 import time
414 vals = {}
415 amount_total = self.pool.get('account.invoice').browse(cr, uid, [ref('account_invoice_customer4')], context=None)[0].amount_total
416 journal_id = self.default_get(cr, uid, ['journal_id']).get('journal_id',None)
417 res = self.onchange_partner_id(cr, uid, [], ref("res_partner7"), journal_id, 0.0, 1, ttype='receipt', date=False)
418 vals = {
419 'account_id': ref('account.cash'),
420 'amount': amount_total,
421 'company_id': ref('base.main_company'),
422 'journal_id': ref('cash_journal_debit'),
423 'partner_id': ref('res_partner7'),
424 'period_id': self.pool.get('account.period').find(
425 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
426 'type': 'receipt',
427 }
428 if not res['value']['line_cr_ids']:
429 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
430 res['value']['line_cr_ids'][0]['amount'] = amount_total
431 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
432 id = self.create(cr, uid, vals)
433 voucher_id = self.browse(cr, uid, id)
434 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
435 wf_service = netsvc.LocalService("workflow")
436 wf_service.trg_validate(uid, 'account.voucher', voucher_id.id, 'proforma_voucher', cr)
437-
438 5.9.- I check if the state of the invoice is "Paid"
439-
440 !assert {model: account.invoice, id: account_invoice_customer4}:
441 - state == 'paid'
442-
443 5.10.- I create a customer refund using the method "Create refund and reconcile" and
444 check the state of the account invoice refund resulting
445-
446 !python {model: account.invoice.refund}: |
447 import time
448 values = {
449 'date': time.strftime('%Y-%m-%d'),
450 'period': self.pool.get('account.period').find(
451 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
452 'journal_id': ref('sale_refund_journal_debit'),
453 'description': 'Desde el test',
454 'filter_refund': 'cancel',
455 }
456 wzr_id = self.create(cr, uid, values)
457 assert wzr_id, 'The wizard instance was not created.'
458 context['wzr_id'] = wzr_id
459 context['active_ids'] = [ref('account_invoice_customer4')]
460 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
461 assert rfnd_id, 'The refund was not created.'
462 context['rfnd_id'] = rfnd_id
463 obj_inv = self.pool.get('account.invoice')
464 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
465 assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
466-
467 5.11.- I check the correct asigning of parent_id in the customer refund created, for that
468 the customer refund must have the customer invoice id in the fiel parent_id
469-
470 !python {model: account.invoice.refund}: |
471 obj_inv = self.pool.get('account.invoice')
472 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
473 customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer4'))
474 assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
475-
476 6.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
477 method in a "Paid" invoice
478-
479 6.1.- I create a new partner
480-
481 !record {model: 'res.partner', id: res_partner9}:
482 name: Maria Perez
483 use_parent_address: True
484 function: Tests
485 email: maria@perez.com
486-
487 6.2.- I create a new customer invoice
488-
489 !record {model: account.invoice, id: account_invoice_customer5}:
490 account_id: account.a_recv
491 company_id: base.main_company
492 currency_id: base.EUR
493 invoice_line:
494 - account_id: account.a_sale
495 name: '[PCSC234] PC Assemble SC234'
496 price_unit: 450.0
497 quantity: 1.0
498 product_id: product.product_product_3
499 uos_id: product.product_uom_unit
500 journal_id: sale_journal_debit
501 partner_id: res_partner9
502-
503 6.3.- I check that Initially customer invoice state is "Draft"
504-
505 !assert {model: account.invoice, id: account_invoice_customer5}:
506 - state == 'draft'
507-
508 6.4.- I check that the customer invoice is a "Customer Invoice"
509-
510 !assert {model: account.invoice, id: account_invoice_customer5, string: This is not a customer invoice}:
511 - type == 'out_invoice'
512-
513 6.5.- I change the state of invoice to open by clicking Validate button
514-
515 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer5}
516-
517 6.6.- I check that the invoice state is now "Open"
518-
519 !assert {model: account.invoice, id: account_invoice_customer5}:
520 - state == 'open'
521-
522 6.7.- I check that a payment entry gets created in the account.move.line
523-
524 !python {model: account.invoice}: |
525 acc_id=self.browse(cr, uid, ref("account_invoice_customer5"))
526 assert(acc_id.move_id)
527-
528 6.8.- I will create and post an account voucher with the amount total
529 of the customer invoice created for the partner Maria Perez.
530-
531 !python {model: account.voucher}: |
532 import netsvc
533 import time
534 vals = {}
535 amount_total = self.pool.get('account.invoice').browse(cr, uid, [ref('account_invoice_customer5')], context=None)[0].amount_total
536 journal_id = self.default_get(cr, uid, ['journal_id']).get('journal_id',None)
537 res = self.onchange_partner_id(cr, uid, [], ref("res_partner9"), journal_id, 0.0, 1, ttype='receipt', date=False)
538 vals = {
539 'account_id': ref('account.cash'),
540 'amount': amount_total,
541 'company_id': ref('base.main_company'),
542 'journal_id': ref('cash_journal_debit'),
543 'partner_id': ref('res_partner9'),
544 'period_id': self.pool.get('account.period').find(
545 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
546 'type': 'receipt',
547 }
548 if not res['value']['line_cr_ids']:
549 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
550 res['value']['line_cr_ids'][0]['amount'] = amount_total
551 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
552 id = self.create(cr, uid, vals)
553 voucher_id = self.browse(cr, uid, id)
554 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
555 wf_service = netsvc.LocalService("workflow")
556 wf_service.trg_validate(uid, 'account.voucher', voucher_id.id, 'proforma_voucher', cr)
557-
558 6.9.- I check if the state of the invoice is "Paid"
559-
560 !assert {model: account.invoice, id: account_invoice_customer5}:
561 - state == 'paid'
562-
563 6.10.- I create a customer refund using the method "Create refund, reconcile and create a new draft invoice" and
564 check the state of the account invoice refund resulting
565-
566 !python {model: account.invoice.refund}: |
567 import time
568 values = {
569 'date': time.strftime('%Y-%m-%d'),
570 'period': self.pool.get('account.period').find(
571 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
572 'journal_id': ref('sale_refund_journal_debit'),
573 'description': 'Desde el test',
574 'filter_refund': 'modify',
575 }
576 wzr_id = self.create(cr, uid, values)
577 assert wzr_id, 'The wizard instance was not created.'
578 context['wzr_id'] = wzr_id
579 context['active_ids'] = [ref('account_invoice_customer5')]
580 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
581 assert rfnd_id, 'The refund was not created.'
582 context['rfnd_id'] = rfnd_id
583 obj_inv = self.pool.get('account.invoice')
584 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
585 assert rfnd_customer_inv_brw[0].state == 'paid', 'The customer refund was not properly created, the state must be Paid.'
586-
587 6.11.- I check the correct asigning of parent_id in the customer refund created, for that
588 the customer refund must have the customer invoice id in the fiel parent_id
589-
590 !python {model: account.invoice.refund}: |
591 obj_inv = self.pool.get('account.invoice')
592 rfnd_customer_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
593 customer_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_customer5'))
594 assert (rfnd_customer_inv_brw[0].parent_id.id == customer_inv_brw.id), 'The customer refund dont have the correct parent_id.'
595-
596 6.12.- I check that the new customer invoice was created in Draft state
597-
598 !python {model: account.invoice.refund}: |
599 obj_inv = self.pool.get('account.invoice')
600 inv_src = obj_inv.search(cr, uid, [], order='id')
601 customer_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
602 assert customer_inv_brw.state == 'draft', 'The new customer invoice was not properly created, the state must be Draft.'
0603
=== added file 'debit_credit_note/test/account_supplier_refund.yml'
--- debit_credit_note/test/account_supplier_refund.yml 1970-01-01 00:00:00 +0000
+++ debit_credit_note/test/account_supplier_refund.yml 2014-02-03 16:27:19 +0000
@@ -0,0 +1,616 @@
1-
2 I set the context that will be used for the encoding of all the invoices of this file
3-
4 !context
5 'type': 'in_invoice'
6-
7 1.- In order to test account refund with "Create a draft refund" method
8-
9 1.1.- I create a supplier invoice
10-
11 !record {model: account.invoice, id: account_invoice_supplier0, view: account.invoice_supplier_form }: &supplier_invoice
12 account_id: account.a_pay
13 company_id: base.main_company
14 currency_id: base.EUR
15 invoice_line:
16 - account_id: account.a_expense
17 name: '[PCSC234] PC Assemble SC234'
18 price_unit: 300.0
19 product_id: product.product_product_3
20 quantity: 10.0
21 uos_id: product.product_uom_unit
22 journal_id: account.expenses_journal
23 partner_id: base.res_partner_12
24 reference_type: none
25 type: 'in_invoice'
26-
27 1.2.- I check that Initially supplier invoice state is "Draft"
28-
29 !assert {model: account.invoice, id: account_invoice_supplier0}:
30 - state == 'draft'
31-
32 1.3.- I check that the supplier invoice is a "Supplier Invoice"
33-
34 !assert {model: account.invoice, id: account_invoice_supplier0, string: This is not a supplier invoice}:
35 - type == 'in_invoice'
36-
37 1.4.- I change the state of invoice to open by clicking Validate button
38-
39 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier0}
40-
41 1.5.- I check that the invoice state is now "Open"
42-
43 !assert {model: account.invoice, id: account_invoice_supplier0}:
44 - state == 'open'
45-
46 1.6.- I create a supplier refund using the method "Create a draft refund" and
47 check the state of the account invoice refund resulting
48-
49 !python {model: account.invoice.refund}: |
50 import time
51 values = {
52 'date': time.strftime('%Y-%m-%d'),
53 'period': self.pool.get('account.period').find(
54 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
55 'journal_id': ref('account.refund_expenses_journal'),
56 'description': 'Desde el test',
57 'filter_refund': 'refund',
58 }
59 wzr_id = self.create(cr, uid, values)
60 context['wzr_id'] = wzr_id
61 context['active_ids'] = [ref('account_invoice_supplier0')]
62 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
63 context['rfnd_id'] = rfnd_id
64 obj_inv = self.pool.get('account.invoice')
65 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
66 assert rfnd_supplier_inv_brw[0].state == 'draft', 'The supplier refund was not properly created, the state must be Draft.'
67-
68 1.7.- I check the correct asigning of parent_id in the supplier refund created, for that
69 the supplier refund must have the supplier invoice id in the fiel parent_id
70-
71 !python {model: account.invoice.refund}: |
72 obj_inv = self.pool.get('account.invoice')
73 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
74 supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier0'))
75 assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
76-
77 2.- In order to test account refund with "Create refund and reconcile" method
78-
79 2.1.- I create a new supplier invoice
80-
81 !record {model: account.invoice, id: account_invoice_supplier1, view: account.invoice_supplier_form }:
82 <<: *supplier_invoice
83-
84 2.2.- I check that Initially supplier invoice state is "Draft"
85-
86 !assert {model: account.invoice, id: account_invoice_supplier1}:
87 - state == 'draft'
88-
89 2.3.- I check that the supplier invoice is a "Supplier Invoice"
90-
91 !assert {model: account.invoice, id: account_invoice_supplier1, string: This is not a supplier invoice}:
92 - type == 'in_invoice'
93-
94 2.4.- I change the state of invoice to open by clicking Validate button
95-
96 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier1}
97-
98 2.5.- I check that the invoice state is now "Open"
99-
100 !assert {model: account.invoice, id: account_invoice_supplier1}:
101 - state == 'open'
102-
103 2.6.- I create a supplier refund using the method "Create refund and reconcile" and
104 check the state of the account invoice refund resulting
105-
106 !python {model: account.invoice.refund}: |
107 import time
108 values = {
109 'date': time.strftime('%Y-%m-%d'),
110 'period': self.pool.get('account.period').find(
111 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
112 'journal_id': ref('account.refund_expenses_journal'),
113 'description': 'Desde el test',
114 'filter_refund': 'cancel',
115 }
116 wzr_id = self.create(cr, uid, values)
117 context['wzr_id'] = wzr_id
118 context['active_ids'] = [ref('account_invoice_supplier1')]
119 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
120 context['rfnd_id'] = rfnd_id
121 obj_inv = self.pool.get('account.invoice')
122 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
123 assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
124-
125 2.7.- I check the correct asigning of parent_id in the supplier refund created, for that
126 the supplier refund must have the supplier invoice id in the fiel parent_id
127-
128 !python {model: account.invoice.refund}: |
129 obj_inv = self.pool.get('account.invoice')
130 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
131 supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier1'))
132 assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
133-
134 3.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
135 method
136-
137 3.1.- I create a new supplier invoice
138-
139 !record {model: account.invoice, id: account_invoice_supplier2, view: account.invoice_supplier_form }:
140 <<: *supplier_invoice
141-
142 3.2.- I check that Initially supplier invoice state is "Draft"
143-
144 !assert {model: account.invoice, id: account_invoice_supplier2}:
145 - state == 'draft'
146-
147 3.3.- I check that the supplier invoice is a "Supplier Invoice"
148-
149 !assert {model: account.invoice, id: account_invoice_supplier2, string: This is not a supplier invoice}:
150 - type == 'in_invoice'
151-
152 3.4.- I change the state of invoice to open by clicking Validate button
153-
154 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier2}
155-
156 3.5.- I check that the invoice state is now "Open"
157-
158 !assert {model: account.invoice, id: account_invoice_supplier2}:
159 - state == 'open'
160-
161 3.6.- I create a supplier refund using the method "Create refund, reconcile and create a new draft invoice" and
162 check the state of the account invoice refund resulting
163-
164 !python {model: account.invoice.refund}: |
165 import time
166 values = {
167 'date': time.strftime('%Y-%m-%d'),
168 'period': self.pool.get('account.period').find(
169 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
170 'journal_id': ref('account.refund_expenses_journal'),
171 'description': 'Desde el test',
172 'filter_refund': 'modify',
173 }
174 wzr_id = self.create(cr, uid, values)
175 context['wzr_id'] = wzr_id
176 context['active_ids'] = [ref('account_invoice_supplier2')]
177 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
178 context['rfnd_id'] = rfnd_id
179 obj_inv = self.pool.get('account.invoice')
180 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
181 assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
182-
183 3.7.- I check the correct asigning of parent_id in the supplier refund created, for that
184 the supplier refund must have the supplier invoice id in the fiel parent_id
185-
186 !python {model: account.invoice.refund}: |
187 obj_inv = self.pool.get('account.invoice')
188 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
189 supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier2'))
190 assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
191-
192 3.8.- I check that the new supplier invoice was created in Draft state
193-
194 !python {model: account.invoice.refund}: |
195 obj_inv = self.pool.get('account.invoice')
196 inv_src = obj_inv.search(cr, uid, [], order='id')
197 supplier_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
198 assert supplier_inv_brw.state == 'draft', 'The new supplier invoice was not properly created, the state must be Draft.'
199-
200 4.- In order to test account refund with "Create a draft refund" method in a "Paid" invoice
201-
202 4.1.- I create a new partner
203-
204 !record {model: 'res.partner', id: res_partner10}:
205 name: Juan Garcia
206 use_parent_address: True
207 function: Tests
208 email: juan@garcia.com
209 supplier: True
210-
211 4.2.- I create a Purchase Journal.
212-
213 !record {model: account.journal, id: purchase_journal_debit}:
214 code: pjou_test
215 company_id: base.main_company
216 name: Purchase Journal For Debit Credit Note Tests
217 sequence_id: account.sequence_purchase_journal
218 type: purchase
219-
220 4.3.- I create a new supplier invoice
221-
222 !record {model: account.invoice, id: account_invoice_supplier3, view: account.invoice_supplier_form }:
223 account_id: account.a_pay
224 company_id: base.main_company
225 currency_id: base.EUR
226 invoice_line:
227 - account_id: account.a_expense
228 name: '[PCSC234] PC Assemble SC234'
229 price_unit: 300.0
230 product_id: product.product_product_3
231 quantity: 10.0
232 uos_id: product.product_uom_unit
233 journal_id: purchase_journal_debit
234 partner_id: res_partner10
235 reference_type: none
236 type: 'in_invoice'
237-
238 4.4.- I check that initially supplier invoice state is "Draft"
239-
240 !assert {model: account.invoice, id: account_invoice_supplier3}:
241 - state == 'draft'
242-
243 4.5.- I check that the supplier invoice is a "Supplier Invoice"
244-
245 !assert {model: account.invoice, id: account_invoice_supplier3, string: This is not a supplier invoice}:
246 - type == 'in_invoice'
247-
248 4.6.- I change the state of invoice to open by clicking Validate button
249-
250 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier3}
251-
252 4.7.- I check that the invoice state is now "Open"
253-
254 !assert {model: account.invoice, id: account_invoice_supplier3}:
255 - state == 'open'
256-
257 4.8.- I check that a payment entry gets created in the account.move.line
258-
259 !python {model: account.invoice}: |
260 acc_id=self.browse(cr, uid, ref("account_invoice_supplier3"))
261 assert(acc_id.move_id)
262-
263 4.9.- I create a Bank Journal.
264-
265 !record {model: account.journal, id: bank_journal_debit}:
266 name: Bank Journal For Debit Credit Note Tests
267 code: bjou_test
268 type: bank
269 analytic_journal_id: account.sit
270 sequence_id: account.sequence_bank_journal
271 default_debit_account_id: account.cash
272 default_credit_account_id: account.cash
273 company_id: base.main_company
274-
275 4.10.- I will create and post an account voucher of amount 3450.00 for the partner Juan Garcia.
276-
277 !record {model: account.voucher, id: account_voucher0, view: account_voucher.view_vendor_payment_form}:
278 type: payment
279 account_id: account.cash
280 amount: 3450.00
281 company_id: base.main_company
282 journal_id: bank_journal_debit
283 name: Voucher x
284 narration: PC Assemble SC234
285 line_dr_ids:
286 - account_id: account.cash
287 amount: 3450.00
288 name: Voucher x
289 partner_id: res_partner10
290 reference: none
291-
292 4.11.- I check that initially vendor voucher is in the "Draft" state
293-
294 !assert {model: account.voucher, id: account_voucher0}:
295 - state == 'draft'
296-
297 4.12.- I create voucher by clicking on create button
298-
299 !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher0}
300-
301 4.13.- I check that the voucher state is "Posted"
302-
303 !assert {model: account.voucher, id: account_voucher0}:
304 - state == 'posted'
305-
306 4.14.- I check if the state of the invoice is "Paid"
307-
308 !assert {model: account.invoice, id: account_invoice_supplier3}:
309 - state == 'paid'
310-
311 4.15.- I modified the sale journal record so it can cancel invoice
312-
313 !record {model: account.journal, id: purchase_journal_debit}:
314 update_posted: 1
315-
316 4.16.- I modified the cash journal record so it can cancel invoice
317-
318 !record {model: account.journal, id: bank_journal_debit}:
319 update_posted: 1
320-
321 4.17.- I create a Purchase Refund Journal.
322-
323 !record {model: account.journal, id: purchase_refund_journal_debit}:
324 code: sprjou_test
325 company_id: base.main_company
326 name: Purchase Refund Journal For Debit Credit Note Tests
327 sequence_id: account.sequence_refund_purchase_journal
328 type: purchase_refund
329-
330 4.18.- I create a supplier refund using the method "Create a draft refund" and
331 check the state of the account invoice refund resulting
332-
333 !python {model: account.invoice.refund}: |
334 import time
335 values = {
336 'date': time.strftime('%Y-%m-%d'),
337 'period': self.pool.get('account.period').find(
338 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
339 'journal_id': ref('purchase_refund_journal_debit'),
340 'description': 'Desde el test',
341 'filter_refund': 'refund',
342 }
343 wzr_id = self.create(cr, uid, values)
344 assert wzr_id, 'The wizard instance was not created.'
345 context['wzr_id'] = wzr_id
346 context['active_ids'] = [ref('account_invoice_supplier3')]
347 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
348 assert rfnd_id, 'The refund was not created.'
349 context['rfnd_id'] = rfnd_id
350 obj_inv = self.pool.get('account.invoice')
351 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
352 assert rfnd_supplier_inv_brw[0].state == 'draft', 'The supplier refund was not properly created, the state must be Draft.'
353-
354 4.19.- I check the correct asigning of parent_id in the supplier refund created, for that
355 the supplier refund must have the supplier invoice id in the fiel parent_id
356-
357 !python {model: account.invoice.refund}: |
358 obj_inv = self.pool.get('account.invoice')
359 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
360 supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier3'))
361 assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
362-
363 5.- In order to test account refund with "Create refund and reconcile" method in a "Paid" invoice
364-
365 5.1.- I create a new partner
366-
367 !record {model: 'res.partner', id: res_partner11}:
368 name: Maria Garcia
369 use_parent_address: True
370 function: Tests
371 email: maria@garcia.com
372 supplier: True
373-
374 5.2.- I create a new supplier invoice
375-
376 !record {model: account.invoice, id: account_invoice_supplier4, view: account.invoice_supplier_form }:
377 account_id: account.a_pay
378 company_id: base.main_company
379 currency_id: base.EUR
380 invoice_line:
381 - account_id: account.a_expense
382 name: '[PCSC234] PC Assemble SC234'
383 price_unit: 300.0
384 product_id: product.product_product_3
385 quantity: 10.0
386 uos_id: product.product_uom_unit
387 journal_id: purchase_journal_debit
388 partner_id: res_partner11
389 reference_type: none
390 type: 'in_invoice'
391-
392 5.3.- I check that initially supplier invoice state is "Draft"
393-
394 !assert {model: account.invoice, id: account_invoice_supplier4}:
395 - state == 'draft'
396-
397 5.4.- I check that the supplier invoice is a "Supplier Invoice"
398-
399 !assert {model: account.invoice, id: account_invoice_supplier4, string: This is not a supplier invoice}:
400 - type == 'in_invoice'
401-
402 5.5.- I change the state of invoice to open by clicking Validate button
403-
404 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier4}
405-
406 5.6.- I check that the invoice state is now "Open"
407-
408 !assert {model: account.invoice, id: account_invoice_supplier4}:
409 - state == 'open'
410-
411 5.7.- I check that a payment entry gets created in the account.move.line
412-
413 !python {model: account.invoice}: |
414 acc_id=self.browse(cr, uid, ref("account_invoice_supplier4"))
415 assert(acc_id.move_id)
416-
417 5.8.- I will create and post an account voucher of amount 3450.00 for the partner Maria Garcia.
418-
419 !record {model: account.voucher, id: account_voucher1, view: account_voucher.view_vendor_payment_form}:
420 type: payment
421 account_id: account.cash
422 amount: 3450.00
423 company_id: base.main_company
424 journal_id: bank_journal_debit
425 name: Voucher x
426 narration: PC Assemble SC234
427 line_dr_ids:
428 - account_id: account.cash
429 amount: 3450.00
430 name: Voucher x
431 partner_id: res_partner11
432 reference: none
433-
434 5.9.- I check that initially vendor voucher is in the "Draft" state
435-
436 !assert {model: account.voucher, id: account_voucher1}:
437 - state == 'draft'
438-
439 5.10.- I create voucher by clicking on create button
440-
441 !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher1}
442-
443 5.11.- I check that the voucher state is "Posted"
444-
445 !assert {model: account.voucher, id: account_voucher1}:
446 - state == 'posted'
447-
448 5.12.- I check if the state of the invoice is "Paid"
449-
450 !assert {model: account.invoice, id: account_invoice_supplier4}:
451 - state == 'paid'
452-
453 5.13.- I create a supplier refund using the method "Create refund and reconcile" and
454 check the state of the account invoice refund resulting
455-
456 !python {model: account.invoice.refund}: |
457 import time
458 values = {
459 'date': time.strftime('%Y-%m-%d'),
460 'period': self.pool.get('account.period').find(
461 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
462 'journal_id': ref('purchase_refund_journal_debit'),
463 'description': 'Desde el test',
464 'filter_refund': 'cancel',
465 }
466 wzr_id = self.create(cr, uid, values)
467 assert wzr_id, 'The wizard instance was not created.'
468 context['wzr_id'] = wzr_id
469 context['active_ids'] = [ref('account_invoice_supplier4')]
470 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
471 assert rfnd_id, 'The refund was not created.'
472 context['rfnd_id'] = rfnd_id
473 obj_inv = self.pool.get('account.invoice')
474 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
475 assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
476-
477 5.14.- I check the correct asigning of parent_id in the supplier refund created, for that
478 the supplier refund must have the supplier invoice id in the fiel parent_id
479-
480 !python {model: account.invoice.refund}: |
481 obj_inv = self.pool.get('account.invoice')
482 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
483 supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier4'))
484 assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
485-
486 6.- In order to test account refund with "Create refund, reconcile and create a new draft invoice"
487 method in a "Paid" invoice
488-
489 6.1.- I create a new partner
490-
491 !record {model: 'res.partner', id: res_partner12}:
492 name: Pablo Garcia
493 use_parent_address: True
494 function: Tests
495 email: pablo@garcia.com
496 supplier: True
497-
498 6.2.- I create a new supplier invoice
499-
500 !record {model: account.invoice, id: account_invoice_supplier5, view: account.invoice_supplier_form }:
501 account_id: account.a_pay
502 company_id: base.main_company
503 currency_id: base.EUR
504 invoice_line:
505 - account_id: account.a_expense
506 name: '[PCSC234] PC Assemble SC234'
507 price_unit: 300.0
508 product_id: product.product_product_3
509 quantity: 10.0
510 uos_id: product.product_uom_unit
511 journal_id: purchase_journal_debit
512 partner_id: res_partner12
513 reference_type: none
514 type: 'in_invoice'
515-
516 6.3.- I check that initially supplier invoice state is "Draft"
517-
518 !assert {model: account.invoice, id: account_invoice_supplier5}:
519 - state == 'draft'
520-
521 6.4.- I check that the supplier invoice is a "Supplier Invoice"
522-
523 !assert {model: account.invoice, id: account_invoice_supplier5, string: This is not a supplier invoice}:
524 - type == 'in_invoice'
525-
526 6.5.- I change the state of invoice to open by clicking Validate button
527-
528 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier5}
529-
530 5.6.- I check that the invoice state is now "Open"
531-
532 !assert {model: account.invoice, id: account_invoice_supplier5}:
533 - state == 'open'
534-
535 6.7.- I check that a payment entry gets created in the account.move.line
536-
537 !python {model: account.invoice}: |
538 acc_id=self.browse(cr, uid, ref("account_invoice_supplier5"))
539 assert(acc_id.move_id)
540-
541 6.8.- I will create and post an account voucher of amount 3450.00 for the partner Maria Garcia.
542-
543 !record {model: account.voucher, id: account_voucher2, view: account_voucher.view_vendor_payment_form}:
544 type: payment
545 account_id: account.cash
546 amount: 3450.00
547 company_id: base.main_company
548 journal_id: bank_journal_debit
549 name: Voucher x
550 narration: PC Assemble SC234
551 line_dr_ids:
552 - account_id: account.cash
553 amount: 3450.00
554 name: Voucher x
555 partner_id: res_partner12
556 reference: none
557-
558 6.9.- I check that initially vendor voucher is in the "Draft" state
559-
560 !assert {model: account.voucher, id: account_voucher2}:
561 - state == 'draft'
562-
563 6.10.- I create voucher by clicking on create button
564-
565 !workflow {model: account.voucher, action: proforma_voucher, ref: account_voucher2}
566-
567 6.11.- I check that the voucher state is "Posted"
568-
569 !assert {model: account.voucher, id: account_voucher2}:
570 - state == 'posted'
571-
572 6.12.- I check if the state of the invoice is "Paid"
573-
574 !assert {model: account.invoice, id: account_invoice_supplier5}:
575 - state == 'paid'
576-
577 6.13.- I create a supplier refund using the method "Create refund, reconcile and create a new draft invoice" and
578 check the state of the account invoice refund resulting
579-
580 !python {model: account.invoice.refund}: |
581 import time
582 values = {
583 'date': time.strftime('%Y-%m-%d'),
584 'period': self.pool.get('account.period').find(
585 cr, uid, time.strftime('%Y/%m/%d'), {'company_id': ref('base.main_company')})[0],
586 'journal_id': ref('purchase_refund_journal_debit'),
587 'description': 'Desde el test',
588 'filter_refund': 'modify',
589 }
590 wzr_id = self.create(cr, uid, values)
591 assert wzr_id, 'The wizard instance was not created.'
592 context['wzr_id'] = wzr_id
593 context['active_ids'] = [ref('account_invoice_supplier5')]
594 rfnd_id = self.invoice_refund(cr, uid, [wzr_id], context=context)
595 assert rfnd_id, 'The refund was not created.'
596 context['rfnd_id'] = rfnd_id
597 obj_inv = self.pool.get('account.invoice')
598 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, rfnd_id['domain'][1][2])
599 assert rfnd_supplier_inv_brw[0].state == 'paid', 'The supplier refund was not properly created, the state must be Paid.'
600-
601 6.14.- I check the correct asigning of parent_id in the supplier refund created, for that
602 the supplier refund must have the supplier invoice id in the fiel parent_id
603-
604 !python {model: account.invoice.refund}: |
605 obj_inv = self.pool.get('account.invoice')
606 rfnd_supplier_inv_brw = obj_inv.browse(cr, uid, context['rfnd_id']['domain'][1][2])
607 supplier_inv_brw = obj_inv.browse(cr, uid, ref('account_invoice_supplier5'))
608 assert (rfnd_supplier_inv_brw[0].parent_id.id == supplier_inv_brw.id), 'The supplier refund dont have the correct parent_id.'
609-
610 6.15.- I check that the new supplier invoice was created in Draft state
611-
612 !python {model: account.invoice.refund}: |
613 obj_inv = self.pool.get('account.invoice')
614 inv_src = obj_inv.search(cr, uid, [], order='id')
615 supplier_inv_brw = obj_inv.browse(cr, uid, inv_src[-1])
616 assert supplier_inv_brw.state == 'draft', 'The new supplier invoice was not properly created, the state must be Draft.'
0617
=== modified file 'debit_credit_note/wizard/account_invoice_refund.py'
--- debit_credit_note/wizard/account_invoice_refund.py 2014-01-17 21:53:54 +0000
+++ debit_credit_note/wizard/account_invoice_refund.py 2014-02-03 16:27:19 +0000
@@ -92,24 +92,21 @@
92 period_id = ids[0]92 period_id = ids[0]
93 return period_id93 return period_id
9494
95 def _get_orig(self, cr, uid, inv, context={}):95 def _get_orig(self, cr, uid, inv, ref, context={}):
96 """96 """ Return default origin value
97 Return default origin value97 """
98 """98 nro_ref = ref
99 nro_ref = ''
100 if inv.type == 'out_invoice':99 if inv.type == 'out_invoice':
101 nro_ref = inv.number100 nro_ref = inv.number
102 orig = _('INV REFUND:') + (nro_ref or '') + _('- DATE:') + (101 orig = 'Devolucion FACT:' +(nro_ref or '') + '- DE FECHA:' + (inv.date_invoice or '') + (' TOTAL:' + str(inv.amount_total) or '')
103 inv.date_invoice or '') + (' TOTAL:' + str(inv.amount_total) or '')
104 return orig102 return orig
105103
106 def compute_refund(self, cr, uid, ids, mode='refund', context=None):104 def compute_refund(self, cr, uid, ids, mode='refund', context=None):
107 """105 """
108 @param cr: the current row, from the database cursor,
109 @param uid: the current user’s ID for security checks,
110 @param ids: the account invoice refund’s ID or list of IDs106 @param ids: the account invoice refund’s ID or list of IDs
111
112 """107 """
108 wzd_brw = self.browse(cr,uid,ids[0],context=context)
109 brw = self.browse(cr,uid,ids[0],context=context)
113 inv_obj = self.pool.get('account.invoice')110 inv_obj = self.pool.get('account.invoice')
114 reconcile_obj = self.pool.get('account.move.reconcile')111 reconcile_obj = self.pool.get('account.move.reconcile')
115 account_m_line_obj = self.pool.get('account.move.line')112 account_m_line_obj = self.pool.get('account.move.line')
@@ -121,70 +118,66 @@
121 res_users_obj = self.pool.get('res.users')118 res_users_obj = self.pool.get('res.users')
122 if context is None:119 if context is None:
123 context = {}120 context = {}
124
125 for form in self.browse(cr, uid, ids, context=context):121 for form in self.browse(cr, uid, ids, context=context):
126 created_inv = []122 created_inv = []
127 date = False123 date = False
128 period = False124 period = False
129 description = False125 description = False
130 company = res_users_obj.browse(126 company = res_users_obj.browse(cr, uid, uid, context=context).company_id
131 cr, uid, uid, context=context).company_id127 journal_brw = form.journal_id or False
132 journal_id = form.journal_id.id128 for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
133 for inv in inv_obj.browse(cr, uid, context.get('active_ids'),
134 context=context):
135 if inv.state in ['draft', 'proforma2', 'cancel']:129 if inv.state in ['draft', 'proforma2', 'cancel']:
136 raise osv.except_osv(_('Error!'), _(130 raise osv.except_osv(_('Error !'), _('Can not %s draft/proforma/cancel invoice.') % (mode))
137 'Cannot %s draft/proforma/cancel invoice.') % (mode))
138 if inv.reconciled and mode in ('cancel', 'modify'):131 if inv.reconciled and mode in ('cancel', 'modify'):
139 raise osv.except_osv(_('Error!'), _(132 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))
140 'Cannot %s invoice which is already reconciled, '133 period = form.period.id or False
141 'invoice should be unreconciled first. You can only '134 if not period:
142 'refund this invoice.') % (mode))135 #Take period from the current date
143 if form.period.id:136 period = self.pool.get('account.period').find(cr, uid, context=context)
144 period = form.period.id137 period = period and period[0] or False
145 else:138 if not period:
146 period = inv.period_id and inv.period_id.id or False139 raise osv.except_osv(_('No Period Defined'), \
140 _('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'))
141 self.write(cr, uid, ids, {'period': period }, context=context)
147142
148 if not journal_id:143 if not journal_brw:
149 journal_id = inv.journal_id.id144 journal_id = inv.journal_id.id
145 else:
146 journal_id=journal_brw.id
150147
151 if form.date:148 if form.date:
152 date = form.date149 date = form.date
153 if not form.period.id:150 if not form.period:
154 cr.execute("select name from ir_model_fields \151 cr.execute("select name from ir_model_fields \
155 where model = 'account.period' \152 where model = 'account.period' \
156 and name = 'company_id'")153 and name = 'company_id'")
157 result_query = cr.fetchone()154 result_query = cr.fetchone()
158 if result_query:155 if result_query:
159 cr.execute("""select p.id from account_fiscalyear y156 cr.execute("""select p.id from account_fiscalyear y, account_period p where y.id=p.fiscalyear_id \
160 , account_period p157 and date(%s) between p.date_start AND p.date_stop and y.company_id = %s limit 1""", (date, company.id,))
161 where y.id=p.fiscalyear_id \158 else:
162 and date(%s) between p.date_start AND159 cr.execute("""SELECT id
163 p.date_stop and y.company_id = %s limit 1""",160 from account_period where date(%s)
164 (date, company.id,))161 between date_start AND date_stop \
165 else:162 limit 1 """, (date,))
166 cr.execute("""SELECT id163 res = cr.fetchone()
167 from account_period where date(%s)164 if res:
168 between date_start AND date_stop \165 period = res[0]
169 limit 1 """, (date,))
170 res = cr.fetchone()
171 if res:
172 period = res[0]
173 else:166 else:
174 date = inv.date_invoice167 #Take current date
168 #date = inv.date_invoice
169 date = time.strftime('%Y-%m-%d')
175 if form.description:170 if form.description:
176 description = form.description171 description = form.description
177 else:172 else:
178 description = inv.name173 description = inv.name
179174
180 if not period:175 if not period:
181 raise osv.except_osv(_('Insufficient Data!'),176 raise osv.except_osv(_('Data Insufficient !'), \
182 _('No period found on the invoice.'))177 _('No Period found on Invoice!'))
183178
184 refund_id = inv_obj.refund(cr, uid, [179 refund_id = inv_obj.refund(cr, uid, [inv.id], date, period, description, journal_id)
185 inv.id], date, period,180
186 description, journal_id,
187 context=context)
188 refund = inv_obj.browse(cr, uid, refund_id[0], context=context)181 refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
189 # Add parent invoice182 # Add parent invoice
190 inv_obj.write(cr, uid, [refund.id],183 inv_obj.write(cr, uid, [refund.id],
@@ -202,43 +195,37 @@
202 to_reconcile_ids[line.account_id.id] = [line.id]195 to_reconcile_ids[line.account_id.id] = [line.id]
203 if type(line.reconcile_id) != osv.orm.browse_null:196 if type(line.reconcile_id) != osv.orm.browse_null:
204 reconcile_obj.unlink(cr, uid, line.reconcile_id.id)197 reconcile_obj.unlink(cr, uid, line.reconcile_id.id)
205 wf_service.trg_validate(uid, 'account.invoice',198 wf_service.trg_validate(uid, 'account.invoice', \
206 refund.id, 'invoice_open', cr)199 refund.id, 'invoice_open', cr)
207 refund = inv_obj.browse(200
208 cr, uid, refund_id[0], context=context)201 refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
209 for tmpline in refund.move_id.line_id:202
203 for tmpline in refund.move_id.line_id:
210 if tmpline.account_id.id == inv.account_id.id:204 if tmpline.account_id.id == inv.account_id.id:
211 to_reconcile_ids[205 to_reconcile_ids[tmpline.account_id.id].append(tmpline.id)
212 tmpline.account_id.id].append(tmpline.id)
213 for account in to_reconcile_ids:206 for account in to_reconcile_ids:
214 account_m_line_obj.reconcile(207 account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account],
215 cr, uid, to_reconcile_ids[account],208 writeoff_period_id=period,
216 writeoff_period_id=period,209 writeoff_journal_id = inv.journal_id.id,
217 writeoff_journal_id=inv.journal_id.id,210 writeoff_acc_id=inv.account_id.id
218 writeoff_acc_id=inv.account_id.id211 )
219 )
220 if mode == 'modify':212 if mode == 'modify':
221 invoice = inv_obj.read(cr, uid, [inv.id],213 invoice = inv_obj.read(cr, uid, [inv.id],
222 ['name', 'type', 'number',214 ['name', 'type', 'number', 'supplier_invoice_number',
223 'reference', 'comment',215 'comment', 'date_due', 'partner_id',
224 'date_due', 'partner_id',216 'partner_insite', 'partner_contact',
225 'partner_insite',217 'partner_ref', 'payment_term', 'account_id',
226 'partner_contact',218 'currency_id', 'invoice_line', 'tax_line',
227 'partner_ref', 'payment_term',219 'journal_id', 'period_id'], context=context)
228 'account_id', 'currency_id',
229 'invoice_line', 'tax_line',
230 'journal_id', 'period_id'],
231 context=context)
232 invoice = invoice[0]220 invoice = invoice[0]
233 del invoice['id']221 del invoice['id']
234 invoice_lines = inv_line_obj.browse(222 invoice_lines = inv_line_obj.browse(cr, uid, invoice['invoice_line'], context=context)
235 cr, uid, invoice['invoice_line'], context=context)223
236 invoice_lines = inv_obj._refund_cleanup_lines(224 invoice_lines = inv_obj._refund_cleanup_lines(cr, uid, invoice_lines)
237 cr, uid, invoice_lines, context=context)225 tax_lines = inv_tax_obj.browse(cr, uid, invoice['tax_line'], context=context)
238 tax_lines = inv_tax_obj.browse(226 tax_lines = inv_obj._refund_cleanup_lines(cr, uid, tax_lines)
239 cr, uid, invoice['tax_line'], context=context)227 #Add origin value
240 tax_lines = inv_obj._refund_cleanup_lines(228 orig = self._get_orig(cr, uid, inv, invoice['supplier_invoice_number'], context)
241 cr, uid, tax_lines, context=context)
242 invoice.update({229 invoice.update({
243 'type': inv.type,230 'type': inv.type,
244 'date_invoice': date,231 'date_invoice': date,
@@ -248,36 +235,99 @@
248 'tax_line': tax_lines,235 'tax_line': tax_lines,
249 'period_id': period,236 'period_id': period,
250 'name': description,237 'name': description,
251 'origin': self._get_orig(cr, uid, inv, context={}),238 'origin': orig,
252 })239 })
253 for field in (240 for field in ( 'partner_id',
254 'partner_id', 'account_id', 'currency_id',241 'account_id', 'currency_id', 'payment_term', 'journal_id'):
255 'payment_term', 'journal_id'):242 invoice[field] = invoice[field] and invoice[field][0]
256 invoice[field] = invoice[
257 field] and invoice[field][0]
258 inv_id = inv_obj.create(cr, uid, invoice, {})243 inv_id = inv_obj.create(cr, uid, invoice, {})
259 if inv.payment_term.id:244 if inv.payment_term.id:
260 data = inv_obj.onchange_payment_term_date_invoice(245 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
261 cr, uid, [inv_id], inv.payment_term.id, date)
262 if 'value' in data and data['value']:246 if 'value' in data and data['value']:
263 inv_obj.write(cr, uid, [inv_id], data['value'])247 inv_obj.write(cr, uid, [inv_id], data['value'])
264 created_inv.append(inv_id)248 created_inv.append(inv_id)
265 xml_id = (inv.type == 'out_refund') and 'action_invoice_tree1' or \249
266 (inv.type == 'in_refund') and 'action_invoice_tree2' or \250 new_inv_brw = inv_obj.browse(cr,uid,created_inv[1],context=context)
267 (inv.type == 'out_invoice') and 'action_invoice_tree3' or \251 inv_obj.write(cr,uid,created_inv[0],{'name':wzd_brw.description,'origin':new_inv_brw.origin},context=context)
268 (inv.type == 'in_invoice') and 'action_invoice_tree4'252 inv_obj.write(cr,uid,created_inv[1],{'origin':inv.origin,'name':wzd_brw.description},context=context)
253 if inv.type in ('out_invoice', 'out_refund'):
254 xml_id = 'action_invoice_tree3'
255 else:
256 xml_id = 'action_invoice_tree4'
269 result = mod_obj.get_object_reference(cr, uid, 'account', xml_id)257 result = mod_obj.get_object_reference(cr, uid, 'account', xml_id)
270 id = result and result[1] or False258 id = result and result[1] or False
271 result = act_obj.read(cr, uid, id, context=context)259 result = act_obj.read(cr, uid, id, context=context)
272 invoice_domain = eval(result['domain'])260 invoice_domain = eval(result['domain'])
273 invoice_domain.append(('id', 'in', created_inv))261 invoice_domain.append(('id', 'in', created_inv))
274 result['domain'] = invoice_domain262 result['domain'] = invoice_domain
263
264 if wzd_brw.filter_refund == 'cancel':
265 orig = self._get_orig(cr, uid, inv, inv.supplier_invoice_number, context)
266 inv_obj.write(cr,uid,created_inv[0],{'origin':orig,'name':wzd_brw.description},context=context)
267
268 if wzd_brw.filter_refund == 'refund':
269 orig = self._get_orig(cr, uid, inv, inv.supplier_invoice_number, context)
270 inv_obj.write(cr,uid,created_inv[0],{'origin':inv.origin,'name':wzd_brw.description},context=context)
275 return result271 return result
272
273 def validate_total_payment_inv(self, cr, uid, ids, context=None):
274 """ Method that validate if invoice is totally paid.
275 @param ids: list of invoices.
276 return: True: if invoice is paid.
277 False: if invoice is not paid.
278 """
279 res = False
280 inv_obj = self.pool.get('account.invoice')
281 for inv in inv_obj.browse(cr, uid, ids, context=context):
282 res = inv.reconciled
283 return res
284
285 def unreconcile_paid_invoices(self, cr, uid, invoiceids, context=None):
286 """ Method that unreconcile the payments of invoice.
287 @param invoiceids: list of invoices.
288 return: True: unreconcile successfully.
289 False: unreconcile unsuccessfully.
290 """
291 inv_obj = self.pool.get('account.invoice')
292 moveline_obj = self.pool.get('account.move.line')
293 voucher_pool = self.pool.get('account.voucher')
294 res = True
295 rec = []
296 mid = []
297 if self.validate_total_payment_inv(cr, uid, invoiceids, context=context):
298 for inv in inv_obj.browse(cr, uid, invoiceids, context=context):
299 movelineids = inv_obj.move_line_id_payment_get(cr, uid,[inv.id])
300 for moveline in moveline_obj.browse(cr, uid, movelineids,context=context):
301 if moveline.reconcile_id:
302 rec += [moveline.reconcile_id.id]
303 if moveline.reconcile_partial_id:
304 rec += [moveline.reconcile_partial_id.id]
305 movelines = moveline_obj.search(cr, uid, [('|'),('reconcile_id','in',rec),('reconcile_partial_id','in',rec)],context=context)
306 for mids in moveline_obj.browse(cr, uid, movelines, context=context):
307 mid +=[mids.move_id.id]
308 voucherids = voucher_pool.search(cr, uid,[('move_id','in',mid)])
309 if voucherids:
310 voucher_pool.cancel_voucher(cr, uid, voucherids, context=context)
311 else:
312 res = False
313 return res
276314
277 def invoice_refund(self, cr, uid, ids, context=None):315 def invoice_refund(self, cr, uid, ids, context=None):
278 data_refund = self.read(cr, uid, ids, [316 """ Create a invoice refund
279 'filter_refund'],317 """
280 context=context)[0]['filter_refund']318 if context is None:
319 context = {}
320 inv_obj = self.pool.get('account.invoice')
321 period_obj = self.pool.get('account.period')
322 wzr_brw = self.browse(cr,uid,ids,context=context)[0]
323 date = wzr_brw.date
324 period = wzr_brw and wzr_brw.period and wzr_brw.period.id
325 period_ids = date and period_obj.search(cr,uid,[('date_start', '<=', date),('date_stop', '>=', date),('special', '=', False)],context=context)
326 if period not in period_ids:
327 raise osv.except_osv(_('Error !'), \
328 _('The date should be chosen to belong to the period'))
329 self.unreconcile_paid_invoices(cr, uid, context.get('active_ids'), context=context)
330 data_refund = self.browse(cr, uid, ids, context=context)[0].filter_refund
281 return self.compute_refund(cr, uid, ids, data_refund, context=context)331 return self.compute_refund(cr, uid, ids, data_refund, context=context)
282332
283333