diff options
| author | Damien Bouvy <dbo@odoo.com> | 2015-07-31 09:57:27 +0200 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2015-09-04 16:08:21 +0200 |
| commit | f8a98d977e5e665689b9adb3954ef55bbf04008b (patch) | |
| tree | 5ca09fbfd0e3eb9febb0c1d3813ef14e52fca812 | |
| parent | 4bdfa3b6caefc6621d7043738708a766b4f80f69 (diff) | |
[IMP] payment: usability improvements
- general:
- add payment.method and payment.transaction menu in invoicing
- payment.acquirer:
- add image field
- add stat button to see payment.transaction objects
- payment.transaction:
- language field is now a selection instead of a char
- rename s2s_cb_eval field in callback_eval
- form view cleaning
- on_change_partner_id now fills in the partner details
- add an ir.sequence for transaction name
- add a many2one to payment.method
- country defaults to the country of the company
- payment.method:
- add a one2many to payment.transaction
- add a stat button to see payment.transaction objects
[IMP] website_quote: rename s2s_cb_eval payment.transaction field to callback_eval
[IMP] payment_* (all providers): add image data and rename s2s_cb_eval field to callback_eval
| -rw-r--r-- | addons/payment/models/payment_acquirer.py | 69 | ||||
| -rw-r--r-- | addons/payment/views/payment_acquirer.xml | 141 | ||||
| -rw-r--r-- | addons/payment_adyen/data/adyen.xml | 1 | ||||
| -rw-r--r-- | addons/payment_authorize/data/authorize.xml | 1 | ||||
| -rw-r--r-- | addons/payment_buckaroo/data/buckaroo.xml | 1 | ||||
| -rw-r--r-- | addons/payment_ogone/data/ogone.xml | 1 | ||||
| -rw-r--r-- | addons/payment_ogone/models/ogone.py | 8 | ||||
| -rw-r--r-- | addons/payment_paypal/data/paypal.xml | 1 | ||||
| -rw-r--r-- | addons/payment_transfer/data/transfer.xml | 1 | ||||
| -rw-r--r-- | addons/website_quote/controllers/main.py | 2 |
10 files changed, 169 insertions, 57 deletions
diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 5da97735e5a..c099ce866f4 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -2,7 +2,7 @@ import logging from openerp.osv import osv, fields -from openerp.tools import float_round, float_repr +from openerp.tools import float_round, float_repr, image_get_resized_images, image_resize_image_big from openerp.tools.translate import _ _logger = logging.getLogger(__name__) @@ -55,12 +55,34 @@ class PaymentAcquirer(osv.Model): def _get_providers(self, cr, uid, context=None): return [] + def _get_image(self, cr, uid, ids, name, args, context=None): + return dict((p.id, image_get_resized_images(p.image)) for p in self.browse(cr, uid, ids, context=context)) + + def _set_image(self, cr, uid, id, name, value, args, context=None): + return self.write({'image': image_resize_image_big(value)}) + # indirection to ease inheritance _provider_selection = lambda self, *args, **kwargs: self._get_providers(*args, **kwargs) _columns = { 'name': fields.char('Name', required=True, translate=True), 'provider': fields.selection(_provider_selection, string='Provider', required=True), + 'image': fields.binary("Image", help="This field holds the image used for this provider, limited to 1024x1024px"), + 'image_medium': fields.function(_get_image, fnct_inv=_set_image, string="Medium-sized image", type="binary", multi="_get_image", + store={ + 'payment.acquirer': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized image of this provider. It is automatically "\ + "resized as a 128x128px image, with aspect ratio preserved. "\ + "Use this field in form views or some kanban views."), + 'image_small': fields.function(_get_image, fnct_inv=_set_image, + string="Small-sized image", type="binary", multi="_get_image", + store={ + 'payment.acquirer': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized image of this provider. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required."), 'company_id': fields.many2one('res.company', 'Company', required=True), 'pre_msg': fields.html('Help Message', translate=True, help='Message displayed to explain and help the payment process.'), @@ -100,7 +122,6 @@ class PaymentAcquirer(osv.Model): _defaults = { 'company_id': lambda self, cr, uid, obj, ctx=None: self.pool['res.users'].browse(cr, uid, uid).company_id.id, 'environment': 'prod', - 'validation': 'manual', 'website_published': False, 'auto_confirm': 'at_pay_confirm', 'pending_msg': '<i>Pending,</i> Your online payment has been successfully processed. But your order is not validated yet.', @@ -158,7 +179,6 @@ class PaymentAcquirer(osv.Model): 'country_id': tx.partner_country_id.id, 'country': tx.partner_country_id, 'phone': tx.partner_phone, - 'reference': tx.partner_reference, 'state': None, } else: @@ -370,12 +390,20 @@ class PaymentTransaction(osv.Model): """ _name = 'payment.transaction' _description = 'Payment Transaction' - _inherit = ['mail.thread'] _order = 'id desc' _rec_name = 'reference' + def _lang_get(self, cr, uid, context=None): + lang_ids = self.pool['res.lang'].search(cr, uid, [], context=context) + languages = self.pool['res.lang'].browse(cr, uid, lang_ids, context=context) + return [(language.code, language.name) for language in languages] + + def _default_partner_country_id(self, cr, uid, context=None): + comp = self.pool['res.company'].browse(cr, uid, context.get('company_id', 1), context=context) + return comp.country_id.id + _columns = { - 'date_create': fields.datetime('Creation Date', readonly=True, required=True), + 'create_date': fields.datetime('Creation Date', readonly=True), 'date_validate': fields.datetime('Validation Date'), 'acquirer_id': fields.many2one( 'payment.acquirer', 'Acquirer', @@ -396,32 +424,31 @@ class PaymentTransaction(osv.Model): 'amount': fields.float('Amount', required=True, digits=(16, 2), track_visibility='always', - help='Amount in cents'), + help='Amount'), 'fees': fields.float('Fees', digits=(16, 2), track_visibility='always', help='Fees amount; set by the system because depends on the acquirer'), 'currency_id': fields.many2one('res.currency', 'Currency', required=True), - 'reference': fields.char('Order Reference', required=True), - 'acquirer_reference': fields.char('Acquirer Order Reference', + 'reference': fields.char('Reference', required=True, help='Internal reference of the TX'), + 'acquirer_reference': fields.char('Acquirer Reference', help='Reference of the TX as stored in the acquirer database'), # duplicate partner / transaction data to store the values at transaction time 'partner_id': fields.many2one('res.partner', 'Partner', track_visibility='onchange',), 'partner_name': fields.char('Partner Name'), - 'partner_lang': fields.char('Lang'), + 'partner_lang': fields.selection(_lang_get, 'Language'), 'partner_email': fields.char('Email'), 'partner_zip': fields.char('Zip'), 'partner_address': fields.char('Address'), 'partner_city': fields.char('City'), 'partner_country_id': fields.many2one('res.country', 'Country', required=True), 'partner_phone': fields.char('Phone'), - 'partner_reference': fields.char('Partner Reference', - help='Reference of the customer in the acquirer database'), 'html_3ds': fields.char('3D Secure HTML'), - 's2s_cb_eval': fields.char('S2S Callback', help="""\ + 'callback_eval': fields.char('S2S Callback', help="""\ Will be safe_eval with `self` being the current transaction. i.e.: - self.env['my.model'].payment_validated(self)"""), + self.env['my.model'].payment_validated(self)""", oldname="s2s_cb_eval"), + 'payment_method_id': fields.many2one('payment.method', 'Payment Method', domain="[('acquirer_id', '=', acquirer_id)]"), } def _check_reference(self, cr, uid, ids, context=None): @@ -436,17 +463,18 @@ class PaymentTransaction(osv.Model): ] _defaults = { - 'date_create': fields.datetime.now, 'type': 'form', 'state': 'draft', 'partner_lang': 'en_US', + 'partner_country_id': _default_partner_country_id, + 'reference': lambda s, c, u, ctx=None: s.pool['ir.sequence'].next_by_code(c, u, 'payment.transaction', context=ctx), } def create(self, cr, uid, values, context=None): Acquirer = self.pool['payment.acquirer'] if values.get('partner_id'): # @TDENOTE: not sure - values.update(self.on_change_partner_id(cr, uid, None, values.get('partner_id'), context=context)['values']) + values.update(self.on_change_partner_id(cr, uid, None, values.get('partner_id'), context=context)['value']) # call custom create method if defined (i.e. ogone_create for ogone) if values.get('acquirer_id'): @@ -464,13 +492,17 @@ class PaymentTransaction(osv.Model): if hasattr(self, custom_method_name): values.update(getattr(self, custom_method_name)(cr, uid, values, context=context)) - return super(PaymentTransaction, self).create(cr, uid, values, context=context) + # Default value of reference is + tx_id = super(PaymentTransaction, self).create(cr, uid, values, context=context) + if not values.get('reference'): + self.write(cr, uid, [tx_id], {'reference': str(tx_id)}, context=context) + return tx_id def on_change_partner_id(self, cr, uid, ids, partner_id, context=None): partner = None if partner_id: partner = self.pool['res.partner'].browse(cr, uid, partner_id, context=context) - return {'values': { + return {'value': { 'partner_name': partner and partner.name or False, 'partner_lang': partner and partner.lang or 'en_US', 'partner_email': partner and partner.email or False, @@ -543,7 +575,8 @@ class PaymentMethod(osv.Model): 'partner_id': fields.many2one('res.partner', 'Partner', required=True), 'acquirer_id': fields.many2one('payment.acquirer', 'Acquirer Account', required=True), 'acquirer_ref': fields.char('Acquirer Ref.', required=True), - 'active': fields.boolean('Active') + 'active': fields.boolean('Active'), + 'payment_ids': fields.one2many('payment.transaction', 'payment_method_id', 'Payment Transactions'), } _defaults = { diff --git a/addons/payment/views/payment_acquirer.xml b/addons/payment/views/payment_acquirer.xml index fa7ee57596b..57a0ca32fcb 100644 --- a/addons/payment/views/payment_acquirer.xml +++ b/addons/payment/views/payment_acquirer.xml @@ -2,26 +2,49 @@ <openerp> <data> - <!-- Acquirer --> - + <!-- Payment menu in settings --> <menuitem name='Payments' id='root_payment_menu' parent='base.menu_administration'/> + <!-- Payment menu in invoicing --> + <menuitem + name='Payments' + id='finance_payment_menu' + parent='account.menu_finance'/> + + <!-- Payment acquirers --> + <record id="payment_transaction_action_child" model="ir.actions.act_window"> + <field name="name">Payment Transactions</field> + <field name="res_model">payment.transaction</field> + <field name='view_type'>form</field> + <field name='view_mode'>tree,form</field> + <field name='domain'>[('acquirer_id','=',active_id)]</field> + <field name="context">{'default_acquirer_id': active_id}</field> + </record> + <record id="acquirer_form" model="ir.ui.view"> <field name="name">payment.acquirer.form</field> <field name="model">payment.acquirer</field> <field name="arch" type="xml"> <form string="Payment Acquirer"> <sheet> - <group name="acquirer_base"> + <div class="oe_button_box" name="button_box"> + <button class="oe_stat_button" name="%(payment_transaction_action_child)d" + type="action" icon="fa-money" string="Payments"> + </button> + </div> + <field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/> + <div class="oe_title"> + <h1><field name="name" placeholder="Name"/></h1> + <label for="provider" class="oe_edit_only"/> + <field name="provider"/> + </div> + <group name="acquirer_base" col="2"> <group name="acquirer_left"> <field name="name"/> <field name="environment" groups="base.group_no_one"/> - </group> - <group name="acquirer_right"> - <field name="provider"/> <field name="company_id" groups="base.group_multi_company" options='{"no_open":True}'/> </group> </group> @@ -42,7 +65,6 @@ </page> <page string="Configuration" groups="base.group_no_one"> <group name="acquirer_config"> - <field name="validation"/> <field name="auto_confirm"/> <field name="fees_active"/> <field name="fees_dom_fixed" attrs="{'invisible': [('fees_active', '=', False)]}"/> @@ -118,48 +140,53 @@ parent='root_payment_menu' sequence='10' /> - <!-- Transactions --> - + <!-- Payment transactions --> <record id="transaction_form" model="ir.ui.view"> <field name="name">payment.transaction.form</field> <field name="model">payment.transaction</field> <field name="arch" type="xml"> <form string="Payment Transactions"> + <header> + <field name="state" widget="statusbar" clickable="True"/> + </header> <sheet> <group> <group> <field name="reference"/> - <field name="amount"/> - <field name="date_create"/> + <label for="amount"/> + <div class="o_row"> + <field name="amount" class="oe_inline" /> + <field name="currency_id" options="{'no_open': True, 'no_create': True}" class="oe_inline" /> + </div> <field name="fees"/> - <field name="currency_id"/> - <field name="partner_id"/> - <field name="partner_reference"/> + <field name="partner_id" on_change="on_change_partner_id(partner_id)"/> + <label for="partner_details" string="Customer Details"/> + <div name="partner_details"> + <field name="partner_name" placeholder="Name" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + <field name="partner_address" placeholder="Address" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + <div class="o_row"> + <field name="partner_zip" class="oe_inline" placeholder="ZIP" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + <field name="partner_city" class="oe_inline" placeholder="City" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + </div> + <field name="partner_country_id" placeholder="Country" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + <field name="partner_lang" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + <field name="partner_email" placeholder="E-mail" attrs="{'readonly': [('partner_id', '!=', False)]}"/> + </div> </group> <group> <field name="acquirer_id"/> + <field name="payment_method_id"/> <field name="acquirer_reference"/> + <field name="create_date"/> <field name="date_validate"/> - <field name="state"/> - <field name="state_message"/> - </group> - <group> - <field name="partner_name"/> - <field name="partner_address"/> - <field name="partner_email"/> - <field name="partner_lang"/> - <field name="partner_zip"/> - <field name="partner_city"/> - <field name="partner_country_id"/> </group> </group> + <group string="Message"> + <field name="state_message" nolabel="1"/> + </group> <notebook> </notebook> </sheet> - <div class="oe_chatter"> - <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/> - <field name="message_ids" widget="mail_thread" options='{"thread_level": 1}' placeholder="Send a message to the group"/> - </div> </form> </field> </record> @@ -170,6 +197,7 @@ <field name="arch" type="xml"> <tree string="Payment Transactions"> <field name="reference"/> + <field name="create_date"/> <field name="acquirer_id"/> <field name="partner_id"/> <field name="partner_name"/> @@ -204,12 +232,18 @@ parent='root_payment_menu' sequence='20' /> - <!-- Methods --> - <record id='payment_method_view_tree' model='ir.ui.view'> + <menuitem + action='action_payment_transaction' + id='finance_pay_tx_menu' + parent='finance_payment_menu' + sequence='20' /> + + <!-- Payment Methods --> + <record model='ir.ui.view' id='payment_method_tree_view'> <field name='name'>payment.method.tree</field> <field name='model'>payment.method</field> <field name='arch' type='xml'> - <tree string='Payment Methods' create='false' editable='bottom'> + <tree string='Payment Methods'> <field name="name"/> <field name="active"/> <field name='partner_id' /> @@ -229,11 +263,45 @@ </field> </record> - <record id='payment_method_action' model='ir.actions.act_window'> + <record id="action_payment_tx_ids" model="ir.actions.act_window"> + <field name="name">Payment Transactions</field> + <field name="res_model">payment.transaction</field> + <field name="view_type">form</field> + <field name="view_mode">tree,form</field> + <field name="domain">[('payment_method_id','=', active_id)]</field> + <field name="context">{'create': False}</field> + </record> + + <record model='ir.ui.view' id='payment_method_form_view'> + <field name='name'>payment.method.form</field> + <field name='model'>payment.method</field> + <field name='arch' type='xml'> + <form string='Payment Methods' create='false' editable='bottom'> + <sheet> + <div class="oe_button_box" name="button_box"> + <button class="oe_stat_button" name="%(action_payment_tx_ids)d" + type="action" icon="fa-money" string="Payments"> + </button> + </div> + <group> + <field name="name"/> + <field name='partner_id' /> + </group> + <group> + <field name="active"/> + <field name='acquirer_id'/> + <field name='acquirer_ref'/> + </group> + </sheet> + </form> + </field> + </record> + + <record model='ir.actions.act_window' id='payment_method_action'> <field name='name'>Saved Payment Data</field> <field name='res_model'>payment.method</field> <field name='view_type'>form</field> - <field name='view_mode'>tree</field> + <field name='view_mode'>tree,form</field> </record> <menuitem @@ -241,5 +309,10 @@ id='payment_method_menu' parent='root_payment_menu'/> + <menuitem + action='payment_method_action' + id='finance_pay_method_menu' + parent='finance_payment_menu' /> + </data> </openerp> diff --git a/addons/payment_adyen/data/adyen.xml b/addons/payment_adyen/data/adyen.xml index 7d774d45064..0b29ea95532 100644 --- a/addons/payment_adyen/data/adyen.xml +++ b/addons/payment_adyen/data/adyen.xml @@ -4,6 +4,7 @@ <record id="payment_acquirer_adyen" model="payment.acquirer"> <field name="name">Adyen</field> + <field name="image" type="base64" file="payment_adyen/static/description/icon.png"/> <field name="provider">adyen</field> <field name="company_id" ref="base.main_company"/> <field name="view_template_id" ref="adyen_acquirer_button"/> diff --git a/addons/payment_authorize/data/authorize.xml b/addons/payment_authorize/data/authorize.xml index c33fe5dcff4..a574e0e56d2 100644 --- a/addons/payment_authorize/data/authorize.xml +++ b/addons/payment_authorize/data/authorize.xml @@ -4,6 +4,7 @@ <record id="payment_acquirer_authorize" model="payment.acquirer"> <field name="name">Authorize.Net</field> + <field name="image" type="base64" file="payment_authorize/static/description/icon.png"/> <field name="provider">authorize</field> <field name="company_id" ref="base.main_company"/> <field name="view_template_id" ref="authorize_acquirer_button"/> diff --git a/addons/payment_buckaroo/data/buckaroo.xml b/addons/payment_buckaroo/data/buckaroo.xml index e0e3ad8b7c5..ff6f2504d97 100644 --- a/addons/payment_buckaroo/data/buckaroo.xml +++ b/addons/payment_buckaroo/data/buckaroo.xml @@ -4,6 +4,7 @@ <record id="payment_acquirer_buckaroo" model="payment.acquirer"> <field name="name">Buckaroo</field> + <field name="image" type="base64" file="payment_buckaroo/static/description/icon.png"/> <field name="provider">buckaroo</field> <field name="company_id" ref="base.main_company"/> <field name="view_template_id" ref="buckaroo_acquirer_button"/> diff --git a/addons/payment_ogone/data/ogone.xml b/addons/payment_ogone/data/ogone.xml index 3f0f0844640..9c1e53be443 100644 --- a/addons/payment_ogone/data/ogone.xml +++ b/addons/payment_ogone/data/ogone.xml @@ -4,6 +4,7 @@ <record id="payment_acquirer_ogone" model="payment.acquirer"> <field name="name">Ogone</field> + <field name="image" type="base64" file="payment_ogone/static/description/icon.png"/> <field name="provider">ogone</field> <field name="company_id" ref="base.main_company"/> <field name="view_template_id" ref="ogone_acquirer_button"/> diff --git a/addons/payment_ogone/models/ogone.py b/addons/payment_ogone/models/ogone.py index a70dda7d35f..f2a57807436 100644 --- a/addons/payment_ogone/models/ogone.py +++ b/addons/payment_ogone/models/ogone.py @@ -294,8 +294,8 @@ class PaymentTxOgone(osv.Model): 'date_validate': datetime.datetime.strptime(data['TRXDATE'],'%m/%d/%y').strftime(DEFAULT_SERVER_DATE_FORMAT), 'acquirer_reference': data['PAYID'], }) - if tx.s2s_cb_eval: - safe_eval(tx.s2s_cb_eval, {'self': tx}) + if tx.callback_eval: + safe_eval(tx.callback_eval, {'self': tx}) return True elif status in self._ogone_cancel_tx_status: tx.write({ @@ -390,8 +390,8 @@ class PaymentTxOgone(osv.Model): 'date_validate': datetime.date.today().strftime(DEFAULT_SERVER_DATE_FORMAT), 'acquirer_reference': tree.get('PAYID'), }) - if tx.s2s_cb_eval: - safe_eval(tx.s2s_cb_eval, {'self': tx}) + if tx.callback_eval: + safe_eval(tx.callback_eval, {'self': tx}) return True elif status in self._ogone_cancel_tx_status: tx.write({ diff --git a/addons/payment_paypal/data/paypal.xml b/addons/payment_paypal/data/paypal.xml index 746af24126b..c4f08f5dfcb 100644 --- a/addons/payment_paypal/data/paypal.xml +++ b/addons/payment_paypal/data/paypal.xml @@ -4,6 +4,7 @@ <record id="payment_acquirer_paypal" model="payment.acquirer"> <field name="name">Paypal</field> + <field name="image" type="base64" file="payment_paypal/static/description/icon.png"/> <field name="provider">paypal</field> <field name="company_id" ref="base.main_company"/> <field name="view_template_id" ref="paypal_acquirer_button"/> diff --git a/addons/payment_transfer/data/transfer.xml b/addons/payment_transfer/data/transfer.xml index f62a8bd9036..3df2d143736 100644 --- a/addons/payment_transfer/data/transfer.xml +++ b/addons/payment_transfer/data/transfer.xml @@ -4,6 +4,7 @@ <record id="payment_acquirer_transfer" model="payment.acquirer"> <field name="name">Wire Transfer</field> + <field name="image" type="base64" file="payment_transfer/static/description/icon.png"/> <field name="provider">transfer</field> <field name="company_id" ref="base.main_company"/> <field name="view_template_id" ref="transfer_acquirer_button"/> diff --git a/addons/website_quote/controllers/main.py b/addons/website_quote/controllers/main.py index e033b55d951..84c69e5f1f5 100644 --- a/addons/website_quote/controllers/main.py +++ b/addons/website_quote/controllers/main.py @@ -190,7 +190,7 @@ class sale_quote(http.Controller): 'partner_country_id': order.partner_id.country_id.id, 'reference': order.name, 'sale_order_id': order.id, - 's2s_cb_eval': "self.env['sale.order']._confirm_online_quote(self.sale_order_id.id, self)" + 'callback_eval': "self.env['sale.order']._confirm_online_quote(self.sale_order_id.id, self)" }, context=context) tx = transaction_obj.browse(cr, SUPERUSER_ID, tx_id, context=context) |
