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

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 7
Proposed branch: lp:~openbig/bigconsulting/changes_account_invoice_discount
Merge into: lp:bigconsulting
Diff against target: 584 lines (+548/-0)
7 files modified
account_invoice_cash_discount/__init__.py (+26/-0)
account_invoice_cash_discount/__terp__.py (+45/-0)
account_invoice_cash_discount/account_invoice_cash_discount.py (+195/-0)
account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+47/-0)
account_invoice_cash_discount/account_wizard.xml (+6/-0)
account_invoice_cash_discount/wizard/__init__.py (+26/-0)
account_invoice_cash_discount/wizard/wizard_pay_invoice.py (+203/-0)
To merge this branch: bzr merge lp:~openbig/bigconsulting/changes_account_invoice_discount
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+26124@code.launchpad.net

Description of the change

Changes on the account_invoice_cash_discount

To post a comment you must log in.
7. By gpa(OpenERP)

changes on the account_invoice_cash_discount

Revision history for this message
Husen Daudi (husendaudi) wrote :

In __terp__.py
Website should be : http://www.openbig.org
there must be short description.

In account_invoice_cash_discount.py useless import statements are there.
Clean up code
import mx.DateTime
from mx.DateTime import RelativeDateTime

Wizard_pay_invoice.py
useless import : import netsvc

clean up code and resubmit merge.

8. By gpa(OpenERP)

Remove useless import statements and added Description

9. By gpa(OpenERP)

