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

Proposed by gpa(OpenERP)
Status: Superseded
Proposed branch: lp:~openbig/bigconsulting/toleance_field
Merge into: lp:bigconsulting
Diff against target: 291 lines (+60/-60)
3 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+38/-35)
account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+4/-8)
account_invoice_cash_discount/wizard/account_pay_invoice.py (+18/-17)
To merge this branch: bzr merge lp:~openbig/bigconsulting/toleance_field
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+30115@code.launchpad.net

This proposal supersedes a proposal from 2010-07-16.

This proposal has been superseded by a proposal from 2010-07-16.

Description of the change

Added tolreance field in the payment term and remove the one2many payment term lines from the discount lines.

To post a comment you must log in.

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/account_invoice_cash_discount.py'
2--- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-28 12:20:14 +0000
3+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-16 14:43:55 +0000
4@@ -23,6 +23,7 @@
5 from osv import fields, osv
6 from tools import config
7 import time
8+from tools.translate import _
9
10 class account_payment_term(osv.osv):
11 _name = "account.payment.term"
12@@ -44,8 +45,8 @@
13 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
14 'credit_account_id': fields.many2one('account.account', 'Credit Account'),
15 'debit_account_id': fields.many2one('account.account', 'Debit Account'),
16- 'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'),
17- 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True),
18+# 'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'),
19+# 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True),
20 'sup_discount_account_id': fields.many2one('account.account', 'Supplier Discount Account',required=True),
21 }
22 account_cash_discount()
23@@ -53,7 +54,8 @@
24 class account_payment_term_line(osv.osv):
25 _inherit = "account.payment.term.line"
26 _columns = {
27- 'cash_account_discount_id': fields.many2one('account.cash.discount', 'Discount Lines',),
28+# 'cash_account_discount_id': fields.many2one('account.cash.discount', 'Discount Lines',),
29+ 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True),
30 'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=False, select=True),
31 'compl_cash_discount':fields.boolean('Use Complete Cash Discount'),
32 }
33@@ -92,34 +94,29 @@
34
35 discount = 0.0
36 amount = 0.0
37- payment_line_found = False
38+ tol_days = 0.0
39+ payment_line_found = False
40+
41 if payment_term:
42 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
43- for payment_term_line_id in payment_term_lines.line_ids:
44- payment_use_complete = payment_term_line_id.compl_cash_discount
45- if payment_use_complete:
46- if payment_term_lines.cash_discount_ids:
47- dis = 0
48- for discount_line in payment_term_lines.cash_discount_ids:
49- if diff_day >= dis and diff_day <= discount_line.delay:
50- if resudial_amonut:
51- dis1 = 0
52- if discount_line.payment_term_ids:
53- payment_line_found = True
54- for dis_payment_id in discount_line.payment_term_ids:
55- if diff_day >= dis1 and diff_day<= dis_payment_id.days:
56- if dis_payment_id.value == 'procent':
57- amount = resudial_amonut * dis_payment_id.value_amount
58- elif dis_payment_id.value == 'fixed':
59- amount = dis_payment_id.value_amount
60- else:
61- amount = resudial_amonut
62- dis1 = dis_payment_id.days
63- dis = discount_line.delay
64- else:
65- amount = resudial_amonut
66-
67- return {'amount':amount,'found':payment_line_found}
68+ if payment_term_lines.line_ids:
69+ res = 0.0
70+ dis = 0
71+ for payment_line in payment_term_lines.line_ids:
72+ if diff_day >= dis and diff_day <= payment_line.days:
73+ if resudial_amonut:
74+ payment_line_found = True
75+ tol_days = payment_line.day_tolerance
76+ if payment_line.value == 'procent':
77+ res = resudial_amonut * payment_line.value_amount
78+ elif payment_line.value == 'fixed':
79+ res = payment_line.value_amount
80+ else:
81+ res = resudial_amonut
82+ amount = res
83+ dis = payment_line.days
84+
85+ return {'amount':amount,'tol_days':tol_days,'found':payment_line_found}
86
87 def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
88 """
89@@ -150,6 +147,9 @@
90 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
91 diff_day = (from_dt-to_dt)/(3600*24)
92
93+ tolerance = self._get_amount(cr, uid, ids, resudial_amonut, payment_term, context)
94+ tolerance_days = tolerance['tol_days']
95+
96 discount = 0.0
97 if payment_term:
98 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
99@@ -157,11 +157,11 @@
100 res = 0.0
101 dis = 0
102 for discount_line in payment_term_lines.cash_discount_ids:
103- if diff_day >= dis and diff_day <= discount_line.delay:
104+ if diff_day >= dis and diff_day <= discount_line.delay + tolerance_days:
105 if resudial_amonut:
106 res = resudial_amonut * discount_line.discount
107 discount = res
108- dis = discount_line.delay
109+ dis = discount_line.delay + tolerance_days
110 return discount
111
112 def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
113@@ -194,19 +194,22 @@
114 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
115 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
116 diff_day = (from_dt-to_dt)/(3600*24)
117-
118+
119+ tolerance = self._get_amount(cr, uid, ids, resudial_amonut, payment_term, context)
120+ tolerance_days = tolerance['tol_days']
121+
122 if payment_term:
123 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
124 if payment_term_lines.cash_discount_ids:
125 res = 0.0
126 dis = 0.0
127 for discount_line in payment_term_lines.cash_discount_ids:
128- if diff_day >= dis and diff_day <= discount_line.delay:
129+ if diff_day >= dis and diff_day <= discount_line.delay + tolerance_days:
130 if invoice.type in ('in_invoice', 'in_refund'):
131 account_id = discount_line.sup_discount_account_id.id
132 else:
133 account_id = discount_line.discount_account_id.id
134- dis = discount_line.delay
135+ dis = discount_line.delay + tolerance_days
136 return account_id
137
138 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=''):
139@@ -290,7 +293,7 @@
140 l1['name'] = name
141 l2['name'] = name
142 lines = [(0, 0, l1), (0, 0, l2)]
143-
144+
145 ### When we make payment by pay invoice wizard and if found the taxes move then directly take the entry from the wizard
146 if 'tax_move_ids' in context and context['tax_move_ids']:
147 move_line = context['tax_move_ids']
148
149=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml'
150--- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-14 14:51:36 +0000
151+++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-16 14:43:55 +0000
152@@ -14,13 +14,9 @@
153 <field name="name" select="1"/>
154 <field name="delay" select="1"/>
155 <field name="discount" select="1"/>
156+ <separator string="Discount Account for Supplier And Customer Invoice " colspan="4"/>
157 <field name="discount_account_id" />
158- <field name="day_tolerance"/>
159 <field name="sup_discount_account_id"/>
160- <group colspan="4">
161- <separator string="Related Payment Terms Lines" colspan="4"/>
162- <field name="payment_term_ids" widget="one2many_list" nolabel="1"/>
163- </group>
164 </form>
165 </field>
166 </record>
167@@ -51,7 +47,7 @@
168 </field>
169 </field>
170 </record>
171-
172+
173 <record id="bank_statement_form_view1" model="ir.ui.view">
174 <field name="name">account.bank.statement.form</field>
175 <field name="model">account.bank.statement</field>
176@@ -100,10 +96,10 @@
177 <field name="arch" type="xml">
178 <field name="days2" position="after">
179 <field name="compl_cash_discount"/>
180- <label string="" colspan="2"/>
181+ <field name="day_tolerance"/>
182 </field>
183 </field>
184 </record>
185-
186+
187 </data>
188 </openerp>
189
190=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py'
191--- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-28 12:20:14 +0000
192+++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-16 14:43:55 +0000
193@@ -153,7 +153,7 @@
194 return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}}
195
196 def _calculation(self, cr, uid, ids, context=None):
197-
198+
199 invoice_obj = self.pool.get('account.invoice')
200 data = self.read(cr, uid, ids,context=context)[0]
201 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)
202@@ -207,13 +207,13 @@
203 line_tax_amount = 0.0
204
205 #####get the ratio of the line in the total invoice amount
206- 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):
207- line_tax_amount = tax['amount']
208+ 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):
209+ line_tax_amount = tax['amount']
210 line_total = line.price_subtotal + line_tax_amount
211 invoice_res_amount = invoice.amount_total
212 line_ratio = line_total / invoice_res_amount
213 ###########################
214-
215+
216 if line.invoice_line_tax_id:
217 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):
218 tax_amount = tax['amount']
219@@ -282,17 +282,19 @@
220 def _message(self, cr, uid, ids, context=None):
221 mod_obj = self.pool.get('ir.model.data')
222 data = self.read(cr, uid, ids,context=context)[0]
223-
224- if data['discount_move_ids']:
225+ if data.get('discount_move_ids',False):
226 context.update({'discount_move_ids':data['discount_move_ids']})
227
228- if data['tax_move_ids']:
229+ if data.get('id',False):
230+ context.update({'t_ids':ids})
231+
232+ if data.get('tax_move_ids',False):
233 context.update({'tax_move_ids':data['tax_move_ids']})
234-
235- if data['amount']:
236+
237+ if data.get('amount',False):
238 context.update({'amount':data['amount']})
239
240- if data['cash_amount']:
241+ if data.get('cash_amount',False):
242 context.update({'cash_amount':data['cash_amount']})
243
244 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_message')], context=context)
245@@ -354,7 +356,6 @@
246 # if found_h:
247
248 ####### Here when we do make full payment then to get the previous Discount and Tax Move added in context
249-
250 if context.get('discount_move_ids',False):
251 context.update({'discount_move_ids':context['discount_move_ids']})
252 if context.get('tax_move_ids',False):
253@@ -363,10 +364,11 @@
254 context.update({'amount':context['amount']})
255 if context.get('cash_amount',False):
256 context.update({'cash_amount':context['cash_amount']})
257-
258+ if context.get('t_ids',False):
259+ ids = context['t_ids']
260 # return self.pay_and_reconcile(cr, uid, ids, context=context)
261 # else:
262-
263+
264 if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,
265 (amount_paid - inv_amount_company_currency)) or data['cash_residual_amount'] == 0.0:
266 return self.pay_and_reconcile(cr, uid, ids, context=context)
267@@ -386,7 +388,6 @@
268 }
269
270 def pay_and_reconcile(self, cr, uid, ids, context=None):
271-
272 cur_obj = self.pool.get('res.currency')
273 if context is None:
274 context = {}
275@@ -431,14 +432,14 @@
276 context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id})
277
278 context.update({'account_id':data['account_id'],'date_p':data['date'],'comment':comment or False})
279-
280+
281 if context.get('discount_move_ids',False):
282 context.update({'discount_move_ids':context['discount_move_ids']})
283 else:
284 context.update({'discount_move_ids':data['discount_move_ids']})
285-
286+
287 if context.get('tax_move_ids',False):
288- context.update({'tax_move_ids':context['tax_move_ids']})
289+ context.update({'tax_move_ids':context['tax_move_ids']})
290 else:
291 context.update({'tax_move_ids':data['tax_move_ids']})
292

Subscribers

People subscribed via source and target branches