Merge lp:~openbig/bigconsulting/milestone1 into lp:bigconsulting
- milestone1
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Superseded |
---|---|
Proposed branch: | lp:~openbig/bigconsulting/milestone1 |
Merge into: | lp:bigconsulting |
Diff against target: |
955 lines (+453/-241) 5 files modified
account_invoice_cash_discount/__terp__.py (+1/-1) account_invoice_cash_discount/account_invoice_cash_discount.py (+59/-54) account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+16/-0) account_invoice_cash_discount/wizard/account_pay_invoice.py (+323/-180) account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+54/-6) |
To merge this branch: | bzr merge lp:~openbig/bigconsulting/milestone1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+30379@code.launchpad.net |
This proposal has been superseded by a proposal from 2010-07-27.
Commit message
Description of the change
Improvement in milestone1
To post a comment you must log in.
- 52. By gpa(OpenERP)
-
added message in the milestone1 on partial payment and full paymentn
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'account_invoice_cash_discount/__terp__.py' | |||
2 | --- account_invoice_cash_discount/__terp__.py 2010-06-30 07:25:25 +0000 | |||
3 | +++ account_invoice_cash_discount/__terp__.py 2010-07-27 09:11:48 +0000 | |||
4 | @@ -20,7 +20,7 @@ | |||
5 | 20 | # | 20 | # |
6 | 21 | ############################################################################## | 21 | ############################################################################## |
7 | 22 | { | 22 | { |
9 | 23 | "name" : "Payement Term with Cash Discount", | 23 | "name" : "Payment Term with Cash Discount", |
10 | 24 | "version" : "1.0", | 24 | "version" : "1.0", |
11 | 25 | "depends" : ["account",], | 25 | "depends" : ["account",], |
12 | 26 | "author" : "Big Consulting", | 26 | "author" : "Big Consulting", |
13 | 27 | 27 | ||
14 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py' | |||
15 | --- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-23 11:30:07 +0000 | |||
16 | +++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-27 09:11:48 +0000 | |||
17 | @@ -45,8 +45,6 @@ | |||
18 | 45 | 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'), | 45 | 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'), |
19 | 46 | 'credit_account_id': fields.many2one('account.account', 'Credit Account'), | 46 | 'credit_account_id': fields.many2one('account.account', 'Credit Account'), |
20 | 47 | 'debit_account_id': fields.many2one('account.account', 'Debit Account'), | 47 | 'debit_account_id': fields.many2one('account.account', 'Debit Account'), |
21 | 48 | # 'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'), | ||
22 | 49 | # 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True), | ||
23 | 50 | 'sup_discount_account_id': fields.many2one('account.account', 'Supplier Discount Account',required=True), | 48 | 'sup_discount_account_id': fields.many2one('account.account', 'Supplier Discount Account',required=True), |
24 | 51 | } | 49 | } |
25 | 52 | account_cash_discount() | 50 | account_cash_discount() |
26 | @@ -54,7 +52,6 @@ | |||
27 | 54 | class account_payment_term_line(osv.osv): | 52 | class account_payment_term_line(osv.osv): |
28 | 55 | _inherit = "account.payment.term.line" | 53 | _inherit = "account.payment.term.line" |
29 | 56 | _columns = { | 54 | _columns = { |
30 | 57 | # 'cash_account_discount_id': fields.many2one('account.cash.discount', 'Discount Lines',), | ||
31 | 58 | 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True), | 55 | 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True), |
32 | 59 | 'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=False, select=True), | 56 | 'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=False, select=True), |
33 | 60 | 'compl_cash_discount':fields.boolean('Use Complete Cash Discount'), | 57 | 'compl_cash_discount':fields.boolean('Use Complete Cash Discount'), |
34 | @@ -115,6 +112,8 @@ | |||
35 | 115 | res = resudial_amonut | 112 | res = resudial_amonut |
36 | 116 | amount = res | 113 | amount = res |
37 | 117 | dis = payment_line.days | 114 | dis = payment_line.days |
38 | 115 | else: | ||
39 | 116 | amount = resudial_amonut | ||
40 | 118 | 117 | ||
41 | 119 | return {'amount':amount,'tol_days':tol_days,'found':payment_line_found} | 118 | return {'amount':amount,'tol_days':tol_days,'found':payment_line_found} |
42 | 120 | 119 | ||
43 | @@ -223,6 +222,7 @@ | |||
44 | 223 | invoice_tax_obj = self.pool.get("account.invoice.tax") | 222 | invoice_tax_obj = self.pool.get("account.invoice.tax") |
45 | 224 | move_line_obj = self.pool.get('account.move.line') | 223 | move_line_obj = self.pool.get('account.move.line') |
46 | 225 | move_obj = self.pool.get('account.move') | 224 | move_obj = self.pool.get('account.move') |
47 | 225 | move_line_obj_memory = self.pool.get('account.move.line.memory') | ||
48 | 226 | 226 | ||
49 | 227 | amount_discount = 0.0 | 227 | amount_discount = 0.0 |
50 | 228 | if invoice.payment_term: | 228 | if invoice.payment_term: |
51 | @@ -298,23 +298,21 @@ | |||
52 | 298 | if 'tax_move_ids' in context and context['tax_move_ids']: | 298 | if 'tax_move_ids' in context and context['tax_move_ids']: |
53 | 299 | move_line = context['tax_move_ids'] | 299 | move_line = context['tax_move_ids'] |
54 | 300 | for move_line_id in move_line: | 300 | for move_line_id in move_line: |
56 | 301 | move_line_data = move_line_obj.browse(cr, uid,move_line_id) | 301 | move_line_data = move_line_obj_memory.browse(cr, uid,move_line_id) |
57 | 302 | l3 = { | 302 | l3 = { |
58 | 303 | 'debit': move_line_data.debit, | 303 | 'debit': move_line_data.debit, |
59 | 304 | 'credit': move_line_data.credit, | 304 | 'credit': move_line_data.credit, |
60 | 305 | 'account_id': move_line_data.account_id.id, | 305 | 'account_id': move_line_data.account_id.id, |
63 | 306 | 'partner_id': move_line_data.partner_id.id, | 306 | 'partner_id': invoice.partner_id.id, |
64 | 307 | 'ref':move_line_data.ref, | 307 | 'ref':ref, |
65 | 308 | 'date': move_line_data.date, | 308 | 'date': move_line_data.date, |
68 | 309 | 'currency_id':currency_id, | 309 | 'currency_id':move_line_data.currency_id.id, |
69 | 310 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | 310 | 'amount_currency':move_line_data.amount_currency and direction * move_line_data.amount_currency or 0.0, |
70 | 311 | 'name':move_line_data.name, | 311 | 'name':move_line_data.name, |
71 | 312 | 'tax_code_id':move_line_data.tax_code_id.id, | 312 | 'tax_code_id':move_line_data.tax_code_id.id, |
72 | 313 | 'tax_amount':move_line_data.tax_amount, | 313 | 'tax_amount':move_line_data.tax_amount, |
73 | 314 | } | 314 | } |
74 | 315 | lines.append((0, 0, l3)) | 315 | lines.append((0, 0, l3)) |
75 | 316 | move_line_obj.unlink(cr, uid,[move_line_id]) | ||
76 | 317 | move_obj.unlink(cr, uid,[move_line_data.move_id.id]) | ||
77 | 318 | else: | 316 | else: |
78 | 319 | if amount_discount>0.0: | 317 | if amount_discount>0.0: |
79 | 320 | for line in invoice.invoice_line: | 318 | for line in invoice.invoice_line: |
80 | @@ -345,44 +343,60 @@ | |||
81 | 345 | if 'discount_move_ids' in context and context['discount_move_ids']: | 343 | if 'discount_move_ids' in context and context['discount_move_ids']: |
82 | 346 | move_line = context['discount_move_ids'] | 344 | move_line = context['discount_move_ids'] |
83 | 347 | for move_line_id in move_line: | 345 | for move_line_id in move_line: |
85 | 348 | move_line_data = move_line_obj.browse(cr, uid,move_line_id) | 346 | move_line_data = move_line_obj_memory.browse(cr, uid, move_line_id) |
86 | 349 | l4 = { | 347 | l4 = { |
87 | 350 | 'debit': move_line_data.debit, | 348 | 'debit': move_line_data.debit, |
88 | 351 | 'credit':move_line_data.credit, | 349 | 'credit':move_line_data.credit, |
89 | 352 | 'account_id': move_line_data.account_id.id, | 350 | 'account_id': move_line_data.account_id.id, |
92 | 353 | 'partner_id': move_line_data.partner_id.id, | 351 | 'partner_id': invoice.partner_id.id, |
93 | 354 | 'ref':move_line_data.ref, | 352 | 'ref':ref, |
94 | 355 | 'date': move_line_data.date, | 353 | 'date': move_line_data.date, |
97 | 356 | 'currency_id':currency_id, | 354 | 'currency_id':move_line_data.currency_id.id, |
98 | 357 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | 355 | 'amount_currency':move_line_data.amount_currency and direction * move_line_data.amount_currency or 0.0, |
99 | 358 | 'name':move_line_data.name, | 356 | 'name':move_line_data.name, |
100 | 359 | 'tax_code_id':move_line_data.tax_code_id.id, | 357 | 'tax_code_id':move_line_data.tax_code_id.id, |
101 | 360 | 'tax_amount':move_line_data.tax_amount, | 358 | 'tax_amount':move_line_data.tax_amount, |
102 | 361 | } | 359 | } |
103 | 362 | lines.append((0, 0, l4)) | 360 | lines.append((0, 0, l4)) |
106 | 363 | move_line_obj.unlink(cr, uid,[move_line_id]) | 361 | |
105 | 364 | move_obj.unlink(cr, uid,[move_line_data.move_id.id]) | ||
107 | 365 | else: | 362 | else: |
108 | 366 | if amount_discount>0: | 363 | if amount_discount>0: |
109 | 364 | account_id = False | ||
110 | 367 | if 'account_id' in context and context['account_id']: | 365 | if 'account_id' in context and context['account_id']: |
129 | 368 | account_id = context['account_id'] | 366 | account_id = context['account_id'] |
130 | 369 | if tax_total_amount>0: | 367 | # if tax_total_amount>0: |
131 | 370 | amount_discount = (amount_discount - tax_total_amount) | 368 | # amount_discount = (amount_discount - tax_total_amount) |
132 | 371 | else: | 369 | # else: |
133 | 372 | amount_discount = amount_discount | 370 | # amount_discount = amount_discount |
134 | 373 | l4 = { | 371 | for line in invoice.invoice_line: |
135 | 374 | 'debit': direction * amount_discount<0 and - direction * amount_discount, | 372 | line_tax_amount = 0.0 |
136 | 375 | 'credit': direction * amount_discount>0 and direction * amount_discount, | 373 | tax_amount = 0.0 |
137 | 376 | 'account_id': account_id, | 374 | discount = 0.0 |
138 | 377 | 'partner_id': invoice.partner_id.id, | 375 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
139 | 378 | 'ref':ref, | 376 | line_tax_amount = tax['amount'] |
140 | 379 | 'date': date, | 377 | |
141 | 380 | 'currency_id':currency_id, | 378 | line_total = line.price_subtotal + line_tax_amount |
142 | 381 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | 379 | invoice_res_amount = invoice.amount_total |
143 | 382 | } | 380 | line_ratio = line_total / invoice_res_amount |
144 | 383 | l4['name'] = name | 381 | |
145 | 384 | lines.append((0, 0, l4)) | 382 | discount = amount_discount * line_ratio |
146 | 385 | 383 | ||
147 | 384 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, amount_discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | ||
148 | 385 | tax_amount = tax['amount'] | ||
149 | 386 | |||
150 | 387 | l4 = { | ||
151 | 388 | 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), | ||
152 | 389 | 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), | ||
153 | 390 | 'account_id': account_id, | ||
154 | 391 | 'partner_id': invoice.partner_id.id, | ||
155 | 392 | 'ref':ref, | ||
156 | 393 | 'date': date, | ||
157 | 394 | 'currency_id':currency_id, | ||
158 | 395 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | ||
159 | 396 | } | ||
160 | 397 | l4['name'] = name | ||
161 | 398 | lines.append((0, 0, l4)) | ||
162 | 399 | |||
163 | 386 | move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date} | 400 | move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date} |
164 | 387 | move_id = move_obj.create(cr, uid, move, context=context) | 401 | move_id = move_obj.create(cr, uid, move, context=context) |
165 | 388 | 402 | ||
166 | @@ -407,25 +421,16 @@ | |||
167 | 407 | 421 | ||
168 | 408 | account_invoice() | 422 | account_invoice() |
169 | 409 | 423 | ||
189 | 410 | class account_move_line(osv.osv): | 424 | class account_bank_statement_reconcile(osv.osv): |
190 | 411 | _name = 'account.move.line' | 425 | _inherit='account.bank.statement.reconcile' |
191 | 412 | _inherit = 'account.move.line' | 426 | def name_get(self, cursor, user, ids, context=None): |
192 | 413 | 427 | res = [] | |
193 | 414 | def _invoice(self, cr, uid, ids, name, arg, context=None): | 428 | res = super(account_bank_statement_reconcile, self).name_get(cursor, user, ids, context) |
194 | 415 | res = {} | 429 | for o in self.browse(cursor, user, ids, context=context): |
195 | 416 | if ids: | 430 | data = res[0][1] + o.name |
196 | 417 | return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context) | 431 | res.append((o.id,data)) |
197 | 418 | else: | 432 | return res |
198 | 419 | return res | 433 | account_bank_statement_reconcile() |
180 | 420 | |||
181 | 421 | def _invoice_search(self, cr, uid, obj, name, args, context={}): | ||
182 | 422 | return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context) | ||
183 | 423 | |||
184 | 424 | _columns = { | ||
185 | 425 | 'invoice': fields.function(_invoice, method=True, string='Invoice', | ||
186 | 426 | type='many2one', relation='account.invoice', fnct_search=_invoice_search), | ||
187 | 427 | } | ||
188 | 428 | account_move_line() | ||
199 | 429 | 434 | ||
200 | 430 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | 435 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
201 | 431 | 436 | ||
202 | 432 | 437 | ||
203 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml' | |||
204 | --- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-08-23 12:13:39 +0000 | |||
205 | +++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-27 09:11:48 +0000 | |||
206 | @@ -72,6 +72,22 @@ | |||
207 | 72 | </field> | 72 | </field> |
208 | 73 | </record> | 73 | </record> |
209 | 74 | 74 | ||
210 | 75 | <record id="view_bank_statement_reconcile_tree" model="ir.ui.view"> | ||
211 | 76 | <field name="name">account.bank.statement.reconcile.tree</field> | ||
212 | 77 | <field name="model">account.bank.statement.reconcile</field> | ||
213 | 78 | <field name="type">tree</field> | ||
214 | 79 | <field name="arch" type="xml"> | ||
215 | 80 | <tree string="Reconcile"> | ||
216 | 81 | <field name="name" select="1"/> | ||
217 | 82 | <field name="total_amount"/> | ||
218 | 83 | <field name="total_currency"/> | ||
219 | 84 | <field name="total_entry"/> | ||
220 | 85 | <field name="total_new"/> | ||
221 | 86 | <field name="total_balance"/> | ||
222 | 87 | </tree> | ||
223 | 88 | </field> | ||
224 | 89 | </record> | ||
225 | 90 | |||
226 | 75 | <record id="bank_statement_reconcile_form_view2" model="ir.ui.view"> | 91 | <record id="bank_statement_reconcile_form_view2" model="ir.ui.view"> |
227 | 76 | <field name="name">account.bank.statement.reconcile.form</field> | 92 | <field name="name">account.bank.statement.reconcile.form</field> |
228 | 77 | <field name="model">account.bank.statement.reconcile</field> | 93 | <field name="model">account.bank.statement.reconcile</field> |
229 | 78 | 94 | ||
230 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py' | |||
231 | --- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-23 11:30:07 +0000 | |||
232 | +++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-27 09:11:48 +0000 | |||
233 | @@ -66,8 +66,8 @@ | |||
234 | 66 | 'cal_method_selection': fields.selection([('method_gross_methodology','Calculate Discount with Net Gross Methodology'), | 66 | 'cal_method_selection': fields.selection([('method_gross_methodology','Calculate Discount with Net Gross Methodology'), |
235 | 67 | ('method_net_methodology','Calculate Discount with Net Methodology'),], | 67 | ('method_net_methodology','Calculate Discount with Net Methodology'),], |
236 | 68 | 'Method To Calculation'), | 68 | 'Method To Calculation'), |
239 | 69 | 'discount_move_ids': fields.many2many('account.move.line', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'), | 69 | 'discount_move_ids': fields.many2many('account.move.line.memory', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'), |
240 | 70 | 'tax_move_ids': fields.many2many('account.move.line', 'account_tax_move_rel', 'tax_account_id', 'tax_move_id', 'Account Taxes Moves'), | 70 | 'tax_move_ids': fields.many2many('account.move.line.memory', 'account_tax_move_rel', 'tax_account_id', 'tax_move_id', 'Account Taxes Moves'), |
241 | 71 | } | 71 | } |
242 | 72 | 72 | ||
243 | 73 | def _get_period(self, cr, uid, context=None): | 73 | def _get_period(self, cr, uid, context=None): |
244 | @@ -111,6 +111,135 @@ | |||
245 | 111 | account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account) | 111 | account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account) |
246 | 112 | return account | 112 | return account |
247 | 113 | 113 | ||
248 | 114 | def _get_discount_move(self, cr, uid, context=None): | ||
249 | 115 | |||
250 | 116 | cur_obj = self.pool.get('res.currency') | ||
251 | 117 | invoice_obj = self.pool.get('account.invoice') | ||
252 | 118 | |||
253 | 119 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) | ||
254 | 120 | tax_obj = self.pool.get('account.tax') | ||
255 | 121 | invoice_tax_obj = self.pool.get("account.invoice.tax") | ||
256 | 122 | move_line_obj_memory = self.pool.get('account.move.line.memory') | ||
257 | 123 | |||
258 | 124 | #### to get direction | ||
259 | 125 | types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} | ||
260 | 126 | direction = types[invoice.type] | ||
261 | 127 | date=time.strftime('%Y-%m-%d') | ||
262 | 128 | |||
263 | 129 | #### to get name | ||
264 | 130 | name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number | ||
265 | 131 | ##### Entry in the discount account moves and entry in the tax account moves | ||
266 | 132 | |||
267 | 133 | amount = 0.0 | ||
268 | 134 | discount = 0.0 | ||
269 | 135 | discount_line_ids = [] | ||
270 | 136 | discount_account_id = False | ||
271 | 137 | base_code_id = False | ||
272 | 138 | |||
273 | 139 | discount = self._get_discount(cr, uid, context=context) | ||
274 | 140 | discount_account_id = self._get_account(cr, uid, context=context) | ||
275 | 141 | if discount>0.0: | ||
276 | 142 | for line in invoice.invoice_line: | ||
277 | 143 | tax_amount = 0.0 | ||
278 | 144 | line_tax_amount = 0.0 | ||
279 | 145 | |||
280 | 146 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | ||
281 | 147 | line_tax_amount = tax['amount'] | ||
282 | 148 | |||
283 | 149 | line_total = line.price_subtotal + line_tax_amount | ||
284 | 150 | invoice_res_amount = invoice.amount_total | ||
285 | 151 | line_ratio = line_total / invoice_res_amount | ||
286 | 152 | |||
287 | 153 | if line.invoice_line_tax_id: | ||
288 | 154 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | ||
289 | 155 | tax_amount = tax['amount'] | ||
290 | 156 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | ||
291 | 157 | for tax_id in tax_invoice_id: | ||
292 | 158 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | ||
293 | 159 | tax_account_id = tax_value.account_id.id | ||
294 | 160 | base_code_id = tax_value.base_code_id.id | ||
295 | 161 | |||
296 | 162 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | ||
297 | 163 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | ||
298 | 164 | |||
299 | 165 | discount_pay = discount * line_ratio | ||
300 | 166 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | ||
301 | 167 | discount_amount = discount - tax_amount | ||
302 | 168 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) | ||
303 | 169 | |||
304 | 170 | l4 = { | ||
305 | 171 | 'debit': direction * (discount_pay - tax_amount)<0 and - direction * (discount_pay - tax_amount), | ||
306 | 172 | 'credit': direction * (discount_pay - tax_amount)>0 and direction * (discount_pay - tax_amount), | ||
307 | 173 | 'account_id': discount_account_id, | ||
308 | 174 | 'date': date, | ||
309 | 175 | 'name':name, | ||
310 | 176 | 'currency_id':invoice.currency_id.id or False, | ||
311 | 177 | 'journal_id':invoice.journal_id.id, | ||
312 | 178 | 'tax_code_id':base_code_id, | ||
313 | 179 | 'tax_amount':tax_amount, | ||
314 | 180 | 'amount_currency':amount and direction * amount or 0.0, | ||
315 | 181 | 'analytic_account_id':line.account_analytic_id.id or False, | ||
316 | 182 | } | ||
317 | 183 | |||
318 | 184 | discount_line_id = move_line_obj_memory.create(cr, uid, l4, context=context) | ||
319 | 185 | discount_line_ids.append(l4) | ||
320 | 186 | return discount_line_ids | ||
321 | 187 | |||
322 | 188 | def _get_taxes_move(self, cr, uid, context=None): | ||
323 | 189 | cur_obj = self.pool.get('res.currency') | ||
324 | 190 | invoice_obj = self.pool.get('account.invoice') | ||
325 | 191 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) | ||
326 | 192 | tax_obj = self.pool.get('account.tax') | ||
327 | 193 | invoice_tax_obj = self.pool.get("account.invoice.tax") | ||
328 | 194 | move_line_obj_memory = self.pool.get('account.move.line.memory') | ||
329 | 195 | |||
330 | 196 | #### to get direction | ||
331 | 197 | types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} | ||
332 | 198 | direction = types[invoice.type] | ||
333 | 199 | date=time.strftime('%Y-%m-%d') | ||
334 | 200 | |||
335 | 201 | #### to get name | ||
336 | 202 | name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number | ||
337 | 203 | ##### Entry in the discount account moves and entry in the tax account moves | ||
338 | 204 | amount = 0.0 | ||
339 | 205 | discount = 0.0 | ||
340 | 206 | line_ids = [] | ||
341 | 207 | |||
342 | 208 | tax_code_id = False | ||
343 | 209 | discount = self._get_discount(cr, uid, context=context) | ||
344 | 210 | if discount>0.0: | ||
345 | 211 | for line in invoice.invoice_line: | ||
346 | 212 | tax_amount = 0.0 | ||
347 | 213 | line_tax_amount = 0.0 | ||
348 | 214 | if line.invoice_line_tax_id: | ||
349 | 215 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | ||
350 | 216 | tax_amount = tax['amount'] | ||
351 | 217 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | ||
352 | 218 | for tax_id in tax_invoice_id: | ||
353 | 219 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | ||
354 | 220 | tax_account_id = tax_value.account_id.id | ||
355 | 221 | tax_code_id = tax_value.tax_code_id.id | ||
356 | 222 | |||
357 | 223 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | ||
358 | 224 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | ||
359 | 225 | |||
360 | 226 | l3 = { | ||
361 | 227 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | ||
362 | 228 | 'credit': direction * tax_amount>0 and direction * tax_amount, | ||
363 | 229 | 'account_id': tax_account_id, | ||
364 | 230 | 'date': date, | ||
365 | 231 | 'journal_id':invoice.journal_id.id or False, | ||
366 | 232 | 'name':name, | ||
367 | 233 | 'currency_id':invoice.currency_id.id or False, | ||
368 | 234 | 'tax_code_id':tax_value.tax_code_id.id, | ||
369 | 235 | 'tax_amount':-tax_amount, | ||
370 | 236 | 'amount_currency':amount and direction * amount or 0.0, | ||
371 | 237 | 'analytic_account_id':line.account_analytic_id.id or False, | ||
372 | 238 | } | ||
373 | 239 | line_id = move_line_obj_memory.create(cr, uid, l3, context=context) | ||
374 | 240 | line_ids.append(l3) | ||
375 | 241 | return line_ids | ||
376 | 242 | |||
377 | 114 | _defaults = { | 243 | _defaults = { |
378 | 115 | 'date': lambda *a: time.strftime('%Y-%m-%d'), | 244 | 'date': lambda *a: time.strftime('%Y-%m-%d'), |
379 | 116 | 'period_id': _get_period, | 245 | 'period_id': _get_period, |
380 | @@ -119,9 +248,11 @@ | |||
381 | 119 | 'account_id':_get_account, | 248 | 'account_id':_get_account, |
382 | 120 | 'cash_residual_amount': lambda *a:0.0, | 249 | 'cash_residual_amount': lambda *a:0.0, |
383 | 121 | 'cal_method_selection':lambda *a :'method_gross_methodology', | 250 | 'cal_method_selection':lambda *a :'method_gross_methodology', |
384 | 251 | 'discount_move_ids':_get_discount_move, | ||
385 | 252 | 'tax_move_ids':_get_taxes_move, | ||
386 | 122 | } | 253 | } |
387 | 123 | 254 | ||
389 | 124 | def on_change_ammount(self, cr, uid, ids, amount, context=None): | 255 | def on_change_ammount(self, cr, uid, ids, amount, cash_amount, context=None): |
390 | 125 | """ | 256 | """ |
391 | 126 | Function return the Discount according to the Amount paid and Payment Term Cash Discount | 257 | Function return the Discount according to the Amount paid and Payment Term Cash Discount |
392 | 127 | """ | 258 | """ |
393 | @@ -131,10 +262,8 @@ | |||
394 | 131 | cal_amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) | 262 | cal_amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
395 | 132 | 263 | ||
396 | 133 | old_cal_amount = cal_amount['amount'] | 264 | old_cal_amount = cal_amount['amount'] |
397 | 134 | discount = obj_inv._get_payment(cr, uid, [context['id']] , old_cal_amount, invoice.payment_term.id, context=context) | ||
398 | 135 | old_amount = old_cal_amount | 265 | old_amount = old_cal_amount |
401 | 136 | diff_amount = round(old_amount - (amount + discount),2) | 266 | diff_amount = round(old_amount - (amount + cash_amount),2) |
400 | 137 | |||
402 | 138 | return {'value' : {'cash_residual_amount':diff_amount}} | 267 | return {'value' : {'cash_residual_amount':diff_amount}} |
403 | 139 | 268 | ||
404 | 140 | def on_change_cash_discount_amount(self, cr, uid, ids, discount_amount, amount, context=None): | 269 | def on_change_cash_discount_amount(self, cr, uid, ids, discount_amount, amount, context=None): |
405 | @@ -153,35 +282,13 @@ | |||
406 | 153 | return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}} | 282 | return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}} |
407 | 154 | 283 | ||
408 | 155 | def _calculation(self, cr, uid, ids, context=None): | 284 | def _calculation(self, cr, uid, ids, context=None): |
410 | 156 | 285 | cur_obj = self.pool.get('res.currency') | |
411 | 157 | invoice_obj = self.pool.get('account.invoice') | 286 | invoice_obj = self.pool.get('account.invoice') |
412 | 158 | data = self.read(cr, uid, ids,context=context)[0] | 287 | data = self.read(cr, uid, ids,context=context)[0] |
413 | 159 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) | 288 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) |
414 | 160 | tax_obj = self.pool.get('account.tax') | 289 | tax_obj = self.pool.get('account.tax') |
415 | 161 | invoice_tax_obj = self.pool.get("account.invoice.tax") | 290 | invoice_tax_obj = self.pool.get("account.invoice.tax") |
439 | 162 | move_obj = self.pool.get('account.move') | 291 | move_line_obj_memory = self.pool.get('account.move.line.memory') |
417 | 163 | move_line_obj = self.pool.get('account.move.line') | ||
418 | 164 | |||
419 | 165 | ############## Delete another lines of taxes and discount | ||
420 | 166 | if data['tax_move_ids']: | ||
421 | 167 | move_line = data['tax_move_ids'] | ||
422 | 168 | for move_line_id in move_line: | ||
423 | 169 | move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id | ||
424 | 170 | move_line_obj.unlink(cr, uid,[move_line_id]) | ||
425 | 171 | move_obj.unlink(cr, uid,[move_id]) | ||
426 | 172 | |||
427 | 173 | if data['discount_move_ids']: | ||
428 | 174 | discount_move_line = data['discount_move_ids'] | ||
429 | 175 | for move_line_id in discount_move_line: | ||
430 | 176 | move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id | ||
431 | 177 | move_line_obj.unlink(cr, uid,[move_line_id]) | ||
432 | 178 | move_obj.unlink(cr, uid,[move_id]) | ||
433 | 179 | |||
434 | 180 | ######## to get ref | ||
435 | 181 | if invoice.type in ('in_invoice', 'in_refund'): | ||
436 | 182 | ref = invoice.reference | ||
437 | 183 | else: | ||
438 | 184 | ref = invoice_obj._convert_ref(cr, uid, invoice.number) | ||
440 | 185 | 292 | ||
441 | 186 | #### to get direction | 293 | #### to get direction |
442 | 187 | types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} | 294 | types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} |
443 | @@ -192,84 +299,102 @@ | |||
444 | 192 | name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number | 299 | name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number |
445 | 193 | ##### Entry in the discount account moves and entry in the tax account moves | 300 | ##### Entry in the discount account moves and entry in the tax account moves |
446 | 194 | 301 | ||
453 | 195 | if data.get('cash_amount',0.0)>0.0: | 302 | if data.get('cash_amount', 0.0) <= 0.0: |
454 | 196 | tax_total_amount = 0.0 | 303 | return True |
455 | 197 | amount = 0.0 | 304 | |
456 | 198 | discount = 0.0 | 305 | tax_total_amount = 0.0 |
457 | 199 | line_ids = [] | 306 | amount = 0.0 |
458 | 200 | discount_line_ids = [] | 307 | discount = 0.0 |
459 | 308 | line_ids = [] | ||
460 | 309 | discount_line_ids = [] | ||
461 | 201 | 310 | ||
464 | 202 | discount_account_id = False | 311 | discount_account_id = False |
465 | 203 | tax_code_id = False | 312 | tax_code_id = False |
466 | 313 | base_code_id = False | ||
467 | 314 | |||
468 | 315 | for line in invoice.invoice_line: | ||
469 | 316 | tax_amount = 0.0 | ||
470 | 317 | line_tax_amount = 0.0 | ||
471 | 204 | 318 | ||
512 | 205 | for line in invoice.invoice_line: | 319 | #####get the ratio of the line in the total invoice amount |
513 | 206 | tax_amount = 0.0 | 320 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
514 | 207 | line_tax_amount = 0.0 | 321 | line_tax_amount = tax['amount'] |
515 | 208 | 322 | line_total = line.price_subtotal + line_tax_amount | |
516 | 209 | #####get the ratio of the line in the total invoice amount | 323 | invoice_res_amount = invoice.amount_total |
517 | 210 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | 324 | line_ratio = line_total / invoice_res_amount |
518 | 211 | line_tax_amount = tax['amount'] | 325 | ########################### |
519 | 212 | line_total = line.price_subtotal + line_tax_amount | 326 | if line.invoice_line_tax_id: |
520 | 213 | invoice_res_amount = invoice.amount_total | 327 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, data['cash_amount'], line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
521 | 214 | line_ratio = line_total / invoice_res_amount | 328 | tax_amount = tax['amount'] |
522 | 215 | ########################### | 329 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
523 | 216 | 330 | for tax_id in tax_invoice_id: | |
524 | 217 | if line.invoice_line_tax_id: | 331 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
525 | 218 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, data['cash_amount'], line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | 332 | tax_account_id = tax_value.account_id.id |
526 | 219 | tax_amount = tax['amount'] | 333 | tax_code_id = tax_value.tax_code_id.id |
527 | 220 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 334 | base_code_id = tax_value.base_code_id.id |
528 | 221 | for tax_id in tax_invoice_id: | 335 | |
529 | 222 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 336 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
530 | 223 | tax_account_id = tax_value.account_id.id | 337 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
531 | 224 | tax_code_id = tax_value.tax_code_id.id | 338 | |
532 | 225 | 339 | l3 = { | |
533 | 226 | l3 = { | 340 | 'debit': direction * tax_amount<0 and - direction * tax_amount, |
534 | 227 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | 341 | 'credit': direction * tax_amount>0 and direction * tax_amount, |
535 | 228 | 'credit': direction * tax_amount>0 and direction * tax_amount, | 342 | 'account_id': tax_account_id, |
536 | 229 | 'account_id': tax_account_id, | 343 | 'date': date, |
537 | 230 | 'partner_id': invoice.partner_id.id, | 344 | 'journal_id':data.get('journal_id',False) , |
538 | 231 | 'ref':ref, | 345 | 'name':name, |
539 | 232 | 'date': date, | 346 | 'currency_id':invoice.currency_id.id or False, |
540 | 233 | 'journal_id':data.get('journal_id',False) , | 347 | 'tax_code_id':tax_value.tax_code_id.id, |
541 | 234 | 'period_id':data.get('period_id',False), | 348 | 'tax_amount':-tax_amount, |
542 | 235 | 'name':name, | 349 | 'amount_currency':amount and direction * amount or 0.0, |
543 | 236 | 'tax_code_id':tax_value.tax_code_id.id, | 350 | 'analytic_account_id':line.account_analytic_id.id or False, |
544 | 237 | 'tax_amount':-tax_amount, | 351 | } |
545 | 238 | } | 352 | line_id = move_line_obj_memory.create(cr, uid, l3, context=context) |
546 | 239 | line_id = move_line_obj.create(cr, uid, l3, context=context) | 353 | line_ids.append(line_id) |
547 | 240 | line_ids.append(line_id) | 354 | |
548 | 241 | 355 | ### if calculation on the Net Methology then in discount field it will take product income account or product category income account | |
549 | 242 | ### if calculation on the Net Methology then in discount field it will take product income account or product category income account | 356 | if data['cal_method_selection'] == 'method_net_methodology': |
550 | 243 | 357 | if invoice.type == 'in_invoice': | |
511 | 244 | if data['cal_method_selection'] == 'method_net_methodology': | ||
551 | 245 | if line.product_id.property_account_income: | 358 | if line.product_id.property_account_income: |
552 | 246 | discount_account_id = line.product_id.property_account_income.id | 359 | discount_account_id = line.product_id.property_account_income.id |
553 | 247 | else: | 360 | else: |
554 | 248 | discount_account_id = line.product_id.categ_id.property_account_income_categ.id | 361 | discount_account_id = line.product_id.categ_id.property_account_income_categ.id |
555 | 249 | else: | 362 | else: |
579 | 250 | discount_account_id = data['account_id'] | 363 | if line.product_id.property_account_income: |
580 | 251 | 364 | discount_account_id = line.product_id.property_account_expense.id | |
581 | 252 | discount = data['cash_amount'] * line_ratio | 365 | else: |
582 | 253 | l4 = { | 366 | discount_account_id = line.product_id.categ_id.property_account_expense_categ.id |
583 | 254 | 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), | 367 | |
584 | 255 | 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), | 368 | else: |
585 | 256 | 'account_id': discount_account_id, | 369 | discount_account_id = data['account_id'] |
586 | 257 | 'partner_id': invoice.partner_id.id, | 370 | |
587 | 258 | 'ref':ref, | 371 | discount = data['cash_amount'] * line_ratio |
588 | 259 | 'date': date, | 372 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
589 | 260 | 'name':name, | 373 | discount_amount = discount - tax_amount |
590 | 261 | 'journal_id':data.get('journal_id',False), | 374 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
591 | 262 | 'period_id':data.get('period_id',False), | 375 | |
592 | 263 | 'tax_code_id':tax_code_id, | 376 | l4 = { |
593 | 264 | 'tax_amount':-tax_amount, | 377 | 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), |
594 | 265 | } | 378 | 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), |
595 | 266 | 379 | 'account_id': discount_account_id, | |
596 | 267 | discount_line_id = move_line_obj.create(cr, uid, l4, context=context) | 380 | 'date': date, |
597 | 268 | discount_line_ids.append(discount_line_id) | 381 | 'name':name, |
598 | 269 | 382 | 'currency_id':invoice.currency_id.id or False, | |
599 | 270 | self.write(cr, uid, ids, {'tax_move_ids':[(6,0,line_ids)]}, context) | 383 | 'journal_id':data.get('journal_id',False), |
600 | 271 | self.write(cr, uid, ids, {'discount_move_ids':[(6,0,discount_line_ids)]}, context) | 384 | 'tax_code_id':base_code_id, |
601 | 272 | 385 | 'tax_amount':tax_amount, | |
602 | 386 | 'amount_currency':amount and direction * amount or 0.0, | ||
603 | 387 | 'analytic_account_id':line.account_analytic_id.id or False, | ||
604 | 388 | } | ||
605 | 389 | |||
606 | 390 | discount_line_id = move_line_obj_memory.create(cr, uid, l4, context=context) | ||
607 | 391 | discount_line_ids.append(discount_line_id) | ||
608 | 392 | |||
609 | 393 | self.write(cr, uid, ids, | ||
610 | 394 | {'tax_move_ids':[(6,0,line_ids)], | ||
611 | 395 | 'discount_move_ids' : [(6, 0, discount_line_ids)], | ||
612 | 396 | }, context=context) | ||
613 | 397 | |||
614 | 273 | return True | 398 | return True |
615 | 274 | 399 | ||
616 | 275 | def default_get(self, cr, uid, fields, context=None): | 400 | def default_get(self, cr, uid, fields, context=None): |
617 | @@ -282,35 +407,79 @@ | |||
618 | 282 | def _message(self, cr, uid, ids, context=None): | 407 | def _message(self, cr, uid, ids, context=None): |
619 | 283 | mod_obj = self.pool.get('ir.model.data') | 408 | mod_obj = self.pool.get('ir.model.data') |
620 | 284 | data = self.read(cr, uid, ids,context=context)[0] | 409 | data = self.read(cr, uid, ids,context=context)[0] |
621 | 410 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context) | ||
622 | 411 | |||
623 | 285 | if data.get('discount_move_ids',False): | 412 | if data.get('discount_move_ids',False): |
624 | 286 | context.update({'discount_move_ids':data['discount_move_ids']}) | 413 | context.update({'discount_move_ids':data['discount_move_ids']}) |
625 | 287 | |||
626 | 288 | if data.get('id',False): | ||
627 | 289 | context.update({'t_ids':ids}) | ||
628 | 290 | |||
629 | 291 | if data.get('tax_move_ids',False): | 414 | if data.get('tax_move_ids',False): |
630 | 292 | context.update({'tax_move_ids':data['tax_move_ids']}) | 415 | context.update({'tax_move_ids':data['tax_move_ids']}) |
631 | 293 | |||
632 | 294 | if data.get('amount',False): | 416 | if data.get('amount',False): |
633 | 295 | context.update({'amount':data['amount']}) | 417 | context.update({'amount':data['amount']}) |
634 | 296 | |||
635 | 297 | if data.get('cash_amount',False): | 418 | if data.get('cash_amount',False): |
636 | 298 | context.update({'cash_amount':data['cash_amount']}) | 419 | context.update({'cash_amount':data['cash_amount']}) |
638 | 299 | 420 | ||
639 | 421 | total_data_amount = 0.00 | ||
640 | 422 | total_invoice_amount = 0.00 | ||
641 | 423 | total_data_amount = data['amount'] + data['cash_amount'] | ||
642 | 424 | total_invoice_amount = invoice.residual | ||
643 | 425 | |||
644 | 426 | |||
645 | 300 | model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_message')], context=context) | 427 | model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_message')], context=context) |
646 | 301 | resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] | 428 | resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
659 | 302 | 429 | if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,(total_invoice_amount - total_data_amount)): | |
660 | 303 | return { | 430 | self.pool.get('account.invoice.pay').pay_and_reconcile(cr, uid, ids, context=context) |
661 | 304 | 'name': _('Message'), | 431 | return {} |
662 | 305 | 'context': context, | 432 | else: |
663 | 306 | 'view_type': 'form', | 433 | return { |
664 | 307 | 'view_mode': 'form', | 434 | 'name': _('Message'), |
665 | 308 | 'res_model': 'account.message', | 435 | 'context': context, |
666 | 309 | 'views': [(resource_id,'form')], | 436 | 'view_type': 'form', |
667 | 310 | 'type': 'ir.actions.act_window', | 437 | 'view_mode': 'form', |
668 | 311 | 'target': 'new', | 438 | 'res_model': 'account.message', |
669 | 312 | } | 439 | 'views': [(resource_id,'form')], |
670 | 313 | 440 | 'type': 'ir.actions.act_window', | |
671 | 441 | 'target': 'new', | ||
672 | 442 | } | ||
673 | 443 | |||
674 | 444 | |||
675 | 445 | def _message_partial(self, cr, uid, ids, context=None): | ||
676 | 446 | mod_obj = self.pool.get('ir.model.data') | ||
677 | 447 | data = self.read(cr, uid, ids,context=context)[0] | ||
678 | 448 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context) | ||
679 | 449 | |||
680 | 450 | total_data_amount = 0.0 | ||
681 | 451 | total_invoice_amount = 0.0 | ||
682 | 452 | |||
683 | 453 | if data.get('discount_move_ids',False): | ||
684 | 454 | context.update({'discount_move_ids':data['discount_move_ids']}) | ||
685 | 455 | if data.get('tax_move_ids',False): | ||
686 | 456 | context.update({'tax_move_ids':data['tax_move_ids']}) | ||
687 | 457 | |||
688 | 458 | if data.get('amount',False): | ||
689 | 459 | context.update({'amount':data['amount']}) | ||
690 | 460 | if data.get('cash_amount',False): | ||
691 | 461 | context.update({'cash_amount':data['cash_amount']}) | ||
692 | 462 | |||
693 | 463 | total_data_amount = data['amount'] + data['cash_amount'] | ||
694 | 464 | total_invoice_amount = invoice.residual | ||
695 | 465 | |||
696 | 466 | if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,(total_invoice_amount - total_data_amount)): | ||
697 | 467 | model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_partial_message')], context=context) | ||
698 | 468 | resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] | ||
699 | 469 | return { | ||
700 | 470 | 'name': _('Message'), | ||
701 | 471 | 'context': context, | ||
702 | 472 | 'view_type': 'form', | ||
703 | 473 | 'view_mode': 'form', | ||
704 | 474 | 'res_model': 'account.partial.message', | ||
705 | 475 | 'views': [(resource_id,'form')], | ||
706 | 476 | 'type': 'ir.actions.act_window', | ||
707 | 477 | 'target': 'new', | ||
708 | 478 | } | ||
709 | 479 | else: | ||
710 | 480 | self.pool.get('account.invoice.pay').pay_and_reconcile(cr, uid, ids, context=context) | ||
711 | 481 | return {} | ||
712 | 482 | |||
713 | 314 | def wo_check(self, cr, uid, ids, context=None): | 483 | def wo_check(self, cr, uid, ids, context=None): |
714 | 315 | cur_obj = self.pool.get('res.currency') | 484 | cur_obj = self.pool.get('res.currency') |
715 | 316 | mod_obj = self.pool.get('ir.model.data') | 485 | mod_obj = self.pool.get('ir.model.data') |
716 | @@ -347,32 +516,10 @@ | |||
717 | 347 | debit+=payment.debit | 516 | debit+=payment.debit |
718 | 348 | credit+=payment.credit | 517 | credit+=payment.credit |
719 | 349 | amount_paid+=abs(debit-credit) | 518 | amount_paid+=abs(debit-credit) |
744 | 350 | 519 | ||
745 | 351 | # Test if there is a difference according to currency rouding setting | 520 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
746 | 352 | # amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) | 521 | (amount_paid - inv_amount_company_currency)): |
723 | 353 | # | ||
724 | 354 | # found_h = amount['found'] | ||
725 | 355 | # | ||
726 | 356 | # if found_h: | ||
727 | 357 | |||
728 | 358 | ####### Here when we do make full payment then to get the previous Discount and Tax Move added in context | ||
729 | 359 | if context.get('discount_move_ids',False): | ||
730 | 360 | context.update({'discount_move_ids':context['discount_move_ids']}) | ||
731 | 361 | if context.get('tax_move_ids',False): | ||
732 | 362 | context.update({'tax_move_ids':context['tax_move_ids']}) | ||
733 | 363 | if context.get('amount',False): | ||
734 | 364 | context.update({'amount':context['amount']}) | ||
735 | 365 | if context.get('cash_amount',False): | ||
736 | 366 | context.update({'cash_amount':context['cash_amount']}) | ||
737 | 367 | if context.get('t_ids',False): | ||
738 | 368 | ids = context['t_ids'] | ||
739 | 369 | # return self.pay_and_reconcile(cr, uid, ids, context=context) | ||
740 | 370 | # else: | ||
741 | 371 | |||
742 | 372 | if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, | ||
743 | 373 | (amount_paid - inv_amount_company_currency)) or data['cash_residual_amount'] == 0.0: | ||
747 | 374 | return self.pay_and_reconcile(cr, uid, ids, context=context) | 522 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
748 | 375 | |||
749 | 376 | else: | 523 | else: |
750 | 377 | model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context) | 524 | model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context) |
751 | 378 | resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] | 525 | resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
752 | @@ -401,7 +548,7 @@ | |||
753 | 401 | writeoff_account_id = context['write_off']['writeoff_acc_id'] | 548 | writeoff_account_id = context['write_off']['writeoff_acc_id'] |
754 | 402 | writeoff_journal_id = context['write_off']['writeoff_journal_id'] | 549 | writeoff_journal_id = context['write_off']['writeoff_journal_id'] |
755 | 403 | comment = context['write_off']['comment'] | 550 | comment = context['write_off']['comment'] |
757 | 404 | 551 | ||
758 | 405 | if context.get('amount',False): | 552 | if context.get('amount',False): |
759 | 406 | amount = context['amount'] + context.get('cash_amount',0.0) | 553 | amount = context['amount'] + context.get('cash_amount',0.0) |
760 | 407 | else: | 554 | else: |
761 | @@ -421,6 +568,7 @@ | |||
762 | 421 | else: | 568 | else: |
763 | 422 | context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id}) | 569 | context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id}) |
764 | 423 | 570 | ||
765 | 571 | |||
766 | 424 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 572 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
767 | 425 | ctx = {'date':data['date']} | 573 | ctx = {'date':data['date']} |
768 | 426 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, amount, context=ctx) | 574 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, amount, context=ctx) |
769 | @@ -442,21 +590,11 @@ | |||
770 | 442 | context.update({'tax_move_ids':context['tax_move_ids']}) | 590 | context.update({'tax_move_ids':context['tax_move_ids']}) |
771 | 443 | else: | 591 | else: |
772 | 444 | context.update({'tax_move_ids':data['tax_move_ids']}) | 592 | context.update({'tax_move_ids':data['tax_move_ids']}) |
774 | 445 | 593 | ||
775 | 446 | if context.get('cash_amount',False): | 594 | if context.get('cash_amount',False): |
776 | 447 | cash_amount = context['cash_amount'] | ||
777 | 448 | context.update({'cash_amount':context['cash_amount']}) | 595 | context.update({'cash_amount':context['cash_amount']}) |
778 | 449 | else: | 596 | else: |
779 | 450 | cash_amount = data['cash_amount'] | ||
780 | 451 | context.update({'cash_amount':data['cash_amount']}) | 597 | context.update({'cash_amount':data['cash_amount']}) |
781 | 452 | |||
782 | 453 | if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id: | ||
783 | 454 | cash_amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, cash_amount, context=ctx) | ||
784 | 455 | context.update({'cash_amount':cash_amount}) | ||
785 | 456 | |||
786 | 457 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | ||
787 | 458 | cash_amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, cash_amount, context=ctx) | ||
788 | 459 | context.update({'cash_amount':cash_amount}) | ||
789 | 460 | 598 | ||
790 | 461 | acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id | 599 | acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id |
791 | 462 | if not acc_id: | 600 | if not acc_id: |
792 | @@ -468,7 +606,6 @@ | |||
793 | 468 | return {} | 606 | return {} |
794 | 469 | 607 | ||
795 | 470 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False): | 608 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False): |
796 | 471 | |||
797 | 472 | res = super(account_invoice_pay,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar) | 609 | res = super(account_invoice_pay,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar) |
798 | 473 | fields=res.get('fields',{}) | 610 | fields=res.get('fields',{}) |
799 | 474 | word = "Supplier Cash Discount Account" | 611 | word = "Supplier Cash Discount Account" |
800 | @@ -481,29 +618,26 @@ | |||
801 | 481 | res['fields'][f]['string'] = res['fields'][f]['string'].replace('Customers Cash Discount Account',word) | 618 | res['fields'][f]['string'] = res['fields'][f]['string'].replace('Customers Cash Discount Account',word) |
802 | 482 | return res | 619 | return res |
803 | 483 | 620 | ||
804 | 484 | def _cancel_line(self, cr, uid, ids, context=None): | ||
805 | 485 | move_obj = self.pool.get('account.move') | ||
806 | 486 | move_line_obj = self.pool.get('account.move.line') | ||
807 | 487 | data = self.read(cr, uid, ids,context=context)[0] | ||
808 | 488 | |||
809 | 489 | if data['tax_move_ids']: | ||
810 | 490 | move_line = data['tax_move_ids'] | ||
811 | 491 | for move_line_id in move_line: | ||
812 | 492 | move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id | ||
813 | 493 | move_line_obj.unlink(cr, uid,[move_line_id]) | ||
814 | 494 | move_obj.unlink(cr, uid,[move_id]) | ||
815 | 495 | |||
816 | 496 | if data['discount_move_ids']: | ||
817 | 497 | discount_move_line = data['discount_move_ids'] | ||
818 | 498 | for move_line_id in discount_move_line: | ||
819 | 499 | move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id | ||
820 | 500 | move_line_obj.unlink(cr, uid,[move_line_id]) | ||
821 | 501 | move_obj.unlink(cr, uid,[move_id]) | ||
822 | 502 | |||
823 | 503 | return {} | ||
824 | 504 | |||
825 | 505 | account_invoice_pay() | 621 | account_invoice_pay() |
826 | 506 | 622 | ||
827 | 623 | class account_move_line_memory(osv.osv_memory): | ||
828 | 624 | _name= "account.move.line.memory" | ||
829 | 625 | _description = "Account move line memory " | ||
830 | 626 | _columns = { | ||
831 | 627 | 'date': fields.date('Effective Date', required=True), | ||
832 | 628 | 'name': fields.char('Name', size=64, required=True), | ||
833 | 629 | 'account_id': fields.many2one('account.account', 'Account',), | ||
834 | 630 | 'journal_id': fields.many2one('account.journal', 'Journal', required=True, select=1), | ||
835 | 631 | 'debit': fields.float('Debit', digits=(16,2)), | ||
836 | 632 | 'credit': fields.float('Credit', digits=(16,2)), | ||
837 | 633 | 'tax_code_id': fields.many2one('account.tax.code', 'Tax Account', help="The Account can either be a base tax code or tax code account."), | ||
838 | 634 | 'tax_amount': fields.float('Tax/Base Amount', digits=(16,2), select=True), | ||
839 | 635 | 'currency_id': fields.many2one('res.currency', 'Currency', help="The optional other currency if it is a multi-currency entry."), | ||
840 | 636 | 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency if it is a multi-currency entry."), | ||
841 | 637 | 'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account'), | ||
842 | 638 | } | ||
843 | 639 | account_move_line_memory() | ||
844 | 640 | |||
845 | 507 | class account_message(osv.osv_memory): | 641 | class account_message(osv.osv_memory): |
846 | 508 | _name = "account.message" | 642 | _name = "account.message" |
847 | 509 | def _check(self, cr, uid, ids, context=None): | 643 | def _check(self, cr, uid, ids, context=None): |
848 | @@ -511,6 +645,15 @@ | |||
849 | 511 | result = self.pool.get('account.invoice.pay').wo_check(cr, uid, ids, context=context) | 645 | result = self.pool.get('account.invoice.pay').wo_check(cr, uid, ids, context=context) |
850 | 512 | return result | 646 | return result |
851 | 513 | 647 | ||
853 | 514 | account_message() | 648 | account_message() |
854 | 649 | |||
855 | 650 | class account_partial_message(osv.osv_memory): | ||
856 | 651 | _name = "account.partial.message" | ||
857 | 652 | def _check_partial(self, cr, uid, ids, context=None): | ||
858 | 653 | data = self.read(cr, uid, ids,context=context)[0] | ||
859 | 654 | result = self.pool.get('account.invoice.pay').pay_and_reconcile(cr, uid, ids, context=context) | ||
860 | 655 | return result | ||
861 | 656 | |||
862 | 657 | account_partial_message() | ||
863 | 515 | 658 | ||
864 | 516 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | 659 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
865 | 517 | \ No newline at end of file | 660 | \ No newline at end of file |
866 | 518 | 661 | ||
867 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml' | |||
868 | --- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-28 12:20:14 +0000 | |||
869 | +++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-27 09:11:48 +0000 | |||
870 | @@ -8,7 +8,7 @@ | |||
871 | 8 | <field name="arch" type="xml"> | 8 | <field name="arch" type="xml"> |
872 | 9 | <form string="Pay invoice"> | 9 | <form string="Pay invoice"> |
873 | 10 | <group colspan="4" > | 10 | <group colspan="4" > |
875 | 11 | <field name="amount" on_change="on_change_ammount(amount,context)"/> | 11 | <field name="amount" on_change="on_change_ammount(amount,cash_amount,context)"/> |
876 | 12 | <field name="cash_residual_amount"/> | 12 | <field name="cash_residual_amount"/> |
877 | 13 | <field name="name"/> | 13 | <field name="name"/> |
878 | 14 | <field name="date"/> | 14 | <field name="date"/> |
879 | @@ -32,8 +32,8 @@ | |||
880 | 32 | </group> | 32 | </group> |
881 | 33 | <group colspan="4" col="6"> | 33 | <group colspan="4" col="6"> |
882 | 34 | <label string ="" colspan="2"/> | 34 | <label string ="" colspan="2"/> |
885 | 35 | <button icon="gtk-cancel" string="Cancel" name="_cancel_line" type="object"/> | 35 | <button icon="gtk-cancel" special="cancel" string="Cancel"/> |
886 | 36 | <button icon="gtk-execute" string="Partial Payment" name="pay_and_reconcile" type="object"/> | 36 | <button icon="gtk-execute" string="Partial Payment" name="_message_partial" type="object"/> |
887 | 37 | <button icon="gtk-execute" string="Full-Payment" name="_message" type="object"/> | 37 | <button icon="gtk-execute" string="Full-Payment" name="_message" type="object"/> |
888 | 38 | </group> | 38 | </group> |
889 | 39 | </form> | 39 | </form> |
890 | @@ -71,14 +71,62 @@ | |||
891 | 71 | </field> | 71 | </field> |
892 | 72 | </record> | 72 | </record> |
893 | 73 | 73 | ||
894 | 74 | <record id="view_account_move_line_memory" model="ir.ui.view"> | ||
895 | 75 | <field name="name">account.move.line.memory.form</field> | ||
896 | 76 | <field name="model">account.move.line.memory</field> | ||
897 | 77 | <field name="type">tree</field> | ||
898 | 78 | <field name="arch" type="xml"> | ||
899 | 79 | <tree string="Account Move Line"> | ||
900 | 80 | <field name="date"/> | ||
901 | 81 | <field name="name"/> | ||
902 | 82 | <field name="account_id"/> | ||
903 | 83 | <field name="journal_id"/> | ||
904 | 84 | <field name="debit"/> | ||
905 | 85 | <field name="credit"/> | ||
906 | 86 | <field name="tax_code_id"/> | ||
907 | 87 | <field name="tax_amount"/> | ||
908 | 88 | <field name="currency_id"/> | ||
909 | 89 | <field name="amount_currency"/> | ||
910 | 90 | <field name="analytic_account_id"/> | ||
911 | 91 | </tree> | ||
912 | 92 | </field> | ||
913 | 93 | </record> | ||
914 | 94 | |||
915 | 74 | <record id="view_account_message" model="ir.ui.view"> | 95 | <record id="view_account_message" model="ir.ui.view"> |
916 | 75 | <field name="name">account.message.form</field> | 96 | <field name="name">account.message.form</field> |
917 | 76 | <field name="model">account.message</field> | 97 | <field name="model">account.message</field> |
918 | 77 | <field name="type">form</field> | 98 | <field name="type">form</field> |
919 | 78 | <field name="arch" type="xml"> | 99 | <field name="arch" type="xml"> |
923 | 79 | <form string="Your Messages"> | 100 | <form string="Messages"> |
924 | 80 | <label colspan="8" string="Are you really want to reconcile this invoice" /> | 101 | <group> |
925 | 81 | <button icon="gtk-execute" string="OK" name="_check" type="object"/> | 102 | <separator string="Full Payment" colspan="4"/> |
926 | 103 | <label string ="Are you really want to reconcile this invoice. | ||
927 | 104 | The proposed payment does not cover 100 percent of the invoice. | ||
928 | 105 | Please check payment term lines. Normally a user would click | ||
929 | 106 | on Partial Payment to avoid ready / paid state for this invoice." colspan="2"/> | ||
930 | 107 | <newline/> | ||
931 | 108 | <button icon="gtk-cancel" special="cancel" string="Cancel" colspan="1"/> | ||
932 | 109 | <button icon="gtk-execute" string="OK" name="_check" type="object" colspan="1"/> | ||
933 | 110 | </group> | ||
934 | 111 | </form> | ||
935 | 112 | </field> | ||
936 | 113 | </record> | ||
937 | 114 | |||
938 | 115 | <record id="view_account_partial_message" model="ir.ui.view"> | ||
939 | 116 | <field name="name">account.partial.message.form</field> | ||
940 | 117 | <field name="model">account.partial.message</field> | ||
941 | 118 | <field name="type">form</field> | ||
942 | 119 | <field name="arch" type="xml"> | ||
943 | 120 | <form string="Messages"> | ||
944 | 121 | <group> | ||
945 | 122 | <separator string="Partial Payment" colspan="4"/> | ||
946 | 123 | <label string ="Don't you really want to reconcile this invoice. | ||
947 | 124 | The proposed payment balances this invoice. Please check payment term lines. | ||
948 | 125 | Normally a user would click on Full Payment to receive ready / paid state for this invoice." colspan="2"/> | ||
949 | 126 | <newline/> | ||
950 | 127 | <button icon="gtk-cancel" special="cancel" string="Cancel" colspan="1"/> | ||
951 | 128 | <button icon="gtk-execute" string="OK" name="_check_partial" type="object" colspan="1"/> | ||
952 | 129 | </group> | ||
953 | 82 | </form> | 130 | </form> |
954 | 83 | </field> | 131 | </field> |
955 | 84 | </record> | 132 | </record> |