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

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 26
Proposed branch: lp:~openbig/bigconsulting/added_new_changes_in_cash_account
Merge into: lp:bigconsulting
Diff against target: 228 lines (+77/-32)
4 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+47/-9)
account_invoice_cash_discount/wizard/account_pay_invoice.py (+14/-8)
account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+1/-1)
product_ean13_generator/product_ean13_generator.py (+15/-14)
To merge this branch: bzr merge lp:~openbig/bigconsulting/added_new_changes_in_cash_account
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+28053@code.launchpad.net

Description of the change

Added modification in cash discount module by client. And solve problem of product_ean13_generator

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-06-18 13:06:05 +0000
3+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-06-21 13:43:25 +0000
4@@ -128,19 +128,23 @@
5 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
6 if payment_term_lines.cash_discount_ids:
7 res = 0.0
8+ dis = 0.0
9 for discount_line in payment_term_lines.cash_discount_ids:
10- if diff_day == discount_line.delay or diff_day < discount_line.delay:
11+ if diff_day >= dis and diff_day <= discount_line.delay:
12 account_id = discount_line.discount_account_id.id
13+ dis = discount_line.delay
14 return account_id
15
16 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=''):
17-
18 if context is None:
19 context = {}
20 #TODO check if we can use different period for payment and the writeoff line
21 assert len(ids)==1, "Can only pay one invoice at a time"
22 invoice = self.browse(cr, uid, ids[0])
23
24+ tax_obj = self.pool.get('account.tax')
25+ invoice_tax_obj = self.pool.get("account.invoice.tax")
26+
27 if 'amount_currency' in context and context['amount_currency']:
28 amount_currency = context['amount_currency']
29 else:
30@@ -183,6 +187,7 @@
31 'currency_id':currency_id,
32 'amount_currency':amount_currency and direction * amount_currency or 0.0,
33 }
34+
35 l2 = {
36 'debit': direction * (pay_amount-amount_discount)<0 and - direction * (pay_amount-amount_discount),
37 'credit': direction * (pay_amount-amount_discount)>0 and direction * (pay_amount-amount_discount),
38@@ -199,12 +204,47 @@
39 l1['name'] = name
40 l2['name'] = name
41 lines = [(0, 0, l1), (0, 0, l2)]
42+
43+ discount_amount = 0.0
44+ tax_total_amount = 0.0
45+ if 'cash_amount' in context and context['cash_amount']:
46+ discount_amount = context['cash_amount']
47+
48+ if discount_amount>0.0:
49+ for line in invoice.invoice_line:
50+ if line.invoice_line_tax_id:
51+ for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, discount_amount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id):
52+ tax_amount = tax['amount']
53+ tax_total_amount += tax['amount']
54+
55+ tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])])
56+ for tax_id in tax_invoice_id:
57+ tax_value = invoice_tax_obj.browse(cr, uid, tax_id)
58+ tax_account_id = tax_value.account_id.id
59
60+ l3 = {
61+ 'debit': direction * tax_amount<0 and - direction * tax_amount,
62+ 'credit': direction * tax_amount>0 and direction * tax_amount,
63+ 'account_id': tax_account_id,
64+ 'partner_id': invoice.partner_id.id,
65+ 'ref':ref,
66+ 'date': date,
67+ 'currency_id':currency_id,
68+ 'amount_currency':amount_currency and direction * amount_currency or 0.0,
69+ }
70+ l3['name'] = name
71+ lines.append((0, 0, l3))
72+
73 if amount_discount>0:
74 if 'account_id' in context and context['account_id']:
75- account_id = context['account_id']
76-
77- l3 = {
78+ account_id = context['account_id']
79+
80+ if tax_total_amount>0:
81+ amount_discount = (amount_discount - tax_total_amount)
82+ else:
83+ amount_discount = amount_discount
84+
85+ l4 = {
86 'debit': direction * amount_discount<0 and - direction * amount_discount,
87 'credit': direction * amount_discount>0 and direction * amount_discount,
88 'account_id': account_id,
89@@ -214,10 +254,8 @@
90 'currency_id':currency_id,
91 'amount_currency':amount_currency and direction * amount_currency or 0.0,
92 }
93- l3['name'] = name
94-
95- lines = [(0, 0, l1), (0, 0, l2), (0, 0, l3)]
96-
97+ l4['name'] = name
98+ lines.append((0, 0, l4))
99
100 move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}
101 move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
102
103=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py'
104--- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-06-18 13:06:05 +0000
105+++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-06-21 13:43:25 +0000
106@@ -79,7 +79,6 @@
107
108 def _get_amount(self, cr, uid, context=None):
109 residual_amount = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context).residual
110- residual_amount -= self._get_discount(cr, uid, context=context)
111 return residual_amount
112
113 def on_change_ammount(self, cr, uid, ids, amount, context=None):
114@@ -110,6 +109,13 @@
115 account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account)
116 return account
117
118+ def default_get(self, cr, uid, fields, context=None):
119+ res = super(account_invoice_pay, self).default_get(cr, uid, fields, context=context)
120+ invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)
121+ if invoice.state in ['draft', 'proforma2', 'cancel']:
122+ raise osv.except_osv(_('Error !'), _('Can not pay draft/proforma/cancel invoice.'))
123+ return res
124+
125 _defaults = {
126 'date': lambda *a: time.strftime('%Y-%m-%d'),
127 'period_id': _get_period,
128@@ -143,9 +149,9 @@
129 # Get the current amount paid in company currency
130 if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
131 ctx = {'date':data['date']}
132- amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['amount']+data['cash_amount'], round=True, context=ctx)
133+ amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['amount'], round=True, context=ctx)
134 else:
135- amount_paid = data['amount'] + data['cash_amount']
136+ amount_paid = data['amount']
137 # Get the old payment if there are some
138 if invoice.payment_ids:
139 debit=credit=0.0
140@@ -186,8 +192,8 @@
141 writeoff_journal_id = context['write_off']['writeoff_journal_id']
142 comment = context['write_off']['comment']
143
144- amount = data['amount'] + data['cash_amount']
145-
146+ amount = data['amount']
147+
148 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)
149 journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context=context)
150 # Compute the amount in company's currency, with the journal currency (which is equal to payment currency)
151@@ -197,14 +203,14 @@
152 amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
153 currency_id = journal.currency.id
154 # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency
155- context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id})
156+ context.update({'amount_currency':data['amount'],'currency_id':currency_id})
157
158 if invoice.company_id.currency_id.id<>invoice.currency_id.id:
159 ctx = {'date':data['date']}
160 amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, amount, context=ctx)
161 currency_id = invoice.currency_id.id
162 # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency
163- context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id})
164+ context.update({'amount_currency':data['amount'],'currency_id':currency_id})
165
166 # Take the choosen date
167 if comment:
168@@ -212,7 +218,7 @@
169 else:
170 context.update({'date_p':data['date'],'comment':False})
171
172- context.update({'account_id':data['account_id'],'cash_amount':data['cash_amount'],'amount_currency':data['amount'] + data['cash_amount']})
173+ context.update({'account_id':data['account_id'],'cash_amount':data['cash_amount'],'amount_currency':data['amount']})
174
175 acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
176 if not acc_id:
177
178=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml'
179--- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-08-05 13:41:54 +0000
180+++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-06-21 13:43:25 +0000
181@@ -12,7 +12,7 @@
182 <newline/>
183 <field name="name"/>
184 <field name="date"/>
185- <field name="journal_id"/>
186+ <field name="journal_id" domain="[('type','=','cash')]"/>
187 <field name="period_id"/>
188 <field name="cash_amount" attrs="{'required':[('cash_amount','>',0)]}"/>
189 <field name="account_id" attrs="{'required':[('cash_amount','>',0)]}"/>
190
191=== modified file 'product_ean13_generator/product_ean13_generator.py'
192--- product_ean13_generator/product_ean13_generator.py 2010-06-03 06:48:10 +0000
193+++ product_ean13_generator/product_ean13_generator.py 2010-06-21 13:43:25 +0000
194@@ -37,20 +37,21 @@
195 raise ValueError('invalid test')
196 cr.execute('select id from ir_sequence where '+test+' and active=%s', (sequence_id, True,))
197 res = cr.dictfetchone()
198- ean_nr = self.browse(cr, uid, res['id'], context=context)
199- sequence = super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context)
200- code = 'generator.ean13'
201-
202- if ean_nr.code == code:
203- number = ean_nr.number_max
204- check_seq = sequence[8:]
205- if check_seq >= ean_nr.warning_number:
206- obj = self.pool.get("ir.actions.server")
207- action_name = "EAN Generator Action"
208- id = obj.search(cr, uid, [('name',"ilike",action_name)])
209- context.update({'active_id':res['id']})
210- obj.run(cr, uid, id, context)
211- return sequence
212+ if res:
213+ ean_nr = self.browse(cr, uid, res['id'], context=context)
214+ sequence = super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context)
215+ code = 'generator.ean13'
216+
217+ if ean_nr.code == code:
218+ number = ean_nr.number_max
219+ check_seq = sequence[8:]
220+ if check_seq >= ean_nr.warning_number:
221+ obj = self.pool.get("ir.actions.server")
222+ action_name = "EAN Generator Action"
223+ id = obj.search(cr, uid, [('name',"ilike",action_name)])
224+ context.update({'active_id':res['id']})
225+ obj.run(cr, uid, id, context)
226+ return sequence
227
228 ir_sequence()
229

Subscribers

People subscribed via source and target branches