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