Merge lp:~openerp-dev/openobject-addons/trunk-bug-827649-bde into lp:openobject-addons

Proposed by Bharat Devnani (Open ERP)
Status: Rejected
Rejected by: Fabien (Open ERP)
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-827649-bde
Merge into: lp:openobject-addons
Diff against target: 165 lines (+48/-18)
1 file modified
account_voucher/account_voucher.py (+48/-18)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-827649-bde
Reviewer Review Type Date Requested Status
Bharat Devnani (Open ERP) (community) Needs Resubmitting
Purnendu Singh (OpenERP) (community) Needs Fixing
OpenERP Core Team Pending
Review via email: mp+80869@code.launchpad.net

Description of the change

Hello Sir,

I have corrected the tax value in account_voucher when in it was included in the price.

Thanks & Regards,
Devnani Bharat R.

To post a comment you must log in.
5449. By Bharat Devnani (Open ERP)

[REM] Account : removed unnecessary code

5450. By Bharat Devnani (Open ERP)

[REM] Account : removed unnecessary code

Revision history for this message
Purnendu Singh (OpenERP) (purnendu-singh) wrote :

1) if there isn't any change in account_move_line.py then why it is in your patch!!!!

2) in your patch line 91
    + voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context=context)
    * please make a habit of pooling all required objects at the start of the method
    * browse(cr,uid,voucher_id,context=context)..... we generally using a space between each arguments
3) line 137 to 159 it can be optimize. there are too many variables used!!!! Improve this

review: Needs Fixing
5451. By Bharat Devnani (Open ERP)

[IMP] account_voucher : improved the code in account_voucher/account_voucher.py

Revision history for this message
Bharat Devnani (Open ERP) (bde-openerp) wrote :

Hello Sir,

I have improved the code in account_voucher/account_voucher.py

Thanks & Regards,
Devnani Bharat R.

review: Needs Resubmitting
5452. By Bharat Devnani (Open ERP)

[IMP] account_voucher : pooled the object at start of the method

5453. By Bharat Devnani (Open ERP)

[IMP] account_voucher : optimized the code and made the searching next move_line more dynamic

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

I do not understand why we compute the tax manually ?
The tax object should compute the tax itself.

Unmerged revisions

5453. By Bharat Devnani (Open ERP)

[IMP] account_voucher : optimized the code and made the searching next move_line more dynamic

5452. By Bharat Devnani (Open ERP)

[IMP] account_voucher : pooled the object at start of the method

5451. By Bharat Devnani (Open ERP)

[IMP] account_voucher : improved the code in account_voucher/account_voucher.py

5450. By Bharat Devnani (Open ERP)

[REM] Account : removed unnecessary code

5449. By Bharat Devnani (Open ERP)

[REM] Account : removed unnecessary code

5448. By Bharat Devnani (Open ERP)

[FIX] Account : Supplier voucher - wrong for tax inclusive

5447. By Bharat Devnani (Open ERP)

