Merge lp:~openbig/bigconsulting/multi_currency_milestone2 into lp:bigconsulting

Proposed by Atik Agewan(OpenERP)
Status: Merged
Merged at revision: 53
Proposed branch: lp:~openbig/bigconsulting/multi_currency_milestone2
Merge into: lp:bigconsulting
Diff against target: 748 lines (+408/-68)
2 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+353/-58)
account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+55/-10)
To merge this branch: bzr merge lp:~openbig/bigconsulting/multi_currency_milestone2
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+31034@code.launchpad.net

Description of the change

changes in milestone2 multicurrency

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py'
--- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-23 11:30:07 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-27 10:15:58 +0000
@@ -1,7 +1,7 @@
1# -*- encoding: utf-8 -*-1# -*- encoding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# OpenERP, Open Source Management Solution 4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved5# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6# $Id$6# $Id$
7#7#
@@ -63,7 +63,7 @@
6363
64class account_invoice(osv.osv):64class account_invoice(osv.osv):
65 _inherit = "account.invoice"65 _inherit = "account.invoice"
66 66
67 def _get_amount(self, cr, uid, ids, resudial_amonut, payment_term, context=None):67 def _get_amount(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
68 """68 """
69 This function return the Amount to paid according to the payment term cash discount payment term lines69 This function return the Amount to paid according to the payment term cash discount payment term lines
@@ -72,16 +72,16 @@
72 context = {}72 context = {}
73 tax_obj = self.pool.get('account.tax')73 tax_obj = self.pool.get('account.tax')
74 invoice = self.browse(cr, uid, ids[0], context=context)74 invoice = self.browse(cr, uid, ids[0], context=context)
75 75
76 if invoice.date_invoice:76 if invoice.date_invoice:
77 date1 = invoice.date_invoice77 date1 = invoice.date_invoice
78 else:78 else:
79 date1 = time.strftime('%Y-%m-%d')79 date1 = time.strftime('%Y-%m-%d')
80 80
81 if 'date_p' in context and context['date_p']: 81 if 'date_p' in context and context['date_p']:
82 date2 = context['date_p']82 date2 = context['date_p']
83 else:83 else:
84 date2 = time.strftime('%Y-%m-%d') 84 date2 = time.strftime('%Y-%m-%d')
8585
86 if date1 >= date2:86 if date1 >= date2:
87 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))87 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
@@ -91,12 +91,12 @@
91 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))91 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
92 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))92 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
93 diff_day = (from_dt-to_dt)/(3600*24)93 diff_day = (from_dt-to_dt)/(3600*24)
94 94
95 discount = 0.095 discount = 0.0
96 amount = 0.096 amount = 0.0
97 tol_days = 0.097 tol_days = 0.0
98 payment_line_found = False98 payment_line_found = False
99 99
100 if payment_term:100 if payment_term:
101 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)101 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
102 if payment_term_lines.line_ids:102 if payment_term_lines.line_ids:
@@ -115,28 +115,28 @@
115 res = resudial_amonut115 res = resudial_amonut
116 amount = res116 amount = res
117 dis = payment_line.days117 dis = payment_line.days
118 118
119 return {'amount':amount,'tol_days':tol_days,'found':payment_line_found}119 return {'amount':amount,'tol_days':tol_days,'found':payment_line_found}
120 120
121 def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None):121 def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
122 """122 """
123 This function return the Discount according to the payment term cash discount term123 This function return the Discount according to the payment term cash discount term
124 """124 """
125 if context is None:125 if context is None:
126 context = {}126 context = {}
127 127
128 tax_obj = self.pool.get('account.tax')128 tax_obj = self.pool.get('account.tax')
129 invoice = self.browse(cr, uid, ids[0], context=context)129 invoice = self.browse(cr, uid, ids[0], context=context)
130 130
131 if invoice.date_invoice:131 if invoice.date_invoice:
132 date1 = invoice.date_invoice132 date1 = invoice.date_invoice
133 else:133 else:
134 date1 = time.strftime('%Y-%m-%d')134 date1 = time.strftime('%Y-%m-%d')
135 135
136 if 'date_p' in context and context['date_p']: 136 if 'date_p' in context and context['date_p']:
137 date2 = context['date_p']137 date2 = context['date_p']
138 else:138 else:
139 date2 = time.strftime('%Y-%m-%d') 139 date2 = time.strftime('%Y-%m-%d')
140140
141 if date1 >= date2:141 if date1 >= date2:
142 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))142 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
@@ -146,10 +146,10 @@
146 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))146 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
147 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))147 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
148 diff_day = (from_dt-to_dt)/(3600*24)148 diff_day = (from_dt-to_dt)/(3600*24)
149 149
150 tolerance = self._get_amount(cr, uid, ids, resudial_amonut, payment_term, context)150 tolerance = self._get_amount(cr, uid, ids, resudial_amonut, payment_term, context)
151 tolerance_days = tolerance['tol_days']151 tolerance_days = tolerance['tol_days']
152 152
153 discount = 0.0153 discount = 0.0
154 if payment_term:154 if payment_term:
155 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)155 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
@@ -163,29 +163,29 @@
163 discount = res163 discount = res
164 dis = discount_line.delay + tolerance_days164 dis = discount_line.delay + tolerance_days
165 return discount165 return discount
166 166
167 def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None):167 def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
168 """168 """
169 This function return the Account according to the payment term cash discount term169 This function return the Account according to the payment term cash discount term
170 """170 """
171 if context is None:171 if context is None:
172 context = {}172 context = {}
173 173
174 account_id = False174 account_id = False
175 175
176 tax_obj = self.pool.get('account.tax')176 tax_obj = self.pool.get('account.tax')
177 invoice = self.browse(cr, uid, ids[0], context=context)177 invoice = self.browse(cr, uid, ids[0], context=context)
178 178
179 if invoice.date_invoice:179 if invoice.date_invoice:
180 date1 = invoice.date_invoice180 date1 = invoice.date_invoice
181 else: 181 else:
182 date1 = time.strftime('%Y-%m-%d')182 date1 = time.strftime('%Y-%m-%d')
183 183
184 if 'date_p' in context and context['date_p']: 184 if 'date_p' in context and context['date_p']:
185 date2 = context['date_p']185 date2 = context['date_p']
186 else:186 else:
187 date2 = time.strftime('%Y-%m-%d') 187 date2 = time.strftime('%Y-%m-%d')
188 188
189 if date1 > date2:189 if date1 > date2:
190 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))190 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
191 to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))191 to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
@@ -193,11 +193,11 @@
193 else:193 else:
194 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))194 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
195 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))195 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
196 diff_day = (from_dt-to_dt)/(3600*24) 196 diff_day = (from_dt-to_dt)/(3600*24)
197 197
198 tolerance = self._get_amount(cr, uid, ids, resudial_amonut, payment_term, context)198 tolerance = self._get_amount(cr, uid, ids, resudial_amonut, payment_term, context)
199 tolerance_days = tolerance['tol_days']199 tolerance_days = tolerance['tol_days']
200 200
201 if payment_term:201 if payment_term:
202 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)202 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
203 if payment_term_lines.cash_discount_ids:203 if payment_term_lines.cash_discount_ids:
@@ -207,29 +207,29 @@
207 if diff_day >= dis and diff_day <= discount_line.delay + tolerance_days:207 if diff_day >= dis and diff_day <= discount_line.delay + tolerance_days:
208 if invoice.type in ('in_invoice', 'in_refund'):208 if invoice.type in ('in_invoice', 'in_refund'):
209 account_id = discount_line.sup_discount_account_id.id209 account_id = discount_line.sup_discount_account_id.id
210 else: 210 else:
211 account_id = discount_line.discount_account_id.id211 account_id = discount_line.discount_account_id.id
212 dis = discount_line.delay + tolerance_days212 dis = discount_line.delay + tolerance_days
213 return account_id 213 return account_id
214 214
215 def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''):215 def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''):
216 if context is None:216 if context is None:
217 context = {}217 context = {}
218 #TODO check if we can use different period for payment and the writeoff line218 #TODO check if we can use different period for payment and the writeoff line
219 assert len(ids)==1, "Can only pay one invoice at a time"219 assert len(ids)==1, "Can only pay one invoice at a time"
220 invoice = self.browse(cr, uid, ids[0])220 invoice = self.browse(cr, uid, ids[0])
221 221
222 tax_obj = self.pool.get('account.tax')222 tax_obj = self.pool.get('account.tax')
223 invoice_tax_obj = self.pool.get("account.invoice.tax")223 invoice_tax_obj = self.pool.get("account.invoice.tax")
224 move_line_obj = self.pool.get('account.move.line')224 move_line_obj = self.pool.get('account.move.line')
225 move_obj = self.pool.get('account.move')225 move_obj = self.pool.get('account.move')
226 226
227 amount_discount = 0.0 227 amount_discount = 0.0
228 if invoice.payment_term:228 if invoice.payment_term:
229 # Return the discount on for the payment term229 # Return the discount on for the payment term
230 amount_discount = self._get_payment(cr, uid, ids, pay_amount, invoice.payment_term.id, context=context)230 amount_discount = self._get_payment(cr, uid, ids, pay_amount, invoice.payment_term.id, context=context)
231231
232 232
233 src_account_id = invoice.account_id.id233 src_account_id = invoice.account_id.id
234 # Take the seq as name for move234 # Take the seq as name for move
235 types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}235 types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}
@@ -239,7 +239,7 @@
239 date=context['date_p']239 date=context['date_p']
240 else:240 else:
241 date=time.strftime('%Y-%m-%d')241 date=time.strftime('%Y-%m-%d')
242 242
243 # Take the amount in currency and the currency of the payment243 # Take the amount in currency and the currency of the payment
244 if 'amount_currency' in context and context['amount_currency'] and 'currency_id' in context and context['currency_id']:244 if 'amount_currency' in context and context['amount_currency'] and 'currency_id' in context and context['currency_id']:
245 amount_currency = context['amount_currency']245 amount_currency = context['amount_currency']
@@ -247,18 +247,18 @@
247 else:247 else:
248 amount_currency = False248 amount_currency = False
249 currency_id = False249 currency_id = False
250 250
251 if invoice.type in ('in_invoice', 'in_refund'):251 if invoice.type in ('in_invoice', 'in_refund'):
252 ref = invoice.reference252 ref = invoice.reference
253 else:253 else:
254 ref = self._convert_ref(cr, uid, invoice.number)254 ref = self._convert_ref(cr, uid, invoice.number)
255 255
256 discount_amount = 0.0256 discount_amount = 0.0
257 tax_total_amount = 0.0257 tax_total_amount = 0.0
258 258
259 if 'cash_amount' in context and context['cash_amount']:259 if 'cash_amount' in context and context['cash_amount']:
260 discount_amount = context['cash_amount']260 discount_amount = context['cash_amount']
261 261
262 # Pay attention to the sign for both debit/credit AND amount_currency262 # Pay attention to the sign for both debit/credit AND amount_currency
263 l1 = {263 l1 = {
264 'debit': direction * (pay_amount)>0 and direction * (pay_amount),264 'debit': direction * (pay_amount)>0 and direction * (pay_amount),
@@ -270,12 +270,12 @@
270 'currency_id':currency_id,270 'currency_id':currency_id,
271 'amount_currency':amount_currency and direction * amount_currency or 0.0,271 'amount_currency':amount_currency and direction * amount_currency or 0.0,
272 }272 }
273 273
274 ### if we change the amount paid and in the disocunt then it used the changes discount274 ### if we change the amount paid and in the disocunt then it used the changes discount
275 275
276 if amount_discount != discount_amount and discount_amount>0.0:276 if amount_discount != discount_amount and discount_amount>0.0:
277 amount_discount = discount_amount277 amount_discount = discount_amount
278 278
279 l2 = {279 l2 = {
280 'debit': direction * (pay_amount-amount_discount)<0 and - direction * (pay_amount-amount_discount),280 'debit': direction * (pay_amount-amount_discount)<0 and - direction * (pay_amount-amount_discount),
281 'credit': direction * (pay_amount-amount_discount)>0 and direction * (pay_amount-amount_discount),281 'credit': direction * (pay_amount-amount_discount)>0 and direction * (pay_amount-amount_discount),
@@ -289,12 +289,12 @@
289289
290 if not name:290 if not name:
291 name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number291 name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number
292 292
293 l1['name'] = name293 l1['name'] = name
294 l2['name'] = name294 l2['name'] = name
295 lines = [(0, 0, l1), (0, 0, l2)]295 lines = [(0, 0, l1), (0, 0, l2)]
296 296
297 ### When we make payment by pay invoice wizard and if found the taxes move then directly take the entry from the wizard 297 ### When we make payment by pay invoice wizard and if found the taxes move then directly take the entry from the wizard
298 if 'tax_move_ids' in context and context['tax_move_ids']:298 if 'tax_move_ids' in context and context['tax_move_ids']:
299 move_line = context['tax_move_ids']299 move_line = context['tax_move_ids']
300 for move_line_id in move_line:300 for move_line_id in move_line:
@@ -316,7 +316,7 @@
316 move_line_obj.unlink(cr, uid,[move_line_id])316 move_line_obj.unlink(cr, uid,[move_line_id])
317 move_obj.unlink(cr, uid,[move_line_data.move_id.id])317 move_obj.unlink(cr, uid,[move_line_data.move_id.id])
318 else:318 else:
319 if amount_discount>0.0: 319 if amount_discount>0.0:
320 for line in invoice.invoice_line:320 for line in invoice.invoice_line:
321 if line.invoice_line_tax_id:321 if line.invoice_line_tax_id:
322 for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, amount_discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id):322 for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, amount_discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id):
@@ -340,9 +340,9 @@
340 }340 }
341 l3['name'] = name341 l3['name'] = name
342 lines.append((0, 0, l3))342 lines.append((0, 0, l3))
343 343
344 ### When we make payment by pay invoice wizard and if found the discount moves in wizard discount move then directly take the entry from the wizard344 ### When we make payment by pay invoice wizard and if found the discount moves in wizard discount move then directly take the entry from the wizard
345 if 'discount_move_ids' in context and context['discount_move_ids']: 345 if 'discount_move_ids' in context and context['discount_move_ids']:
346 move_line = context['discount_move_ids']346 move_line = context['discount_move_ids']
347 for move_line_id in move_line:347 for move_line_id in move_line:
348 move_line_data = move_line_obj.browse(cr, uid,move_line_id)348 move_line_data = move_line_obj.browse(cr, uid,move_line_id)
@@ -365,7 +365,7 @@
365 else:365 else:
366 if amount_discount>0:366 if amount_discount>0:
367 if 'account_id' in context and context['account_id']:367 if 'account_id' in context and context['account_id']:
368 account_id = context['account_id'] 368 account_id = context['account_id']
369 if tax_total_amount>0:369 if tax_total_amount>0:
370 amount_discount = (amount_discount - tax_total_amount)370 amount_discount = (amount_discount - tax_total_amount)
371 else:371 else:
@@ -382,15 +382,15 @@
382 }382 }
383 l4['name'] = name383 l4['name'] = name
384 lines.append((0, 0, l4))384 lines.append((0, 0, l4))
385 385
386 move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}386 move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}
387 move_id = move_obj.create(cr, uid, move, context=context)387 move_id = move_obj.create(cr, uid, move, context=context)
388 388
389 line_ids = []389 line_ids = []
390 total = 0.0390 total = 0.0
391 line = self.pool.get('account.move.line')391 line = self.pool.get('account.move.line')
392 cr.execute('select id from account_move_line where move_id in ('+str(move_id)+','+str(invoice.move_id.id)+')')392 cr.execute('select id from account_move_line where move_id in ('+str(move_id)+','+str(invoice.move_id.id)+')')
393 393
394 lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )394 lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
395 for l in lines+invoice.payment_ids:395 for l in lines+invoice.payment_ids:
396 if l.account_id.id==src_account_id:396 if l.account_id.id==src_account_id:
@@ -404,28 +404,323 @@
404 # Update the stored value (fields.function), so we write to trigger recompute404 # Update the stored value (fields.function), so we write to trigger recompute
405 self.pool.get('account.invoice').write(cr, uid, ids, {}, context=context)405 self.pool.get('account.invoice').write(cr, uid, ids, {}, context=context)
406 return True406 return True
407 407
408account_invoice()408account_invoice()
409409
410class account_move_line(osv.osv):410class account_move_line(osv.osv):
411 _name = 'account.move.line'411 _name = 'account.move.line'
412 _inherit = 'account.move.line'412 _inherit = 'account.move.line'
413 413
414 def _invoice(self, cr, uid, ids, name, arg, context=None):414 def _invoice(self, cr, uid, ids, name, arg, context=None):
415 res = {}415 res = {}
416 if ids:416 if ids:
417 return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context)417 return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context)
418 else:418 else:
419 return res419 return res
420 420
421 def _invoice_search(self, cr, uid, obj, name, args, context={}):421 def _invoice_search(self, cr, uid, obj, name, args, context={}):
422 return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context)422 return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context)
423 423
424 _columns = {424 _columns = {
425 'invoice': fields.function(_invoice, method=True, string='Invoice',425 'invoice': fields.function(_invoice, method=True, string='Invoice',
426 type='many2one', relation='account.invoice', fnct_search=_invoice_search),426 type='many2one', relation='account.invoice', fnct_search=_invoice_search),
427 }427 }
428account_move_line()428account_move_line()
429429
430class res_company(osv.osv):
431 _inherit = "res.company"
432
433 _columns = {
434 'expense_account_id': fields.many2one('account.account', 'Expenses',required=True),
435 'revenue_account_id': fields.many2one('account.account', 'Revenues',required=True),
436 }
437res_company()
438
439class res_company_wizard(osv.osv_memory):
440 _name = 'res.company.wizard'
441 _columns = {
442 'expense_account_id': fields.many2one('account.account', 'Expenses',required=True),
443 'revenue_account_id': fields.many2one('account.account', 'Revenues',required=True),
444 }
445 _defaults = {
446 'expense_account_id': lambda *a: 2,
447 'revenue_account_id': lambda *a: 3,
448 }
449
450 def set_default(self, cr, uid, ids, context=None):
451 company_id =self.pool.get('res.users').browse(cr,uid,[uid],context)[0].company_id
452 for o in self.browse(cr, uid, ids, context=context):
453 self.pool.get('res.company').write(cr, uid, [company_id.id], {'expense_account_id':o.expense_account_id.id,'revenue_account_id':o.revenue_account_id.id})
454 return {
455 'view_type': 'form',
456 "view_mode": 'form',
457 'res_model': 'ir.actions.configuration.wizard',
458 'type': 'ir.actions.act_window',
459 'target': 'new',
460 }
461
462 def action_cancel(self,cr,uid,ids,conect=None):
463 return {
464 'view_type': 'form',
465 "view_mode": 'form',
466 'res_model': 'ir.actions.configuration.wizard',
467 'type': 'ir.actions.act_window',
468 'target':'new',
469 }
470
471res_company_wizard()
472
473class account_bank_statement(osv.osv):
474 _inherit="account.bank.statement"
475
476 def button_confirm(self, cr, uid, ids, context={}):
477 done = []
478 res_currency_obj = self.pool.get('res.currency')
479 res_users_obj = self.pool.get('res.users')
480 account_move_obj = self.pool.get('account.move')
481 account_move_line_obj = self.pool.get('account.move.line')
482 cur_obj = self.pool.get('res.currency')
483 account_bank_statement_line_obj = \
484 self.pool.get('account.bank.statement.line')
485 account_bank_reconcil = self.pool.get('account.bank.statement.reconcile')
486 company_currency_id = res_users_obj.browse(cr, uid, uid,
487 context=context).company_id.currency_id.id
488 for st in self.browse(cr, uid, ids, context):
489 if not st.state=='draft':
490 continue
491 if not (abs(st.balance_end - st.balance_end_real) < 0.0001):
492 raise osv.except_osv(_('Error !'),
493 _('The statement balance is incorrect !\n') +
494 _('The expected balance (%.2f) is different than the computed one. (%.2f)') % (st.balance_end_real, st.balance_end))
495 if (not st.journal_id.default_credit_account_id) \
496 or (not st.journal_id.default_debit_account_id):
497 raise osv.except_osv(_('Configuration Error !'),
498 _('Please verify that an account is defined in the journal.'))
499
500 for line in st.move_line_ids:
501 if line.state <> 'valid':
502 raise osv.except_osv(_('Error !'),
503 _('The account entries lines are not in valid state.'))
504 # for bank.statement.lines
505 # In line we get reconcile_id on bank.ste.rec.
506 # in bank stat.rec we get line_new_ids on bank.stat.rec.line
507 for move in st.line_ids:
508 context.update({'date':move.date})
509 move_id = account_move_obj.create(cr, uid, {
510 'journal_id': st.journal_id.id,
511 'period_id': st.period_id.id,
512 'date': move.date,
513 }, context=context)
514 account_bank_statement_line_obj.write(cr, uid, [move.id], {
515 'move_ids': [(4,move_id, False)]
516 })
517 if not move.amount:
518 continue
519 torec = []
520 if move.amount >= 0:
521 account_id = st.journal_id.default_credit_account_id.id
522 else:
523 account_id = st.journal_id.default_debit_account_id.id
524 acc_cur = ((move.amount<=0) and st.journal_id.default_debit_account_id) or move.account_id
525 amount = res_currency_obj.compute(cr, uid, st.currency.id,
526 company_currency_id, move.amount, context=context,
527 account=acc_cur)
528 if move.reconcile_id and move.reconcile_id.line_new_ids:
529 for newline in move.reconcile_id.line_new_ids:
530 amount += newline.amount
531
532 val = {
533 'name': move.name,
534 'date': move.date,
535 'ref': move.ref,
536 'move_id': move_id,
537 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
538 'account_id': (move.account_id) and move.account_id.id,
539 'credit': ((amount>0) and amount) or 0.0,
540 'debit': ((amount<0) and -amount) or 0.0,
541 'statement_id': st.id,
542 'journal_id': st.journal_id.id,
543 'period_id': st.period_id.id,
544 'currency_id': st.currency.id,
545 }
546
547 amount = res_currency_obj.compute(cr, uid, st.currency.id,
548 company_currency_id, move.amount, context=context,
549 account=acc_cur)
550 if st.currency.id <> company_currency_id:
551 amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
552 st.currency.id, amount, context=context,
553 account=acc_cur)
554 val['amount_currency'] = -amount_cur
555
556 if move.account_id and move.account_id.currency_id and move.account_id.currency_id.id <> company_currency_id:
557 val['currency_id'] = move.account_id.currency_id.id
558 if company_currency_id==move.account_id.currency_id.id:
559 amount_cur = move.amount
560 else:
561 amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
562 move.account_id.currency_id.id, amount, context=context,
563 account=acc_cur)
564 val['amount_currency'] = amount_cur
565
566 torec.append(account_move_line_obj.create(cr, uid, val , context=context))
567
568 if move.reconcile_id and move.reconcile_id.line_new_ids:
569 for newline in move.reconcile_id.line_new_ids:
570 account_move_line_obj.create(cr, uid, {
571 'name': newline.name or move.name,
572 'date': move.date,
573 'ref': move.ref,
574 'move_id': move_id,
575 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
576 'account_id': (newline.account_id) and newline.account_id.id,
577 'debit': newline.amount>0 and newline.amount or 0.0,
578 'credit': newline.amount<0 and -newline.amount or 0.0,
579 'statement_id': st.id,
580 'journal_id': st.journal_id.id,
581 'period_id': st.period_id.id,
582
583 }, context=context)
584
585 amount_currency = False
586 currency_id = False
587 partner_acc_id = False
588
589 if st.currency.id <> company_currency_id:
590 amount_currency = move.amount
591 expense_acc = res_users_obj.browse(cr, uid, uid, context=context).company_id.expense_account_id
592 revene_acc = res_users_obj.browse(cr, uid, uid, context=context).company_id.revenue_account_id
593 currency_id = st.currency.id
594
595 if move.type=='customer':
596 partner_acc_id = move.partner_id.property_account_receivable.id
597 elif move.type=='supplier':
598 partner_acc_id = move.partner_id.property_account_payable.id
599
600 for line in move.reconcile_id.line_ids:
601 balance = 0.0
602 move_line_data = self.pool.get('account.move.line').browse(cr, uid, line.id, context=context)
603 context.update({'amount': move_line_data.amount_currency, 'currency_id': move_line_data.currency_id.id})
604 balance = self.pool.get("account.bank.statement.reconcile").browse(cr, uid, move.reconcile_id.id, context=context).total_balance
605
606 if balance < 0.00:
607 account_move_line_obj.create(cr, uid, {
608 'name': move.name,
609 'date': move.date,
610 'ref': move.ref,
611 'move_id': move_id,
612 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
613 'account_id': expense_acc.id,
614 'credit': abs(balance),
615 'debit': 0.0,
616 'statement_id': st.id,
617 'journal_id': st.journal_id.id,
618 'period_id': st.period_id.id,
619 'amount_currency': amount_currency,
620 'currency_id': currency_id,
621 }, context=context)
622
623 account_move_line_obj.create(cr, uid, {
624 'name': move.name,
625 'date': move.date,
626 'ref': move.ref,
627 'move_id': move_id,
628 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
629 'account_id': partner_acc_id,
630 'credit': 0.0,
631 'debit': abs(balance),
632 'statement_id': st.id,
633 'journal_id': st.journal_id.id,
634 'period_id': st.period_id.id,
635 'amount_currency': amount_currency,
636 'currency_id': currency_id,
637 }, context=context)
638
639 elif balance > 0.00:
640 account_move_line_obj.create(cr, uid, {
641 'name': move.name,
642 'date': move.date,
643 'ref': move.ref,
644 'move_id': move_id,
645 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
646 'account_id':revene_acc.id,
647 'credit': abs(balance),
648 'debit': 0.0,
649 'statement_id': st.id,
650 'journal_id': st.journal_id.id,
651 'period_id': st.period_id.id,
652 'amount_currency': amount_currency,
653 'currency_id': currency_id,
654 }, context=context)
655
656 account_move_line_obj.create(cr, uid, {
657 'name': move.name,
658 'date': move.date,
659 'ref': move.ref,
660 'move_id': move_id,
661 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
662 'account_id': partner_acc_id,
663 'credit': 0.0,
664 'debit': abs(balance),
665 'statement_id': st.id,
666 'journal_id': st.journal_id.id,
667 'period_id': st.period_id.id,
668 'amount_currency': amount_currency,
669 'currency_id': currency_id,
670 }, context=context)
671 else:
672 continue
673
674 account_move_line_obj.create(cr, uid, {
675 'name': move.name,
676 'date': move.date,
677 'ref': move.ref,
678 'move_id': move_id,
679 'partner_id': ((move.partner_id) and move.partner_id.id) or False,
680 'account_id': account_id,
681 'credit': ((amount < 0) and -amount) or 0.0,
682 'debit': ((amount > 0) and amount) or 0.0,
683 'statement_id': st.id,
684 'journal_id': st.journal_id.id,
685 'period_id': st.period_id.id,
686 'amount_currency': amount_currency,
687 'currency_id': currency_id,
688 }, context=context)
689
690 for line in account_move_line_obj.browse(cr, uid, [x.id for x in
691 account_move_obj.browse(cr, uid, move_id,
692 context=context).line_id],
693 context=context):
694 if line.state <> 'valid':
695 raise osv.except_osv(_('Error !'),
696 _('Account move line "%s" is not valid') % line.name)
697
698 if move.reconcile_id and move.reconcile_id.line_ids:
699 torec += map(lambda x: x.id, move.reconcile_id.line_ids)
700 #try:
701 if abs(move.reconcile_amount-move.amount)<0.0001:
702
703 writeoff_acc_id = False
704 #There should only be one write-off account!
705 for entry in move.reconcile_id.line_new_ids:
706 writeoff_acc_id = entry.account_id.id
707 break
708
709 account_move_line_obj.reconcile(cr, uid, torec, 'statement', writeoff_acc_id=writeoff_acc_id, writeoff_period_id=st.period_id.id, writeoff_journal_id=st.journal_id.id, context=context)
710 else:
711 account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context)
712 #except:
713 # raise osv.except_osv(_('Error !'), _('Unable to reconcile entry "%s": %.2f') % (move.name, move.amount))
714
715 if st.journal_id.entry_posted:
716 account_move_obj.write(cr, uid, [move_id], {'state':'posted'})
717 done.append(st.id)
718 self.write(cr, uid, done, {'state':'confirm'}, context=context)
719
720 return True
721
722account_bank_statement()
723
724
430# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:725# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
431726
432727
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml'
--- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-08-23 12:13:39 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-27 10:15:58 +0000
@@ -47,7 +47,7 @@
47 </field>47 </field>
48 </field>48 </field>
49 </record>49 </record>
50 50
51 <record id="bank_statement_form_view1" model="ir.ui.view">51 <record id="bank_statement_form_view1" model="ir.ui.view">
52 <field name="name">account.bank.statement.form</field>52 <field name="name">account.bank.statement.form</field>
53 <field name="model">account.bank.statement</field>53 <field name="model">account.bank.statement</field>
@@ -56,10 +56,10 @@
56 <field name="arch" type="xml">56 <field name="arch" type="xml">
57 <xpath expr="//button[@string='Import Invoice']" position="replace">57 <xpath expr="//button[@string='Import Invoice']" position="replace">
58 <button name="%(wizard_populate_statement_from_inv1)d" type="action" string="Import Invoice" attrs="{'invisible':[('state','=','confirm')]}"/>58 <button name="%(wizard_populate_statement_from_inv1)d" type="action" string="Import Invoice" attrs="{'invisible':[('state','=','confirm')]}"/>
59 </xpath> 59 </xpath>
60 </field>60 </field>
61 </record>61 </record>
62 62
63 <record id="bank_statement_reconcile_form_view1" model="ir.ui.view">63 <record id="bank_statement_reconcile_form_view1" model="ir.ui.view">
64 <field name="name">account.bank.statement.reconcile.form</field>64 <field name="name">account.bank.statement.reconcile.form</field>
65 <field name="model">account.bank.statement.reconcile</field>65 <field name="model">account.bank.statement.reconcile</field>
@@ -68,10 +68,10 @@
68 <field name="arch" type="xml">68 <field name="arch" type="xml">
69 <field name="total_new" position="replace">69 <field name="total_new" position="replace">
70 <field name="total_new" string="Total Write Off / Cash Discount"/>70 <field name="total_new" string="Total Write Off / Cash Discount"/>
71 </field> 71 </field>
72 </field>72 </field>
73 </record>73 </record>
74 74
75 <record id="bank_statement_reconcile_form_view2" model="ir.ui.view">75 <record id="bank_statement_reconcile_form_view2" model="ir.ui.view">
76 <field name="name">account.bank.statement.reconcile.form</field>76 <field name="name">account.bank.statement.reconcile.form</field>
77 <field name="model">account.bank.statement.reconcile</field>77 <field name="model">account.bank.statement.reconcile</field>
@@ -84,10 +84,10 @@
84 <field name="amount"/>84 <field name="amount"/>
85 <field name="name"/>85 <field name="name"/>
86 </tree>86 </tree>
87 </xpath> 87 </xpath>
88 </field>88 </field>
89 </record>89 </record>
90 90
91 <record id="account_payment_term_line_view1" model="ir.ui.view">91 <record id="account_payment_term_line_view1" model="ir.ui.view">
92 <field name="name">account.payment.term.line.form</field>92 <field name="name">account.payment.term.line.form</field>
93 <field name="model">account.payment.term.line</field>93 <field name="model">account.payment.term.line</field>
@@ -97,9 +97,54 @@
97 <field name="days2" position="after">97 <field name="days2" position="after">
98 <field name="compl_cash_discount"/>98 <field name="compl_cash_discount"/>
99 <field name="day_tolerance"/>99 <field name="day_tolerance"/>
100 </field> 100 </field>
101 </field>101 </field>
102 </record>102 </record>
103
104 <record id="view_res_company_inherit_form" model="ir.ui.view">
105 <field name="name">res.company.inherit.form</field>
106 <field name="model">res.company</field>
107 <field name="type">form</field>
108 <field name="inherit_id" ref="base.view_company_form"/>
109 <field name="arch" type="xml">
110 <field name="currency_id" position="after">
111 <field name="expense_account_id"/>
112 <field name="revenue_account_id"/>
113 </field>
114 </field>
115 </record>
116
117 <record id="view_res_company_wizard" model="ir.ui.view">
118 <field name="name">Account set in Company</field>
119 <field name="model">res.company.wizard</field>
120 <field name="type">form</field>
121 <field name="arch" type="xml">
122 <form string="Account Configuration">
123 <field name="expense_account_id"/>
124 <field name="revenue_account_id"/>
125 <newline/>
126 <group col="4" colspan="4">
127 <button icon="gtk-cancel" name="action_cancel" type="object" special="cancel" string="Cancel"/>
128 <button icon="gtk-ok" name="set_default" string="Set Default" type="object"/>
129 </group>
130 </form>
131 </field>
132 </record>
133
134 <record id="action_res_company_wizard" model="ir.actions.act_window">
135 <field name="name">Account set in Company</field>
136 <field name="type">ir.actions.act_window</field>
137 <field name="res_model">res.company.wizard</field>
138 <field name="view_type">form</field>
139 <field name="view_mode">form</field>
140 <field name="target">new</field>
141 </record>
142
143 <record id="config_wizard_res_company_wizard" model="ir.actions.todo">
144 <field name="name">Account set in Company</field>
145 <field name="note">This Configuration step use to set default Account</field>
146 <field name="action_id" ref="action_res_company_wizard"/>
147 </record>
103148
104 </data>149 </data>
105</openerp>150</openerp>

Subscribers

People subscribed via source and target branches