Merge lp:~openbig/bigconsulting/ending_balance into lp:bigconsulting
- ending_balance
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Merged |
---|---|
Merged at revision: | 109 |
Proposed branch: | lp:~openbig/bigconsulting/ending_balance |
Merge into: | lp:bigconsulting |
Diff against target: |
320 lines (+113/-31) 3 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+58/-6) account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+50/-24) account_invoice_cash_discount/wizard/invoice_statement_payment.py (+5/-1) |
To merge this branch: | bzr merge lp:~openbig/bigconsulting/ending_balance |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+36537@code.launchpad.net |
Commit message
Description of the change
Improvement for the Ending Balance
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-09-23 15:13:30 +0000 |
3 | +++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-09-24 09:43:39 +0000 |
4 | @@ -645,6 +645,43 @@ |
5 | class account_bank_statement(osv.osv): |
6 | _inherit="account.bank.statement" |
7 | |
8 | + def _end_balance(self, cursor, user, ids, name, attr, context=None): |
9 | + res_currency_obj = self.pool.get('res.currency') |
10 | + res_users_obj = self.pool.get('res.users') |
11 | + |
12 | + res = {} |
13 | + |
14 | + company_currency_id = res_users_obj.browse(cursor, user, user, |
15 | + context=context).company_id.currency_id.id |
16 | + statements = self.browse(cursor, user, ids, context=context) |
17 | + for statement in statements: |
18 | + res[statement.id] = statement.balance_start |
19 | + currency_id = statement.currency.id |
20 | + for line in statement.move_line_ids: |
21 | + if line.debit > 0: |
22 | + if line.account_id.id == \ |
23 | + statement.journal_id.default_debit_account_id.id: |
24 | + res[statement.id] += res_currency_obj.compute(cursor, |
25 | + user, company_currency_id, currency_id, |
26 | + line.debit, context=context) |
27 | + else: |
28 | + if line.account_id.id == \ |
29 | + statement.journal_id.default_credit_account_id.id: |
30 | + res[statement.id] -= res_currency_obj.compute(cursor, |
31 | + user, company_currency_id, currency_id, |
32 | + line.credit, context=context) |
33 | + if statement.state == 'draft': |
34 | + for line in statement.line_ids: |
35 | + res[statement.id] += line.amount - line.cash_discount |
36 | + |
37 | + for r in res: |
38 | + res[r] = round(res[r], 2) |
39 | + return res |
40 | + |
41 | + _columns = { |
42 | + 'balance_end': fields.function(_end_balance, method=True, string='Balance'), |
43 | + } |
44 | + |
45 | def button_confirm(self, cr, uid, ids, context={}): |
46 | done = [] |
47 | tax_obj = self.pool.get('account.tax') |
48 | @@ -884,7 +921,7 @@ |
49 | 'amount_currency': 0.0, |
50 | 'currency_id': currency_id, |
51 | }, context=context) |
52 | - |
53 | + |
54 | currency_diff2 = account_move_line_obj.create(cr, uid, { |
55 | 'name': move.name, |
56 | 'date': move.date, |
57 | @@ -920,7 +957,7 @@ |
58 | 'amount_currency': 0.0, |
59 | 'currency_id': currency_id, |
60 | }, context=context) |
61 | - |
62 | + |
63 | currency_diff2 = account_move_line_obj.create(cr, uid, { |
64 | 'name': move.name, |
65 | 'date': move.date, |
66 | @@ -939,15 +976,14 @@ |
67 | |
68 | if move_line_data.invoice.currency_id.id != company_currency_id: |
69 | torec.append(currency_diff1) |
70 | - |
71 | + |
72 | new_end_value += amount+st_tax_amount-newline_sum |
73 | - |
74 | if st.currency.id <> company_currency_id: |
75 | amount_currency = res_currency_obj.compute(cr, uid, company_currency_id, st.currency.id, |
76 | (amount+st_tax_amount-newline_sum), context=context, |
77 | account=acc_cur) |
78 | currency_id = st.currency.id |
79 | - |
80 | + |
81 | account_move_line_obj.create(cr, uid, { |
82 | 'name': move.name, |
83 | 'date': move.date, |
84 | @@ -964,10 +1000,10 @@ |
85 | 'currency_id': currency_id, |
86 | }, context=context) |
87 | |
88 | + |
89 | account_move_line_obj.write(cr, uid, [x.id for x in |
90 | account_move_obj.browse(cr, uid, move_id, |
91 | context=context).line_id], {'statement_id': st.id,}) |
92 | - |
93 | for line in account_move_line_obj.browse(cr, uid, [x.id for x in |
94 | account_move_obj.browse(cr, uid, move_id, |
95 | context=context).line_id], |
96 | @@ -976,6 +1012,7 @@ |
97 | if line.state <> 'valid': |
98 | raise osv.except_osv(_('Error !'), |
99 | _('Account move line "%s" is not valid') % line.name) |
100 | + |
101 | if move.reconcile_id and move.reconcile_id.line_ids: |
102 | torec += map(lambda x: x.id, move.reconcile_id.line_ids) |
103 | #try: |
104 | @@ -998,7 +1035,13 @@ |
105 | #### to write the balace value in the ending balance |
106 | balance_end_value = 0.0 |
107 | balance_start_value = self.browse(cr, uid, st.id, context=context).balance_start |
108 | + |
109 | + if st.currency.id <> company_currency_id: |
110 | + new_end_value = res_currency_obj.compute(cr, uid, company_currency_id, st.currency.id, |
111 | + new_end_value, context=context, |
112 | + account=acc_cur) |
113 | balance_end_value = balance_start_value + new_end_value |
114 | + |
115 | self.write(cr, uid, done, {'state':'confirm','balance_end_real':balance_end_value}, context=context) |
116 | |
117 | return True |
118 | @@ -1012,6 +1055,9 @@ |
119 | 'tax_type': fields.selection([('tax_included','Tax included'), |
120 | ('tax_excluded','Tax excluded')], |
121 | 'Tax method', required=True,), |
122 | + 'cash_discount': fields.float('Cash Discount'), |
123 | + 'transferred_amount': fields.float('Transferred'), |
124 | + |
125 | } |
126 | |
127 | def onchange_account_id(self, cr, uid, ids, account_id, context=None): |
128 | @@ -1026,7 +1072,13 @@ |
129 | result['tax_id'] = False |
130 | |
131 | return {'value': result} |
132 | + |
133 | + def onchange_cash_discount(self, cr, uid, ids, amount, cash_discount, context=None): |
134 | + return {'value': {'transferred_amount': amount - cash_discount}} |
135 | |
136 | + def onchange_transferred_amount(self, cr, uid, ids, amount, transferred_amount, context=None): |
137 | + return {'value': {'cash_discount': amount - transferred_amount}} |
138 | + |
139 | def onchange_type(self, cr, uid, ids, type, context=None): |
140 | result={} |
141 | tax_id = self.pool.get('account.tax').search(cr, uid, []) |
142 | |
143 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml' |
144 | --- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-08-11 12:51:31 +0000 |
145 | +++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-09-24 09:43:39 +0000 |
146 | @@ -46,27 +46,27 @@ |
147 | </field> |
148 | </record> |
149 | |
150 | - <record id="bank_statement_form_view1" model="ir.ui.view"> |
151 | + <record id="bank_statement_form_view1" model="ir.ui.view"> |
152 | <field name="name">account.bank.statement.form</field> |
153 | <field name="model">account.bank.statement</field> |
154 | <field name="type">form</field> |
155 | <field name="inherit_id" ref="account.view_bank_statement_form"/> |
156 | <field name="arch" type="xml"> |
157 | - <xpath expr="//button[@string='Import Invoice']" position="replace"> |
158 | + <xpath expr="//button[@string='Import Invoice']" position="replace"> |
159 | <button name="%(wizard_populate_statement_from_inv1)d" type="action" string="Import Invoice" attrs="{'invisible':[('state','=','confirm')]}"/> |
160 | - </xpath> |
161 | + </xpath> |
162 | </field> |
163 | </record> |
164 | |
165 | - <record id="bank_statement_reconcile_form_view1" model="ir.ui.view"> |
166 | + <record id="bank_statement_reconcile_form_view1" model="ir.ui.view"> |
167 | <field name="name">account.bank.statement.reconcile.form</field> |
168 | <field name="model">account.bank.statement.reconcile</field> |
169 | <field name="type">form</field> |
170 | <field name="inherit_id" ref="account.view_bank_statement_reconcile"/> |
171 | <field name="arch" type="xml"> |
172 | - <field name="total_new" position="replace"> |
173 | - <field name="total_new" string="Total Write Off / Cash Discount"/> |
174 | - </field> |
175 | + <field name="total_new" position="replace"> |
176 | + <field name="total_new" string="Total Write Off / Cash Discount"/> |
177 | + </field> |
178 | </field> |
179 | </record> |
180 | |
181 | @@ -92,13 +92,13 @@ |
182 | <field name="type">form</field> |
183 | <field name="inherit_id" ref="account.view_bank_statement_reconcile"/> |
184 | <field name="arch" type="xml"> |
185 | - <xpath expr="//tree[@string='Write-Off']" position="replace"> |
186 | - <tree editable="bottom" string="Write-Off and Cash-Discount"> |
187 | + <xpath expr="//tree[@string='Write-Off']" position="replace"> |
188 | + <tree editable="bottom" string="Write-Off and Cash-Discount"> |
189 | <field name="account_id" domain="[('type','<>','view'),('type','<>','consolidation')]"/> |
190 | <field name="amount"/> |
191 | <field name="name"/> |
192 | </tree> |
193 | - </xpath> |
194 | + </xpath> |
195 | </field> |
196 | </record> |
197 | |
198 | @@ -108,10 +108,10 @@ |
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 | - <field name="compl_cash_discount"/> |
204 | - <field name="day_tolerance" required="1" /> |
205 | - </field> |
206 | + <field name="days2" position="after"> |
207 | + <field name="compl_cash_discount"/> |
208 | + <field name="day_tolerance" required="1" /> |
209 | + </field> |
210 | </field> |
211 | </record> |
212 | |
213 | @@ -143,25 +143,25 @@ |
214 | </group> |
215 | </form> |
216 | </field> |
217 | - </record> |
218 | + </record> |
219 | |
220 | - <record id="action_res_company_wizard" model="ir.actions.act_window"> |
221 | + <record id="action_res_company_wizard" model="ir.actions.act_window"> |
222 | <field name="name">Account set in Company</field> |
223 | <field name="type">ir.actions.act_window</field> |
224 | <field name="res_model">res.company.wizard</field> |
225 | <field name="view_type">form</field> |
226 | <field name="view_mode">form</field> |
227 | <field name="target">new</field> |
228 | - </record> |
229 | + </record> |
230 | |
231 | - <record id="config_wizard_res_company_wizard" model="ir.actions.todo"> |
232 | + <record id="config_wizard_res_company_wizard" model="ir.actions.todo"> |
233 | <field name="name">Account set in Company</field> |
234 | <field name="note">This Configuration step use to set default Account</field> |
235 | <field name="action_id" ref="action_res_company_wizard"/> |
236 | - </record> |
237 | - |
238 | - |
239 | - <record model="ir.ui.view" id="view_bank_statement_reconcile_view122"> |
240 | + </record> |
241 | + |
242 | + |
243 | + <record model="ir.ui.view" id="view_bank_statement_reconcile_view122"> |
244 | <field name="name">account.bank.statement.reconcile.form</field> |
245 | <field name="model">account.bank.statement.reconcile</field> |
246 | <field name="inherit_id" ref="account.view_bank_statement_reconcile" /> |
247 | @@ -173,7 +173,7 @@ |
248 | </field> |
249 | </record> |
250 | |
251 | - <record id="view_move_line_tree1" model="ir.ui.view"> |
252 | + <record id="view_move_line_tree1" model="ir.ui.view"> |
253 | <field name="name">account.move.line.tree</field> |
254 | <field name="model">account.move.line</field> |
255 | <field name="type">tree</field> |
256 | @@ -194,7 +194,7 @@ |
257 | <field name="type">form</field> |
258 | <field name="arch" type="xml"> |
259 | <field name="account_id" position="replace"> |
260 | - <field name="account_id" on_change="onchange_account_id(account_id)"/> |
261 | + <field name="account_id" on_change="onchange_account_id(account_id)"/> |
262 | </field> |
263 | </field> |
264 | </record> |
265 | @@ -236,6 +236,32 @@ |
266 | </field> |
267 | </field> |
268 | </record> |
269 | + |
270 | + <record model="ir.ui.view" id="view_bank_statement_tax_tree1"> |
271 | + <field name="name">account.bank.statement.tree1</field> |
272 | + <field name="model">account.bank.statement</field> |
273 | + <field name="inherit_id" ref="account.view_bank_statement_form"/> |
274 | + <field name="type">form</field> |
275 | + <field name="arch" type="xml"> |
276 | + <xpath expr="//field[@name='line_ids']/tree/field[@name='amount']" position="after"> |
277 | + <field name="cash_discount" on_change="onchange_cash_discount(amount,cash_discount)"/> |
278 | + <field name="transferred_amount" on_change="onchange_transferred_amount(amount,transferred_amount)"/> |
279 | + </xpath> |
280 | + </field> |
281 | + </record> |
282 | |
283 | + <record model="ir.ui.view" id="view_bank_statement_tax_form1"> |
284 | + <field name="name">account.bank.statement.form1</field> |
285 | + <field name="model">account.bank.statement</field> |
286 | + <field name="inherit_id" ref="account.view_bank_statement_form"/> |
287 | + <field name="type">form</field> |
288 | + <field name="arch" type="xml"> |
289 | + <xpath expr="//field[@name='line_ids']/form/field[@name='amount']" position="after"> |
290 | + <field name="cash_discount" on_change="onchange_cash_discount(amount,cash_discount)"/> |
291 | + <field name="transferred_amount" on_change="onchange_transferred_amount(amount,transferred_amount)"/> |
292 | + </xpath> |
293 | + </field> |
294 | + </record> |
295 | + |
296 | </data> |
297 | </openerp> |
298 | |
299 | === modified file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py' |
300 | --- account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-09-21 12:22:46 +0000 |
301 | +++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-09-24 09:43:39 +0000 |
302 | @@ -115,7 +115,9 @@ |
303 | obj_inv = pool.get('account.invoice') |
304 | tax_obj = pool.get('account.tax') |
305 | invoice_tax_obj = pool.get("account.invoice.tax") |
306 | - |
307 | + |
308 | + discount = 0.0 |
309 | + |
310 | statement = statement_obj.browse(cursor, user, data['id'], context=context) |
311 | # for each selected move lines |
312 | for line in line_obj.browse(cursor, user, line_ids, context=context): |
313 | @@ -230,6 +232,8 @@ |
314 | 'ref': line.ref, |
315 | 'reconcile_id': reconcile_id, |
316 | 'date':line_date, #time.strftime('%Y-%m-%d'), #line.date_maturity or, |
317 | + 'cash_discount': discount, |
318 | + 'transferred_amount': cal_invoice_amount - discount, |
319 | }, context=context) |
320 | return {} |
321 |