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

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 37
Proposed branch: lp:~openbig/bigconsulting/added_wizard
Merge into: lp:bigconsulting
Diff against target: 259 lines (+250/-0)
2 files modified
account_invoice_cash_discount/account_invoice_cash_discount_wizard.xml (+11/-0)
account_invoice_cash_discount/wizard/invoice_statement_payment.py (+239/-0)
To merge this branch: bzr merge lp:~openbig/bigconsulting/added_wizard
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+28830@code.launchpad.net

Description of the change

Added wizard of statement

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=== added file 'account_invoice_cash_discount/account_invoice_cash_discount_wizard.xml'
2--- account_invoice_cash_discount/account_invoice_cash_discount_wizard.xml 1970-01-01 00:00:00 +0000
3+++ account_invoice_cash_discount/account_invoice_cash_discount_wizard.xml 2010-06-30 05:24:28 +0000
4@@ -0,0 +1,11 @@
5+<?xml version="1.0"?>
6+<openerp>
7+ <data>
8+ <wizard
9+ string="Import invoices11"
10+ model="account.bank.statement"
11+ name="populate_statement_from_inv1"
12+ menu="False"
13+ id="wizard_populate_statement_from_inv1"/>
14+ </data>
15+</openerp>
16
17=== added file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py'
18--- account_invoice_cash_discount/wizard/invoice_statement_payment.py 1970-01-01 00:00:00 +0000
19+++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-06-30 05:24:28 +0000
20@@ -0,0 +1,239 @@
21+# -*- encoding: utf-8 -*-
22+##############################################################################
23+#
24+# Copyright (c) 2008 Camptocamp SA All Rights Reserved. (JGG)
25+#
26+# WARNING: This program as such is intended to be used by professional
27+# programmers who take the whole responsability of assessing all potential
28+# consequences resulting from its eventual inadequacies and bugs
29+# End users who are looking for a ready-to-use solution with commercial
30+# garantees and support are strongly adviced to contract a Free Software
31+# Service Company
32+#
33+# This program is Free Software; you can redistribute it and/or
34+# modify it under the terms of the GNU General Public License
35+# as published by the Free Software Foundation; either version 2
36+# of the License, or (at your option) any later version.
37+#
38+# This program is distributed in the hope that it will be useful,
39+# but WITHOUT ANY WARRANTY; without even the implied warranty of
40+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41+# GNU General Public License for more details.
42+#
43+# You should have received a copy of the GNU General Public License
44+# along with this program; if not, write to the Free Software
45+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46+#
47+##############################################################################
48+
49+import wizard
50+import pooler
51+from tools.misc import UpdateableStr
52+import time
53+
54+FORM = UpdateableStr()
55+
56+FIELDS = {
57+ 'lines': {'string': 'Invoices', 'type': 'many2many',
58+ 'relation': 'account.move.line'},
59+
60+}
61+
62+START_FIELD = {
63+ 'date': {'string': 'Date payment', 'type': 'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
64+ 'journal_id': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'domain': '[("type","in",["sale","purchase","cash"])]', 'help': 'This field allow you to choose the accounting journals you want for filtering the invoices. If you left this field empty, it will search on all sale, purchase and cash journals.'},
65+}
66+
67+START_FORM = '''<?xml version="1.0"?>
68+<form string="Import Invoices in Statement">
69+ <label string="Choose Journal and Payment Date" colspan="4"/>
70+ <field name="date"/>
71+ <field name="journal_id" colspan="4"/>
72+</form>'''
73+
74+def _search_invoices(obj, cr, uid, data, context):
75+ pool = pooler.get_pool(cr.dbname)
76+ line_obj = pool.get('account.move.line')
77+ statement_obj = pool.get('account.bank.statement')
78+ journal_obj = pool.get('account.journal')
79+
80+ statement = statement_obj.browse(cr, uid, data['id'], context=context)
81+ args_move_line = []
82+ repeated_move_line_ids = []
83+ # Creating a group that is unique for importing move lines(move lines, once imported into statement lines, should not appear again)
84+ for st_line in statement.line_ids:
85+ args_move_line = []
86+ args_move_line.append(('name','=', st_line.name))
87+ args_move_line.append(('ref','=',st_line.ref))
88+ if st_line.partner_id:
89+ args_move_line.append(('partner_id','=',st_line.partner_id.id))
90+ args_move_line.append(('account_id','=',st_line.account_id.id))
91+
92+ move_line_id = line_obj.search(cr, uid, args_move_line,context=context)
93+ if move_line_id:
94+ repeated_move_line_ids += move_line_id
95+
96+ journal_ids = data['form']['journal_id'][0][2]
97+
98+ if journal_ids == []:
99+ journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale','cash','purchase'))], context=context)
100+
101+ args = [
102+ ('reconcile_id', '=', False),
103+ ('journal_id', 'in', journal_ids),
104+ ('account_id.reconcile', '=', True)]
105+
106+ if repeated_move_line_ids:
107+ args.append(('id','not in',repeated_move_line_ids))
108+
109+ line_ids = line_obj.search(cr, uid, args,
110+ #order='date DESC, id DESC', #doesn't work
111+ context=context)
112+
113+ FORM.string = '''<?xml version="1.0"?>
114+<form string="Import Entries">
115+ <field name="lines" colspan="4" height="300" width="800" nolabel="1"
116+ domain="[('id', 'in', [%s])]"/>
117+</form>''' % (','.join([str(x) for x in line_ids]))
118+ return {}
119+
120+def _populate_statement(obj, cursor, user, data, context):
121+
122+ line_ids = data['form']['lines'][0][2]
123+ line_date=data['form']['date']
124+ if not line_ids:
125+ return {}
126+
127+ pool = pooler.get_pool(cursor.dbname)
128+ line_obj = pool.get('account.move.line')
129+ statement_obj = pool.get('account.bank.statement')
130+ statement_line_obj = pool.get('account.bank.statement.line')
131+ currency_obj = pool.get('res.currency')
132+ statement_reconcile_obj = pool.get('account.bank.statement.reconcile')
133+ statement_reconcile_line_obj = pool.get('account.bank.statement.reconcile.line')
134+
135+ obj_inv = pool.get('account.invoice')
136+ tax_obj = pool.get('account.tax')
137+ invoice_tax_obj = pool.get("account.invoice.tax")
138+
139+ statement = statement_obj.browse(cursor, user, data['id'], context=context)
140+ # for each selected move lines
141+ for line in line_obj.browse(cursor, user, line_ids, context=context):
142+ ctx = context.copy()
143+ # take the date for computation of currency => use payment date
144+ # if line.date_maturity:
145+ # ctx['date'] = line.date_maturity
146+ # else:
147+ ctx['date'] = line_date
148+ amount = 0.0
149+ if line.amount_currency:
150+ amount = currency_obj.compute(cursor, user, line.currency_id.id,
151+ statement.currency.id, line.amount_currency, context=ctx)
152+ else:
153+ if line.debit > 0:
154+ amount=line.debit
155+ elif line.credit > 0:
156+ amount=-line.credit
157+
158+ reconcile_id = statement_reconcile_obj.create(cursor, user, {
159+ 'line_ids': [(6, 0, [line.id])]
160+ }, context=context)
161+
162+ ######################################### Calculation for discount and taxes######
163+ if line.invoice.id:
164+
165+ discount = 0.0
166+ account = False
167+ tax_total_amount = 0.0
168+
169+ invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context)
170+ discount = obj_inv._get_payment(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context)
171+ account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context)
172+
173+ for invoice_line in invoice.invoice_line:
174+ if invoice_line.invoice_line_tax_id:
175+ for tax in tax_obj.compute(cursor, user, invoice_line.invoice_line_tax_id, discount, invoice_line.quantity, invoice.address_invoice_id.id, invoice_line.product_id, invoice.partner_id):
176+ tax_amount = tax['amount']
177+ tax_total_amount += tax['amount']
178+ tax_invoice_id = invoice_tax_obj.search(cursor,user,[('invoice_id','=',invoice.id),('name','=',tax['name'])])
179+ for tax_id in tax_invoice_id:
180+ tax_value = invoice_tax_obj.browse(cursor, user, tax_id)
181+ tax_account_id = tax_value.account_id.id
182+
183+ if tax_amount>0:
184+ statement_reconcile_line_obj.create(cursor, user, {
185+ 'name': line.name,
186+ 'amount': tax_amount,
187+ 'account_id': tax_account_id,
188+ 'line_id': reconcile_id,
189+ }, context=context)
190+ if discount>0:
191+ statement_reconcile_line_obj.create(cursor, user, {
192+ 'name': line.name,
193+ 'amount': discount - tax_total_amount,
194+ 'account_id': account,
195+ 'line_id': reconcile_id,
196+ }, context=context)
197+ ##########################################################################
198+
199+ if line.journal_id.type == 'sale':
200+ type = 'customer'
201+ elif line.journal_id.type == 'purchase':
202+ type = 'supplier'
203+ else:
204+ type = 'general'
205+ statement_line_obj.create(cursor, user, {
206+ 'name': line.name or '?',
207+ 'amount': amount,
208+ 'type': type,
209+ 'partner_id': line.partner_id.id,
210+ 'account_id': line.account_id.id,
211+ 'statement_id': statement.id,
212+ 'ref': line.ref,
213+ 'reconcile_id': reconcile_id,
214+ 'date':line_date, #time.strftime('%Y-%m-%d'), #line.date_maturity or,
215+ }, context=context)
216+ return {}
217+
218+
219+class PopulateStatementFromInv(wizard.interface):
220+ """
221+ Populate the current statement with selected invoices
222+ """
223+ states = {
224+ 'init': {
225+ 'actions': [],
226+ 'result': {
227+ 'type': 'form',
228+ 'arch': START_FORM,
229+ 'fields':START_FIELD,
230+ 'state': [
231+ ('end', '_Cancel'),
232+ ('go', '_Go', '', True),
233+ ]
234+ },
235+ },
236+ 'go': {
237+ 'actions': [_search_invoices],
238+ 'result': {
239+ 'type': 'form',
240+ 'arch': FORM,
241+ 'fields': FIELDS,
242+ 'state': [
243+ ('end', '_Cancel','', True),
244+ ('finish', 'O_k','', True)
245+ ]
246+ },
247+ },
248+
249+ 'finish': {
250+ 'actions': [],
251+ 'result': {
252+ 'type': 'action',
253+ 'action': _populate_statement,
254+ 'state': 'end'
255+ },
256+ },
257+ }
258+PopulateStatementFromInv('populate_statement_from_inv1')
259+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches