Merge lp:~serpent-consulting-services/openerp-usa/account_payment_creditcard_RSA into lp:openerp-usa/6.0

Proposed by Serpent Consulting Services
Status: Merged
Merged at revision: 98
Proposed branch: lp:~serpent-consulting-services/openerp-usa/account_payment_creditcard_RSA
Merge into: lp:openerp-usa/6.0
Diff against target: 2374 lines (+2237/-1)
24 files modified
account_payment_ccapi_authdotnet/Change Log.txt (+65/-0)
account_payment_ccapi_authdotnet/__init__.py (+25/-0)
account_payment_ccapi_authdotnet/__openerp__.py (+44/-0)
account_payment_ccapi_authdotnet/account_voucher.py (+33/-0)
account_payment_ccapi_authdotnet/account_voucher.xml (+43/-0)
account_payment_ccapi_authdotnet/cc_auth_api.py (+583/-0)
account_payment_ccapi_authdotnet/security/ir.model.access.csv (+3/-0)
account_payment_ccapi_authdotnet/stock_return_picking.py (+226/-0)
account_payment_ccapi_authdotnet/stock_view.xml (+28/-0)
account_payment_creditcard/Change Log.txt (+50/-0)
account_payment_creditcard/__init__.py (+29/-0)
account_payment_creditcard/__openerp__.py (+45/-0)
account_payment_creditcard/account_journal.py (+73/-0)
account_payment_creditcard/account_journal_view.xml (+74/-0)
account_payment_creditcard/account_voucher.py (+301/-0)
account_payment_creditcard/account_voucher_view.xml (+156/-0)
account_payment_creditcard/invoice.py (+37/-0)
account_payment_creditcard/invoice_view.xml (+26/-0)
account_payment_creditcard/rsa_encrypt.py (+62/-0)
account_payment_creditcard/sale.py (+225/-0)
account_payment_creditcard/security/account_security.xml (+10/-0)
account_payment_creditcard/stock_picking.py (+52/-0)
account_payment_creditcard/stock_picking_view.xml (+47/-0)
account_voucher_credits_us/voucher_view.xml (+0/-1)
To merge this branch: bzr merge lp:~serpent-consulting-services/openerp-usa/account_payment_creditcard_RSA
Reviewer Review Type Date Requested Status
npg Pending
Review via email: mp+129831@code.launchpad.net
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=== added directory 'account_payment_ccapi_authdotnet'
2=== added file 'account_payment_ccapi_authdotnet/Change Log.txt'
3--- account_payment_ccapi_authdotnet/Change Log.txt 1970-01-01 00:00:00 +0000
4+++ account_payment_ccapi_authdotnet/Change Log.txt 2012-10-16 09:27:13 +0000
5@@ -0,0 +1,65 @@
6+===============================================================================
7+ Version Change Log (account_payment_ccapi_authdotnet)
8+===============================================================================
9+1.22 on 2012-10-16 by Serpent Consulting Services
10+ * Added necessary code for pre-auth duplication check and othe improvements.
11+
12+1.21 On 2011-11-15 by Arif
13+ * Corrected the unit price in refund invoice - Now it takes from sale order instead of products unit price
14+ * Fixed the bug - Shipping cost was not added to total and residual amounts
15+ * Fixed the AuthnetAIMError
16+
17+1.20 0n 2011-11-09 by Arif
18+ * Moved credicard refund on product return to after processing of related incoming shipment
19+
20+1.19 on 2011-11-08 By Janeesh
21+ * Fixed error on creating invoice (removed _get_invoice_type function. need to test more the effect of this)
22+
23+1.18 on 2011-10-06 By Janeesh
24+ * When Sale Order is cancelled, Invoice and Picking automatically cancelled for CreditCard
25+
26+1.17 on 2011-09-29 By Arif
27+ * Removed the attribute modification on Authorize button since it has been
28+ moved near to Post buttor where required modification has been made.
29+
30+1.16 on 2011-08-25 by Arif
31+ * Modifications related with credit card refund
32+
33+1.15 on 2011-08-17 by Janeesh
34+ * Added Origin field in Sales receipt
35+
36+1.14 on 2011-08-17 by Arif
37+ * Added check box for ship refund in product return wizard
38+
39+1.13 on 2011-08-10 by Arif
40+ * Partial credit card refund from product retrun from delivered products
41+
42+1.12 on 2011-08-09 by Arif
43+ * Removed reconcillation
44+ * Created Refund sales receipt
45+ * Creait card fields read only in Pay Invoice
46+
47+1.11 on 11 July 2011 by Arif
48+ * Cancelled sales receipt on Refund
49+1.10 on 11 July 2011 by Jabir
50+ * CCV saved on bank details
51+1.08 -> 1.09
52+ * Added Security for the model created from this module
53+1.07 -> 1.08
54+ * Created the sales reciept line for shipping charge
55+1.06 -> 1.07
56+ * Created the sales reciept on sale order confirm and validate it on payment
57+
58+1.05 -> 1.06
59+ * Fixed the wrong account issue on sales receipt
60+
61+1.04 -> 1.05
62+ * Fixed issue with sale order state being draft authorised even after payed and delivered
63+
64+1.03 -> 1.04
65+ * Created sales reciept before posting sales payment
66+
67+1.0 -> 1.03
68+ * Add function to hook methods authorize and cc_refund which is added on account_payment_creditcard module
69+ * Add class to do credit card transaction
70+ * Add function to Authorize button
71
72=== added file 'account_payment_ccapi_authdotnet/__init__.py'
73--- account_payment_ccapi_authdotnet/__init__.py 1970-01-01 00:00:00 +0000
74+++ account_payment_ccapi_authdotnet/__init__.py 2012-10-16 09:27:13 +0000
75@@ -0,0 +1,25 @@
76+# -*- coding: utf-8 -*-
77+##############################################################################
78+#
79+# OpenERP, Open Source Management Solution
80+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
81+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
82+#
83+# This program is free software: you can redistribute it and/or modify
84+# it under the terms of the GNU General Public License as published by
85+# the Free Software Foundation, either version 3 of the License, or
86+# (at your option) any later version.
87+#
88+# This program is distributed in the hope that it will be useful,
89+# but WITHOUT ANY WARRANTY; without even the implied warranty of
90+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91+# GNU General Public License for more details.
92+#
93+# You should have received a copy of the GNU General Public License
94+# along with this program. If not, see <http://www.gnu.org/licenses/>
95+#
96+##############################################################################
97+import account_voucher
98+import cc_auth_api
99+import stock_return_picking
100+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
101
102=== added file 'account_payment_ccapi_authdotnet/__openerp__.py'
103--- account_payment_ccapi_authdotnet/__openerp__.py 1970-01-01 00:00:00 +0000
104+++ account_payment_ccapi_authdotnet/__openerp__.py 2012-10-16 09:27:13 +0000
105@@ -0,0 +1,44 @@
106+# -*- coding: utf-8 -*-
107+##############################################################################
108+#
109+# OpenERP, Open Source Management Solution
110+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
111+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
112+#
113+# This program is free software: you can redistribute it and/or modify
114+# it under the terms of the GNU General Public License as published by
115+# the Free Software Foundation, either version 3 of the License, or
116+# (at your option) any later version.
117+#
118+# This program is distributed in the hope that it will be useful,
119+# but WITHOUT ANY WARRANTY; without even the implied warranty of
120+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121+# GNU General Public License for more details.
122+#
123+# You should have received a copy of the GNU General Public License
124+# along with this program. If not, see <http://www.gnu.org/licenses/>
125+#
126+##############################################################################
127+{
128+ 'name': 'CreditCard Payment',
129+ 'version': '1.22',
130+ 'category': 'Generic Modules/Others',
131+ 'description': """
132+ Module for Credit card payment using authorise.net
133+ """,
134+ 'author': 'NovaPoint Group LLC',
135+ 'website': ' http://www.novapointgroup.com',
136+ 'depends': ['account_voucher_credits_us'],
137+ 'init_xml': [
138+ ],
139+ 'update_xml': [
140+ 'account_voucher.xml',
141+ 'security/ir.model.access.csv',
142+ 'stock_view.xml',
143+ ],
144+ 'demo_xml': [
145+ ],
146+ 'installable': True,
147+ 'auto_install': False,
148+}
149+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
150
151=== added file 'account_payment_ccapi_authdotnet/account_voucher.py'
152--- account_payment_ccapi_authdotnet/account_voucher.py 1970-01-01 00:00:00 +0000
153+++ account_payment_ccapi_authdotnet/account_voucher.py 2012-10-16 09:27:13 +0000
154@@ -0,0 +1,33 @@
155+# -*- coding: utf-8 -*-
156+##############################################################################
157+#
158+# OpenERP, Open Source Management Solution
159+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
160+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
161+#
162+# This program is free software: you can redistribute it and/or modify
163+# it under the terms of the GNU General Public License as published by
164+# the Free Software Foundation, either version 3 of the License, or
165+# (at your option) any later version.
166+#
167+# This program is distributed in the hope that it will be useful,
168+# but WITHOUT ANY WARRANTY; without even the implied warranty of
169+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
170+# GNU General Public License for more details.
171+#
172+# You should have received a copy of the GNU General Public License
173+# along with this program. If not, see <http://www.gnu.org/licenses/>
174+#
175+##############################################################################
176+
177+from osv import osv, fields
178+
179+class account_voucher(osv.osv):
180+
181+ _inherit = 'account.voucher'
182+
183+ _columns = {
184+ 'origin':fields.char('Origin',size=16,readonly=True)
185+ }
186+
187+account_voucher()
188\ No newline at end of file
189
190=== added file 'account_payment_ccapi_authdotnet/account_voucher.xml'
191--- account_payment_ccapi_authdotnet/account_voucher.xml 1970-01-01 00:00:00 +0000
192+++ account_payment_ccapi_authdotnet/account_voucher.xml 2012-10-16 09:27:13 +0000
193@@ -0,0 +1,43 @@
194+<?xml version="1.0" encoding="UTF-8"?>
195+<openerp>
196+ <data>
197+ <record id="account_voucher_changes_for_credit_card_02_inherit" model="ir.ui.view">
198+ <field name="name">account_voucher_changes_for_credit_card_02.inherit</field>
199+ <field name="model">account.voucher</field>
200+ <field name="type">form</field>
201+ <field name="inherit_id" ref="account_payment_creditcard.account_voucher_changes_for_credit_card_02"/>
202+ <field name="arch" type="xml">
203+ <xpath expr="//button[@name='authorize']" position="after">
204+ <!-- button name="authorize" string="Authorize" type="object" colspan="2" attrs="{'readonly': [('state','!=','draft') ] }"/ -->
205+ </xpath>
206+ </field>
207+ </record>
208+
209+ <record id="view_sale_receipt_form_inherit_id" model="ir.ui.view">
210+ <field name="name">account.voucher.sale.form.inherit</field>
211+ <field name="model">account.voucher</field>
212+ <field name="type">form</field>
213+ <field name="inherit_id" ref="account_voucher.view_sale_receipt_form"/>
214+ <field name="arch" type="xml">
215+ <xpath expr="//field[@name='partner_id']" position="after">
216+ <field name="origin"/>
217+ </xpath>
218+ </field>
219+ </record>
220+
221+ <record id="view_voucher_filter_sale_inherit" model="ir.ui.view">
222+ <field name="name">account.voucher.sale.select.inherit</field>
223+ <field name="model">account.voucher</field>
224+ <field name="type">search</field>
225+ <field name="inherit_id" ref="account_voucher.view_voucher_filter_sale"/>
226+ <field name="arch" type="xml">
227+ <xpath expr="//field[@name='partner_id']" position="after">
228+ <field name="origin"/>
229+ </xpath>
230+ </field>
231+ </record>
232+
233+ </data>
234+</openerp>
235+
236+
237\ No newline at end of file
238
239=== added file 'account_payment_ccapi_authdotnet/cc_auth_api.py'
240--- account_payment_ccapi_authdotnet/cc_auth_api.py 1970-01-01 00:00:00 +0000
241+++ account_payment_ccapi_authdotnet/cc_auth_api.py 2012-10-16 09:27:13 +0000
242@@ -0,0 +1,583 @@
243+# -*- coding: utf-8 -*-
244+##############################################################################
245+#
246+# OpenERP, Open Source Management Solution
247+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
248+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
249+#
250+# This program is free software: you can redistribute it and/or modify
251+# it under the terms of the GNU General Public License as published by
252+# the Free Software Foundation, either version 3 of the License, or
253+# (at your option) any later version.
254+#
255+# This program is distributed in the hope that it will be useful,
256+# but WITHOUT ANY WARRANTY; without even the implied warranty of
257+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
258+# GNU General Public License for more details.
259+#
260+# You should have received a copy of the GNU General Public License
261+# along with this program. If not, see <http://www.gnu.org/licenses/>
262+#
263+##############################################################################
264+
265+from osv import osv, fields
266+import pooler
267+import socket
268+import sys
269+import urllib
270+import collections
271+from time import time
272+from tools.translate import _
273+from Crypto.Cipher import DES3
274+import base64
275+import netsvc
276+
277+class AuthnetAIMError(Exception):
278+ '''
279+ Class to display exceptions
280+ '''
281+ def __init__(self, value):
282+ self.parameter = value
283+ def __str__(self):
284+ return str(self.parameter)
285+ def setParameter(self, parameters={},key=None, value=None):
286+
287+ if key != None and value != None and str(key).strip() != '' and str(value).strip() != '':
288+ parameters[key] = str(value).strip()
289+ else:
290+ raise AuthnetAIMError('Incorrect parameters passed to setParameter(): {0}:{1}'.format(key, value))
291+ return parameters
292+
293+class auth_net_cc_api(osv.osv):
294+ _name = "auth.net.cc.api"
295+ '''
296+ Class to do credit card transaction
297+ '''
298+
299+ def _get_prod_acc(self, product_id, journal_obj, context=False):
300+ if product_id and product_id.property_account_income:
301+ return product_id.property_account_income.id
302+ elif product_id and product_id.categ_id.property_account_income_categ:
303+ return product_id.categ_id.property_account_income_categ.id
304+ else:
305+ if journal_obj.default_credit_account_id:
306+ return journal_obj.default_credit_account_id.id
307+ return False
308+
309+ def validate_sales_reciept(self, cr, uid, ids, context={}):
310+ if type(ids) == type([]):
311+ voucher_objs=self.pool.get('account.voucher').browse(cr,uid,ids,context=context)
312+ else:
313+ voucher_objs=self.pool.get('account.voucher').browse(cr,uid,[ids],context=context)
314+ for voucher_obj in voucher_objs:
315+ rel_sale_order_id = voucher_obj.rel_sale_order_id.id
316+ sale_reciepts_ids = self.pool.get('account.voucher').search(cr,uid,[('type','=','sale'),('rel_sale_order_id','=',rel_sale_order_id),('state','in',['draft'])])
317+
318+ if sale_reciepts_ids:
319+ self.pool.get('account.voucher').action_move_line_create(cr, uid, sale_reciepts_ids, context=context)
320+ else:
321+ sale_reciepts_id = self.pool.get('sale.order').create_sales_reciept(cr, uid, [rel_sale_order_id], context=context)
322+ self.pool.get('account.voucher').action_move_line_create(cr, uid, [sale_reciepts_id], context=context)
323+ return True
324+
325+ def _get_prod_deb_acc(self, product_id, journal_obj, context=False):
326+ if product_id and product_id.property_account_income:
327+ return product_id.property_account_expense.id
328+ elif product_id and product_id.categ_id.property_account_expense_categ:
329+ return product_id.categ_id.property_account_expense_categ.id
330+ else:
331+ if journal_obj.default_debit_account_id:
332+ return journal_obj.default_debit_account_id.id
333+ return False
334+ def cancel_sales_reciept(self, cr, uid, ids, context={}):
335+ voucher_obj = self.pool.get('account.voucher')
336+ sale_obj = self.browse(cr,uid,ids,context=context)
337+# vals={}
338+# cr_ids_list = []
339+# cr_ids = {}
340+ sales_receipt_ids = voucher_obj.search(cr,uid,[('rel_sale_order_id','=',ids),('state','=','posted')], context=context)
341+ if sales_receipt_ids:
342+ voucher_obj.cancel_voucher(cr, uid, sales_receipt_ids, context=context)
343+# journal_ids = self.pool.get('account.journal').search(cr,uid,[('type','=','sale_refund')])
344+# if journal_ids:
345+# vals['journal_id'] = journal_ids[0]
346+# journal_obj = self.pool.get('account.journal').browse(cr,uid,journal_ids[0])
347+# if sale_obj and sale_obj.order_line:
348+# for sale_line in sale_obj.order_line:
349+# cr_ids['account_id'] = self._get_prod_deb_acc(sale_line.product_id and sale_line.product_id, journal_obj)#journal_obj.default_debit_account_id.id #Change this account to product's income account
350+# cr_ids['amount'] = sale_line.price_subtotal
351+# cr_ids['partner_id'] = sale_obj.partner_id.id
352+# cr_ids['name'] = sale_line.name
353+# cr_ids_list.append(cr_ids.copy())
354+# if sale_obj.shipcharge and sale_obj.ship_method_id and sale_obj.ship_method_id.account_id:
355+# cr_ids['account_id'] = sale_obj.ship_method_id.account_id.id
356+# cr_ids['amount'] = sale_obj.shipcharge
357+# cr_ids['partner_id'] = sale_obj.partner_id.id
358+# cr_ids['name'] = 'Shipping Charge for %s'%sale_line.name
359+# cr_ids_list.append(cr_ids.copy())
360+#
361+#
362+# else:
363+# vals['journal_id'] = False
364+# vals['partner_id'] = sale_obj.partner_id.id
365+# vals['date'] = sale_obj.date_order
366+# vals['rel_sale_order_id'] = ids[0]
367+# vals['name'] = 'Auto generated Sales Receipt'
368+# vals['type'] = 'sale'
369+# vals['currency_id'] = journal_obj.company_id.currency_id.id
370+# vals['line_cr_ids'] = [(0,0,cr_ids) for cr_ids in cr_ids_list]
371+## vals['narration'] = voucher_obj.narration
372+# vals['pay_now'] = 'pay_now'
373+# vals['account_id'] = journal_obj.default_debit_account_id.id
374+## vals['reference'] = voucher_obj.reference
375+## vals['tax_id'] = voucher_obj.tax_id.id
376+# vals['amount'] = sale_obj.amount_total
377+# vals['company_id'] = journal_obj.company_id.id
378+# voucher_id = self.pool.get('account.voucher').create(cr,uid,vals,context)
379+# print voucher_id,'--------------------------'
380+ return True
381+
382+ def do_this_transaction(self, cr, uid, ids, refund=False, context=None):
383+ '''
384+ Do credit card transaction
385+ '''
386+
387+ ret = False
388+ if type([]) == type(ids):
389+ acc_voucher_obj=pooler.get_pool(cr.dbname).get('account.voucher').browse(cr,uid,ids[0],context={'cc_no':'no_mask'})
390+ else:
391+ acc_voucher_obj=pooler.get_pool(cr.dbname).get('account.voucher').browse(cr,uid,ids,context={'cc_no':'no_mask'})
392+ user = pooler.get_pool(cr.dbname).get('res.users').browse(cr,uid,uid)
393+ creditcard =acc_voucher_obj.cc_number# CREDIT CARD NUMBER
394+ expiration =acc_voucher_obj.cc_e_d_month+acc_voucher_obj.cc_e_d_year ################ EXPIRATION DATE MM + YY
395+ total =acc_voucher_obj.cc_order_amt ############## ORDER AMOUNT
396+
397+ if acc_voucher_obj.cc_save_card_details:
398+ if not acc_voucher_obj.cc_bank:
399+ raise osv.except_osv(_('No Bank selected!'),_("Please select the bank to save credit card details on customer bank details.") )
400+ else:
401+ if not pooler.get_pool(cr.dbname).get('res.partner.bank').search(cr,uid,[('cc_number','=',creditcard),('partner_id','=',acc_voucher_obj.partner_id.id)]):
402+ pooler.get_pool(cr.dbname).get('res.partner.bank').create(cr,uid,{'state':'bank',
403+ 'acc_number':'nil',
404+ 'cc_number':creditcard,
405+ 'cc_e_d_month':acc_voucher_obj.cc_e_d_month,
406+ 'cc_e_d_year':acc_voucher_obj.cc_e_d_year,
407+ 'partner_id':acc_voucher_obj.partner_id.id,
408+ 'bank':acc_voucher_obj.cc_bank.id,
409+ 'cc_v':acc_voucher_obj.cc_v
410+ })
411+ if refund:
412+ x_type = 'CREDIT'
413+ if not acc_voucher_obj.cc_trans_id:
414+ raise osv.except_osv(_('No Transaction ID!'),_(" Unable to find transaction id for refund.") )
415+ if not acc_voucher_obj.journal_id.cc_allow_refunds:
416+ raise osv.except_osv(_('Unable to do Refund!'),_("Please check \"Allow Credit Card Refunds\" on journal to do refund.") )
417+ elif acc_voucher_obj.cc_p_authorize:
418+ x_type='AUTH_ONLY'
419+
420+ elif acc_voucher_obj.cc_charge and acc_voucher_obj.cc_auth_code:
421+ x_type = 'CAPTURE_ONLY'
422+
423+ elif acc_voucher_obj.cc_charge:
424+ x_type='AUTH_CAPTURE'
425+ else:
426+ raise osv.except_osv(_('No "Type of transaction"!'),_("No Transaction type selected. Please select pre-authorize or charge from \"Type of transaction\" section.") )
427+
428+ if acc_voucher_obj.cc_v:
429+ cvv = acc_voucher_obj.cc_v
430+ else:
431+ cvv=None
432+
433+ tax = '0.00'
434+
435+ login= user.company_id.cc_login
436+ transkey=user.company_id.cc_transaction_key
437+ testmode=user.company_id.cc_testmode
438+
439+ if str(login).strip() == '' or login == None:
440+ raise osv.except_osv(_('Error'),_("No login name provided"))
441+ #raise AuthnetAIMError('No login name provided')
442+ if str(transkey).strip() == '' or transkey == None:
443+ raise osv.except_osv(_('Error'),_("No transaction key provided"))
444+ #raise AuthnetAIMError('No transaction key provided')
445+ if testmode != True and testmode != False:
446+ raise osv.except_osv(_('Error'),_("Invalid value for testmode. Must be True or False. "))
447+ #raise AuthnetAIMError('Invalid value for testmode. Must be True or False. "{0}" given.'.format(testmode))
448+
449+ parameters={}
450+ proxy = None;
451+ delimiter = '|'
452+ results = []
453+ error = True
454+ success = False
455+ declined = False
456+
457+ ############ initialize
458+ parameters = {}
459+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_delim_data', 'true')
460+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_delim_data', 'true')
461+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_delim_char', delimiter)
462+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_relay_response', 'FALSE')
463+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_url', 'FALSE')
464+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_version', '3.1')
465+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_method', 'CC')
466+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_type', x_type)
467+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_login', login)
468+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_tran_key', transkey)
469+
470+ if acc_voucher_obj.cc_charge:
471+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_auth_code', acc_voucher_obj.cc_auth_code)
472+
473+ ########## setTransaction
474+ if str(creditcard).strip() == '' or creditcard == None:
475+ raise osv.except_osv(_('Error'),_("No credit card number passed to setTransaction()"))
476+ #raise AuthnetAIMError('No credit card number passed to setTransaction(): {0}').format(creditcard)
477+ if str(expiration).strip() == '' or expiration == None:
478+ raise osv.except_osv(_('Error'),_("No expiration number to setTransaction()"))
479+ #raise AuthnetAIMError('No expiration number to setTransaction(): {0}').format(expiration)
480+ if str(total).strip() == '' or total == None:
481+ raise osv.except_osv(_('Error'),_("No total amount passed to setTransaction()"))
482+
483+ #raise AuthnetAIMError('No total amount passed to setTransaction(): {0}').format(total)
484+
485+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_card_num', creditcard)
486+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_exp_date', expiration)
487+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_amount', total)
488+ if cvv != None:
489+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_card_code', cvv)
490+ if tax != None:
491+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_tax', tax)
492+
493+ ##################initialize
494+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_duplicate_window', 180)
495+ parameters=acc_voucher_obj.cc_name and pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_first_name', acc_voucher_obj.cc_name or None) or parameters
496+ parameters=acc_voucher_obj.cc_b_addr_1 and pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_address', acc_voucher_obj.cc_b_addr_1 or None) or parameters
497+ parameters=acc_voucher_obj.cc_city and pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_city', acc_voucher_obj.cc_city or None) or parameters
498+ parameters=acc_voucher_obj.cc_state and pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_state', acc_voucher_obj.cc_state or None) or parameters
499+ parameters=acc_voucher_obj.cc_zip and pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_zip', acc_voucher_obj.cc_zip or None) or parameters
500+ parameters=acc_voucher_obj.cc_country and pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_country', acc_voucher_obj.cc_country or None) or parameters
501+ parameters=pooler.get_pool(cr.dbname).get('account.voucher').setParameter(parameters,'x_customer_ip', socket.gethostbyname(socket.gethostname()))
502+
503+ # Actual Processing
504+
505+ encoded_args = urllib.urlencode(parameters)
506+ if testmode:
507+ url = 'https://test.authorize.net/gateway/transact.dll'
508+ else:
509+ url = 'https://secure.authorize.net/gateway/transact.dll'
510+
511+ results += str(urllib.urlopen(url, encoded_args).read()).split(delimiter)
512+
513+# Results = collections.namedtuple('Results', 'ResponseCode ResponseSubcode ResponseReasonCode ResponseText AuthCode \
514+# AVSResponse TransactionID InvoiceNumber Description Amount PaymentMethod \
515+# TransactionType CustomerID CHFirstName CHLastName Company BillingAddress \
516+# BillingCity BillingState BillingZip BillingCountry Phone Fax Email ShippingFirstName \
517+# ShippingLastName ShippingCompany ShippingAddress ShippingCity ShippingState \
518+# ShippingZip ShippingCountry TaxAmount DutyAmount FreightAmount TaxExemptFlag \
519+# PONumber MD5Hash CVVResponse CAVVResponse')
520+# response = Results(*tuple(r for r in results)[0:40])
521+#
522+ if results[0]=='1' and acc_voucher_obj.rel_sale_order_id and acc_voucher_obj.rel_sale_order_id.id:
523+
524+ if acc_voucher_obj.rel_sale_order_id.state == 'done':
525+ pooler.get_pool(cr.dbname).get('sale.order').write(cr,uid,[acc_voucher_obj.rel_sale_order_id.id],{'cc_pre_auth':True,'rel_account_voucher_id':acc_voucher_obj.id})
526+ else:
527+ pooler.get_pool(cr.dbname).get('sale.order').write(cr,uid,[acc_voucher_obj.rel_sale_order_id.id],{'state':'cc_auth','cc_pre_auth':True,'rel_account_voucher_id':acc_voucher_obj.id})
528+
529+ ret_dic={'cc_auth_code':results[4],
530+ 'cc_trans_id':results[6]
531+ }
532+ if x_type == 'AUTH_ONLY':
533+ status = 'Authorization: '+str(results[3])
534+ ret_dic['cc_status'] = status
535+ pooler.get_pool(cr.dbname).get('account.voucher').write(cr, uid, ids, ret_dic)
536+
537+ if x_type == 'CAPTURE_ONLY':
538+ status = "Capture: " + str(results[3])
539+ ret_dic['cc_status'] = status
540+ pooler.get_pool(cr.dbname).get('account.voucher').write(cr, uid, ids, ret_dic)
541+
542+ elif x_type == 'AUTH_CAPTURE':
543+ status = 'Prior Authorization and Capture: '+str(results[3])
544+ ret_dic['amount'] = acc_voucher_obj.cc_order_amt
545+ ret_dic['cc_status'] = status
546+ ret_dic['cc_transaction'] = True
547+
548+ pooler.get_pool(cr.dbname).get('account.voucher').write(cr, uid, ids, ret_dic)
549+ cr.commit()
550+ if results[0]=='1':
551+ '''
552+ Validating sales reciept
553+ '''
554+ #self.validate_sales_reciept(cr, uid, ids, context=context)
555+
556+ '''
557+ Posting payment voucher
558+ '''
559+ pooler.get_pool(cr.dbname).get('account.voucher').action_move_line_create(cr, uid, ids, context)
560+ ret = True
561+ elif x_type == 'CREDIT':
562+ print "1"* 10, x_type
563+ status = 'Refund: '+str(results[3])
564+ ret_dic['cc_status'] = status
565+ if results[0]=='1':
566+
567+ ret_dic['cc_transaction'] = False
568+
569+ #Domain : [('type','=','out_refund')]
570+ #Context: {'type':'out_refund', 'journal_type': 'sale_refund'}
571+
572+ refund_journal_id = False
573+ if user.company_id.cc_refund_journal_id:
574+ refund_journal_id = user.company_id.cc_refund_journal_id.id
575+ else:
576+ j_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')], context=context)
577+ if j_ids:
578+ refund_journal_id = j_ids[0]
579+ if refund_journal_id and self.get('cc_refund'):
580+ invoice_obj = self.pool.get('account.invoice')
581+ invoice_line_obj=self.pool.get('account.invoice.line')
582+ inv_vals = {
583+ 'type' : 'out_refund',
584+ 'journal_id': refund_journal_id,
585+ 'partner_id': acc_voucher_obj.partner_id.id,
586+ 'shipcharge': context.get('cc_ship_refund'),
587+ 'ship_method_id' : context.get('ship_method_id')
588+ }
589+ if context.get('ship_method_id'):
590+ ship_method = self.pool.get('shipping.rate.config').browse(cr, uid, context.get('ship_method_id'), context=context)
591+ inv_vals['sale_account_id'] = ship_method.account_id and ship_method.account_id.id,
592+
593+ inv_vals.update(invoice_obj.onchange_partner_id(cr, uid, [], 'out_refund',acc_voucher_obj.partner_id.id,'', '', '', '')['value'])
594+ inv_lines = []
595+ for line in context['cc_refund']:
596+
597+ inv_line_vals = {
598+ 'quantity' : line['qty'],
599+ 'product_id' : line['product_id'],
600+ }
601+
602+ onchage_vals = invoice_line_obj.product_id_change(cr, uid, [], line['product_id'], False, line['qty'], '', 'out_refund', inv_vals['partner_id'], False ,inv_vals['address_invoice_id'] , False, False, {})['value']
603+ onchage_vals['price_unit'] = line['price_unit']
604+ inv_line_vals.update(onchage_vals)
605+
606+ inv_lines.append((0, 0, inv_line_vals))
607+ inv_vals['abstract_line_ids'] = inv_lines
608+
609+ print "Creating with val : ", inv_vals
610+ print "Context ", context
611+ invoice_id = invoice_obj.create(cr, uid, inv_vals, context=context)
612+ wf_service = netsvc.LocalService("workflow")
613+ wf_service.trg_validate(uid, 'account.invoice', invoice_id, 'invoice_open', cr)
614+
615+ print "Created refund ivoice and validated ", invoice_id
616+# ret = True
617+# voucher_obj = self.pool.get('account.voucher')
618+#
619+#
620+# refund_journal_id = False
621+# if user.company_id.cc_refund_journal_id:
622+# refund_journal_id = user.company_id.cc_refund_journal_id.id
623+# else
624+# j_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')], context=context)
625+# if j_ids:
626+# refund_journal_id = j_ids[0]
627+#
628+# account_id=False
629+# if refund_journal_id:
630+# default_debit_account_id = self.pool.get('account.journal').browse(cr, uid, refund_journal_id,context=context).default_debit_account_id.id
631+#
632+#
633+# vals1 = {
634+#
635+# 'name' : 'Refund : ' + (acc_voucher_obj.rel_sale_order_id and str(acc_voucher_obj.rel_sale_order_id.name) or ''),
636+# 'account_id' : default_debit_account_id,
637+# 'partner_id' : acc_voucher_obj.partner_id.id,
638+# 'amount' : acc_voucher_obj.cc_order_amt,
639+# 'currency_id' : user.company_id.currency_id.id,
640+# 'origin':acc_voucher_obj.rel_sale_order_id and acc_voucher_obj.rel_sale_order_id.name or ''
641+# }
642+#
643+#
644+# vals = voucher_obj.onchange_partner_id(cr, uid, [], acc_voucher_obj.partner_id.id, refund_journal_id , acc_voucher_obj.cc_order_amt , user.company_id.currency_id.id, 'sale', time())
645+#
646+# vals.update(vals1)
647+#
648+# vals['journal_id'] = refund_journal_id
649+# vals['type'] = 'sale'
650+#
651+#
652+#
653+#
654+# voucher_id = voucher_obj.create(cr, uid, vals, context=context)
655+#
656+#
657+# if acc_voucher_obj.cc_order_amt == acc_voucher_obj.rel_sale_order_id.amount_total and acc_voucher_obj.rel_sale_order_id.shipcharge:
658+# self.pool.get('sale.order').write(cr, uid, [acc_voucher_obj.rel_sale_order_id.id],{'cc_ship_refund':True},context=context)
659+#
660+# refund_voucher=False
661+# if 'cc_refund' not in context:
662+# refund_voucher=True
663+# sales_receipt_ids = voucher_obj.search(cr,uid,[('rel_sale_order_id','=',acc_voucher_obj.rel_sale_order_id.id),('state','=','posted'),('type','=','sale')], order="id desc",context=context)
664+#
665+# for receipt in voucher_obj.browse(cr, uid, sales_receipt_ids, context):
666+#
667+# for line in receipt.line_ids:
668+#
669+# if line.amount:
670+# vals = {
671+# 'voucher_id': voucher_id,
672+# 'name' : line.name,
673+# 'account_id' : line.account_id.id,
674+# 'partner_id' : line.partner_id.id,
675+# 'amount' : line.amount,
676+# 'type': line.type,
677+#
678+# }
679+# line_id = self.pool.get('account.voucher.line').create(cr, uid, vals, context)
680+# break
681+# else:
682+# for line in context['cc_refund']:
683+# product=self.pool.get('product.product').browse(cr, uid, line['product_id'],context)
684+#
685+# vals = {
686+# 'voucher_id': voucher_id,
687+# 'name' : product.name,
688+# 'account_id' : product.product_tmpl_id.property_account_income.id,
689+# 'partner_id' : acc_voucher_obj.partner_id.id,
690+# 'amount' : product.list_price * line['qty'],
691+# 'type' : 'cr',
692+# }
693+# line_id = self.pool.get('account.voucher.line').create(cr, uid, vals, context)
694+# if context.get('cc_ship_refund'):
695+# vals = {
696+# 'voucher_id': voucher_id,
697+# 'name' : 'Shipping Charges of ' + acc_voucher_obj.rel_sale_order_id.name,
698+# 'account_id' : acc_voucher_obj.rel_sale_order_id.ship_method_id and acc_voucher_obj.rel_sale_order_id.ship_method_id.account_id.id or False,
699+# 'partner_id' : acc_voucher_obj.partner_id.id,
700+# 'amount' : context['cc_ship_refund'],
701+# 'type' : 'cr',
702+# }
703+# line_id = self.pool.get('account.voucher.line').create(cr, uid, vals, context)
704+# self.pool.get('sale.order').write(cr, uid, [acc_voucher_obj.rel_sale_order_id.id],{'cc_ship_refund':True},context=context)
705+#
706+#
707+# if not refund_voucher:
708+# wf_service = netsvc.LocalService('workflow')
709+# wf_service.trg_validate(uid, 'account.voucher', voucher_id, 'proforma_voucher', cr)
710+
711+ else:
712+ ret_dic['cc_transaction'] = True
713+ pooler.get_pool(cr.dbname).get('account.voucher').write(cr, uid, ids, ret_dic)
714+ else:
715+ status = ''
716+ return ret
717+
718+auth_net_cc_api()
719+
720+class account_voucher(osv.osv):
721+
722+ _inherit = 'account.voucher'
723+ '''
724+ Add function to hook methods authorize and cc_refund which is added on account_payment_creditcard module
725+ '''
726+ def check_transaction(self, cr, uid, ids, context=None):
727+ transaction_record = self.browse( cr, uid, ids,context)
728+ for record in transaction_record:
729+ if record.cc_p_authorize and record.cc_auth_code:
730+ raise osv.except_osv(_('Error'), _("Already Authorized!"))
731+ if record.cc_charge and not record.cc_auth_code:
732+ raise osv.except_osv(_('Error'), _("Pre-Authorize Transaction first!"))
733+ return True
734+
735+ def authorize(self, cr, uid, ids, context=None):
736+ self.check_transaction(cr, uid, ids, context)
737+ return self.pool.get('auth.net.cc.api').do_this_transaction(cr, uid, ids,refund=False, context=context)
738+ def cc_refund(self, cr, uid, ids, context=None):
739+ return self.pool.get('auth.net.cc.api').do_this_transaction(cr, uid, ids,refund=True, context=context)
740+
741+account_voucher()
742+
743+class sale_order(osv.osv):
744+ _name = "sale.order"
745+ _inherit = "sale.order"
746+ def _get_prod_acc(self, product_id, journal_obj, context=False):
747+ if product_id and product_id.property_account_income:
748+ return product_id.property_account_income.id
749+ elif product_id and product_id.categ_id.property_account_income_categ:
750+ return product_id.categ_id.property_account_income_categ.id
751+ else:
752+ if journal_obj.default_credit_account_id:
753+ return journal_obj.default_credit_account_id.id
754+ return False
755+ def create_sales_reciept(self, cr, uid, ids, context={}):
756+ sale_obj = self.browse(cr,uid,ids[0],context=context)
757+ vals={}
758+ cr_ids_list = []
759+ cr_ids = {}
760+ journal_ids = self.pool.get('account.journal').search(cr,uid,[('type','=','sale')])
761+ if journal_ids:
762+ vals['journal_id'] = journal_ids[0]
763+ journal_obj = self.pool.get('account.journal').browse(cr,uid,journal_ids[0])
764+ if sale_obj and sale_obj.order_line:
765+ for sale_line in sale_obj.order_line:
766+ cr_ids['account_id'] = self._get_prod_acc(sale_line.product_id and sale_line.product_id, journal_obj)#journal_obj.default_debit_account_id.id #Change this account to product's income account
767+ cr_ids['amount'] = sale_line.price_subtotal
768+ cr_ids['partner_id'] = sale_obj.partner_id.id
769+ cr_ids['name'] = sale_line.name
770+ cr_ids_list.append(cr_ids.copy())
771+ if sale_obj.shipcharge and sale_obj.ship_method_id and sale_obj.ship_method_id.account_id:
772+ cr_ids['account_id'] = sale_obj.ship_method_id.account_id.id
773+ cr_ids['amount'] = sale_obj.shipcharge
774+ cr_ids['partner_id'] = sale_obj.partner_id.id
775+ cr_ids['name'] = 'Shipping Charge for %s'%sale_line.name
776+ cr_ids_list.append(cr_ids.copy())
777+
778+
779+ else:
780+ vals['journal_id'] = False
781+ vals['partner_id'] = sale_obj.partner_id.id
782+ #vals['date'] = sale_obj.date_order
783+ vals['rel_sale_order_id'] = ids[0]
784+ vals['name'] = 'Auto generated Sales Receipt'
785+ vals['type'] = 'sale'
786+ vals['currency_id'] = journal_obj.company_id.currency_id.id
787+ vals['line_cr_ids'] = [(0,0,cr_ids) for cr_ids in cr_ids_list]
788+# vals['narration'] = voucher_obj.narration
789+ vals['pay_now'] = 'pay_now'
790+ vals['account_id'] = journal_obj.default_debit_account_id.id
791+# vals['reference'] = voucher_obj.reference
792+# vals['tax_id'] = voucher_obj.tax_id.id
793+ vals['amount'] = sale_obj.amount_total
794+ vals['company_id'] = journal_obj.company_id.id
795+ vals['origin'] = sale_obj.name
796+ #print "Vals : ", vals
797+
798+ voucher_id = self.pool.get('account.voucher').create(cr,uid,vals,context)
799+
800+ #print "Sales Receipt ID : ", voucher_id
801+ return voucher_id
802+
803+ def action_wait(self, cr, uid, ids, *args):
804+
805+ ret = super(sale_order, self).action_wait(cr, uid, ids, *args)
806+ for o in self.browse(cr, uid, ids):
807+ if (o.order_policy == 'credit_card'):
808+ #self.create_sales_reciept(cr, uid, [o.id])
809+ invoice_id = self.action_invoice_create(cr, uid, [o.id])
810+ wf_service = netsvc.LocalService('workflow')
811+ wf_service.trg_validate(uid, 'account.invoice', invoice_id, 'invoice_open', cr)
812+ self.pool.get('account.invoice').write(cr, uid, invoice_id, {'credit_card': True}, context={})
813+ return ret
814+
815+ def action_cancel(self, cr, uid, ids, context=None):
816+ for sale in self.browse(cr, uid, ids, context=context):
817+ for picking in sale.picking_ids:
818+ if sale.order_policy == 'credit_card' and picking.state not in ('done','cancel'):
819+ self.pool.get('stock.picking').action_cancel(cr,uid,[picking.id],{})
820+ for inv in sale.invoice_ids:
821+ if sale.order_policy == 'credit_card':
822+ self.pool.get('account.invoice').action_cancel(cr,uid,[inv.id],{})
823+ return super(sale_order, self).action_cancel(cr, uid, ids, context)
824+sale_order()
825+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
826
827=== added directory 'account_payment_ccapi_authdotnet/security'
828=== added file 'account_payment_ccapi_authdotnet/security/ir.model.access.csv'
829--- account_payment_ccapi_authdotnet/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
830+++ account_payment_ccapi_authdotnet/security/ir.model.access.csv 2012-10-16 09:27:13 +0000
831@@ -0,0 +1,3 @@
832+"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
833+"auth_user","auth_net_cc_api","model_auth_net_cc_api","account.group_account_user",1,1,1,1
834+"auth_manager","auth_net_cc_api","model_auth_net_cc_api","account.group_account_manager",1,1,1,1
835
836=== added file 'account_payment_ccapi_authdotnet/stock_return_picking.py'
837--- account_payment_ccapi_authdotnet/stock_return_picking.py 1970-01-01 00:00:00 +0000
838+++ account_payment_ccapi_authdotnet/stock_return_picking.py 2012-10-16 09:27:13 +0000
839@@ -0,0 +1,226 @@
840+# -*- coding: utf-8 -*-
841+##############################################################################
842+#
843+# OpenERP, Open Source Management Solution
844+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
845+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
846+#
847+# This program is free software: you can redistribute it and/or modify
848+# it under the terms of the GNU General Public License as published by
849+# the Free Software Foundation, either version 3 of the License, or
850+# (at your option) any later version.
851+#
852+# This program is distributed in the hope that it will be useful,
853+# but WITHOUT ANY WARRANTY; without even the implied warranty of
854+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
855+# GNU General Public License for more details.
856+#
857+# You should have received a copy of the GNU General Public License
858+# along with this program. If not, see <http://www.gnu.org/licenses/>
859+#
860+##############################################################################
861+import netsvc
862+import time
863+
864+from osv import osv,fields
865+from tools.translate import _
866+
867+
868+class stock_return_picking(osv.osv_memory):
869+ _inherit = 'stock.return.picking'
870+ _description = 'Return Picking'
871+ _columns = { 'cc_ship_refund' : fields.boolean(string='Refund Shipcharge', required=True) }
872+ def default_get(self, cr, uid, fields, context=None):
873+ """
874+ To get default values for the object.
875+ @param self: The object pointer.
876+ @param cr: A database cursor
877+ @param uid: ID of the user currently logged in
878+ @param fields: List of fields for which we want default values
879+ @param context: A standard dictionary
880+ @return: A dictionary with default values for all field in ``fields``
881+ """
882+ if context is None:
883+ context = {}
884+ res = super(stock_return_picking, self).default_get(cr, uid, fields, context=context)
885+ record_id = context and context.get('active_id', False) or False
886+ pick_obj = self.pool.get('stock.picking')
887+ pick = pick_obj.browse(cr, uid, record_id, context=context)
888+ if pick:
889+ if 'invoice_state' in fields:
890+ if pick.cc_pre_auth:
891+ res['invoice_state'] = 'cc_refund'
892+ return res
893+
894+ def view_init(self, cr, uid, fields_list, context=None):
895+ """
896+ Creates view dynamically and adding fields at runtime.
897+ @param self: The object pointer.
898+ @param cr: A database cursor
899+ @param uid: ID of the user currently logged in
900+ @param context: A standard dictionary
901+ @return: New arch of view with new columns.
902+ """
903+ if context is None:
904+ context = {}
905+ res = super(stock_return_picking, self).view_init(cr, uid, fields_list, context=context)
906+ record_id = context and context.get('active_id', False)
907+ if record_id:
908+ pick_obj = self.pool.get('stock.picking')
909+ pick = pick_obj.browse(cr, uid, record_id, context=context)
910+ if 'invoice_state' in self._columns and pick.cc_pre_auth:
911+ invoice_state_vals = [('2binvoiced', _('To be refunded/invoiced')), ('none', _('No invoicing')), ('cc_refund','Credit Card Refund')]
912+ self._columns['invoice_state'] = fields.selection(invoice_state_vals, string='Invoicing', required=True)
913+
914+ # if pick.sale_id and pick.sale_id.shipcharge and not pick.sale_id.cc_ship_refund :
915+ # self._columns['cc_ship_refund'] = fields.boolean(string='Refund Shipcharge', required=True),
916+
917+ return res
918+
919+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
920+ """
921+ Changes the view dynamically
922+ @param self: The object pointer.
923+ @param cr: A database cursor
924+ @param uid: ID of the user currently logged in
925+ @param context: A standard dictionary
926+ @return: New arch of view.
927+ """
928+ res = super(stock_return_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
929+ record_id = context and context.get('active_id', False)
930+ active_model = context.get('active_model')
931+ if active_model != 'stock.picking':
932+ return res
933+ if record_id:
934+ pick_obj = self.pool.get('stock.picking')
935+ pick = pick_obj.browse(cr, uid, record_id)
936+ return_history = {}
937+ res['fields'].clear()
938+ arch_lst=['<?xml version="1.0"?>', '<form string="%s">' % _('Return lines'), '<label string="%s" colspan="4"/>' % _('Provide the quantities of the returned products.')]
939+ for m in pick.move_lines:
940+ return_history[m.id] = 0
941+
942+ #print m.move_history_ids2
943+
944+ for rec in m.move_history_ids2:
945+ if m.id != rec.id:
946+ return_history[m.id] += rec.product_qty
947+ quantity = m.product_qty
948+ if m.state=='done' and quantity > return_history[m.id]:
949+ arch_lst.append('<field name="return%s"/>\n<newline/>' % (m.id,))
950+ res['fields']['return%s' % m.id]={'string':m.name, 'type':'float', 'required':True}
951+ res.setdefault('returns', []).append(m.id)
952+ #print "1" * 10, res
953+ arch_lst.append('<field name="invoice_state"/>\n<newline/>')
954+ invoice_state_vals = [('2binvoiced', _('To be refunded/invoiced')), ('none', _('No invoicing'))]
955+ if pick.cc_pre_auth:
956+ invoice_state_vals.append(('cc_refund','Credit Card Refund'))
957+ if pick.sale_id and pick.sale_id.shipcharge and not pick.sale_id.cc_ship_refund :
958+ res['fields']['cc_ship_refund'] = {'string':'Refund Shipcharge','type':'boolean'}
959+ arch_lst.append('<field name="cc_ship_refund"/>\n<newline/>')
960+ res['fields']['invoice_state']={'string':_('Invoicing'), 'type':'selection','required':True, 'selection':invoice_state_vals}
961+ arch_lst.append('<group col="2" colspan="4">')
962+ arch_lst.append('<button icon="gtk-cancel" special="cancel" string="Cancel" />')
963+ arch_lst.append('<button name="create_returns" string="Return" colspan="1" type="object" icon="gtk-apply" />')
964+ arch_lst.append('</group>')
965+ arch_lst.append('</form>')
966+ res['arch'] = '\n'.join(arch_lst)
967+ return res
968+
969+
970+ def create_returns(self, cr, uid, ids, context=None):
971+ """
972+ Creates return picking.
973+ @param self: The object pointer.
974+ @param cr: A database cursor
975+ @param uid: ID of the user currently logged in
976+ @param ids: List of ids selected
977+ @param context: A standard dictionary
978+ @return: A dictionary which of fields with values.
979+ """
980+ if context is None:
981+ context = {}
982+ record_id = context and context.get('active_id', False) or False
983+ move_obj = self.pool.get('stock.move')
984+ pick_obj = self.pool.get('stock.picking')
985+ uom_obj = self.pool.get('product.uom')
986+ seq_obj = self.pool.get('ir.sequence')
987+ loc_obj = self.pool.get('stock.location')
988+ warehouse_obj = self.pool.get('stock.warehouse')
989+
990+ wf_service = netsvc.LocalService("workflow")
991+
992+ pick = pick_obj.browse(cr, uid, record_id, context=context)
993+ data = self.read(cr, uid, ids[0])
994+
995+ res = super(stock_return_picking, self).create_returns( cr, uid, ids, context)
996+
997+ ctx=[]
998+
999+ #@ Moving the refund process to On Delivery process of related incoming shipment
1000+ if data['invoice_state'] == 'cc_refund':
1001+ amount=0.00
1002+ for move in pick.move_lines:
1003+ new_qty = data['return%s' % move.id]
1004+ amount = amount + new_qty * move.product_id.list_price
1005+ line ={}
1006+ line['product_id'] = move.product_id.id
1007+ line['qty'] = new_qty
1008+ line['price_unit'] = move.product_id.list_price
1009+ if pick.sale_id:
1010+ for sale_line in pick.sale_id.order_line:
1011+ if sale_line.product_id and sale_line.product_id.id == move.product_id.id:
1012+ line['price_unit'] = sale_line.price_unit
1013+ break
1014+
1015+ ctx.append(line)
1016+ if pick.sale_id and pick.sale_id.shipcharge and data.get('cc_ship_refund') and not pick.sale_id.cc_ship_refund :
1017+ amount=amount+pick.sale_id.shipcharge
1018+ context['cc_ship_refund'] = pick.sale_id.shipcharge
1019+ context['ship_method_id'] = pick.sale_id.ship_method_id and pick.sale_id.ship_method_id.id or False
1020+ if amount:
1021+ voucher_obj = self.pool.get('account.voucher')
1022+ voucher_ids = voucher_obj.search(cr,uid,[('rel_sale_order_id','=', pick.sale_id.id),('state','=','posted'),('type','=','receipt'),('cc_charge','=',True)], order="id desc",context=context)
1023+ if voucher_ids:
1024+ voucher_obj.write(cr, uid, [voucher_ids[0]], {'cc_order_amt':amount}, context )
1025+ context['cc_refund'] = ctx
1026+
1027+ #self.pool.get('auth.net.cc.api').do_this_transaction(cr, uid, [voucher_ids[0]] , refund=True, context=context)
1028+ #voucher = voucher_obj.browse(cr, uid, voucher_ids[0] , context)
1029+
1030+ #@ Get picking id and write voucher_id
1031+ domain = res.get('domain') and eval(res['domain'])
1032+ new_pick_id = False
1033+ if domain and len(domain) and len(domain[0])==3:
1034+ new_pick_id = domain[0][2][0]
1035+ if new_pick_id:
1036+ self.pool.get('stock.picking').write(cr, uid, new_pick_id , {'voucher_id':voucher_ids[0]},context=context )
1037+
1038+ return res
1039+stock_return_picking()
1040+
1041+class stock_picking(osv.osv):
1042+ _inherit = "stock.picking"
1043+ _columns = {
1044+ 'invoice_state': fields.selection([
1045+ ("invoiced", "Invoiced"),
1046+ ("2binvoiced", "To Be Invoiced"),
1047+ ("none", "Not Applicable"),
1048+ ("credit_card", "Credit Card"),
1049+ ("cc_refund", "Credit Card Refund")
1050+ ], "Invoice Control", select=True, required=True, readonly=True, states={'draft': [('readonly', False)]}),
1051+ 'voucher_id' : fields.many2one('account.voucher','Refund Voucher', readonly=True)
1052+ }
1053+
1054+ def do_partial(self, cr, uid, ids, partial_datas, context=None):
1055+ res = super(stock_picking, self).do_partial(cr, uid, ids, partial_datas, context=context)
1056+ for pick in self.pool.get('stock.picking').browse(cr, uid, ids, context=context):
1057+ if pick.state =='done' and pick.invoice_state=='cc_refund' and pick.voucher_id:
1058+ self.pool.get('auth.net.cc.api').do_this_transaction(cr, uid, [pick.voucher_id.id] , refund=True, context=context)
1059+ return res
1060+# def _get_invoice_type(self, pick):
1061+# if pick.sale_id and pick.sale_id.order_policy=='credit_card':
1062+# return 'credit_card'
1063+# return super(stock_picking, self)._get_invoice_type(pick)
1064+stock_picking()
1065+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1066
1067=== added file 'account_payment_ccapi_authdotnet/stock_view.xml'
1068--- account_payment_ccapi_authdotnet/stock_view.xml 1970-01-01 00:00:00 +0000
1069+++ account_payment_ccapi_authdotnet/stock_view.xml 2012-10-16 09:27:13 +0000
1070@@ -0,0 +1,28 @@
1071+<?xml version="1.0" encoding="UTF-8"?>
1072+<openerp>
1073+ <data>
1074+ <record id="view_picking_form_cc_refund" model="ir.ui.view">
1075+ <field name="name">stock.picking.form.inherit.cc_refund</field>
1076+ <field name="model">stock.picking</field>
1077+ <field name="type">form</field>
1078+ <field name="inherit_id" ref="stock.view_picking_form" />
1079+ <field name="arch" type="xml">
1080+ <xpath expr="//button[@name=%(stock.action_stock_invoice_onshipping)d]" position="replace">
1081+ <button name="%(stock.action_stock_invoice_onshipping)d" string="Create Invoice" attrs="{'invisible': ['|','|','|','|','|',('state','&lt;&gt;','done'),('invoice_state','=','invoiced'),('invoice_state','=','none'),('invoice_state','=','cc_refund'),('invoice_state','=','credit_card')]}" type="action" icon="terp-gtk-go-back-rtl" />
1082+ </xpath>
1083+ </field>
1084+ </record>
1085+
1086+ <record id="view_picking_form_cc_refund_out" model="ir.ui.view">
1087+ <field name="name">stock.picking.form.inherit.cc_refund.out</field>
1088+ <field name="model">stock.picking</field>
1089+ <field name="type">form</field>
1090+ <field name="inherit_id" ref="stock.view_picking_out_form" />
1091+ <field name="arch" type="xml">
1092+ <xpath expr="//button[@name=%(stock.action_stock_invoice_onshipping)d]" position="replace">
1093+ <button name="%(stock.action_stock_invoice_onshipping)d" string="Create Invoice" attrs="{'invisible': ['|','|','|','|','|',('state','&lt;&gt;','done'),('invoice_state','=','invoiced'),('invoice_state','=','none'),('invoice_state','=','cc_refund'),('invoice_state','=','credit_card')]}" type="action" icon="terp-gtk-go-back-rtl" />
1094+ </xpath>
1095+ </field>
1096+ </record>
1097+ </data>
1098+</openerp>
1099\ No newline at end of file
1100
1101=== added directory 'account_payment_creditcard'
1102=== added file 'account_payment_creditcard/Change Log.txt'
1103--- account_payment_creditcard/Change Log.txt 1970-01-01 00:00:00 +0000
1104+++ account_payment_creditcard/Change Log.txt 2012-10-16 09:27:13 +0000
1105@@ -0,0 +1,50 @@
1106+===============================================================================
1107+ Version Change Log (account_payment_creditcard)
1108+===============================================================================
1109+Version 1.17 : Serpent Consulting Services
1110+ : Added RSA Encryption
1111+
1112+Version 1.16
1113+ Auto selection of Pay in outstanding transation lines
1114+
1115+Version 1.15
1116+ * Made Shipping Policy changes automatically corresponding to Payment Method in Sale Order
1117+ * Shipping Policy: CC Pre-Auth Pick Charge Ship when Payment Method: Credit Card
1118+ * Shipping Policy: Invoice from the Picking when Payment Method: Invoice
1119+ * Added Authorize button
1120+Version 1.14
1121+ * Added new search buttons Manual Invoice and Credit Card Invoice in Customer Invoice
1122+Version 1.13
1123+ * Remove the authorize buttom to move near to Post button
1124+
1125+Version 1.12
1126+ * Removed buttons Pre-authorized and Paid from Deliver Orders and added new button Pre-authorized or Invoiced
1127+Version 1.11
1128+ * Store function invoiced field in sale order for make it searchable in delivery order
1129+Version 1.10
1130+ * Default Payment Order in Sale Order
1131+Version 1.09
1132+ * Added field to indicate the status of refund of ship
1133+
1134+Version 1.08
1135+ * Made save creditcard details available for all customer
1136+Version 1.07
1137+ * Modification of the default payment method in sale order to Invoice On Order After Delivery for Reseller
1138+
1139+Version 1.06
1140+ * Modification of the default payment method in sale order
1141+
1142+Version 1.05
1143+ * Displayed sale order pay button on in progress state
1144+
1145+Version 1.04
1146+ * Made sale order done if it is payed and shipped
1147+Version 1.03
1148+ * Add group CreditCard / Manager. Only this group member can use refund button.
1149+ * Added Allow Credit Card Processing and Allow Credit Card Refunds on journal
1150+ * Modified sale order view to add credit card pay button and made all buttons on a row
1151+ * Add Credit Card information on partner bank
1152+ * Add credit card details fields on voucher
1153+ * Encrypt credit card details
1154+ * Add credit card configuration fields on company
1155+ * Add credit card preauthorised and invoiced check field on stock picking
1156
1157=== added file 'account_payment_creditcard/__init__.py'
1158--- account_payment_creditcard/__init__.py 1970-01-01 00:00:00 +0000
1159+++ account_payment_creditcard/__init__.py 2012-10-16 09:27:13 +0000
1160@@ -0,0 +1,29 @@
1161+# -*- coding: utf-8 -*-
1162+##############################################################################
1163+#
1164+# OpenERP, Open Source Management Solution
1165+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
1166+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
1167+#
1168+# This program is free software: you can redistribute it and/or modify
1169+# it under the terms of the GNU General Public License as published by
1170+# the Free Software Foundation, either version 3 of the License, or
1171+# (at your option) any later version.
1172+#
1173+# This program is distributed in the hope that it will be useful,
1174+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1175+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1176+# GNU General Public License for more details.
1177+#
1178+# You should have received a copy of the GNU General Public License
1179+# along with this program. If not, see <http://www.gnu.org/licenses/>
1180+#
1181+##############################################################################
1182+
1183+import account_voucher
1184+import account_journal
1185+import stock_picking
1186+import sale
1187+import invoice
1188+import rsa_encrypt
1189+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1190
1191=== added file 'account_payment_creditcard/__openerp__.py'
1192--- account_payment_creditcard/__openerp__.py 1970-01-01 00:00:00 +0000
1193+++ account_payment_creditcard/__openerp__.py 2012-10-16 09:27:13 +0000
1194@@ -0,0 +1,45 @@
1195+# -*- coding: utf-8 -*-
1196+##############################################################################
1197+#
1198+# OpenERP, Open Source Management Solution
1199+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
1200+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
1201+#
1202+# This program is free software: you can redistribute it and/or modify
1203+# it under the terms of the GNU General Public License as published by
1204+# the Free Software Foundation, either version 3 of the License, or
1205+# (at your option) any later version.
1206+#
1207+# This program is distributed in the hope that it will be useful,
1208+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1209+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1210+# GNU General Public License for more details.
1211+#
1212+# You should have received a copy of the GNU General Public License
1213+# along with this program. If not, see <http://www.gnu.org/licenses/>
1214+#
1215+##############################################################################
1216+
1217+
1218+{
1219+ 'name': 'Account Payment Credit Card',
1220+ 'version': '1.17',
1221+ 'category': 'Generic Modules/Others',
1222+ 'description': """
1223+ Module for Credit card payment
1224+ """,
1225+ 'author': 'NovaPoint Group LLC',
1226+ 'website': ' http://www.novapointgroup.com',
1227+ 'depends': ['sale', 'account_voucher'],
1228+ 'init_xml': [],
1229+ 'update_xml': ['security/account_security.xml',
1230+ 'account_voucher_view.xml',
1231+ 'account_journal_view.xml',
1232+ 'stock_picking_view.xml',
1233+ 'invoice_view.xml'
1234+ ],
1235+ 'demo_xml': [],
1236+ 'installable': True,
1237+ 'active': False,
1238+}
1239+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1240
1241=== added file 'account_payment_creditcard/account_journal.py'
1242--- account_payment_creditcard/account_journal.py 1970-01-01 00:00:00 +0000
1243+++ account_payment_creditcard/account_journal.py 2012-10-16 09:27:13 +0000
1244@@ -0,0 +1,73 @@
1245+# -*- coding: utf-8 -*-
1246+##############################################################################
1247+#
1248+# OpenERP, Open Source Management Solution
1249+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
1250+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
1251+#
1252+# This program is free software: you can redistribute it and/or modify
1253+# it under the terms of the GNU General Public License as published by
1254+# the Free Software Foundation, either version 3 of the License, or
1255+# (at your option) any later version.
1256+#
1257+# This program is distributed in the hope that it will be useful,
1258+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1259+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1260+# GNU General Public License for more details.
1261+#
1262+# You should have received a copy of the GNU General Public License
1263+# along with this program. If not, see <http://www.gnu.org/licenses/>
1264+#
1265+##############################################################################
1266+
1267+from osv import osv, fields
1268+
1269+class account_journal(osv.osv):
1270+ _inherit = "account.journal"
1271+ _columns = {
1272+ 'cc_allow_processing': fields.boolean('Allow Credit Card Processing',),
1273+ 'cc_allow_refunds': fields.boolean('Allow Credit Card Refunds',),
1274+ }
1275+account_journal()
1276+
1277+
1278+class res_partner(osv.osv):
1279+ _inherit = "res.partner"
1280+
1281+ def write(self, cr, uid, ids, vals, context=None):
1282+ if vals.get('bank_ids',[]) and len(vals['bank_ids'][0]) > 3 and vals['bank_ids'][0][2] :
1283+ if vals['bank_ids'][0][2].get('cc_number',False):
1284+ if ('XXXXXXXXX' in vals['bank_ids'][0][2]['cc_number']):
1285+ del vals['cc_number']
1286+ print "gggg",vals
1287+ result = super(res_partner, self).write(cr, uid, ids, vals, context)
1288+ return True
1289+
1290+res_partner()
1291+
1292+class res_partner_bank(osv.osv):
1293+ '''Bank Accounts'''
1294+
1295+ def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
1296+ if context is None:
1297+ context = {}
1298+ vals = super(res_partner_bank,self).read(cr,user,ids,fields,context,load)
1299+ if context.get('cc_no','') != 'no_mask':
1300+ if len(vals) == 1:
1301+ if vals[0].get('cc_number',False):
1302+ t = vals[0]['cc_number']
1303+ i = len(t)-4
1304+ vals[0]['cc_number'] = 'X'*i+t[-4:len(t)]
1305+ return vals
1306+
1307+ _inherit = "res.partner.bank"
1308+ _columns = {
1309+ 'cc_number':fields.char('Credit Card Number', size=256),#Given size 256 because the credit card is stored as encrypted format.
1310+# 'cc_type':fields.many2one('cc.type','Card type'),
1311+ 'cc_e_d_month':fields.char('Expiration Date MM', size=32),
1312+ 'cc_e_d_year':fields.char('Expiration Date YY', size=32),
1313+ 'cc_v':fields.char('Card Code Verification', size=32),
1314+ }
1315+res_partner_bank()
1316+
1317+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1318\ No newline at end of file
1319
1320=== added file 'account_payment_creditcard/account_journal_view.xml'
1321--- account_payment_creditcard/account_journal_view.xml 1970-01-01 00:00:00 +0000
1322+++ account_payment_creditcard/account_journal_view.xml 2012-10-16 09:27:13 +0000
1323@@ -0,0 +1,74 @@
1324+<?xml version="1.0" encoding="UTF-8"?>
1325+<openerp>
1326+ <data>
1327+ <!-- Journal -->
1328+ <record id="account_journal_changes_for_credit_card_01" model="ir.ui.view">
1329+ <field name="name">account_journal_changes_for_credit_card_01</field>
1330+ <field name="model">account.journal</field>
1331+ <field name="type">form</field>
1332+ <field name="inherit_id" ref="account.view_account_journal_form"/>
1333+ <field name="arch" type="xml">
1334+ <xpath expr="//page[@string='General Information']" position="inside">
1335+ <group colspan="2" col="2">
1336+ <separator string="Credit Card Processing" colspan="4"/>
1337+ <field name="cc_allow_processing" />
1338+ <field name="cc_allow_refunds"/>
1339+ </group>
1340+ </xpath>
1341+ </field>
1342+ </record>
1343+
1344+ <!-- Sale Order -->
1345+ <record id="sale_order_changes_for_credit_card_01" model="ir.ui.view">
1346+ <field name="name">sale_order_changes_for_credit_card_01</field>
1347+ <field name="model">sale.order</field>
1348+ <field name="type">form</field>
1349+ <field name="inherit_id" ref="sale.view_order_form"/>
1350+ <field name="arch" type="xml">
1351+ <xpath expr="//field[@name='pricelist_id']" position="after">
1352+ <field name="payment_method" on_change="on_change_payment_method(payment_method,order_policy,partner_id)"/>
1353+ </xpath>
1354+ <xpath expr="//field[@name='shipped']" position="after">
1355+ <field name="rel_account_voucher_id" readonly="1"/><label/><label/>
1356+ <field name="cc_pre_auth" readonly="1"/>
1357+ <field name="cc_ship_refund" readonly="1" invisible="1" />
1358+ </xpath>
1359+ <xpath expr="//notebook[@colspan='5']/page[@string='Sales Order']/group[@colspan='4']" position="replace">
1360+ <group col="16" colspan="4">
1361+ <field name="state"/>
1362+ <button name="invoice_recreate" states="invoice_except" string="Recreate Invoice" icon="gtk-go-forward"/>
1363+ <button name="invoice_corrected" states="invoice_except" string="Ignore Exception" icon="gtk-apply"/>
1364+ <button name="ship_recreate" states="shipping_except" string="Recreate Packing" icon="gtk-ok"/>
1365+ <button name="ship_corrected" states="shipping_except" string="Ignore Exception" icon="gtk-apply"/>
1366+ <button name="action_cancel" states="manual,progress" string="Cancel Order" type="object" icon="gtk-cancel"/>
1367+ <button name="manual_invoice" states="manual" string="Create Final Invoice" icon="gtk-go-forward" type="object"/>
1368+ <button name="ship_cancel" states="shipping_except" string="Cancel Order" icon="gtk-cancel"/>
1369+ <button name="action_cancel_draft" states="cancel" string="Set to Draft" type="object" icon="gtk-convert"/>
1370+ <button name="cancel" states="draft,cc_auth" string="Cancel Order" icon="gtk-cancel"/>
1371+ <button name="invoice_cancel" states="invoice_except" string="Cancel Order" icon="gtk-cancel"/>
1372+ <button name="order_confirm" states="draft" string="Confirm Order" icon="gtk-apply"/>
1373+ <button icon="gtk-apply" string="Pay" type="object" name="pay" states="progress"/>
1374+ </group>
1375+ </xpath>
1376+ </field>
1377+ </record>
1378+
1379+ <!-- Partner -->
1380+ <record id="res_partner_bank_changes_for_credit_card_01" model="ir.ui.view">
1381+ <field name="name">res_partner_bank_changes_for_credit_card_01</field>
1382+ <field name="model">res.partner</field>
1383+ <field name="type">form</field>
1384+ <field name="inherit_id" ref="account.view_partner_property_form"/>
1385+ <field name="arch" type="xml">
1386+ <xpath expr="//field[@name='bank_ids']//field[@name='state_id']" position="after">
1387+ <group string="Credit Card Information" colspan="4" cols="4">
1388+ <field name="cc_number"/>
1389+ <field name="cc_e_d_month"/>
1390+ <field name="cc_e_d_year"/>
1391+ <field name="cc_v"/>
1392+ </group>
1393+ </xpath>
1394+ </field>
1395+ </record>
1396+ </data>
1397+</openerp>
1398
1399=== added file 'account_payment_creditcard/account_voucher.py'
1400--- account_payment_creditcard/account_voucher.py 1970-01-01 00:00:00 +0000
1401+++ account_payment_creditcard/account_voucher.py 2012-10-16 09:27:13 +0000
1402@@ -0,0 +1,301 @@
1403+# -*- coding: utf-8 -*-
1404+##############################################################################
1405+#
1406+# OpenERP, Open Source Management Solution
1407+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
1408+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
1409+#
1410+# This program is free software: you can redistribute it and/or modify
1411+# it under the terms of the GNU General Public License as published by
1412+# the Free Software Foundation, either version 3 of the License, or
1413+# (at your option) any later version.
1414+#
1415+# This program is distributed in the hope that it will be useful,
1416+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1417+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1418+# GNU General Public License for more details.
1419+#
1420+# You should have received a copy of the GNU General Public License
1421+# along with this program. If not, see <http://www.gnu.org/licenses/>
1422+#
1423+##############################################################################
1424+
1425+from osv import osv, fields
1426+import rsa_encrypt
1427+import base64
1428+
1429+
1430+class AuthnetAIMError(Exception):
1431+ def __init__(self, value):
1432+ self.parameter = value
1433+ def __str__(self):
1434+ return str(self.parameter)
1435+
1436+class account_voucher(osv.osv):
1437+
1438+ def setParameter(self, parameters={}, key=None, value=None):
1439+
1440+ if key != None and value != None and str(key).strip() != '' and str(value).strip() != '':
1441+ parameters[key] = str(value).strip()
1442+ else:
1443+ raise AuthnetAIMError('Incorrect parameters passed to setParameter(): {0}:{1}'.format(key, value))
1444+ return parameters
1445+
1446+ def cancel_cc(self, cr, uid, ids, context=None):
1447+ return self.write(cr, uid, ids, { 'cc_number':'',
1448+ 'cc_e_d_month':'',
1449+ 'cc_e_d_year':'',
1450+ 'cc_v':'',
1451+ 'cc_auth_code':'',
1452+ 'cc_trans_id':'', })
1453+
1454+ def authorize(self, cr, uid, ids, context=None):
1455+# self.do_transaction(cr, uid, ids,refund=False, context=context)
1456+ return False
1457+
1458+ def cc_refund(self, cr, uid, ids, context=None):
1459+# self.do_transaction(cr, uid, ids, refund=True,context=context)
1460+ return True
1461+
1462+ def _get_zip(self, cr, uid, ids, zip_id, context={}):
1463+ if zip_id:
1464+ zip_code = self.pool.get('address.zip').browse(cr, uid, zip_id)
1465+ return zip_code.zipcode
1466+ return ''
1467+
1468+ def _get_country(self, cr, uid, ids, country_id, context={}):
1469+ if country_id:
1470+ country = self.pool.get('res.country').browse(cr, uid, country_id)
1471+ return country.name
1472+ return ''
1473+
1474+ def _get_state(self, cr, uid, ids, state_id, context={}):
1475+ if state_id:
1476+ state = self.pool.get('res.country.state').browse(cr, uid, state_id)
1477+ return state.name
1478+ return ''
1479+
1480+ def _get_cardholder_details(self, cr, uid, ids, partner_id, context={}):
1481+ ret = {}
1482+ if partner_id:
1483+ partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
1484+ ret = {'name':partner.name,
1485+ 'street':partner.address[0].street,
1486+ 'street2':partner.address[0].street2,
1487+ 'city':partner.address[0].city,
1488+ 'country':self._get_country(cr, uid, ids, partner.address[0].country_id.id),
1489+ "zip":partner.address[0].zip,
1490+ "state":self._get_state(cr, uid, ids, partner.address[0].state_id.id),
1491+ 'title':partner.title and partner.title.name
1492+ }
1493+ return ret
1494+
1495+ def create(self, cr, uid, vals, context=None):
1496+ """
1497+ Encrypt credit card number before writing to database
1498+ @param self : The object pointer
1499+ @param cr: A database cursor
1500+ @param uid: ID of the user currently logged in
1501+ @param vals: Dictionary of Values.
1502+ @param context: A standard dictionary
1503+ @return:ID of newly created record.
1504+ """
1505+ if context is None:
1506+ context = {}
1507+ if vals.get('cc_number', False):
1508+ res = rsa_encrypt.encrypt(vals.get('cc_number', False))
1509+ res['cc_number'] = res['enc_value']
1510+ del res['enc_value']
1511+ vals.update(res)
1512+ result = super(account_voucher, self).create(cr, uid, vals, context)
1513+ return result
1514+
1515+ def write(self, cr, uid, ids, vals, context=None):
1516+ '''
1517+ Encrypt credit card number before writing to database
1518+ @param self : The object pointer
1519+ @param cr: A database cursor
1520+ @param uid: ID of the user currently logged in
1521+ @param ids: List of ids selected
1522+ @param vals: Dictionary of Values.
1523+ @param context: A standard dictionary
1524+ @return:True.
1525+ '''
1526+ if context is None:
1527+ context = {}
1528+ context.update({'cc_no':'no_mask'})
1529+ if not isinstance(ids,list):
1530+ ids = [ids]
1531+ for record in self.browse(cr, uid, ids, context=context):
1532+ if vals.get('cc_number', False):
1533+ res = rsa_encrypt.encrypt(vals.get('cc_number', False), record.key)
1534+ res['cc_number'] = res['enc_value']
1535+ del res['enc_value']
1536+ vals.update(res)
1537+ result = super(account_voucher, self).write(cr, uid, ids, vals, context)
1538+ return result
1539+
1540+ def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
1541+ '''
1542+ Decrypt credit card number after reading from database and display last four digits if there is
1543+ no no_mask in context
1544+ @param self : The object pointer
1545+ @param cr: A database cursor
1546+ @param uid: ID of the user currently logged in
1547+ @param ids: List of ids selected
1548+ @param fields: List of fields
1549+ @param context: A standard dictionary
1550+ @param load: a parameter used for reading the values of functional fields
1551+ @return:List of dictionary of fields,values pair
1552+ '''
1553+ if context is None:
1554+ context = {}
1555+ if 'cc_number' in fields and 'key' not in fields:
1556+ fields.append('key')
1557+ vals = super(account_voucher, self).read(cr, uid, ids, fields, context, load)
1558+ for val in vals:
1559+ if val.get('cc_number', False) :
1560+ dec_data = rsa_encrypt.decrypt(val.get('cc_number', False), val.get('key', False))
1561+ val['cc_number'] = dec_data
1562+ if context.get('cc_no', '') != 'no_mask':
1563+ i = len(val['cc_number']) - 4
1564+ val['cc_number'] = 'X' * i + val['cc_number'][-4:len(val['cc_number'])]
1565+ return vals
1566+
1567+
1568+ def copy(self, cr, uid, id, default=None, context=None):
1569+ """Overrides orm copy method
1570+ @param self: The object pointer
1571+ @param cr: the current row, from the database cursor,
1572+ @param uid: the current user’s ID for security checks,
1573+ @param ids: List of case’s IDs
1574+ @param context: A standard dictionary for contextual values
1575+ """
1576+ if default is None:
1577+ default = {}
1578+ default.update({'cc_number': '', 'cc_length': 0, 'cc_v':'', 'cc_e_d_month':'', 'cc_e_d_year':''})
1579+ return super(account_voucher, self).copy(cr, uid, id, default=default, context=context)
1580+
1581+
1582+ def oncahnge_pre_authorize(self, cr, uid, ids, cc_p_authorize, context={}):
1583+ if cc_p_authorize:
1584+ return{'value':{'cc_charge':False, 'cc_p_authorize':True } }
1585+ else:
1586+ return{'value':{'cc_charge':True, 'cc_p_authorize':False } }
1587+
1588+ def oncahnge_cc_charge(self, cr, uid, ids, cc_charge, context={}):
1589+ if cc_charge:
1590+ return{'value':{'cc_charge':True, 'cc_p_authorize':False } }
1591+ else:
1592+ return{'value':{'cc_charge':False, 'cc_p_authorize':True } }
1593+
1594+ _inherit = 'account.voucher'
1595+ _columns = {
1596+ 'cc_name':fields.char('Cardholders Name', size=32,),
1597+ 'cc_b_addr_1':fields.char('Billing Address1', size=32,),
1598+ 'cc_b_addr_2':fields.char('Billing Address2', size=32,),
1599+ 'cc_city': fields.char('City', size=32,),
1600+ 'cc_state':fields.char('State', size=32,),
1601+ 'cc_zip':fields.char('Postal/Zip', size=32,),
1602+ 'cc_country':fields.char('Country', size=32,),
1603+ 'cc_order_date':fields.date('Order Date',),
1604+ 'cc_order_amt':fields.float('Order Amt',),
1605+ 'cc_number':fields.char('Credit Card Number', size=256),
1606+ 'cc_v':fields.char('Card Code Verification', size=32,),
1607+ 'cc_e_d_month':fields.char('Expiration Date MM', size=32),
1608+ 'cc_e_d_year':fields.char('Expiration Date YY', size=32),
1609+ 'cc_comment':fields.char('Comment', size=128,),
1610+ 'cc_auth_code':fields.char('Authorization Code', size=32),
1611+ 'cc_save_card_details':fields.boolean('Save Credit Card details'),
1612+ 'cc_ecommerce_sale':fields.boolean('Ecommerce sale'),
1613+ 'cc_p_authorize':fields.boolean('pre-authorize'),
1614+ 'cc_charge':fields.boolean('charge'),
1615+ 'cc_info_hide':fields.boolean('Credit Info Hide'),
1616+ 'cc_status':fields.text('Status Message'),
1617+ 'cc_details_autofill':fields.boolean('Credit Card Details Auto Fill'),
1618+ 'cc_reseller':fields.boolean('Reseller'),
1619+ 'rel_sale_order_id':fields.many2one('sale.order', 'Related Sale Order'),
1620+ 'cc_trans_id':fields.char('Transaction ID', size=128),
1621+ 'cc_bank':fields.many2one('res.bank', 'Bank'),
1622+ 'cc_details':fields.many2one('res.partner.bank', 'Bank'),
1623+ 'cc_length':fields.integer('CC Length'),
1624+ 'cc_transaction':fields.boolean('Transaction Done'),
1625+ 'key':fields.char('Encryption Key', size=1024,
1626+ help="The Key used to Encrypt the Credit Card Number"),
1627+ }
1628+ _defaults = {
1629+ 'cc_info_hide': lambda * a: True,
1630+ 'cc_p_authorize': lambda * a: True,
1631+ }
1632+
1633+
1634+ def onchange_cc_details(self, cr, uid, ids, cc_details, context={}):
1635+ dic = {}
1636+ if cc_details:
1637+ context['cc_no'] = 'no_mask'
1638+ bank = self.pool.get('res.partner.bank').browse(cr, uid, cc_details, context=context)
1639+ dic['cc_e_d_month'] = bank.cc_e_d_month
1640+ dic['cc_e_d_year'] = bank.cc_e_d_year
1641+ dic['cc_number'] = bank.cc_number
1642+ dic['cc_v'] = bank.cc_v
1643+ return{'value':dic}
1644+
1645+
1646+ def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context={}, sale_id=False):
1647+ res = super(account_voucher, self).onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
1648+ if not res.has_key('value'):
1649+ res['value'] = {}
1650+ jorurnal_cc_allow = False
1651+ cardholder_details = self._get_cardholder_details(cr, uid, ids, partner_id, context=context)
1652+ if journal_id and cardholder_details:
1653+ jorurnal_cc_allow = self.pool.get('account.journal').read(cr, uid, journal_id, ['cc_allow_processing'])['cc_allow_processing']
1654+ res['value']['cc_name'] = cardholder_details['name']
1655+ res['value']['cc_b_addr_1'] = cardholder_details['street']
1656+ res['value']['cc_b_addr_2'] = cardholder_details['street2']
1657+ res['value']['cc_city'] = cardholder_details['city']
1658+ res['value']['cc_country'] = cardholder_details['country']
1659+ res['value']['cc_zip'] = cardholder_details['zip']
1660+ res['value']['cc_state'] = cardholder_details['state']
1661+ res['value']['cc_reseller'] = cardholder_details['title'] == 'Reseller' and True or False
1662+ res['value']['cc_save_card_details'] = False
1663+ if jorurnal_cc_allow:
1664+ res['value']['cc_info_hide'] = False
1665+ else:
1666+ res['value']['cc_info_hide'] = True
1667+
1668+ if not context:
1669+ context = {}
1670+ context.update({'sale_id':sale_id})
1671+ if not sale_id:
1672+ sale_id = context.get('sale_id')
1673+ if sale_id and res['value'].get('line_cr_ids') :
1674+ sale = self.pool.get('sale.order').browse(cr, uid, sale_id, context=context)
1675+ lines = []
1676+ for line in res['value']['line_cr_ids']:
1677+ for invoice in sale.invoice_ids:
1678+ if not (line.get('invoice_id') and line.get('invoice_id') and line['invoice_id'] == invoice.id):
1679+ line['pay'] = False
1680+ else:
1681+ line['pay'] = True
1682+ line['amount'] = line['amount_original']
1683+
1684+ lines.append(line)
1685+ res['value']['line_cr_ids'] = lines
1686+
1687+ return res
1688+account_voucher()
1689+
1690+class res_company(osv.osv):
1691+ '''
1692+ Add credit card details on company configuration
1693+ '''
1694+ _inherit = "res.company"
1695+ _columns = {
1696+ 'cc_login': fields.char('CreditCard Login ID', size=64),
1697+ 'cc_transaction_key': fields.char('Transaction Key', size=64),
1698+ 'cc_testmode': fields.boolean('Test Mode'),
1699+ 'cc_journal_id':fields.many2one('account.journal', 'Payment Method', help="The default payment method on payment voucher open using the Pay button from sale order."),
1700+ 'cc_refund_journal_id' : fields.many2one('account.journal', 'Refund Journal', help="The default refund journal for credit card payments.")
1701+ }
1702+res_company()
1703+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1704
1705=== added file 'account_payment_creditcard/account_voucher_view.xml'
1706--- account_payment_creditcard/account_voucher_view.xml 1970-01-01 00:00:00 +0000
1707+++ account_payment_creditcard/account_voucher_view.xml 2012-10-16 09:27:13 +0000
1708@@ -0,0 +1,156 @@
1709+<?xml version="1.0" encoding="UTF-8"?>
1710+<openerp>
1711+ <data>
1712+ <record id="account_voucher_changes_for_credit_card_01" model="ir.ui.view">
1713+ <field name="name">account_voucher_changes_for_credit_card_01</field>
1714+ <field name="model">account.voucher</field>
1715+ <field name="type">form</field>
1716+ <field name="inherit_id" ref="account_voucher.view_vendor_receipt_form"/>
1717+ <field name="arch" type="xml">
1718+ <xpath expr="//field[@name='journal_id']" position="replace">
1719+
1720+ <field name="journal_id"
1721+ domain="[('type','in',['bank', 'cash'])]"
1722+ widget="selection" select="1"
1723+ on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context, rel_sale_order_id)"
1724+ string="Payment Method"/>
1725+
1726+ </xpath>
1727+ <xpath expr="//field[@name='partner_id']" position='attributes'>
1728+ <attribute name='on_change'>onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context, rel_sale_order_id )</attribute>
1729+ </xpath>
1730+ </field>
1731+ </record>
1732+
1733+ <record id="account_voucher_changes_for_credit_card_02" model="ir.ui.view">
1734+ <field name="name">account_voucher_changes_for_credit_card_02</field>
1735+ <field name="model">account.voucher</field>
1736+ <field name="type">form</field>
1737+ <field name="inherit_id" ref="account_voucher_changes_for_credit_card_01"/>
1738+ <field name="arch" type="xml">
1739+ <xpath expr="//notebook[@colspan='4']" position="inside">
1740+
1741+ <page string="Credit Card Info" attrs="{'invisible': [('cc_info_hide','=',True)]}" >
1742+ <group string="Cardholder details">
1743+ <field name="cc_info_hide" invisible="True"/>
1744+ <field name="cc_name" colspan='4' attrs="{'readonly': [('state','!=','draft')]}"/>
1745+ <field name="cc_b_addr_1" attrs="{'readonly': [('state','!=','draft')]}"/>
1746+ <field name="cc_b_addr_2" attrs="{'readonly': [('state','!=','draft')]}"/>
1747+ <field name="cc_city" attrs="{'readonly': [('state','!=','draft')]}"/>
1748+ <field name="cc_state" attrs="{'readonly': [('state','!=','draft')]}"/>
1749+ <field name="cc_zip" attrs="{'readonly': [('state','!=','draft')]}"/>
1750+ <field name="cc_country" attrs="{'readonly': [('state','!=','draft')]}"/>
1751+ </group>
1752+ <group>
1753+ <field name="rel_sale_order_id" readonly="1"/>
1754+ </group>
1755+ <newline/>
1756+ <newline/>
1757+
1758+ <group>
1759+ <field name="cc_order_date" attrs="{'readonly': [('state','!=','draft')]}"/>
1760+ <field name="cc_order_amt" attrs="{'readonly': [('state','!=','draft')]}" />
1761+ </group>
1762+ <newline/>
1763+ <group>
1764+
1765+ <field name="cc_details" attrs="{'readonly': [('state','!=','draft')]}" string="CreditCard Details Auto Fill" domain="[('cc_number','!=',False),('partner_id','=',partner_id)]" on_change="onchange_cc_details(cc_details)"/>
1766+ </group>
1767+ <newline/>
1768+ <group>
1769+ <field name="cc_number" attrs="{'required':[('cc_info_hide','!=',True)],'readonly': [('state','!=','draft')]}" colspan="4"/><newline/>
1770+ <field name="cc_e_d_month" attrs="{'required':[('cc_info_hide','!=',True)],'readonly': [('state','!=','draft')]}"/>
1771+ <field name="cc_e_d_year" attrs="{'required':[('cc_info_hide','!=',True)],'readonly': [('state','!=','draft')]}"/>
1772+ <field name="cc_v" attrs="{'required':[('cc_info_hide','!=',True)],'readonly': [('state','!=','draft')]}"/>
1773+ <button icon="terp-camera_test" name="authorize" string="Authorize" type="object" colspan="2" attrs="{'readonly': [('cc_transaction','!=',False),('state','!=','draft') ] , 'invisible' : [('cc_info_hide','=',True),('state','=','draft')] }" />
1774+ <!--field name="cc_type" widget="selection" attrs="{'required':[('cc_info_hide','!=',True)]}"/-->
1775+ <newline/>
1776+ <field name="cc_comment" colspan="4"/>
1777+ <field name="cc_reseller" invisible="1"/>
1778+ <field name="cc_bank" attrs="{'invisible': [('cc_save_card_details','=',False)]}"/>
1779+ <field name="cc_save_card_details" attrs="{'readonly': [('state','!=','draft')]}" />
1780+ <field name="cc_ecommerce_sale" attrs="{'readonly': [('state','!=','draft')]}" />
1781+ </group>
1782+ <newline/>
1783+ <group>
1784+ <field name="cc_auth_code" readonly="1"/>
1785+ </group>
1786+ <group colspan='3' string="Type of transaction">
1787+ <field name="cc_p_authorize" on_change="oncahnge_pre_authorize(cc_p_authorize)" attrs="{'readonly': [('state','!=','draft')]}"/>
1788+ <field name="cc_charge" on_change="oncahnge_cc_charge(cc_charge)" attrs="{'readonly': [('state','!=','draft')]}"/>
1789+ </group>
1790+ <newline/>
1791+ <button name="cancel_cc" string="Cancel" type="object" states="draft"/>
1792+ <button name="cc_refund" string="Refund" type="object" attrs="{'readonly': [('cc_transaction','!=',True)]}" groups="account_payment_creditcard.group_cc_mgr"/>
1793+ <field name="cc_transaction" invisible="1"/>
1794+ <newline/>
1795+ <group>
1796+ <field name="cc_status" colsapn="4" readonly="1"/>
1797+ </group>
1798+ </page>
1799+ </xpath>
1800+ <xpath expr="//group[@col='10']" position="inside" >
1801+ <button icon="terp-camera_test" name="authorize" string="Authorize" type="object" colspan="2" attrs="{'readonly': [('cc_transaction','!=',False),('state','!=','draft') ] , 'invisible' : [('cc_info_hide','=',True),('state','=','draft')] }" />
1802+ </xpath>
1803+ </field>
1804+ </record>
1805+
1806+ <!-- Company Form -->
1807+ <record id="cc_company" model="ir.ui.view">
1808+ <field name="name">res.company.cc.config</field>
1809+ <field name="model">res.company</field>
1810+ <field name="type">form</field>
1811+ <field name="inherit_id" ref="base.view_company_form"/>
1812+ <field name="arch" type="xml">
1813+ <page string="Configuration" position="inside">
1814+ <newline/>
1815+ <separator string="Credit Card Details" colspan="4"/>
1816+ <newline/>
1817+ <field name="cc_transaction_key" password="1"/>
1818+ <field name="cc_login"/>
1819+ <field name="cc_testmode"/>
1820+ <field name="cc_journal_id" domain="[('type','in',('bank','cash'))]" />
1821+ <field name="cc_refund_journal_id" domain="[('type','=','sale_refund')]" />
1822+ <newline/>
1823+ </page>
1824+ </field>
1825+ </record>
1826+
1827+ <!-- Bank-->
1828+ <record id="view_partner_bank_form_inherit" model="ir.ui.view">
1829+ <field name="name">res.partner.bank.form.inherit</field>
1830+ <field name="model">res.partner.bank</field>
1831+ <field name="type">form</field>
1832+ <field name="inherit_id" ref="base.view_partner_bank_form"/>
1833+ <field name="arch" type="xml">
1834+ <xpath expr="//field[@name='state_id']" position="replace">
1835+ <group string="Credit Card Information" colspan="4" cols="4">
1836+ <field name="cc_number"/>
1837+ <!--field name="cc_type"/-->
1838+ <field name="cc_e_d_month"/>
1839+ <field name="cc_e_d_year"/>
1840+ <field name="cc_v"/>
1841+ </group>
1842+ </xpath>
1843+ </field>
1844+ </record>
1845+ <record id="view_partner_bank_tree_inherit" model="ir.ui.view">
1846+ <field name="name">res.partner.bank.tree.inherit</field>
1847+ <field name="model">res.partner.bank</field>
1848+ <field name="type">tree</field>
1849+ <field name="inherit_id" ref="base.view_partner_bank_tree"/>
1850+ <field name="arch" type="xml">
1851+ <xpath expr="//field[@name='owner_name']" position="after">
1852+ <field name="cc_number"/>
1853+ <!--field name="cc_type"/-->
1854+ <field name="cc_e_d_month"/>
1855+ <field name="cc_e_d_year"/>
1856+ </xpath>
1857+ </field>
1858+ </record>
1859+
1860+ <!-- CreditCard Type -->
1861+ <menuitem id="menu_cc" name="Credit Card" parent="account.menu_finance_configuration"/>
1862+
1863+ </data>
1864+</openerp>
1865\ No newline at end of file
1866
1867=== added file 'account_payment_creditcard/invoice.py'
1868--- account_payment_creditcard/invoice.py 1970-01-01 00:00:00 +0000
1869+++ account_payment_creditcard/invoice.py 2012-10-16 09:27:13 +0000
1870@@ -0,0 +1,37 @@
1871+# -*- coding: utf-8 -*-
1872+##############################################################################
1873+#
1874+# OpenERP, Open Source Management Solution
1875+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
1876+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
1877+#
1878+# This program is free software: you can redistribute it and/or modify
1879+# it under the terms of the GNU General Public License as published by
1880+# the Free Software Foundation, either version 3 of the License, or
1881+# (at your option) any later version.
1882+#
1883+# This program is distributed in the hope that it will be useful,
1884+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1885+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1886+# GNU General Public License for more details.
1887+#
1888+# You should have received a copy of the GNU General Public License
1889+# along with this program. If not, see <http://www.gnu.org/licenses/>
1890+#
1891+##############################################################################
1892+
1893+from osv import osv, fields
1894+
1895+class account_invoice(osv.osv):
1896+
1897+ _inherit = 'account.invoice'
1898+ _columns = {
1899+ 'credit_card' : fields.boolean('Credit Card', readonly=True)
1900+ }
1901+
1902+ _defaults = {
1903+ 'credit_card' : False
1904+ }
1905+account_invoice()
1906+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1907+
1908
1909=== added file 'account_payment_creditcard/invoice_view.xml'
1910--- account_payment_creditcard/invoice_view.xml 1970-01-01 00:00:00 +0000
1911+++ account_payment_creditcard/invoice_view.xml 2012-10-16 09:27:13 +0000
1912@@ -0,0 +1,26 @@
1913+<?xml version="1.0" encoding="utf-8"?>
1914+<openerp>
1915+ <data>
1916+
1917+
1918+ <record id="view_account_invoice_filter_inherit" model="ir.ui.view">
1919+ <field name="name">account.invoice.search.inherit</field>
1920+ <field name="model">account.invoice</field>
1921+ <field name="type">search</field>
1922+ <field name="inherit_id" ref="account.view_account_invoice_filter" />
1923+ <field name="arch" type="xml">
1924+ <xpath expr="/search/group/filter[@name='unpaid']" position="after">
1925+ <filter name="manual" icon="terp-dolar_ok!" string="Manual Invoices" domain="[('credit_card','=',False)]" help="Unpaid Invoices"/>
1926+ <filter name="credit" icon="terp-dolar_ok!" string="Credit Card Invoices" domain="[('credit_card','=',True)]" help="Unpaid Invoices"/>
1927+ </xpath>
1928+ </field>
1929+ </record>
1930+
1931+
1932+ <record id="account.action_invoice_tree1" model="ir.actions.act_window">
1933+ <field name="context">{'type':'out_invoice', 'journal_type': 'sale','search_default_manual':1}</field>
1934+ </record>
1935+
1936+
1937+</data>
1938+</openerp>
1939\ No newline at end of file
1940
1941=== added file 'account_payment_creditcard/rsa_encrypt.py'
1942--- account_payment_creditcard/rsa_encrypt.py 1970-01-01 00:00:00 +0000
1943+++ account_payment_creditcard/rsa_encrypt.py 2012-10-16 09:27:13 +0000
1944@@ -0,0 +1,62 @@
1945+# -*- coding: utf-8 -*-
1946+##############################################################################
1947+#
1948+# OpenERP, Open Source Management Solution
1949+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
1950+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
1951+#
1952+# This program is free software: you can redistribute it and/or modify
1953+# it under the terms of the GNU General Public License as published by
1954+# the Free Software Foundation, either version 3 of the License, or
1955+# (at your option) any later version.
1956+#
1957+# This program is distributed in the hope that it will be useful,
1958+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1959+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1960+# GNU General Public License for more details.
1961+#
1962+# You should have received a copy of the GNU General Public License
1963+# along with this program. If not, see <http://www.gnu.org/licenses/>
1964+#
1965+##############################################################################
1966+
1967+from Crypto.PublicKey import RSA
1968+import base64
1969+import tools
1970+
1971+def rsa_enc():
1972+ """
1973+ Generate a key for RSA Encryption
1974+ @return : key
1975+ """
1976+ key = RSA.generate(1024)
1977+ return key
1978+
1979+def encrypt(value, key=False):
1980+ """
1981+ Encryption using RSA
1982+ @params value: Value to Encrypt
1983+ @key: The Key used to Encrypt
1984+ @return:Dictionary containing the encrypted data and key
1985+ """
1986+ res = {}
1987+ if not key:
1988+ pub_key = rsa_enc()
1989+ public_key = pub_key.publickey()
1990+ enc_data = public_key.encrypt(str(value), 32)
1991+ res['key'] = base64.encodestring(pub_key.exportKey('DER'))
1992+ else:
1993+ privatekey = RSA.importKey(base64.decodestring(key))
1994+ enc_data = privatekey.encrypt(str(value), 32)
1995+ res['enc_value'] = base64.encodestring(enc_data[0])
1996+ return res
1997+
1998+def decrypt(value, key):
1999+ """
2000+ Decryption using RSA
2001+ @params value: Value to Decrypt
2002+ @key: The Key used to Decrypt
2003+ @return:The decrypted data
2004+ """
2005+ privatekey = RSA.importKey(base64.decodestring(key))
2006+ return privatekey.decrypt(base64.decodestring(value))
2007
2008=== added file 'account_payment_creditcard/sale.py'
2009--- account_payment_creditcard/sale.py 1970-01-01 00:00:00 +0000
2010+++ account_payment_creditcard/sale.py 2012-10-16 09:27:13 +0000
2011@@ -0,0 +1,225 @@
2012+# -*- coding: utf-8 -*-
2013+##############################################################################
2014+#
2015+# OpenERP, Open Source Management Solution
2016+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
2017+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
2018+#
2019+# This program is free software: you can redistribute it and/or modify
2020+# it under the terms of the GNU General Public License as published by
2021+# the Free Software Foundation, either version 3 of the License, or
2022+# (at your option) any later version.
2023+#
2024+# This program is distributed in the hope that it will be useful,
2025+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2026+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2027+# GNU General Public License for more details.
2028+#
2029+# You should have received a copy of the GNU General Public License
2030+# along with this program. If not, see <http://www.gnu.org/licenses/>
2031+#
2032+##############################################################################
2033+from osv import fields, osv
2034+from tools.translate import _
2035+import netsvc
2036+
2037+class sale_order(osv.osv):
2038+ _inherit = "sale.order"
2039+
2040+ def onchange_partner_id(self, cr, uid, ids, part_id):
2041+
2042+ result = super(sale_order, self).onchange_partner_id(cr, uid, ids, part_id).get('value', {})
2043+ print result
2044+# if part_id:
2045+# result.update({'payment_method':'cc_pre_auth', 'order_policy':'credit_card'})#Default values for the shiping policy
2046+# partner=self.pool.get('res.partner').browse(cr,uid,part_id)
2047+# if partner.title and (partner.title.name=="Reseller" or partner.title.shortcut == 'reseller'):
2048+# result.update({'payment_method':'invoice','order_policy':'postpaid'})
2049+ return {'value': result}
2050+
2051+ def on_change_payment_method(self, cr, uid, ids, payment_method,order,part):
2052+ order_policy = order
2053+# if payment_method:
2054+# if payment_method in ('invoice'):
2055+# order_policy = 'picking'
2056+# elif payment_method in ('no_charge'):
2057+# order_policy = 'no_charge'
2058+# elif payment_method == 'cc_pre_auth':
2059+# order_policy = 'credit_card'
2060+# elif payment_method =='pay_pal':
2061+# order_policy = 'prepaid'
2062+# {'value': {'order_policy':order_policy}}
2063+ return {'value': {}}
2064+
2065+ def pay(self, cr, uid, ids, context=None):
2066+ '''
2067+ Display Pay invoice form when clicking on Pay button from sale order
2068+ '''
2069+
2070+ wf_service = netsvc.LocalService("workflow")
2071+
2072+ invoice_id = False
2073+ so = self.browse(cr, uid, ids[0], context=context)
2074+ for invoice in so.invoice_ids:
2075+ if invoice.state != 'open':
2076+ wf_service.trg_validate(uid, 'account.invoice', invoice.id, 'invoice_open', cr)
2077+ invoice_id = invoice.id
2078+
2079+ if not ids: return []
2080+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
2081+ #so = self.browse(cr, uid, ids[0], context=context)
2082+ self.pool.get('account.invoice').write(cr, uid, invoice_id, {'credit_card': True}, context=context)
2083+ return {
2084+ 'name':_("Pay Invoice"),
2085+
2086+ 'view_mode': 'form',
2087+ 'view_id': False,
2088+ 'view_type': 'form',
2089+ 'res_model': 'account.voucher',
2090+ 'type': 'ir.actions.act_window',
2091+ 'nodestroy': True,
2092+ 'target': 'current',
2093+ 'domain': '[]',
2094+ 'context': {
2095+ 'default_partner_id': so.partner_id.id,
2096+ 'default_amount': so.amount_total,
2097+ 'default_name':so.name,
2098+ 'close_after_process': True,
2099+ 'invoice_type':'out_invoice',
2100+ 'default_rel_sale_order_id': so.id,
2101+ 'default_cc_order_amt': so.amount_total,
2102+ 'default_cc_order_date': so.date_order,
2103+ 'default_type':'receipt',
2104+ 'default_journal_id':user.company_id.cc_journal_id and user.company_id.cc_journal_id.id or False,
2105+ 'default_invoice_id':invoice_id,
2106+ }
2107+ }
2108+
2109+ def _invoiced_search(self, cursor, user, obj, name, args, context=None):
2110+ if not len(args):
2111+ return []
2112+ clause = ''
2113+ sale_clause = ''
2114+ no_invoiced = False
2115+ for arg in args:
2116+ if arg[1] == '=':
2117+ if arg[2]:
2118+ clause += 'AND inv.state = \'paid\''
2119+ else:
2120+ clause += 'AND inv.state != \'cancel\' AND sale.state != \'cancel\' AND inv.state <> \'paid\' AND rel.order_id = sale.id '
2121+ sale_clause = ', sale_order AS sale '
2122+ no_invoiced = True
2123+
2124+ cursor.execute('SELECT rel.order_id ' \
2125+ 'FROM sale_order_invoice_rel AS rel, account_invoice AS inv ' + sale_clause + \
2126+ 'WHERE rel.invoice_id = inv.id ' + clause)
2127+ res = cursor.fetchall()
2128+ if no_invoiced:
2129+ cursor.execute('SELECT sale.id ' \
2130+ 'FROM sale_order AS sale ' \
2131+ 'WHERE sale.id NOT IN ' \
2132+ '(SELECT rel.order_id ' \
2133+ 'FROM sale_order_invoice_rel AS rel) and sale.state != \'cancel\'')
2134+ res.extend(cursor.fetchall())
2135+ if not res:
2136+ return [('id', '=', 0)]
2137+ return [('id', 'in', [x[0] for x in res])]
2138+
2139+ def _invoiced(self, cursor, user, ids, name, arg, context=None):
2140+ '''
2141+ Update pay boolean field on sale order if creditcard payment is done
2142+ '''
2143+ ret = super(sale_order, self)._invoiced(cursor, user, ids, name, arg, context=context)
2144+ for key, value in ret.items():
2145+ if not value:
2146+ so = self.browse(cursor, user, key, context=context)
2147+ if so.order_policy == 'credit_card' and so.rel_account_voucher_id:
2148+ if so.rel_account_voucher_id.state == 'posted':
2149+ ret[key] = True
2150+
2151+ return ret
2152+
2153+ def write(self, cr, uid, ids, vals, context=None):
2154+ res = super(sale_order, self).write(cr, uid, ids, vals, context=context)
2155+ cr.commit()
2156+ for sale_obj in self.browse(cr, uid, ids, context=context):
2157+ if sale_obj.shipped and sale_obj.invoiced and sale_obj.state != 'done':
2158+ sale_obj.write({'state':'done'})
2159+
2160+ return res
2161+
2162+ def _get_invoice(self, cr, uid, ids, context=None):
2163+ return self.pool.get('sale.order').search(cr, uid, [('invoice_ids', 'in', ids)], context=context)
2164+
2165+ def _get_voucher(self, cr, uid, ids, context=None):
2166+ result = {}
2167+ for line in self.pool.get('account.voucher').browse(cr, uid, ids, context=context):
2168+ if line.rel_sale_order_id:
2169+ result[line.rel_sale_order_id.id] = True
2170+ return result.keys()
2171+
2172+ _inherit = "sale.order"
2173+ _columns = {
2174+
2175+ 'payment_method':fields.selection([('cc_pre_auth', 'Credit Card – PreAuthorized'),
2176+ ('invoice', 'Invoice'),
2177+ ('cod', 'COD'),
2178+ ('p_i_a', 'Pay In Advance'), ], 'Payment Method'),
2179+ 'order_policy': fields.selection([
2180+ ('prepaid', 'Payment Before Delivery'),
2181+ ('manual', 'Shipping & Manual Invoice'),
2182+ ('postpaid', 'Invoice On Order After Delivery'),
2183+ ('picking', 'Invoice From The Picking'),
2184+ ('credit_card', 'CC Pre-Auth Pick Charge Ship'),
2185+ ], 'Shipping Policy', required=True, readonly=True, states={'draft': [('readonly', False)]},
2186+ help="""The Shipping Policy is used to synchronise invoice and delivery operations.
2187+ - The 'Pay Before delivery' choice will first generate the invoice and then generate the picking order after the payment of this invoice.
2188+ - The 'Shipping & Manual Invoice' will create the picking order directly and wait for the user to manually click on the 'Invoice' button to generate the draft invoice.
2189+ - The 'Invoice On Order After Delivery' choice will generate the draft invoice based on sales order after all picking lists have been finished.
2190+ - The 'Invoice From The Picking' choice is used to create an invoice during the picking process."""),
2191+ 'state': fields.selection([
2192+ ('draft', 'Quotation'),
2193+ ('waiting_date', 'Waiting Schedule'),
2194+ ('manual', 'Manual In Progress'),
2195+ ('progress', 'In Progress'),
2196+ ('shipping_except', 'Shipping Exception'),
2197+ ('invoice_except', 'Invoice Exception'),
2198+ ('done', 'Done'),
2199+ ('cancel', 'Cancelled'),
2200+ ('cc_auth', 'Draft Authorized')
2201+ ], 'Order State', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the date 'Ordered Date'.", select=True),
2202+ 'cc_pre_auth':fields.boolean('Creditcard Pre-authorised'),
2203+ 'rel_account_voucher_id':fields.many2one('account.voucher', 'Related Payment'),
2204+ 'invoiced': fields.function(_invoiced, method=True, string='Paid',
2205+ type='boolean', help="It indicates that an invoice has been paid.",
2206+ store={
2207+ 'account.invoice' : (_get_invoice, ['state'], 20),
2208+ 'sale.order' : (lambda self, cr, uid, ids, c={}: ids, ['state'], 20),
2209+ 'account.voucher' : (_get_voucher, ['state'], 20),
2210+ }),
2211+ 'cc_ship_refund' : fields.boolean('Ship Refunded', readonly=True),
2212+ }
2213+
2214+ def copy(self, cr, uid, id, default=None, context=None):
2215+ if default is None:
2216+ default = {}
2217+ if context is None:
2218+ context = {}
2219+ default = default.copy()
2220+ default['rel_account_voucher_id'] = False
2221+ default['cc_pre_auth'] = False
2222+ default['cc_ship_refund'] = False
2223+ return super(sale_order, self).copy(cr, uid, id, default, context=context)
2224+
2225+ _defaults = {
2226+ 'cc_ship_refund': lambda * a : False,
2227+ 'payment_method': lambda * a: 'cc_pre_auth'
2228+ }
2229+ def action_ship_create(self, cr, uid, ids, *args):
2230+ ret = super(sale_order, self).action_ship_create(cr, uid, ids, args)
2231+ for sale_obj in self.browse(cr, uid, ids, context={}):
2232+ if sale_obj.order_policy == 'credit_card':
2233+ for pick in sale_obj.picking_ids:
2234+ self.pool.get('stock.picking').write(cr, uid, [pick.id], {'invoice_state': 'credit_card'}, context={})
2235+ return ret
2236+sale_order()
2237
2238=== added directory 'account_payment_creditcard/security'
2239=== added file 'account_payment_creditcard/security/account_security.xml'
2240--- account_payment_creditcard/security/account_security.xml 1970-01-01 00:00:00 +0000
2241+++ account_payment_creditcard/security/account_security.xml 2012-10-16 09:27:13 +0000
2242@@ -0,0 +1,10 @@
2243+<?xml version="1.0" encoding="utf-8"?>
2244+<openerp>
2245+ <data>
2246+
2247+ <record id="group_cc_mgr" model="res.groups">
2248+ <field name="name">CreditCard / Manager</field>
2249+ </record>
2250+
2251+ </data>
2252+</openerp>
2253
2254=== added file 'account_payment_creditcard/stock_picking.py'
2255--- account_payment_creditcard/stock_picking.py 1970-01-01 00:00:00 +0000
2256+++ account_payment_creditcard/stock_picking.py 2012-10-16 09:27:13 +0000
2257@@ -0,0 +1,52 @@
2258+# -*- coding: utf-8 -*-
2259+##############################################################################
2260+#
2261+# OpenERP, Open Source Management Solution
2262+# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
2263+# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
2264+#
2265+# This program is free software: you can redistribute it and/or modify
2266+# it under the terms of the GNU General Public License as published by
2267+# the Free Software Foundation, either version 3 of the License, or
2268+# (at your option) any later version.
2269+#
2270+# This program is distributed in the hope that it will be useful,
2271+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2272+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2273+# GNU General Public License for more details.
2274+#
2275+# You should have received a copy of the GNU General Public License
2276+# along with this program. If not, see <http://www.gnu.org/licenses/>
2277+#
2278+##############################################################################
2279+
2280+
2281+from osv import fields, osv
2282+
2283+class stock_picking(osv.osv):
2284+
2285+ _inherit = "stock.picking"
2286+ '''
2287+ Adding credit card preauthorised and payed check box on delivery order
2288+ '''
2289+ def _get_sale_order(self, cr, uid, ids, context={}):
2290+ result = []
2291+ move_ids = []
2292+ picking_obj = self.pool.get('stock.picking')
2293+ move_obj = self.pool.get('stock.move')
2294+ for id in ids:
2295+ stock_pick_ids = picking_obj.search(cr, uid, [('sale_id', '=', id)])
2296+ if stock_pick_ids:
2297+ move_ids += move_obj.search(cr, uid, [('picking_id', 'in', stock_pick_ids)])
2298+ move_ids = list(set(move_ids))
2299+ return move_ids
2300+
2301+ _columns = {
2302+ 'cc_pre_auth': fields.related('sale_id', 'cc_pre_auth', string='CC Pre-authorised', type='boolean'),
2303+ 'invoiced': fields.related('sale_id', 'invoiced', string='Paid', type='boolean'),
2304+ }
2305+
2306+stock_picking()
2307+
2308+
2309+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
2310
2311=== added file 'account_payment_creditcard/stock_picking_view.xml'
2312--- account_payment_creditcard/stock_picking_view.xml 1970-01-01 00:00:00 +0000
2313+++ account_payment_creditcard/stock_picking_view.xml 2012-10-16 09:27:13 +0000
2314@@ -0,0 +1,47 @@
2315+<?xml version="1.0" encoding="UTF-8"?>
2316+<openerp>
2317+ <data>
2318+ <!-- Adding credit card preautohrised and payed check box on delivery order -->
2319+ <record id="view_picking_out_form_cc_inherit" model="ir.ui.view">
2320+ <field name="name">stock.picking.out.form.cc_inherit</field>
2321+ <field name="model">stock.picking</field>
2322+ <field name="inherit_id" ref="stock.view_picking_out_form"/>
2323+ <field name="type">form</field>
2324+ <field name="arch" type="xml">
2325+ <xpath expr="//field[@name='company_id']" position="after">
2326+ <field name="cc_pre_auth" readonly="1"/>
2327+ <field name="invoiced" readonly="1"/>
2328+ </xpath>
2329+ </field>
2330+ </record>
2331+ <!-- Tree -->
2332+ <record id="view_picking_out_tree_cc_inherit" model="ir.ui.view">
2333+ <field name="name">stock.picking.out.tree.cc_inherit</field>
2334+ <field name="model">stock.picking</field>
2335+ <field name="inherit_id" ref="stock.view_picking_out_tree"/>
2336+ <field name="type">tree</field>
2337+ <field name="arch" type="xml">
2338+ <xpath expr="//field[@name='backorder_id']" position="before">
2339+ <field name="cc_pre_auth" readonly="1"/>
2340+ <field name="invoiced" readonly="1"/>
2341+ </xpath>
2342+ </field>
2343+ </record>
2344+
2345+ <record id="view_picking_out_search_inherit" model="ir.ui.view">
2346+ <field name="name">stock.picking.out.search.inherit</field>
2347+ <field name="model">stock.picking</field>
2348+ <field name="type">search</field>
2349+ <field name="inherit_id" ref="stock.view_picking_out_search"/>
2350+ <field name="arch" type="xml">
2351+ <xpath expr="/search/group/filter[@name='to_invoice']" position="after">
2352+ <separator orientation="vertical"/>
2353+ <!--<filter icon="terp-rating-rated" string="Pre-authorized" domain="[('cc_pre_auth','=',True)]" />
2354+ <filter icon="terp-rating-rated" string="Paid" domain="[('invoiced','=',True)]" />-->
2355+ <filter icon="terp-rating-rated" string="Pre-authorized / Invoiced" domain="['|',('cc_pre_auth','=',True),('invoiced','=',True)]" />
2356+ </xpath>
2357+ </field>
2358+ </record>
2359+
2360+ </data>
2361+</openerp>
2362\ No newline at end of file
2363
2364=== modified file 'account_voucher_credits_us/voucher_view.xml'
2365--- account_voucher_credits_us/voucher_view.xml 2012-06-18 14:26:40 +0000
2366+++ account_voucher_credits_us/voucher_view.xml 2012-10-16 09:27:13 +0000
2367@@ -58,7 +58,6 @@
2368 <field name="pay" on_change="onchange_pay(amount, pay, amount_unreconciled, parent.line_cr_ids, parent.amount,
2369 credit_used, discount_used, writeoff_amount)"/>
2370 <field name="amount" sum="Payment"/>
2371- <field name="discount" />
2372 <field name="amount_difference"/>
2373 <field name="credit_used"/>
2374 <field name="account_id"/>

Subscribers

People subscribed via source and target branches