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

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 22
Proposed branch: lp:~openbig/bigconsulting/new_branch_changes_on_account_invoice_discount
Merge into: lp:bigconsulting
Diff against target: 185 lines (+49/-31)
3 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+45/-28)
account_invoice_cash_discount/wizard/account_pay_invoice.py (+3/-2)
account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+1/-1)
To merge this branch: bzr merge lp:~openbig/bigconsulting/new_branch_changes_on_account_invoice_discount
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+27727@code.launchpad.net

Description of the change

solved the problem of account_id' referenced and account move lines entry for zero discount

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-07-20 10:11:48 +0000
3+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-06-16 14:56:23 +0000
4@@ -1,7 +1,7 @@
5 # -*- encoding: utf-8 -*-
6 ##############################################################################
7 #
8-# OpenERP, Open Source Management Solution
9+# OpenERP, Open Source Management Solution
10 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
11 # $Id$
12 #
13@@ -70,16 +70,22 @@
14 else:
15 date2 = time.strftime('%Y-%m-%d')
16
17- from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
18- to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
19- diff_day = (from_dt-to_dt)/(3600*24)
20+ if date1 > date2:
21+ from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
22+ to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
23+ diff_day = (from_dt-to_dt)/(3600*24)
24+ else:
25+ from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
26+ to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
27+ diff_day = (from_dt-to_dt)/(3600*24)
28 discount = 0.0
29 if payment_term:
30 pt = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
31 if pt.cash_discount_ids:
32 res = 0.0
33+ dis = 0
34 for d in pt.cash_discount_ids:
35- if diff_day == d.delay or diff_day < d.delay:
36+ if diff_day > dis and diff_day < d.delay:
37 if resudial_amonut:
38 res = resudial_amonut * d.discount
39 ted = 0.0
40@@ -91,7 +97,7 @@
41 rr += tex['amount']
42 ted +=rr
43 discount = res + ted
44-
45+ dis = d.delay
46 return discount
47
48 def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
49@@ -100,7 +106,9 @@
50 """
51 if context is None:
52 context = {}
53-
54+
55+ account_id = False
56+
57 tax_obj = self.pool.get('account.tax')
58 invoice = self.browse(cr, uid, ids[0], context=context)
59
60@@ -113,10 +121,16 @@
61 date2 = context['date_p']
62 else:
63 date2 = time.strftime('%Y-%m-%d')
64+
65+ if date1 > date2:
66+ from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
67+ to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
68+ diff_day = (from_dt-to_dt)/(3600*24)
69+ else:
70+ from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
71+ to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
72+ diff_day = (from_dt-to_dt)/(3600*24)
73
74- from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
75- to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
76- diff_day = (from_dt-to_dt)/(3600*24)
77 if payment_term:
78 pt = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
79 if pt.cash_discount_ids:
80@@ -124,7 +138,7 @@
81 for d in pt.cash_discount_ids:
82 if diff_day == d.delay or diff_day < d.delay:
83 account_id = d.discount_account_id.id
84- return account_id
85+ return account_id
86
87 def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''):
88
89@@ -138,11 +152,11 @@
90 amount_currency = context['amount_currency']
91 else:
92 amount_currency = invoice.residual
93-
94+ amount_discount = 0.0
95 if invoice.payment_term:
96 # Return the discount on for the payment term
97 amount_discount = self._get_payment(cr, uid, ids, amount_currency, invoice.payment_term.id, context=context)
98-
99+
100 src_account_id = invoice.account_id.id
101 # Take the seq as name for move
102 types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}
103@@ -186,28 +200,31 @@
104 'currency_id':currency_id,
105 'amount_currency':amount_currency and - direction * amount_currency or 0.0,
106 }
107- l3 = {
108- 'debit': direction * amount_discount<0 and - direction * amount_discount,
109- 'credit': direction * amount_discount>0 and direction * amount_discount,
110- 'account_id': context['account_id'],
111- 'partner_id': invoice.partner_id.id,
112- 'ref':ref,
113- 'date': date,
114- 'currency_id':currency_id,
115- 'amount_currency':amount_currency and direction * amount_currency or 0.0,
116- }
117
118 if not name:
119 name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number
120 l1['name'] = name
121 l2['name'] = name
122- l3['name'] = name
123-
124+ lines = [(0, 0, l1), (0, 0, l2)]
125+
126 if amount_discount>0:
127+ if 'account_id' in context and context['account_id']:
128+ account_id = context['account_id']
129+
130+ l3 = {
131+ 'debit': direction * amount_discount<0 and - direction * amount_discount,
132+ 'credit': direction * amount_discount>0 and direction * amount_discount,
133+ 'account_id': account_id,
134+ 'partner_id': invoice.partner_id.id,
135+ 'ref':ref,
136+ 'date': date,
137+ 'currency_id':currency_id,
138+ 'amount_currency':amount_currency and direction * amount_currency or 0.0,
139+ }
140+ l3['name'] = name
141+
142 lines = [(0, 0, l1), (0, 0, l2), (0, 0, l3)]
143- else:
144- lines = [(0, 0, l1), (0, 0, l2)]
145-
146+
147
148 move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}
149 move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
150
151=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py'
152--- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-20 10:11:48 +0000
153+++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-06-16 14:56:23 +0000
154@@ -65,7 +65,7 @@
155 }
156
157 def view_init(self, cr, uid, ids, context=None):
158- invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)
159+ invoice = self.pool.get('account.invoice').browse(cr, uid, context['active_id'], context=context)
160 if invoice.state in ['draft', 'proforma2', 'cancel']:
161 raise osv.except_osv(_('Error !'), _('Can not pay draft/proforma/cancel invoice.'))
162 pass
163@@ -104,7 +104,8 @@
164 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
165 account = obj_inv._get_account(cr, uid, [context['id']] , invoice.residual, invoice.payment_term.id, context=context)
166 fpos = invoice.fiscal_position or False
167- account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account)
168+ if account:
169+ account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account)
170 return account
171
172 _defaults = {
173
174=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml'
175--- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-06-01 05:48:55 +0000
176+++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-06-16 14:56:23 +0000
177@@ -15,7 +15,7 @@
178 <field name="journal_id"/>
179 <field name="period_id"/>
180 <field name="cash_amount"/>
181- <field name="account_id"/>
182+ <field name="account_id" attrs="{'required':[('cash_amount','>',0)]}"/>
183 </group>
184 <group colspan="4" col="6">
185 <label string ="" colspan="2"/>

Subscribers

People subscribed via source and target branches