In Progress

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account.py'
2=== modified file 'account_voucher/account_voucher.py'
3--- account_voucher/account_voucher.py 2011-10-27 21:11:24 +0000
4+++ account_voucher/account_voucher.py 2011-11-11 06:04:26 +0000
5@@ -26,6 +26,7 @@
6 from osv import osv, fields
7 import decimal_precision as dp
8 from tools.translate import _
9+import tools
10
11
12 class account_voucher(osv.osv):
13@@ -518,7 +519,7 @@
14 elif currency_id == company_currency:
15 #otherwise treatments is the same but with other field names
16 if line.amount_residual == price:
17- #if the amount residual is equal the amount voucher, we assign it to that voucher
18+ #if the amount residual is equal the amount voucher, we assign it to that voucher
19 #line, whatever the other voucher lines
20 move_line_found = line.id
21 break
22@@ -696,8 +697,8 @@
23 Select the context to use accordingly if it needs to be multicurrency or not.
24
25 :param voucher_id: Id of the actual voucher
26- :return: The returned context will be the same as given in parameter if the voucher currency is the same
27- than the company currency, otherwise it's a copy of the parameter with an extra key 'date' containing
28+ :return: The returned context will be the same as given in parameter if the voucher currency is the same
29+ than the company currency, otherwise it's a copy of the parameter with an extra key 'date' containing
30 the date of the voucher.
31 :rtype: dict
32 """
33@@ -726,13 +727,19 @@
34 voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context)
35 debit = credit = 0.0
36 # TODO: is there any other alternative then the voucher type ??
37- # ANSWER: We can have payment and receipt "In Advance".
38+ # ANSWER: We can have payment and receipt "In Advance".
39 # TODO: Make this logic available.
40 # -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt
41 if voucher_brw.type in ('purchase', 'payment'):
42- credit = voucher_brw.amount / voucher_brw.payment_rate
43+ if voucher_brw.tax_id.price_include:
44+ credit = (voucher_brw.amount - voucher_brw.tax_amount) / voucher_brw.payment_rate
45+ else :
46+ credit = voucher_brw.amount / voucher_brw.payment_rate
47 elif voucher_brw.type in ('sale', 'receipt'):
48- debit = voucher_brw.amount / voucher_brw.payment_rate
49+ if voucher_brw.tax_id.price_include:
50+ debit = (voucher_brw.amount - voucher_brw.tax_amount) / voucher_brw.payment_rate
51+ else:
52+ debit = voucher_brw.amount / voucher_brw.payment_rate
53 if debit < 0: credit = -debit; debit = 0.0
54 if credit < 0: debit = -credit; credit = 0.0
55 sign = debit - credit < 0 and -1 or 1
56@@ -769,7 +776,7 @@
57 elif voucher_brw.journal_id.sequence_id:
58 name = seq_obj.next_by_id(cr, uid, voucher_brw.journal_id.sequence_id.id)
59 else:
60- raise osv.except_osv(_('Error !'),
61+ raise osv.except_osv(_('Error !'),
62 _('Please define a sequence on the journal !'))
63 if not voucher_brw.reference:
64 ref = name.replace('/','')
65@@ -834,7 +841,7 @@
66 def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, company_currency, current_currency, context=None):
67 '''
68 Create one account move line, on the given account move, per voucher line where amount is not 0.0.
69- It returns Tuple with tot_line what is total of difference between debit and credit and
70+ It returns Tuple with tot_line what is total of difference between debit and credit and
71 a list of lists with ids to be reconciled with this format (total_deb_cred,list_of_lists).
72
73 :param voucher_id: Voucher id what we are working with
74@@ -849,8 +856,9 @@
75 currency_obj = self.pool.get('res.currency')
76 tot_line = line_total
77 rec_lst_ids = []
78-
79- voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context)
80+ tax_obj = self.pool.get('account.tax')
81+ account_voucher_obj = self.pool.get('account.voucher')
82+ voucher_brw = account_voucher_obj.browse(cr, uid, voucher_id, context=context)
83 for line in voucher_brw.line_ids:
84 #create one move line per voucher line where amount is not 0.0
85 if not line.amount:
86@@ -860,7 +868,10 @@
87 amount = (line.untax_amount or line.amount) / voucher_brw.payment_rate
88 amount_residual = line.move_line_id.amount_residual - amount #residual amount in company currency
89 else:
90- amount = (line.untax_amount or line.amount) / voucher_brw.payment_rate
91+ if voucher_brw.tax_id.price_include:
92+ amount = line.amount / voucher_brw.payment_rate
93+ else:
94+ amount = (line.untax_amount or line.amount) / voucher_brw.payment_rate
95 amount_residual = 0.0
96 move_line = {
97 'journal_id': voucher_brw.journal_id.id,
98@@ -874,8 +885,9 @@
99 'quantity': 1,
100 'credit': 0.0,
101 'debit': 0.0,
102- 'date': voucher_brw.date
103+ 'date': voucher_brw.date,
104 }
105+
106 if amount < 0:
107 amount = -amount
108 if line.type == 'dr':
109@@ -895,17 +907,37 @@
110 'account_tax_id': voucher_brw.tax_id.id,
111 })
112
113+ # Creates 2nd move line
114 if move_line.get('account_tax_id', False):
115 tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0]
116 if not (tax_data.base_code_id and tax_data.tax_code_id):
117 raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name))
118-
119 sign = (move_line['debit'] - move_line['credit']) < 0 and -1 or 1
120 move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or False
121- voucher_line = move_line_obj.create(cr, uid, move_line)
122+ voucher_line = move_line_obj.create(cr, uid, move_line, context=context)
123+ move_line = move_line_obj.browse(cr, uid, voucher_line, context=context)
124+ next_line = tools.ustr(move_line.name) + ' ' + tools.ustr(voucher_brw.tax_id.name)
125+ line_search = move_line_obj.search(cr, uid, ['&', ('name','=', next_line), ('id', '>', voucher_line)], context=context)
126+ for vals in move_line_obj.browse(cr, uid, line_search, context=context):
127+ vals = vals.id
128+ if voucher_brw.tax_id.amount:
129+ amount = voucher_brw.amount - (voucher_brw.amount * 100) / (100 + (voucher_brw.tax_id.amount * 100))
130+
131+ if voucher_brw.tax_id.price_include:
132+ if (line.type=='dr'):
133+ move_line_obj.write(cr, uid, [vals], {
134+ 'tax_amount': amount,
135+ 'debit': amount,
136+ })
137+
138+ if (line.type=='cr'):
139+ move_line_obj.write(cr, uid, [vals], {
140+ 'tax_amount': amount,
141+ 'credit': amount,
142+ })
143+
144 rec_ids = [voucher_line, line.move_line_id.id]
145-
146- if amount_residual:
147+ if amount_residual:
148 # Change difference entry
149 exch_lines = self._get_exchange_lines(cr, uid, line, move_id, amount_residual, company_currency, current_currency, context=context)
150 new_id = move_line_obj.create(cr, uid, exch_lines[0],context)
151@@ -914,7 +946,6 @@
152
153 if line.move_line_id.id:
154 rec_lst_ids.append(rec_ids)
155-
156 return (tot_line, rec_lst_ids)
157
158 def writeoff_move_line_get(self, cr, uid, voucher_id, line_total, move_id, name, company_currency, current_currency, context=None):
159@@ -1200,7 +1231,6 @@
160 bank_st_line_obj.write(cr, uid, [st_line_id], {
161 'move_ids': [(4, v.move_id.id, False)]
162 })
163-
164 return move_line_obj.write(cr, uid, [x.id for x in v.move_ids], {'statement_id': st_line.statement_id.id}, context=context)
165 return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line.id, company_currency_id, next_number, context=context)
166

Subscribers

People subscribed via source and target branches

to all changes: