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

Subscribers

People subscribed via source and target branches