Merge lp:~openbig/bigconsulting/improvement_changes_milestone1 into lp:bigconsulting
- improvement_changes_milestone1
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Merged |
---|---|
Merged at revision: | 44 |
Proposed branch: | lp:~openbig/bigconsulting/improvement_changes_milestone1 |
Merge into: | lp:bigconsulting |
Diff against target: |
615 lines (+271/-80) 4 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+82/-10) account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+17/-0) account_invoice_cash_discount/wizard/account_pay_invoice.py (+158/-69) account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+14/-1) |
To merge this branch: | bzr merge lp:~openbig/bigconsulting/improvement_changes_milestone1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+29287@code.launchpad.net |
This proposal supersedes a proposal from 2010-07-06.
Commit message
Description of the change
added new changes in milestone1
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
1 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py' |
2 | --- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-01 14:49:31 +0000 |
3 | +++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-06 13:38:28 +0000 |
4 | @@ -44,17 +44,88 @@ |
5 | 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'), |
6 | 'credit_account_id': fields.many2one('account.account', 'Credit Account'), |
7 | 'debit_account_id': fields.many2one('account.account', 'Debit Account'), |
8 | + 'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'), |
9 | } |
10 | account_cash_discount() |
11 | |
12 | +class account_payment_term_line(osv.osv): |
13 | + _inherit = "account.payment.term.line" |
14 | + _columns = { |
15 | + 'cash_account_discount_id': fields.many2one('account.cash.discount', 'Discount Lines',), |
16 | + 'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=False, select=True), |
17 | + 'compl_cash_discount':fields.boolean('Use Complete Cash Discount'), |
18 | + } |
19 | +account_payment_term_line() |
20 | + |
21 | class account_invoice(osv.osv): |
22 | _inherit = "account.invoice" |
23 | |
24 | + def _get_amount(self, cr, uid, ids, resudial_amonut, payment_term, context=None): |
25 | + |
26 | + """ |
27 | + This function return the Amount to paid according to the payment term cash discount payment term lines |
28 | + """ |
29 | + |
30 | + if context is None: |
31 | + context = {} |
32 | + |
33 | + tax_obj = self.pool.get('account.tax') |
34 | + invoice = self.browse(cr, uid, ids[0], context=context) |
35 | + |
36 | + if invoice.date_invoice: |
37 | + date1 = invoice.date_invoice |
38 | + else: |
39 | + date1 = time.strftime('%Y-%m-%d') |
40 | + |
41 | + if 'date_p' in context and context['date_p']: |
42 | + date2 = context['date_p'] |
43 | + else: |
44 | + date2 = time.strftime('%Y-%m-%d') |
45 | + |
46 | + if date1 >= date2: |
47 | + from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d')) |
48 | + to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d')) |
49 | + diff_day = (from_dt-to_dt)/(3600*24) |
50 | + else: |
51 | + from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d')) |
52 | + to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d')) |
53 | + diff_day = (from_dt-to_dt)/(3600*24) |
54 | + |
55 | + discount = 0.0 |
56 | + amount = 0.0 |
57 | + payment_line_found = False |
58 | + if payment_term: |
59 | + payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context) |
60 | + for payment_term_line_id in payment_term_lines.line_ids: |
61 | + payment_use_complete = payment_term_line_id.compl_cash_discount |
62 | + if payment_use_complete: |
63 | + if payment_term_lines.cash_discount_ids: |
64 | + dis = 0 |
65 | + for discount_line in payment_term_lines.cash_discount_ids: |
66 | + if diff_day >= dis and diff_day <= discount_line.delay: |
67 | + if resudial_amonut: |
68 | + dis1 = 0 |
69 | + if discount_line.payment_term_ids: |
70 | + payment_line_found = True |
71 | + for dis_payment_id in discount_line.payment_term_ids: |
72 | + if diff_day >= dis1 and diff_day<= dis_payment_id.days: |
73 | + if dis_payment_id.value == 'procent': |
74 | + amount = resudial_amonut * dis_payment_id.value_amount |
75 | + elif dis_payment_id.value == 'fixed': |
76 | + amount = dis_payment_id.value_amount |
77 | + else: |
78 | + amount = resudial_amonut |
79 | + dis1 = dis_payment_id.days |
80 | + dis = discount_line.delay |
81 | + else: |
82 | + amount = resudial_amonut |
83 | + |
84 | + return {'amount':amount,'found':payment_line_found} |
85 | + |
86 | def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None): |
87 | """ |
88 | This function return the Discount according to the payment term cash discount term |
89 | """ |
90 | - |
91 | if context is None: |
92 | context = {} |
93 | |
94 | @@ -79,6 +150,7 @@ |
95 | from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d')) |
96 | to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d')) |
97 | diff_day = (from_dt-to_dt)/(3600*24) |
98 | + |
99 | discount = 0.0 |
100 | if payment_term: |
101 | payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context) |
102 | @@ -92,7 +164,7 @@ |
103 | discount = res |
104 | dis = discount_line.delay |
105 | return discount |
106 | - |
107 | + |
108 | def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None): |
109 | """ |
110 | This function return the Account according to the payment term cash discount term |
111 | @@ -136,6 +208,7 @@ |
112 | return account_id |
113 | |
114 | 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=''): |
115 | + |
116 | if context is None: |
117 | context = {} |
118 | #TODO check if we can use different period for payment and the writeoff line |
119 | @@ -222,7 +295,7 @@ |
120 | if 'tax_move_ids' in context and context['tax_move_ids']: |
121 | move_line = context['tax_move_ids'] |
122 | for move_line_id in move_line: |
123 | - move_line_data = self.pool.get('account.move.line').browse(cr, uid,move_line_id) |
124 | + move_line_data = move_line_obj.browse(cr, uid,move_line_id) |
125 | l3 = { |
126 | 'debit': move_line_data.debit, |
127 | 'credit': move_line_data.credit, |
128 | @@ -237,8 +310,8 @@ |
129 | 'tax_amount':move_line_data.tax_amount, |
130 | } |
131 | lines.append((0, 0, l3)) |
132 | - self.pool.get('account.move.line').unlink(cr, uid,[move_line_id]) |
133 | - self.pool.get('account.move').unlink(cr, uid,[move_line_data.move_id.id]) |
134 | + move_line_obj.unlink(cr, uid,[move_line_id]) |
135 | + move_obj.unlink(cr, uid,[move_line_data.move_id.id]) |
136 | else: |
137 | if amount_discount>0.0: |
138 | for line in invoice.invoice_line: |
139 | @@ -267,8 +340,8 @@ |
140 | |
141 | if 'discount_move_ids' in context and context['discount_move_ids']: |
142 | dis_move_id = context['discount_move_ids'][0] |
143 | - move_id = self.pool.get('account.move.line').search(cr, uid,[('move_id','=',dis_move_id)]) |
144 | - move_line_data = self.pool.get('account.move.line').browse(cr, uid, move_id[0]) |
145 | + move_id = move_line_obj.search(cr, uid,[('move_id','=',dis_move_id)]) |
146 | + move_line_data = move_line_obj.browse(cr, uid, move_id[0]) |
147 | l4 = { |
148 | 'debit': move_line_data.debit, |
149 | 'credit':move_line_data.credit, |
150 | @@ -282,7 +355,7 @@ |
151 | } |
152 | lines.append((0, 0, l4)) |
153 | |
154 | - self.pool.get('account.move').unlink(cr, uid, context['discount_move_ids']) |
155 | + move_obj.unlink(cr, uid, context['discount_move_ids']) |
156 | else: |
157 | if amount_discount>0: |
158 | if 'account_id' in context and context['account_id']: |
159 | @@ -305,7 +378,7 @@ |
160 | lines.append((0, 0, l4)) |
161 | |
162 | move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date} |
163 | - move_id = self.pool.get('account.move').create(cr, uid, move, context=context) |
164 | + move_id = move_obj.create(cr, uid, move, context=context) |
165 | |
166 | line_ids = [] |
167 | total = 0.0 |
168 | @@ -317,7 +390,6 @@ |
169 | if l.account_id.id==src_account_id: |
170 | line_ids.append(l.id) |
171 | total += (l.debit or 0.0) - (l.credit or 0.0) |
172 | - |
173 | if (not round(total,int(config['price_accuracy']))) or writeoff_acc_id: |
174 | self.pool.get('account.move.line').reconcile(cr, uid, line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context) |
175 | else: |
176 | |
177 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml' |
178 | --- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-06-29 13:22:59 +0000 |
179 | +++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-06 13:38:28 +0000 |
180 | @@ -15,6 +15,10 @@ |
181 | <field name="delay" select="1"/> |
182 | <field name="discount" select="1"/> |
183 | <field name="discount_account_id" /> |
184 | + <group colspan="4"> |
185 | + <separator string="Related Payment Terms Lines" colspan="4"/> |
186 | + <field name="payment_term_ids" widget="one2many_list" nolabel="1"/> |
187 | + </group> |
188 | </form> |
189 | </field> |
190 | </record> |
191 | @@ -84,6 +88,19 @@ |
192 | </xpath> |
193 | </field> |
194 | </record> |
195 | + |
196 | + <record id="account_payment_term_line_view1" model="ir.ui.view"> |
197 | + <field name="name">account.payment.term.line.form</field> |
198 | + <field name="model">account.payment.term.line</field> |
199 | + <field name="type">form</field> |
200 | + <field name="inherit_id" ref="account.view_payment_term_line_form"/> |
201 | + <field name="arch" type="xml"> |
202 | + <field name="days2" position="after"> |
203 | + <label string="" colspan="2"/> |
204 | + <field name="compl_cash_discount"/> |
205 | + </field> |
206 | + </field> |
207 | + </record> |
208 | |
209 | </data> |
210 | </openerp> |
211 | |
212 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py' |
213 | --- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-01 14:49:31 +0000 |
214 | +++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-06 13:38:28 +0000 |
215 | @@ -22,7 +22,6 @@ |
216 | from lxml import etree |
217 | from osv import fields, osv |
218 | from tools.translate import _ |
219 | -#import decimal_precision as dp |
220 | |
221 | class account_invoice_pay_writeoff(osv.osv_memory): |
222 | """ |
223 | @@ -41,6 +40,7 @@ |
224 | } |
225 | |
226 | def pay_and_reconcile_writeoff(self, cr, uid, ids, context=None): |
227 | + pay_invoice = self.pool.get('account.invoice.pay') |
228 | data = self.read(cr, uid, ids,context=context)[0] |
229 | context.update({'write_off':data}) |
230 | self.pool.get('account.invoice.pay').pay_and_reconcile(cr, uid, ids, context=context) |
231 | @@ -58,7 +58,7 @@ |
232 | 'amount': fields.float('Amount paid', required=True), |
233 | 'name': fields.char('Entry Name', size=64, required=True), |
234 | 'date': fields.date('Date payment', required=True), |
235 | - 'cash_residual_amount': fields.float('Residual Amount', readonly=True), |
236 | + 'cash_residual_amount': fields.float('Residual Amount'), |
237 | 'journal_id': fields.many2one('account.journal', 'Journal/Payment Mode', required=True), |
238 | 'period_id': fields.many2one('account.period', 'Period', required=True), |
239 | 'cash_amount':fields.float('Cash Discount Amount',), |
240 | @@ -69,7 +69,7 @@ |
241 | 'discount_move_ids': fields.many2many('account.move', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'), |
242 | 'tax_move_ids': fields.many2many('account.move.line', 'account_tax_move_rel', 'tax_account_id', 'tax_move_id', 'Account Taxes Moves'), |
243 | } |
244 | - |
245 | + |
246 | def _get_period(self, cr, uid, context=None): |
247 | ids = self.pool.get('account.period').find(cr, uid, context=context) |
248 | period_id = False |
249 | @@ -80,34 +80,19 @@ |
250 | def _get_amount(self, cr, uid, context=None): |
251 | obj_inv = self.pool.get('account.invoice') |
252 | invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
253 | - discount = obj_inv._get_payment(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
254 | - residual_amount = invoice.residual - discount |
255 | + amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
256 | + context.update({'found':amount['found']}) |
257 | + amount = amount['amount'] |
258 | + discount = obj_inv._get_payment(cr, uid, [context['id']] ,amount, invoice.payment_term.id, context=context) |
259 | + residual_amount = amount - discount |
260 | return residual_amount |
261 | |
262 | - def on_change_ammount(self, cr, uid, ids, amount, context=None): |
263 | - """ |
264 | - Function return the Discount according to the Amount paid and Payment Term Cash Discount |
265 | - """ |
266 | - res = {} |
267 | - obj_inv = self.pool.get('account.invoice') |
268 | - invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
269 | - discount = obj_inv._get_payment(cr, uid, [context['id']] , invoice.residual, invoice.payment_term.id, context=context) |
270 | - diff_amount = round(invoice.residual - (amount + discount),2) |
271 | - return {'value' : {'cash_residual_amount':diff_amount}} |
272 | - |
273 | - def on_change_cash_discount_amount(self, cr, uid, ids, discount_amount, amount, context=None): |
274 | - ### Return discount amount |
275 | - res = {} |
276 | - obj_inv = self.pool.get('account.invoice') |
277 | - invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
278 | - diff_amount = 0.0 |
279 | - diff_amount = round(invoice.residual - (amount + discount_amount),2) |
280 | - return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}} |
281 | - |
282 | def _get_discount(self, cr, uid, context=None): |
283 | obj_inv = self.pool.get('account.invoice') |
284 | invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
285 | - discount = obj_inv._get_payment(cr, uid, [context['id']] , invoice.residual, invoice.payment_term.id, context=context) |
286 | + amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
287 | + amount = amount['amount'] |
288 | + discount = obj_inv._get_payment(cr, uid, [context['id']] , amount, invoice.payment_term.id, context=context) |
289 | return discount |
290 | |
291 | def _get_account(self, cr, uid, context=None): |
292 | @@ -122,13 +107,47 @@ |
293 | account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account) |
294 | return account |
295 | |
296 | - def default_get(self, cr, uid, fields, context=None): |
297 | - res = super(account_invoice_pay, self).default_get(cr, uid, fields, context=context) |
298 | - invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) |
299 | - if invoice.state in ['draft', 'proforma2', 'cancel']: |
300 | - raise osv.except_osv(_('Error !'), _('Can not pay draft/proforma/cancel invoice.')) |
301 | - return res |
302 | - |
303 | + _defaults = { |
304 | + 'date': lambda *a: time.strftime('%Y-%m-%d'), |
305 | + 'period_id': _get_period, |
306 | + 'amount': _get_amount, |
307 | + 'cash_amount':_get_discount, |
308 | + 'account_id':_get_account, |
309 | + 'cash_residual_amount': lambda *a:0.0, |
310 | + 'cal_method_selection':lambda *a :'method_gross_methodology', |
311 | + } |
312 | + |
313 | + def on_change_ammount(self, cr, uid, ids, amount, context=None): |
314 | + """ |
315 | + Function return the Discount according to the Amount paid and Payment Term Cash Discount |
316 | + """ |
317 | + res = {} |
318 | + obj_inv = self.pool.get('account.invoice') |
319 | + invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
320 | + cal_amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
321 | + |
322 | + old_cal_amount = cal_amount['amount'] |
323 | + discount = obj_inv._get_payment(cr, uid, [context['id']] , old_cal_amount, invoice.payment_term.id, context=context) |
324 | + old_amount = old_cal_amount |
325 | + diff_amount = round(old_amount - (amount + discount),2) |
326 | + |
327 | + return {'value' : {'cash_residual_amount':diff_amount}} |
328 | + |
329 | + def on_change_cash_discount_amount(self, cr, uid, ids, discount_amount, amount, context=None): |
330 | + ### Return discount amount |
331 | + res = {} |
332 | + obj_inv = self.pool.get('account.invoice') |
333 | + invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
334 | + cal_amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
335 | + old_cal_amount = cal_amount['amount'] |
336 | + discount = obj_inv._get_payment(cr, uid, [context['id']] , amount, invoice.payment_term.id, context=context) |
337 | + old_amount = old_cal_amount |
338 | + |
339 | + diff_amount = 0.0 |
340 | + diff_amount = old_amount - (amount + discount_amount) |
341 | + |
342 | + return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}} |
343 | + |
344 | def _calculation(self, cr, uid, ids, context=None): |
345 | invoice_obj = self.pool.get('account.invoice') |
346 | data = self.read(cr, uid, ids,context=context)[0] |
347 | @@ -137,7 +156,19 @@ |
348 | invoice_tax_obj = self.pool.get("account.invoice.tax") |
349 | move_obj = self.pool.get('account.move') |
350 | move_line_obj = self.pool.get('account.move.line') |
351 | - |
352 | + |
353 | + ############## Delete another lines of taxes and discount |
354 | + if data['tax_move_ids']: |
355 | + move_line = data['tax_move_ids'] |
356 | + for move_line_id in move_line: |
357 | + move_id = move_line_data = move_line_obj.browse(cr, uid,move_line_id).move_id.id |
358 | + move_line_obj.unlink(cr, uid,[move_line_id]) |
359 | + move_obj.unlink(cr, uid,[move_id]) |
360 | + |
361 | + if data['discount_move_ids']: |
362 | + dis_move_id = data['discount_move_ids'][0] |
363 | + move_obj.unlink(cr, uid, data['discount_move_ids']) |
364 | + |
365 | ######## to get ref |
366 | if invoice.type in ('in_invoice', 'in_refund'): |
367 | ref = invoice.reference |
368 | @@ -153,7 +184,6 @@ |
369 | name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number |
370 | |
371 | ##### Entry in the discount account moves and entry in the tax account moves |
372 | - |
373 | ### Entry for taxes in the line of wizard tax |
374 | if data.get('cash_amount',0.0)>0.0: |
375 | lines3 = [] |
376 | @@ -202,7 +232,7 @@ |
377 | discount_account_id = self.pool.get('account.journal').browse(cr, uid, journal_id).default_credit_account_id.id |
378 | else: |
379 | discount_account_id = data['account_id'] |
380 | - ###############################################3 |
381 | + ############################################### |
382 | |
383 | l4 = { |
384 | 'debit': direction * data.get('cash_amount',0.0)<0 and - direction * data.get('cash_amount',0.0), |
385 | @@ -218,27 +248,57 @@ |
386 | move = {'ref': ref, 'line_id': lines4, 'journal_id': data['journal_id'], 'period_id': data['period_id'], } |
387 | move_id = move_obj.create(cr, uid, move, context=context) |
388 | self.write(cr, uid, ids, {'discount_move_ids':[(6,0,[move_id])]}, context) |
389 | + |
390 | return True |
391 | |
392 | - _defaults = { |
393 | - 'date': lambda *a: time.strftime('%Y-%m-%d'), |
394 | - 'period_id': _get_period, |
395 | - 'amount': _get_amount, |
396 | - 'cash_amount':_get_discount, |
397 | - 'account_id':_get_account, |
398 | - 'cash_residual_amount': lambda *a:0.0, |
399 | - 'cal_method_selection':lambda *a :'method_gross_methodology', |
400 | - } |
401 | + def default_get(self, cr, uid, fields, context=None): |
402 | + res = super(account_invoice_pay, self).default_get(cr, uid, fields, context=context) |
403 | + invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) |
404 | + if invoice.state in ['draft', 'proforma2', 'cancel','paid']: |
405 | + raise osv.except_osv(_('Error !'), _('Can not pay draft/proforma/cancel/Done invoice.')) |
406 | + return res |
407 | + |
408 | + def _message(self, cr, uid, ids, context=None): |
409 | + mod_obj = self.pool.get('ir.model.data') |
410 | + data = self.read(cr, uid, ids,context=context)[0] |
411 | |
412 | + if data['discount_move_ids']: |
413 | + context.update({'discount_move_ids':data['discount_move_ids']}) |
414 | + |
415 | + if data['tax_move_ids']: |
416 | + context.update({'tax_move_ids':data['tax_move_ids']}) |
417 | + |
418 | + if data['amount']: |
419 | + context.update({'amount':data['amount']}) |
420 | + |
421 | + if data['cash_amount']: |
422 | + context.update({'cash_amount':data['cash_amount']}) |
423 | + |
424 | + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_message')], context=context) |
425 | + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
426 | + |
427 | + return { |
428 | + 'name': _('Message'), |
429 | + 'context': context, |
430 | + 'view_type': 'form', |
431 | + 'view_mode': 'form', |
432 | + 'res_model': 'account.message', |
433 | + 'views': [(resource_id,'form')], |
434 | + 'type': 'ir.actions.act_window', |
435 | + 'target': 'new', |
436 | + } |
437 | + |
438 | def wo_check(self, cr, uid, ids, context=None): |
439 | cur_obj = self.pool.get('res.currency') |
440 | mod_obj = self.pool.get('ir.model.data') |
441 | + obj_inv = self.pool.get('account.invoice') |
442 | + |
443 | if context is None: |
444 | context = {} |
445 | data = self.read(cr, uid, ids,context=context)[0] |
446 | + |
447 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context) |
448 | journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context) |
449 | - |
450 | # Here we need that: |
451 | # The invoice total amount in company's currency <> paid amount in company currency |
452 | # (according to the correct day rate, invoicing rate and payment rate are may be different) |
453 | @@ -251,13 +311,13 @@ |
454 | inv_amount_company_currency += aml.debit |
455 | inv_amount_company_currency -= aml.credit |
456 | inv_amount_company_currency = abs(inv_amount_company_currency) |
457 | - |
458 | # Get the current amount paid in company currency |
459 | if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id: |
460 | ctx = {'date':data['date']} |
461 | amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['amount'], round=True, context=ctx) |
462 | else: |
463 | - amount_paid = data['amount'] |
464 | + amount_paid = data['amount'] + data['cash_amount'] |
465 | + |
466 | # Get the old payment if there are some |
467 | if invoice.payment_ids: |
468 | debit=credit=0.0 |
469 | @@ -267,27 +327,42 @@ |
470 | amount_paid+=abs(debit-credit) |
471 | |
472 | # Test if there is a difference according to currency rouding setting |
473 | - if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
474 | - (amount_paid - inv_amount_company_currency)): |
475 | + amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
476 | + found_h = amount['found'] |
477 | + |
478 | + if found_h: |
479 | + if context.get('discount_move_ids',False): |
480 | + context.update({'discount_move_ids':context['discount_move_ids']}) |
481 | + |
482 | + if context.get('tax_move_ids',False): |
483 | + context.update({'tax_move_ids':context['tax_move_ids']}) |
484 | + |
485 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
486 | else: |
487 | - model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context) |
488 | - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
489 | - return { |
490 | - 'name': _('Information addendum'), |
491 | - 'context': context, |
492 | - 'view_type': 'form', |
493 | - 'view_mode': 'form', |
494 | - 'res_model': 'account.invoice.pay.writeoff', |
495 | - 'views': [(resource_id,'form')], |
496 | - 'type': 'ir.actions.act_window', |
497 | - 'target': 'new', |
498 | - } |
499 | - |
500 | + |
501 | + if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
502 | + (amount_paid - inv_amount_company_currency)): |
503 | + return self.pay_and_reconcile(cr, uid, ids, context=context) |
504 | + |
505 | + else: |
506 | + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context) |
507 | + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
508 | + return { |
509 | + 'name': _('Information addendum'), |
510 | + 'context': context, |
511 | + 'view_type': 'form', |
512 | + 'view_mode': 'form', |
513 | + 'res_model': 'account.invoice.pay.writeoff', |
514 | + 'views': [(resource_id,'form')], |
515 | + 'type': 'ir.actions.act_window', |
516 | + 'target': 'new', |
517 | + } |
518 | + |
519 | def pay_and_reconcile(self, cr, uid, ids, context=None): |
520 | cur_obj = self.pool.get('res.currency') |
521 | if context is None: |
522 | context = {} |
523 | + |
524 | data = self.read(cr, uid, ids,context=context)[0] |
525 | writeoff_account_id = False |
526 | writeoff_journal_id = False |
527 | @@ -297,9 +372,9 @@ |
528 | writeoff_account_id = context['write_off']['writeoff_acc_id'] |
529 | writeoff_journal_id = context['write_off']['writeoff_journal_id'] |
530 | comment = context['write_off']['comment'] |
531 | - |
532 | + |
533 | amount = data['amount'] + data['cash_amount'] |
534 | - |
535 | + |
536 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) |
537 | journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context=context) |
538 | # Compute the amount in company's currency, with the journal currency (which is equal to payment currency) |
539 | @@ -326,12 +401,16 @@ |
540 | |
541 | context.update({'account_id':data['account_id'],'cash_amount':data['cash_amount'],'amount_currency':data['amount'] + data['cash_amount']}) |
542 | |
543 | - if data['discount_move_ids']: |
544 | - context.update({'discount_move_ids':data['discount_move_ids']}) |
545 | + if context.get('discount_move_ids',False): |
546 | + context = context |
547 | + else: |
548 | + context.update({'discount_move_ids':data['discount_move_ids']}) |
549 | |
550 | - if data['tax_move_ids']: |
551 | + if context.get('tax_move_ids',False): |
552 | + context = context |
553 | + else: |
554 | context.update({'tax_move_ids':data['tax_move_ids']}) |
555 | - |
556 | + |
557 | if data['cash_amount']: |
558 | context.update({'cash_amount':data['cash_amount']}) |
559 | |
560 | @@ -344,6 +423,7 @@ |
561 | return {} |
562 | |
563 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False): |
564 | + |
565 | res = super(account_invoice_pay,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar) |
566 | fields=res.get('fields',{}) |
567 | word = "Supplier Cash Discount Account" |
568 | @@ -358,4 +438,13 @@ |
569 | |
570 | account_invoice_pay() |
571 | |
572 | +class account_message(osv.osv_memory): |
573 | + _name = "account.message" |
574 | + def _check(self, cr, uid, ids, context=None): |
575 | + data = self.read(cr, uid, ids,context=context)[0] |
576 | + result = self.pool.get('account.invoice.pay').wo_check(cr, uid, ids, context=context) |
577 | + return result |
578 | + |
579 | +account_message() |
580 | + |
581 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
582 | \ No newline at end of file |
583 | |
584 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml' |
585 | --- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-01 12:19:51 +0000 |
586 | +++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-06 13:38:28 +0000 |
587 | @@ -34,7 +34,7 @@ |
588 | <label string ="" colspan="2"/> |
589 | <button icon="gtk-cancel" special="cancel" string="Cancel"/> |
590 | <button icon="gtk-execute" string="Partial Payment" name="pay_and_reconcile" type="object"/> |
591 | - <button icon="gtk-execute" string="Full Payment" name="wo_check" type="object"/> |
592 | + <button icon="gtk-execute" string="Full-Payment" name="_message" type="object"/> |
593 | </group> |
594 | </form> |
595 | </field> |
596 | @@ -70,5 +70,18 @@ |
597 | </form> |
598 | </field> |
599 | </record> |
600 | + |
601 | + <record id="view_account_message" model="ir.ui.view"> |
602 | + <field name="name">account.message.form</field> |
603 | + <field name="model">account.message</field> |
604 | + <field name="type">form</field> |
605 | + <field name="arch" type="xml"> |
606 | + <form string="Your Messages"> |
607 | + <label colspan="8" string="Are you really want to reconcile this invoice" /> |
608 | + <button icon="gtk-execute" string="OK" name="_check" type="object"/> |
609 | + </form> |
610 | + </field> |
611 | + </record> |
612 | + |
613 | </data> |
614 | </openerp> |
615 | \ No newline at end of file |