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

Proposed by gpa(OpenERP)
Status: Superseded
Proposed branch: lp:~openbig/bigconsulting/improvement_changes_milestone1
Merge into: lp:bigconsulting
Diff against target: 615 lines (+271/-80)
4 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+82/-10)
account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+17/-0)
account_invoice_cash_discount/wizard/account_pay_invoice.py (+158/-69)
account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+14/-1)
To merge this branch: bzr merge lp:~openbig/bigconsulting/improvement_changes_milestone1
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+29283@code.launchpad.net

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

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

Description of the change

added new changes in milestone1

To post a comment you must log in.
47. By gpa(OpenERP)

changes in wocheck context

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py'
--- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-01 14:49:31 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-06 13:37:26 +0000
@@ -44,17 +44,88 @@
44 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),44 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
45 'credit_account_id': fields.many2one('account.account', 'Credit Account'),45 'credit_account_id': fields.many2one('account.account', 'Credit Account'),
46 'debit_account_id': fields.many2one('account.account', 'Debit Account'),46 'debit_account_id': fields.many2one('account.account', 'Debit Account'),
47 'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'),
47 }48 }
48account_cash_discount()49account_cash_discount()
4950
51class account_payment_term_line(osv.osv):
52 _inherit = "account.payment.term.line"
53 _columns = {
54 'cash_account_discount_id': fields.many2one('account.cash.discount', 'Discount Lines',),
55 'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=False, select=True),
56 'compl_cash_discount':fields.boolean('Use Complete Cash Discount'),
57 }
58account_payment_term_line()
59
50class account_invoice(osv.osv):60class account_invoice(osv.osv):
51 _inherit = "account.invoice"61 _inherit = "account.invoice"
52 62
63 def _get_amount(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
64
65 """
66 This function return the Amount to paid according to the payment term cash discount payment term lines
67 """
68
69 if context is None:
70 context = {}
71
72 tax_obj = self.pool.get('account.tax')
73 invoice = self.browse(cr, uid, ids[0], context=context)
74
75 if invoice.date_invoice:
76 date1 = invoice.date_invoice
77 else:
78 date1 = time.strftime('%Y-%m-%d')
79
80 if 'date_p' in context and context['date_p']:
81 date2 = context['date_p']
82 else:
83 date2 = time.strftime('%Y-%m-%d')
84
85 if date1 >= date2:
86 from_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
87 to_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
88 diff_day = (from_dt-to_dt)/(3600*24)
89 else:
90 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
91 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
92 diff_day = (from_dt-to_dt)/(3600*24)
93
94 discount = 0.0
95 amount = 0.0
96 payment_line_found = False
97 if payment_term:
98 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
99 for payment_term_line_id in payment_term_lines.line_ids:
100 payment_use_complete = payment_term_line_id.compl_cash_discount
101 if payment_use_complete:
102 if payment_term_lines.cash_discount_ids:
103 dis = 0
104 for discount_line in payment_term_lines.cash_discount_ids:
105 if diff_day >= dis and diff_day <= discount_line.delay:
106 if resudial_amonut:
107 dis1 = 0
108 if discount_line.payment_term_ids:
109 payment_line_found = True
110 for dis_payment_id in discount_line.payment_term_ids:
111 if diff_day >= dis1 and diff_day<= dis_payment_id.days:
112 if dis_payment_id.value == 'procent':
113 amount = resudial_amonut * dis_payment_id.value_amount
114 elif dis_payment_id.value == 'fixed':
115 amount = dis_payment_id.value_amount
116 else:
117 amount = resudial_amonut
118 dis1 = dis_payment_id.days
119 dis = discount_line.delay
120 else:
121 amount = resudial_amonut
122
123 return {'amount':amount,'found':payment_line_found}
124
53 def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None):125 def _get_payment(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
54 """126 """
55 This function return the Discount according to the payment term cash discount term127 This function return the Discount according to the payment term cash discount term
56 """128 """
57
58 if context is None:129 if context is None:
59 context = {}130 context = {}
60 131
@@ -79,6 +150,7 @@
79 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))150 from_dt = time.mktime(time.strptime(date2,'%Y-%m-%d'))
80 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))151 to_dt = time.mktime(time.strptime(date1,'%Y-%m-%d'))
81 diff_day = (from_dt-to_dt)/(3600*24)152 diff_day = (from_dt-to_dt)/(3600*24)
153
82 discount = 0.0154 discount = 0.0
83 if payment_term:155 if payment_term:
84 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)156 payment_term_lines = self.pool.get('account.payment.term').browse(cr, uid, payment_term, context=context)
@@ -92,7 +164,7 @@
92 discount = res164 discount = res
93 dis = discount_line.delay165 dis = discount_line.delay
94 return discount166 return discount
95 167
96 def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None):168 def _get_account(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
97 """169 """
98 This function return the Account according to the payment term cash discount term170 This function return the Account according to the payment term cash discount term
@@ -136,6 +208,7 @@
136 return account_id 208 return account_id
137 209
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=''):210 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=''):
211
139 if context is None:212 if context is None:
140 context = {}213 context = {}
141 #TODO check if we can use different period for payment and the writeoff line214 #TODO check if we can use different period for payment and the writeoff line
@@ -222,7 +295,7 @@
222 if 'tax_move_ids' in context and context['tax_move_ids']:295 if 'tax_move_ids' in context and context['tax_move_ids']:
223 move_line = context['tax_move_ids']296 move_line = context['tax_move_ids']
224 for move_line_id in move_line:297 for move_line_id in move_line:
225 move_line_data = self.pool.get('account.move.line').browse(cr, uid,move_line_id)298 move_line_data = move_line_obj.browse(cr, uid,move_line_id)
226 l3 = {299 l3 = {
227 'debit': move_line_data.debit,300 'debit': move_line_data.debit,
228 'credit': move_line_data.credit,301 'credit': move_line_data.credit,
@@ -237,8 +310,8 @@
237 'tax_amount':move_line_data.tax_amount,310 'tax_amount':move_line_data.tax_amount,
238 }311 }
239 lines.append((0, 0, l3))312 lines.append((0, 0, l3))
240 self.pool.get('account.move.line').unlink(cr, uid,[move_line_id])313 move_line_obj.unlink(cr, uid,[move_line_id])
241 self.pool.get('account.move').unlink(cr, uid,[move_line_data.move_id.id])314 move_obj.unlink(cr, uid,[move_line_data.move_id.id])
242 else:315 else:
243 if amount_discount>0.0: 316 if amount_discount>0.0:
244 for line in invoice.invoice_line:317 for line in invoice.invoice_line:
@@ -267,8 +340,8 @@
267 340
268 if 'discount_move_ids' in context and context['discount_move_ids']: 341 if 'discount_move_ids' in context and context['discount_move_ids']:
269 dis_move_id = context['discount_move_ids'][0]342 dis_move_id = context['discount_move_ids'][0]
270 move_id = self.pool.get('account.move.line').search(cr, uid,[('move_id','=',dis_move_id)])343 move_id = move_line_obj.search(cr, uid,[('move_id','=',dis_move_id)])
271 move_line_data = self.pool.get('account.move.line').browse(cr, uid, move_id[0])344 move_line_data = move_line_obj.browse(cr, uid, move_id[0])
272 l4 = {345 l4 = {
273 'debit': move_line_data.debit,346 'debit': move_line_data.debit,
274 'credit':move_line_data.credit,347 'credit':move_line_data.credit,
@@ -282,7 +355,7 @@
282 }355 }
283 lines.append((0, 0, l4))356 lines.append((0, 0, l4))
284 357
285 self.pool.get('account.move').unlink(cr, uid, context['discount_move_ids'])358 move_obj.unlink(cr, uid, context['discount_move_ids'])
286 else:359 else:
287 if amount_discount>0:360 if amount_discount>0:
288 if 'account_id' in context and context['account_id']:361 if 'account_id' in context and context['account_id']:
@@ -305,7 +378,7 @@
305 lines.append((0, 0, l4))378 lines.append((0, 0, l4))
306379
307 move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}380 move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date}
308 move_id = self.pool.get('account.move').create(cr, uid, move, context=context)381 move_id = move_obj.create(cr, uid, move, context=context)
309 382
310 line_ids = []383 line_ids = []
311 total = 0.0384 total = 0.0
@@ -317,7 +390,6 @@
317 if l.account_id.id==src_account_id:390 if l.account_id.id==src_account_id:
318 line_ids.append(l.id)391 line_ids.append(l.id)
319 total += (l.debit or 0.0) - (l.credit or 0.0)392 total += (l.debit or 0.0) - (l.credit or 0.0)
320
321 if (not round(total,int(config['price_accuracy']))) or writeoff_acc_id:393 if (not round(total,int(config['price_accuracy']))) or writeoff_acc_id:
322 self.pool.get('account.move.line').reconcile(cr, uid, line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context)394 self.pool.get('account.move.line').reconcile(cr, uid, line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context)
323 else:395 else:
324396
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml'
--- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-06-29 13:22:59 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-06 13:37:26 +0000
@@ -15,6 +15,10 @@
15 <field name="delay" select="1"/>15 <field name="delay" select="1"/>
16 <field name="discount" select="1"/>16 <field name="discount" select="1"/>
17 <field name="discount_account_id" />17 <field name="discount_account_id" />
18 <group colspan="4">
19 <separator string="Related Payment Terms Lines" colspan="4"/>
20 <field name="payment_term_ids" widget="one2many_list" nolabel="1"/>
21 </group>
18 </form>22 </form>
19 </field>23 </field>
20 </record>24 </record>
@@ -84,6 +88,19 @@
84 </xpath> 88 </xpath>
85 </field>89 </field>
86 </record>90 </record>
91
92 <record id="account_payment_term_line_view1" model="ir.ui.view">
93 <field name="name">account.payment.term.line.form</field>
94 <field name="model">account.payment.term.line</field>
95 <field name="type">form</field>
96 <field name="inherit_id" ref="account.view_payment_term_line_form"/>
97 <field name="arch" type="xml">
98 <field name="days2" position="after">
99 <label string="" colspan="2"/>
100 <field name="compl_cash_discount"/>
101 </field>
102 </field>
103 </record>
87 104
88 </data>105 </data>
89</openerp>106</openerp>
90107
=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py'
--- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-01 14:49:31 +0000
+++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-06 13:37:26 +0000
@@ -22,7 +22,6 @@
22from lxml import etree22from lxml import etree
23from osv import fields, osv23from osv import fields, osv
24from tools.translate import _24from tools.translate import _
25#import decimal_precision as dp
2625
27class account_invoice_pay_writeoff(osv.osv_memory):26class account_invoice_pay_writeoff(osv.osv_memory):
28 """27 """
@@ -41,6 +40,7 @@
41 }40 }
4241
43 def pay_and_reconcile_writeoff(self, cr, uid, ids, context=None):42 def pay_and_reconcile_writeoff(self, cr, uid, ids, context=None):
43 pay_invoice = self.pool.get('account.invoice.pay')
44 data = self.read(cr, uid, ids,context=context)[0]44 data = self.read(cr, uid, ids,context=context)[0]
45 context.update({'write_off':data})45 context.update({'write_off':data})
46 self.pool.get('account.invoice.pay').pay_and_reconcile(cr, uid, ids, context=context)46 self.pool.get('account.invoice.pay').pay_and_reconcile(cr, uid, ids, context=context)
@@ -58,7 +58,7 @@
58 'amount': fields.float('Amount paid', required=True),58 'amount': fields.float('Amount paid', required=True),
59 'name': fields.char('Entry Name', size=64, required=True),59 'name': fields.char('Entry Name', size=64, required=True),
60 'date': fields.date('Date payment', required=True),60 'date': fields.date('Date payment', required=True),
61 'cash_residual_amount': fields.float('Residual Amount', readonly=True),61 'cash_residual_amount': fields.float('Residual Amount'),
62 'journal_id': fields.many2one('account.journal', 'Journal/Payment Mode', required=True),62 'journal_id': fields.many2one('account.journal', 'Journal/Payment Mode', required=True),
63 'period_id': fields.many2one('account.period', 'Period', required=True),63 'period_id': fields.many2one('account.period', 'Period', required=True),
64 'cash_amount':fields.float('Cash Discount Amount',),64 'cash_amount':fields.float('Cash Discount Amount',),
@@ -69,7 +69,7 @@
69 'discount_move_ids': fields.many2many('account.move', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'),69 'discount_move_ids': fields.many2many('account.move', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'),
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', 'account_tax_move_rel', 'tax_account_id', 'tax_move_id', 'Account Taxes Moves'),
71 }71 }
7272
73 def _get_period(self, cr, uid, context=None):73 def _get_period(self, cr, uid, context=None):
74 ids = self.pool.get('account.period').find(cr, uid, context=context)74 ids = self.pool.get('account.period').find(cr, uid, context=context)
75 period_id = False75 period_id = False
@@ -80,34 +80,19 @@
80 def _get_amount(self, cr, uid, context=None):80 def _get_amount(self, cr, uid, context=None):
81 obj_inv = self.pool.get('account.invoice')81 obj_inv = self.pool.get('account.invoice')
82 invoice = obj_inv.browse(cr, uid, context['id'], context=context)82 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
83 discount = obj_inv._get_payment(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context)83 amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context)
84 residual_amount = invoice.residual - discount84 context.update({'found':amount['found']})
85 amount = amount['amount']
86 discount = obj_inv._get_payment(cr, uid, [context['id']] ,amount, invoice.payment_term.id, context=context)
87 residual_amount = amount - discount
85 return residual_amount88 return residual_amount
86 89
87 def on_change_ammount(self, cr, uid, ids, amount, context=None):
88 """
89 Function return the Discount according to the Amount paid and Payment Term Cash Discount
90 """
91 res = {}
92 obj_inv = self.pool.get('account.invoice')
93 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
94 discount = obj_inv._get_payment(cr, uid, [context['id']] , invoice.residual, invoice.payment_term.id, context=context)
95 diff_amount = round(invoice.residual - (amount + discount),2)
96 return {'value' : {'cash_residual_amount':diff_amount}}
97
98 def on_change_cash_discount_amount(self, cr, uid, ids, discount_amount, amount, context=None):
99 ### Return discount amount
100 res = {}
101 obj_inv = self.pool.get('account.invoice')
102 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
103 diff_amount = 0.0
104 diff_amount = round(invoice.residual - (amount + discount_amount),2)
105 return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}}
106
107 def _get_discount(self, cr, uid, context=None):90 def _get_discount(self, cr, uid, context=None):
108 obj_inv = self.pool.get('account.invoice')91 obj_inv = self.pool.get('account.invoice')
109 invoice = obj_inv.browse(cr, uid, context['id'], context=context)92 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
110 discount = obj_inv._get_payment(cr, uid, [context['id']] , invoice.residual, invoice.payment_term.id, context=context)93 amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context)
94 amount = amount['amount']
95 discount = obj_inv._get_payment(cr, uid, [context['id']] , amount, invoice.payment_term.id, context=context)
111 return discount96 return discount
112 97
113 def _get_account(self, cr, uid, context=None):98 def _get_account(self, cr, uid, context=None):
@@ -122,13 +107,47 @@
122 account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account)107 account = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account)
123 return account108 return account
124 109
125 def default_get(self, cr, uid, fields, context=None):110 _defaults = {
126 res = super(account_invoice_pay, self).default_get(cr, uid, fields, context=context)111 'date': lambda *a: time.strftime('%Y-%m-%d'),
127 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)112 'period_id': _get_period,
128 if invoice.state in ['draft', 'proforma2', 'cancel']:113 'amount': _get_amount,
129 raise osv.except_osv(_('Error !'), _('Can not pay draft/proforma/cancel invoice.'))114 'cash_amount':_get_discount,
130 return res115 'account_id':_get_account,
131 116 'cash_residual_amount': lambda *a:0.0,
117 'cal_method_selection':lambda *a :'method_gross_methodology',
118 }
119
120 def on_change_ammount(self, cr, uid, ids, amount, context=None):
121 """
122 Function return the Discount according to the Amount paid and Payment Term Cash Discount
123 """
124 res = {}
125 obj_inv = self.pool.get('account.invoice')
126 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
127 cal_amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context)
128
129 old_cal_amount = cal_amount['amount']
130 discount = obj_inv._get_payment(cr, uid, [context['id']] , old_cal_amount, invoice.payment_term.id, context=context)
131 old_amount = old_cal_amount
132 diff_amount = round(old_amount - (amount + discount),2)
133
134 return {'value' : {'cash_residual_amount':diff_amount}}
135
136 def on_change_cash_discount_amount(self, cr, uid, ids, discount_amount, amount, context=None):
137 ### Return discount amount
138 res = {}
139 obj_inv = self.pool.get('account.invoice')
140 invoice = obj_inv.browse(cr, uid, context['id'], context=context)
141 cal_amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context)
142 old_cal_amount = cal_amount['amount']
143 discount = obj_inv._get_payment(cr, uid, [context['id']] , amount, invoice.payment_term.id, context=context)
144 old_amount = old_cal_amount
145
146 diff_amount = 0.0
147 diff_amount = old_amount - (amount + discount_amount)
148
149 return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}}
150
132 def _calculation(self, cr, uid, ids, context=None):151 def _calculation(self, cr, uid, ids, context=None):
133 invoice_obj = self.pool.get('account.invoice')152 invoice_obj = self.pool.get('account.invoice')
134 data = self.read(cr, uid, ids,context=context)[0]153 data = self.read(cr, uid, ids,context=context)[0]
@@ -137,7 +156,19 @@
137 invoice_tax_obj = self.pool.get("account.invoice.tax")156 invoice_tax_obj = self.pool.get("account.invoice.tax")
138 move_obj = self.pool.get('account.move')157 move_obj = self.pool.get('account.move')
139 move_line_obj = self.pool.get('account.move.line')158 move_line_obj = self.pool.get('account.move.line')
140 159
160 ############## Delete another lines of taxes and discount
161 if data['tax_move_ids']:
162 move_line = data['tax_move_ids']
163 for move_line_id in move_line:
164 move_id = move_line_data = move_line_obj.browse(cr, uid,move_line_id).move_id.id
165 move_line_obj.unlink(cr, uid,[move_line_id])
166 move_obj.unlink(cr, uid,[move_id])
167
168 if data['discount_move_ids']:
169 dis_move_id = data['discount_move_ids'][0]
170 move_obj.unlink(cr, uid, data['discount_move_ids'])
171
141 ######## to get ref172 ######## to get ref
142 if invoice.type in ('in_invoice', 'in_refund'):173 if invoice.type in ('in_invoice', 'in_refund'):
143 ref = invoice.reference174 ref = invoice.reference
@@ -153,7 +184,6 @@
153 name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number184 name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number
154 185
155 ##### Entry in the discount account moves and entry in the tax account moves186 ##### Entry in the discount account moves and entry in the tax account moves
156
157 ### Entry for taxes in the line of wizard tax187 ### Entry for taxes in the line of wizard tax
158 if data.get('cash_amount',0.0)>0.0:188 if data.get('cash_amount',0.0)>0.0:
159 lines3 = []189 lines3 = []
@@ -202,7 +232,7 @@
202 discount_account_id = self.pool.get('account.journal').browse(cr, uid, journal_id).default_credit_account_id.id232 discount_account_id = self.pool.get('account.journal').browse(cr, uid, journal_id).default_credit_account_id.id
203 else:233 else:
204 discount_account_id = data['account_id']234 discount_account_id = data['account_id']
205 ###############################################3235 ###############################################
206 236
207 l4 = {237 l4 = {
208 'debit': direction * data.get('cash_amount',0.0)<0 and - direction * data.get('cash_amount',0.0),238 'debit': direction * data.get('cash_amount',0.0)<0 and - direction * data.get('cash_amount',0.0),
@@ -218,27 +248,57 @@
218 move = {'ref': ref, 'line_id': lines4, 'journal_id': data['journal_id'], 'period_id': data['period_id'], }248 move = {'ref': ref, 'line_id': lines4, 'journal_id': data['journal_id'], 'period_id': data['period_id'], }
219 move_id = move_obj.create(cr, uid, move, context=context)249 move_id = move_obj.create(cr, uid, move, context=context)
220 self.write(cr, uid, ids, {'discount_move_ids':[(6,0,[move_id])]}, context)250 self.write(cr, uid, ids, {'discount_move_ids':[(6,0,[move_id])]}, context)
251
221 return True252 return True
222 253
223 _defaults = {254 def default_get(self, cr, uid, fields, context=None):
224 'date': lambda *a: time.strftime('%Y-%m-%d'),255 res = super(account_invoice_pay, self).default_get(cr, uid, fields, context=context)
225 'period_id': _get_period,256 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)
226 'amount': _get_amount,257 if invoice.state in ['draft', 'proforma2', 'cancel','paid']:
227 'cash_amount':_get_discount,258 raise osv.except_osv(_('Error !'), _('Can not pay draft/proforma/cancel/Done invoice.'))
228 'account_id':_get_account,259 return res
229 'cash_residual_amount': lambda *a:0.0,260
230 'cal_method_selection':lambda *a :'method_gross_methodology',261 def _message(self, cr, uid, ids, context=None):
231 }262 mod_obj = self.pool.get('ir.model.data')
263 data = self.read(cr, uid, ids,context=context)[0]
232264
265 if data['discount_move_ids']:
266 context.update({'discount_move_ids':data['discount_move_ids']})
267
268 if data['tax_move_ids']:
269 context.update({'tax_move_ids':data['tax_move_ids']})
270
271 if data['amount']:
272 context.update({'amount':data['amount']})
273
274 if data['cash_amount']:
275 context.update({'cash_amount':data['cash_amount']})
276
277 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_message')], context=context)
278 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
279
280 return {
281 'name': _('Message'),
282 'context': context,
283 'view_type': 'form',
284 'view_mode': 'form',
285 'res_model': 'account.message',
286 'views': [(resource_id,'form')],
287 'type': 'ir.actions.act_window',
288 'target': 'new',
289 }
290
233 def wo_check(self, cr, uid, ids, context=None):291 def wo_check(self, cr, uid, ids, context=None):
234 cur_obj = self.pool.get('res.currency')292 cur_obj = self.pool.get('res.currency')
235 mod_obj = self.pool.get('ir.model.data')293 mod_obj = self.pool.get('ir.model.data')
294 obj_inv = self.pool.get('account.invoice')
295
236 if context is None:296 if context is None:
237 context = {}297 context = {}
238 data = self.read(cr, uid, ids,context=context)[0]298 data = self.read(cr, uid, ids,context=context)[0]
299
239 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context)300 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context)
240 journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context)301 journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context)
241
242 # Here we need that:302 # Here we need that:
243 # The invoice total amount in company's currency <> paid amount in company currency303 # The invoice total amount in company's currency <> paid amount in company currency
244 # (according to the correct day rate, invoicing rate and payment rate are may be different)304 # (according to the correct day rate, invoicing rate and payment rate are may be different)
@@ -251,13 +311,13 @@
251 inv_amount_company_currency += aml.debit311 inv_amount_company_currency += aml.debit
252 inv_amount_company_currency -= aml.credit312 inv_amount_company_currency -= aml.credit
253 inv_amount_company_currency = abs(inv_amount_company_currency)313 inv_amount_company_currency = abs(inv_amount_company_currency)
254
255 # Get the current amount paid in company currency314 # Get the current amount paid in company currency
256 if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:315 if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
257 ctx = {'date':data['date']}316 ctx = {'date':data['date']}
258 amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['amount'], round=True, context=ctx)317 amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['amount'], round=True, context=ctx)
259 else:318 else:
260 amount_paid = data['amount']319 amount_paid = data['amount'] + data['cash_amount']
320
261 # Get the old payment if there are some321 # Get the old payment if there are some
262 if invoice.payment_ids:322 if invoice.payment_ids:
263 debit=credit=0.0323 debit=credit=0.0
@@ -267,27 +327,42 @@
267 amount_paid+=abs(debit-credit)327 amount_paid+=abs(debit-credit)
268328
269 # Test if there is a difference according to currency rouding setting329 # Test if there is a difference according to currency rouding setting
270 if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,330 amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context)
271 (amount_paid - inv_amount_company_currency)):331 found_h = amount['found']
332
333 if found_h:
334 if context.get('discount_move_ids',False):
335 context.update({'discount_move_ids':context['discount_move_ids']})
336
337 if context.get('tax_move_ids',False):
338 context.update({'tax_move_ids':context['tax_move_ids']})
339
272 return self.pay_and_reconcile(cr, uid, ids, context=context)340 return self.pay_and_reconcile(cr, uid, ids, context=context)
273 else:341 else:
274 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context)342
275 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']343 if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,
276 return {344 (amount_paid - inv_amount_company_currency)):
277 'name': _('Information addendum'),345 return self.pay_and_reconcile(cr, uid, ids, context=context)
278 'context': context,346
279 'view_type': 'form',347 else:
280 'view_mode': 'form',348 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context)
281 'res_model': 'account.invoice.pay.writeoff',349 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
282 'views': [(resource_id,'form')],350 return {
283 'type': 'ir.actions.act_window',351 'name': _('Information addendum'),
284 'target': 'new',352 'context': context,
285 }353 'view_type': 'form',
286354 'view_mode': 'form',
355 'res_model': 'account.invoice.pay.writeoff',
356 'views': [(resource_id,'form')],
357 'type': 'ir.actions.act_window',
358 'target': 'new',
359 }
360
287 def pay_and_reconcile(self, cr, uid, ids, context=None):361 def pay_and_reconcile(self, cr, uid, ids, context=None):
288 cur_obj = self.pool.get('res.currency')362 cur_obj = self.pool.get('res.currency')
289 if context is None:363 if context is None:
290 context = {}364 context = {}
365
291 data = self.read(cr, uid, ids,context=context)[0]366 data = self.read(cr, uid, ids,context=context)[0]
292 writeoff_account_id = False367 writeoff_account_id = False
293 writeoff_journal_id = False368 writeoff_journal_id = False
@@ -297,9 +372,9 @@
297 writeoff_account_id = context['write_off']['writeoff_acc_id']372 writeoff_account_id = context['write_off']['writeoff_acc_id']
298 writeoff_journal_id = context['write_off']['writeoff_journal_id']373 writeoff_journal_id = context['write_off']['writeoff_journal_id']
299 comment = context['write_off']['comment']374 comment = context['write_off']['comment']
300375
301 amount = data['amount'] + data['cash_amount']376 amount = data['amount'] + data['cash_amount']
302 377
303 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)378 invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context)
304 journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context=context)379 journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context=context)
305 # Compute the amount in company's currency, with the journal currency (which is equal to payment currency)380 # Compute the amount in company's currency, with the journal currency (which is equal to payment currency)
@@ -326,12 +401,16 @@
326401
327 context.update({'account_id':data['account_id'],'cash_amount':data['cash_amount'],'amount_currency':data['amount'] + data['cash_amount']}) 402 context.update({'account_id':data['account_id'],'cash_amount':data['cash_amount'],'amount_currency':data['amount'] + data['cash_amount']})
328 403
329 if data['discount_move_ids']:404 if context.get('discount_move_ids',False):
330 context.update({'discount_move_ids':data['discount_move_ids']})405 context = context
406 else:
407 context.update({'discount_move_ids':data['discount_move_ids']})
331 408
332 if data['tax_move_ids']:409 if context.get('tax_move_ids',False):
410 context = context
411 else:
333 context.update({'tax_move_ids':data['tax_move_ids']})412 context.update({'tax_move_ids':data['tax_move_ids']})
334 413
335 if data['cash_amount']:414 if data['cash_amount']:
336 context.update({'cash_amount':data['cash_amount']})415 context.update({'cash_amount':data['cash_amount']})
337 416
@@ -344,6 +423,7 @@
344 return {}423 return {}
345 424
346 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False):425 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False):
426
347 res = super(account_invoice_pay,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar)427 res = super(account_invoice_pay,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar)
348 fields=res.get('fields',{})428 fields=res.get('fields',{})
349 word = "Supplier Cash Discount Account"429 word = "Supplier Cash Discount Account"
@@ -358,4 +438,13 @@
358 438
359account_invoice_pay()439account_invoice_pay()
360440
441class account_message(osv.osv_memory):
442 _name = "account.message"
443 def _check(self, cr, uid, ids, context=None):
444 data = self.read(cr, uid, ids,context=context)[0]
445 result = self.pool.get('account.invoice.pay').wo_check(cr, uid, ids, context=context)
446 return result
447
448account_message()
449
361# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:450# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
362\ No newline at end of file451\ No newline at end of file
363452
=== modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml'
--- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-01 12:19:51 +0000
+++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-06 13:37:26 +0000
@@ -34,7 +34,7 @@
34 <label string ="" colspan="2"/>34 <label string ="" colspan="2"/>
35 <button icon="gtk-cancel" special="cancel" string="Cancel"/>35 <button icon="gtk-cancel" special="cancel" string="Cancel"/>
36 <button icon="gtk-execute" string="Partial Payment" name="pay_and_reconcile" type="object"/>36 <button icon="gtk-execute" string="Partial Payment" name="pay_and_reconcile" type="object"/>
37 <button icon="gtk-execute" string="Full Payment" name="wo_check" type="object"/>37 <button icon="gtk-execute" string="Full-Payment" name="_message" type="object"/>
38 </group>38 </group>
39 </form>39 </form>
40 </field>40 </field>
@@ -70,5 +70,18 @@
70 </form>70 </form>
71 </field>71 </field>
72 </record>72 </record>
73
74 <record id="view_account_message" model="ir.ui.view">
75 <field name="name">account.message.form</field>
76 <field name="model">account.message</field>
77 <field name="type">form</field>
78 <field name="arch" type="xml">
79 <form string="Your Messages">
80 <label colspan="8" string="Are you really want to reconcile this invoice" />
81 <button icon="gtk-execute" string="OK" name="_check" type="object"/>
82 </form>
83 </field>
84 </record>
85
73 </data>86 </data>
74</openerp>87</openerp>
75\ No newline at end of file88\ No newline at end of file

Subscribers

People subscribed via source and target branches