change in get_payment function

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'account_invoice_cash_discount'
2=== added file 'account_invoice_cash_discount/__init__.py'
3--- account_invoice_cash_discount/__init__.py 1970-01-01 00:00:00 +0000
4+++ account_invoice_cash_discount/__init__.py 2010-05-27 07:44:26 +0000
5@@ -0,0 +1,26 @@
6+# -*- encoding: utf-8 -*-
7+##############################################################################
8+#
9+# OpenERP, Open Source Management Solution
10+# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
11+# $Id$
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU General Public License as published by
15+# the Free Software Foundation, either version 3 of the License, or
16+# (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU General Public License for more details.
22+#
23+# You should have received a copy of the GNU General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+##############################################################################
27+
28+import account_invoice_cash_discount
29+import wizard
30+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
31+
32
33=== added file 'account_invoice_cash_discount/__terp__.py'
34--- account_invoice_cash_discount/__terp__.py 1970-01-01 00:00:00 +0000
35+++ account_invoice_cash_discount/__terp__.py 2010-05-27 07:44:26 +0000
36@@ -0,0 +1,45 @@
37+# -*- encoding: utf-8 -*-
38+##############################################################################
39+#
40+# OpenERP, Open Source Management Solution
41+# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
42+# $Id$
43+#
44+# This program is free software: you can redistribute it and/or modify
45+# it under the terms of the GNU General Public License as published by
46+# the Free Software Foundation, either version 3 of the License, or
47+# (at your option) any later version.
48+#
49+# This program is distributed in the hope that it will be useful,
50+# but WITHOUT ANY WARRANTY; without even the implied warranty of
51+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52+# GNU General Public License for more details.
53+#
54+# You should have received a copy of the GNU General Public License
55+# along with this program. If not, see <http://www.gnu.org/licenses/>.
56+#
57+##############################################################################
58+{
59+ "name" : "Payement Term with Cash Discount",
60+ "version" : "1.0",
61+ "depends" : ["account",],
62+ "author" : "Big Consulting",
63+ "website" : "",
64+ "category" : "",
65+ "description": """
66+ The Module add automatically account move lines in case of payment with cash discount conditions in reconcilation form.
67+ """,
68+ "init_xml" : [
69+ ],
70+ "demo_xml" : [
71+ ],
72+ "update_xml" : [
73+ "account_invoice_cash_discount_view.xml",
74+ "account_wizard.xml"
75+ ],
76+ "active": False,
77+ "installable": True,
78+
79+}
80+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
81+
82
83=== added file 'account_invoice_cash_discount/account_invoice_cash_discount.py'
84--- account_invoice_cash_discount/account_invoice_cash_discount.py 1970-01-01 00:00:00 +0000
85+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-05-27 07:44:26 +0000
86@@ -0,0 +1,195 @@
87+# -*- encoding: utf-8 -*-
88+##############################################################################
89+#
90+# OpenERP, Open Source Management Solution
91+# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
92+# $Id$
93+#
94+# This program is free software: you can redistribute it and/or modify
95+# it under the terms of the GNU General Public License as published by
96+# the Free Software Foundation, either version 3 of the License, or
97+# (at your option) any later version.
98+#
99+# This program is distributed in the hope that it will be useful,
100+# but WITHOUT ANY WARRANTY; without even the implied warranty of
101+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102+# GNU General Public License for more details.
103+#
104+# You should have received a copy of the GNU General Public License
105+# along with this program. If not, see <http://www.gnu.org/licenses/>.
106+#
107+##############################################################################
108+
109+from osv import fields, osv
110+from tools import config
111+import time
112+from mx import DateTime
113+
114+class account_payment_term(osv.osv):
115+ _name = "account.payment.term"
116+ _inherit = "account.payment.term"
117+ _columns = {
118+ 'cash_discount_ids': fields.one2many('account.cash.discount', 'payment_id', 'Cash Discounts'),
119+ }
120+account_payment_term()
121+
122+class account_cash_discount(osv.osv):
123+ _name = "account.cash.discount"
124+ _description = "Cash Discount" #A reduction in the price if payment is made within a stipulated period.
125+ _columns = {
126+ 'name': fields.char('Name', size=32),
127+ 'delay': fields.integer('Number of Days', required=True),
128+ 'discount': fields.float('Discount (%)', digits=(16,6),required=True),
129+ 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
130+ 'credit_account_id': fields.many2one('account.account', 'Credit Account'),
131+ 'debit_account_id': fields.many2one('account.account', 'Debit Account'),
132+ }
133+account_cash_discount()
134+
135+class account_invoice(osv.osv):
136+ _inherit = "account.invoice"
137+
138+ def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
139+
140+ #This function used to count the discount payment term
141+ if context is None:
142+ context = {}
143+
144+ tax_obj = self.pool.get('account.tax')
145+ invoice = self.browse(cr, uid, ids[0], context=context)
146+
147+ if invoice.date_due:
148+ date1 = invoice.date_due
149+ else:
150+ date1 = time.strftime('%Y-%m-%d')
151+
152+ if 'date_p' in context and context['date_p']:
153+ date2 = context['date_p']
154+ else:
155+ date2 = time.strftime('%Y-%m-%d')
156+
157+ from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
158+ to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
159+ diff_day = (from_dt-to_dt)/(3600*24)
160+ if payment_term:
161+ pt = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
162+ if pt.cash_discount_ids:
163+ res = 0.0
164+ for d in pt.cash_discount_ids:
165+ if diff_day == d.delay or diff_day < d.delay:
166+ if resudial_amonut:
167+ res = resudial_amonut * d.discount
168+ ted = 0.0
169+ for line in invoice.invoice_line:
170+ if line.invoice_line_tax_id:
171+ tt = tax_obj.compute_inv(cr, uid, line.invoice_line_tax_id, res, line.quantity)
172+ for tex in tt:
173+ rr = 0.0
174+ rr += tex['amount']
175+ ted +=rr
176+ discunt = res + ted
177+ return discunt
178+
179+ 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=''):
180+
181+ if context is None:
182+ context = {}
183+ #TODO check if we can use different period for payment and the writeoff line
184+ assert len(ids)==1, "Can only pay one invoice at a time"
185+ invoice = self.browse(cr, uid, ids[0])
186+
187+ if 'amount_currency' in context and context['amount_currency']:
188+ amount_currency = context['amount_currency']
189+ else:
190+ amount_currency = invoice.residual
191+
192+ if invoice.payment_term:
193+ # Return the discount on for the payment term
194+ discunt1 = self._get_payment(cr, uid, ids, amount_currency, invoice.payment_term.id, context=context)
195+
196+ src_account_id = invoice.account_id.id
197+ # Take the seq as name for move
198+ types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}
199+ direction = types[invoice.type]
200+ #take the choosen date
201+ if 'date_p' in context and context['date_p']:
202+ date=context['date_p']
203+ else:
204+ date=time.strftime('%Y-%m-%d')
205+
206+ # Take the amount in currency and the currency of the payment
207+ if 'amount_currency' in context and context['amount_currency'] and 'currency_id' in context and context['currency_id']:
208+ amount_currency = context['amount_currency']
209+ currency_id = context['currency_id']
210+ else:
211+ amount_currency = False
212+ currency_id = False
213+
214+ if invoice.type in ('in_invoice', 'in_refund'):
215+ ref = invoice.reference
216+ else:
217+ ref = self._convert_ref(cr, uid, invoice.number)
218+ # Pay attention to the sign for both debit/credit AND amount_currency
219+ l1 = {
220+ 'debit': direction * (pay_amount)>0 and direction * (pay_amount),
221+ 'credit': direction * (pay_amount)<0 and - direction * (pay_amount),
222+ 'account_id': src_account_id,
223+ 'partner_id': invoice.partner_id.id,
224+ 'ref':ref,
225+ 'date': date,
226+ 'currency_id':currency_id,
227+ 'amount_currency':amount_currency and direction * amount_currency or 0.0,
228+ }
229+ l2 = {
230+ 'debit': direction * (pay_amount-discunt1)<0 and - direction * (pay_amount-discunt1),
231+ 'credit': direction * (pay_amount-discunt1)>0 and direction * (pay_amount-discunt1),
232+ 'account_id': pay_account_id,
233+ 'partner_id': invoice.partner_id.id,
234+ 'ref':ref,
235+ 'date': date,
236+ 'currency_id':currency_id,
237+ 'amount_currency':amount_currency and - direction * amount_currency or 0.0,
238+ }
239+ l3 = {
240+ 'debit': direction * discunt1<0 and - direction * discunt1,
241+ 'credit': direction * discunt1>0 and direction * discunt1,
242+ 'account_id': context['account_id'],
243+ 'partner_id': invoice.partner_id.id,
244+ 'ref':ref,
245+ 'date': date,
246+ 'currency_id':currency_id,
247+ 'amount_currency':amount_currency and direction * amount_currency or 0.0,
248+ }
249+
250+ if not name:
251+ name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number
252+ l1['name'] = name
253+ l2['name'] = name
254+ l3['name'] = name
255+ lines = [(0, 0, l1), (0, 0, l2), (0, 0, l3)]
256+
257+ move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}
258+ move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
259+
260+ line_ids = []
261+ total = 0.0
262+ line = self.pool.get('account.move.line')
263+ cr.execute('select id from account_move_line where move_id in ('+str(move_id)+','+str(invoice.move_id.id)+')')
264+ lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
265+ for l in lines+invoice.payment_ids:
266+ if l.account_id.id==src_account_id:
267+ line_ids.append(l.id)
268+ total += (l.debit or 0.0) - (l.credit or 0.0)
269+ if (not round(total,int(config['price_accuracy']))) or writeoff_acc_id:
270+ self.pool.get('account.move.line').reconcile(cr, uid, line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context)
271+ else:
272+ self.pool.get('account.move.line').reconcile_partial(cr, uid, line_ids, 'manual', context)
273+
274+ # Update the stored value (fields.function), so we write to trigger recompute
275+ self.pool.get('account.invoice').write(cr, uid, ids, {}, context=context)
276+ return True
277+
278+account_invoice()
279+
280+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
281+
282
283=== added file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml'
284--- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 1970-01-01 00:00:00 +0000
285+++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-05-27 07:44:26 +0000
286@@ -0,0 +1,47 @@
287+<?xml version="1.0"?>
288+<openerp>
289+ <data>
290+
291+ <!-- cash discount -->
292+
293+
294+ <record model="ir.ui.view" id="view_cash_discount_form">
295+ <field name="name">account.cash.discount.form</field>
296+ <field name="model">account.cash.discount</field>
297+ <field name="type">form</field>
298+ <field name="arch" type="xml">
299+ <form string="Cash Discount">
300+ <field name="name" select="1"/>
301+ <field name="delay" select="1"/>
302+ <field name="discount" select="1"/>
303+ </form>
304+ </field>
305+ </record>
306+
307+ <record model="ir.ui.view" id="view_cash_discount_tree">
308+ <field name="name">account.cash.discount.tree</field>
309+ <field name="model">account.cash.discount</field>
310+ <field name="type">tree</field>
311+ <field name="arch" type="xml">
312+ <tree string="Cash Discount" editable="bottom">
313+ <field name="name" select="1"/>
314+ <field name="delay" select="1"/>
315+ <field name="discount" select="1"/>
316+ </tree>
317+ </field>
318+ </record>
319+
320+ <record model="ir.ui.view" id="view_payment_term_form">
321+ <field name="name">account.payment.term.form</field>
322+ <field name="model">account.payment.term</field>
323+ <field name="inherit_id" ref="account.view_payment_term_form"/>
324+ <field name="arch" type="xml">
325+ <field name="line_ids" position="after">
326+ <separator string="Cash Discount" colspan="4"/>
327+ <field name="cash_discount_ids" colspan="4"/>
328+ </field>
329+ </field>
330+ </record>
331+
332+ </data>
333+</openerp>
334
335=== added file 'account_invoice_cash_discount/account_wizard.xml'
336--- account_invoice_cash_discount/account_wizard.xml 1970-01-01 00:00:00 +0000
337+++ account_invoice_cash_discount/account_wizard.xml 2010-05-27 07:44:26 +0000
338@@ -0,0 +1,6 @@
339+<?xml version="1.0" encoding="utf-8"?>
340+<openerp>
341+ <data>
342+ <wizard id="wizard_invoice_pay" model="account.invoice" name="account.invoice.pay1" string="Pay invoice" groups="base.group_user"/>
343+ </data>
344+</openerp>
345
346=== added directory 'account_invoice_cash_discount/wizard'
347=== added file 'account_invoice_cash_discount/wizard/__init__.py'
348--- account_invoice_cash_discount/wizard/__init__.py 1970-01-01 00:00:00 +0000
349+++ account_invoice_cash_discount/wizard/__init__.py 2010-05-27 07:44:26 +0000
350@@ -0,0 +1,26 @@
351+# -*- encoding: utf-8 -*-
352+##############################################################################
353+#
354+# OpenERP, Open Source Management Solution
355+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
356+# $Id$
357+#
358+# This program is free software: you can redistribute it and/or modify
359+# it under the terms of the GNU General Public License as published by
360+# the Free Software Foundation, either version 3 of the License, or
361+# (at your option) any later version.
362+#
363+# This program is distributed in the hope that it will be useful,
364+# but WITHOUT ANY WARRANTY; without even the implied warranty of
365+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
366+# GNU General Public License for more details.
367+#
368+# You should have received a copy of the GNU General Public License
369+# along with this program. If not, see <http://www.gnu.org/licenses/>.
370+#
371+##############################################################################
372+
373+import wizard_pay_invoice
374+
375+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
376+
377
378=== added file 'account_invoice_cash_discount/wizard/wizard_pay_invoice.py'
379--- account_invoice_cash_discount/wizard/wizard_pay_invoice.py 1970-01-01 00:00:00 +0000
380+++ account_invoice_cash_discount/wizard/wizard_pay_invoice.py 2010-05-27 07:44:26 +0000
381@@ -0,0 +1,203 @@
382+# -*- encoding: utf-8 -*-
383+##############################################################################
384+#
385+# OpenERP, Open Source Management Solution
386+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
387+# $Id$
388+#
389+# This program is free software: you can redistribute it and/or modify
390+# it under the terms of the GNU General Public License as published by
391+# the Free Software Foundation, either version 3 of the License, or
392+# (at your option) any later version.
393+#
394+# This program is distributed in the hope that it will be useful,
395+# but WITHOUT ANY WARRANTY; without even the implied warranty of
396+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
397+# GNU General Public License for more details.
398+#
399+# You should have received a copy of the GNU General Public License
400+# along with this program. If not, see <http://www.gnu.org/licenses/>.
401+#
402+##############################################################################
403+
404+import wizard
405+import pooler
406+import time
407+from tools.translate import _
408+import tools
409+
410+pay_form = '''<?xml version="1.0"?>
411+<form string="Pay invoice">
412+ <field name="amount"/>
413+ <newline/>
414+ <field name="name"/>
415+ <field name="date"/>
416+ <field name="journal_id"/>
417+ <field name="period_id"/>
418+ <field name="cash_amount"/>
419+ <field name="account_id"/>
420+</form>'''
421+
422+pay_fields = {
423+ 'amount': {'string': 'Amount paid', 'type':'float', 'required':True, 'digits': (16,int(tools.config['price_accuracy']))},
424+ 'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
425+ 'cash_amount': {'string': 'Cash Discount Amount', 'type':'float', 'required':True, 'digits': (16,int(tools.config['price_accuracy']))},
426+ 'account_id': {'string': 'Account For Discount', 'type': 'many2one', 'relation':'account.account', 'required':True},
427+ 'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')},
428+ 'journal_id': {'string': 'Journal/Payment Mode', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
429+ 'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
430+}
431+
432+def _pay_and_reconcile(self, cr, uid, data, context):
433+ form = data['form']
434+ period_id = form.get('period_id', False)
435+ journal_id = form.get('journal_id', False)
436+ writeoff_account_id = form.get('writeoff_acc_id', False)
437+ writeoff_journal_id = form.get('writeoff_journal_id', False)
438+ pool = pooler.get_pool(cr.dbname)
439+ cur_obj = pool.get('res.currency')
440+ amount = form['amount']
441+ context['analytic_id'] = form.get('analytic_id', False)
442+
443+ invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
444+ journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
445+ # Compute the amount in company's currency, with the journal currency (which is equal to payment currency)
446+ # when it is needed : If payment currency (according to selected journal.currency) is <> from company currency
447+ if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
448+ ctx = {'date':data['form']['date']}
449+ amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
450+ currency_id = journal.currency.id
451+ # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency
452+ context.update({'amount_currency':form['amount'],'currency_id':currency_id})
453+
454+ if invoice.company_id.currency_id.id<>invoice.currency_id.id:
455+ ctx = {'date':data['form']['date']}
456+ amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, amount, context=ctx)
457+ currency_id = invoice.currency_id.id
458+ # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency
459+ context.update({'amount_currency':form['amount'],'currency_id':currency_id})
460+
461+ # Take the choosen date
462+ if form.has_key('comment'):
463+ context.update({'date_p':form['date'],'comment':form['comment']})
464+ else:
465+ context.update({'date_p':form['date'],'comment':False})
466+
467+ context.update({'account_id':form['account_id'],'cash_amount':form['cash_amount'],'amount_currency':form['amount']})
468+
469+ acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
470+ if not acc_id:
471+ raise wizard.except_wizard(_('Error !'), _('Your journal must have a default credit and debit account.'))
472+ pool.get('account.invoice').pay_and_reconcile(cr, uid, [data['id']],
473+ amount, acc_id, period_id, journal_id, writeoff_account_id,
474+ period_id, writeoff_journal_id, context, data['form']['name'])
475+ return {}
476+
477+def _wo_check(self, cr, uid, data, context):
478+ pool = pooler.get_pool(cr.dbname)
479+ invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
480+ journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
481+ cur_obj = pool.get('res.currency')
482+ # Here we need that:
483+ # The invoice total amount in company's currency <> paid amount in company currency
484+ # (according to the correct day rate, invoicing rate and payment rate are may be different)
485+ # => Ask to a write-off of the difference. This could happen even if both amount are equal,
486+ # because if the currency rate
487+ # Get the amount in company currency for the invoice (according to move lines)
488+ inv_amount_company_currency = 0
489+ for aml in invoice.move_id.line_id:
490+ if aml.account_id.id == invoice.account_id.id or aml.account_id.type in ('receivable', 'payable'):
491+ inv_amount_company_currency += aml.debit
492+ inv_amount_company_currency -= aml.credit
493+ inv_amount_company_currency = abs(inv_amount_company_currency)
494+
495+ # Get the current amount paid in company currency
496+ if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
497+ ctx = {'date':data['form']['date']}
498+ amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['form']['amount'], round=True, context=ctx)
499+ else:
500+ amount_paid = data['form']['amount']
501+ # Get the old payment if there are some
502+ if invoice.payment_ids:
503+ debit=credit=0.0
504+ for payment in invoice.payment_ids:
505+ debit+=payment.debit
506+ credit+=payment.credit
507+ amount_paid+=abs(debit-credit)
508+
509+ # Test if there is a difference according to currency rouding setting
510+ if pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,
511+ (amount_paid - inv_amount_company_currency)):
512+ return 'reconcile'
513+ return 'addendum'
514+
515+_transaction_add_form = '''<?xml version="1.0"?>
516+<form string="Information addendum">
517+ <separator string="Write-Off Move" colspan="4"/>
518+ <field name="writeoff_journal_id"/>
519+ <field name="writeoff_acc_id" domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]"/>
520+ <field name="comment"/>
521+ <separator string="Analytic" colspan="4"/>
522+ <field name="analytic_id"/>
523+</form>'''
524+
525+_transaction_add_fields = {
526+ 'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
527+ 'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
528+ 'comment': {'string': 'Comment', 'type':'char', 'size': 64 , 'required':True},
529+ 'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'},
530+}
531+
532+def _get_value_addendum(self, cr, uid, data, context={}):
533+ return {'comment': _('Write-Off')}
534+
535+def _compute(self, cr, uid, data, context={}):
536+ pool = pooler.get_pool(cr.dbname)
537+ invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
538+
539+
540+def _get_period(self, cr, uid, data, context={}):
541+ pool = pooler.get_pool(cr.dbname)
542+ ids = pool.get('account.period').find(cr, uid, context=context)
543+ period_id = False
544+ if len(ids):
545+ period_id = ids[0]
546+ invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
547+ cash_amount = pool.get('account.invoice')._get_payment(cr, uid, [data['id']], invoice.residual, invoice.payment_term.id, context=context)
548+ if invoice.state in ['draft', 'proforma2', 'cancel']:
549+ raise wizard.except_wizard(_('Error !'), _('Can not pay draft/proforma/cancel invoice.'))
550+ return {
551+ 'period_id': period_id,
552+ 'amount': invoice.residual,
553+ 'date': time.strftime('%Y-%m-%d'),
554+ 'cash_amount': cash_amount,
555+ }
556+
557+class wizard_pay_invoice(wizard.interface):
558+ states = {
559+ 'init': {
560+ 'actions': [_get_period],
561+ 'result': {'type':'form', 'arch':pay_form, 'fields':pay_fields, 'state':[('end','Cancel'),('reconcile','Partial Payment'),('writeoff_check','Full Payment')]}
562+ },
563+ 'writeoff_check': {
564+ 'actions': [],
565+ 'result' : {'type': 'choice', 'next_state': _wo_check }
566+ },
567+ 'addendum': {
568+ 'actions': [_get_value_addendum],
569+ 'result': {'type': 'form', 'arch':_transaction_add_form, 'fields':_transaction_add_fields, 'state':[('end','Cancel'),('reconcile','Pay and reconcile')]}
570+ },
571+ 'reconcile': {
572+ 'actions': [_pay_and_reconcile],
573+ 'result': {'type':'state', 'state':'end'}
574+ },
575+ 'compute_dis': {
576+ 'actions': [_compute],
577+ 'result': {'type':'state', 'state':'end'}
578+ }
579+ }
580+wizard_pay_invoice('account.invoice.pay1')
581+
582+
583+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
584+

Subscribers

People subscribed via source and target branches