-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] new module magentoerpconnect_transaction_id
- Loading branch information
Showing
10 changed files
with
233 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
================================ | ||
magentoerpconnect_transaction_id | ||
================================ | ||
|
||
This module let's you define on the payment method the path to a value to use as transaction id into | ||
the informations of a sale order returned as json by magento and map this information into | ||
the transaction_id field defined by OCA/bank-statement-reconcile/base_transaction_id. | ||
|
||
The main purpose is to ease the reconciliation process. | ||
|
||
Configuration | ||
============= | ||
|
||
For each payment method, you can define the path to the transaction_id value in | ||
the informations provided by magento. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/107/8.0 | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-magento/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback | ||
`here <https://github.com/OCA/connector-magento/issues/new?body=module:%20magentoerpconnect_transaction_id%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Laurent Mignon <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: http://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: http://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. | ||
|
||
To contribute to this module, please visit http://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
{ | ||
'name': "magentoerpconnect_transaction_id", | ||
'summary': """ | ||
Map the payment identifier in your sale order""", | ||
'author': 'ACSONE SA/NV,' | ||
'Odoo Community Association (OCA)', | ||
'website': "http://acsone.eu", | ||
'category': 'Connector', | ||
'version': '8.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'magentoerpconnect', | ||
'sale_payment_method', | ||
'base_transaction_id', | ||
], | ||
'data': [ | ||
'views/payment_method_view.xml', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import payment_method | ||
from . import sale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp import models, fields | ||
|
||
|
||
class PaymentMethod(models.Model): | ||
_inherit = 'payment.method' | ||
|
||
transaction_id_path = fields.Char( | ||
help=('Path to the value into the informations provided by Magento ' | ||
'for a sale order. Values are provided as a json dict. If the ' | ||
'transaction_id is in a sub dict the path must be specified ' | ||
'by using dots between keys to the value.')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openerp.addons.magentoerpconnect import sale | ||
from openerp.addons.connector.unit.mapper import mapping | ||
from openerp.addons.magentoerpconnect.backend import magento | ||
|
||
|
||
@magento(replacing=sale.SaleOrderPaymentImportMapper) | ||
class SaleOrderImportMapper(sale.SaleOrderPaymentImportMapper): | ||
|
||
@mapping | ||
def payment(self, record): | ||
vals = super(SaleOrderImportMapper, self).payment(record) | ||
payment_method_id = vals.get('payment_method_id') | ||
if not payment_method_id: | ||
return vals | ||
payment_method = self.env['payment.method'].browse(payment_method_id) | ||
if payment_method.transaction_id_path: | ||
value = record | ||
for key in payment_method.transaction_id_path.split('.'): | ||
value = value.get(key) | ||
if not value: | ||
break | ||
vals['transaction_id'] = value | ||
return vals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import test_synchronization |
67 changes: 67 additions & 0 deletions
67
magentoerpconnect_transaction_id/tests/test_synchronization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp.addons.magentoerpconnect.tests.test_synchronization import ( | ||
SetUpMagentoSynchronized) | ||
from openerp.addons.magentoerpconnect.tests.data_base import ( | ||
magento_base_responses) | ||
from openerp.addons.magentoerpconnect.unit.import_synchronizer import ( | ||
import_record) | ||
from openerp.addons.magentoerpconnect.tests.common import ( | ||
mock_api, | ||
mock_urlopen_image) | ||
|
||
SALE_ORDER_DATA_MOCK_KEY = ('sales_order.info', (900000695, )) | ||
|
||
|
||
class TestMagentoSaleImport(SetUpMagentoSynchronized): | ||
""" Test the imports from a Magento Mock. | ||
""" | ||
|
||
def setUp(self): | ||
super(TestMagentoSaleImport, self).setUp() | ||
self.payment_method = self.env['payment.method'].search( | ||
[('name', '=', 'checkmo')]) | ||
self.payment_method.payment_term_id = False | ||
|
||
def test_transaction_id_mapping(self): | ||
""" Test import of sale order with a payment transaction id""" | ||
backend_id = self.backend_id | ||
self.payment_method.transaction_id_path = 'payment.trans_id' | ||
data = magento_base_responses[SALE_ORDER_DATA_MOCK_KEY] | ||
data['payment']['trans_id'] = '123456' | ||
with mock_api(magento_base_responses): | ||
with mock_urlopen_image(): | ||
import_record(self.session, | ||
'magento.sale.order', | ||
backend_id, 900000695) | ||
|
||
order_model = self.env['magento.sale.order'] | ||
mag_order_id = order_model.search([ | ||
('backend_id', '=', backend_id), | ||
('magento_id', '=', '900000695'), | ||
]) | ||
self.assertEqual(len(mag_order_id), 1) | ||
self.assertEqual(mag_order_id.transaction_id, '123456') | ||
|
||
def test_transaction_id_mapping_1(self): | ||
""" Test import of sale order with wrong path to the payment | ||
transaction id""" | ||
backend_id = self.backend_id | ||
self.payment_method.transaction_id_path = 'payment.tra' | ||
data = magento_base_responses[SALE_ORDER_DATA_MOCK_KEY] | ||
data['payment']['trans_id'] = '123456' | ||
with mock_api(magento_base_responses): | ||
with mock_urlopen_image(): | ||
import_record(self.session, | ||
'magento.sale.order', | ||
backend_id, 900000695) | ||
|
||
order_model = self.env['magento.sale.order'] | ||
mag_order_id = order_model.search([ | ||
('backend_id', '=', backend_id), | ||
('magento_id', '=', '900000695'), | ||
]) | ||
self.assertEqual(len(mag_order_id), 1) | ||
self.assertFalse(mag_order_id.transaction_id) |
15 changes: 15 additions & 0 deletions
15
magentoerpconnect_transaction_id/views/payment_method_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<record id="payment_method_view_form" model="ir.ui.view"> | ||
<field name="name">sale_payment_method.payment_method.view_form (magentoerpconnect_transaction_id)</field> | ||
<field name="model">payment.method</field> | ||
<field name="inherit_id" ref="sale_payment_method.payment_method_view_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="journal_id" position="after"> | ||
<field name="transaction_id_path" placeholder="payment.last_trans_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
</data> | ||
</openerp> |