Skip to content

Commit 2a457d4

Browse files
committed
[ADD] new module magentoerpconnect_transaction_id
1 parent 280615b commit 2a457d4

File tree

9 files changed

+209
-0
lines changed

9 files changed

+209
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
================================
6+
magentoerpconnect_transaction_id
7+
================================
8+
9+
This module let's you define on the payment method the path to a value to use as transaction id into
10+
the informations of a sale order returned as json by magento and map this information into
11+
the transaction_id field defined by OCA/bank-statement-reconcile/base_transaction_id.
12+
13+
The main purpose is to ease the reconciliation process.
14+
15+
Configuration
16+
=============
17+
18+
For each payment method, you can define the path to the transaction_id value in
19+
the informations provided by magento.
20+
21+
22+
Usage
23+
=====
24+
25+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
26+
:alt: Try me on Runbot
27+
:target: https://runbot.odoo-community.org/runbot/107/8.0
28+
29+
30+
Bug Tracker
31+
===========
32+
33+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-magento/issues>`_.
34+
In case of trouble, please check there if your issue has already been reported.
35+
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
36+
`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**>`_.
37+
38+
Credits
39+
=======
40+
41+
Contributors
42+
------------
43+
44+
* Laurent Mignon <[email protected]>
45+
46+
Maintainer
47+
----------
48+
49+
.. image:: http://odoo-community.org/logo.png
50+
:alt: Odoo Community Association
51+
:target: http://odoo-community.org
52+
53+
This module is maintained by the OCA.
54+
55+
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.
56+
57+
To contribute to this module, please visit http://odoo-community.org.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
from . import models
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
{
5+
'name': "magentoerpconnect_transaction_id",
6+
'summary': """
7+
Map the payment identifier in your sale order""",
8+
'author': 'ACSONE SA/NV,'
9+
'Odoo Community Association (OCA)',
10+
'website': "http://acsone.eu",
11+
'category': 'Connector',
12+
'version': '8.0.1.0.0',
13+
'license': 'AGPL-3',
14+
'depends': [
15+
'magentoerpconnect',
16+
'sale_payment_method',
17+
'base_transaction_id',
18+
],
19+
'data': [
20+
'views/payment_method_view.xml',
21+
],
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
from . import payment_method
3+
from . import sale
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from openerp import models, fields
6+
7+
8+
class PaymentMethod(models.Model):
9+
_inherit = 'payment.method'
10+
11+
transaction_id_path = fields.Char(
12+
help=('Path to the value into the informations provided by Magento '
13+
'for a sale order. Values are provided as a json dict. If the '
14+
'transaction_id is in a sub dict the path must be specified '
15+
'by using dots between keys to the value.'))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
from openerp.addons.magentoerpconnect import sale
5+
from openerp.addons.connector.unit.mapper import mapping
6+
from openerp.addons.magentoerpconnect.backend import magento
7+
8+
9+
@magento(replacing=sale.SaleOrderPaymentImportMapper)
10+
class SaleOrderImportMapper(sale.SaleOrderPaymentImportMapper):
11+
12+
@mapping
13+
def payment(self, record):
14+
vals = super(SaleOrderImportMapper, self).payment(record)
15+
payment_method_id = vals.get('payment_method_id')
16+
if not payment_method_id:
17+
return vals
18+
payment_method = self.env['payment.method'].browse(payment_method_id)
19+
if payment_method.transaction_id_path:
20+
value = record
21+
for key in payment_method.transaction_id_path.split('.'):
22+
value = value.get(key)
23+
if not value:
24+
break
25+
vals['transaction_id'] = value
26+
return vals
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
from . import test_synchronization
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from openerp.addons.magentoerpconnect.tests.test_synchronization import (
6+
SetUpMagentoSynchronized)
7+
from openerp.addons.magentoerpconnect.tests.data_base import (
8+
magento_base_responses)
9+
from openerp.addons.magentoerpconnect.unit.import_synchronizer import (
10+
import_record)
11+
from openerp.addons.magentoerpconnect.tests.common import (
12+
mock_api,
13+
mock_urlopen_image)
14+
15+
SALE_ORDER_DATA_MOCK_KEY = ('sales_order.info', (900000695, ))
16+
17+
18+
class TestMagentoSaleImport(SetUpMagentoSynchronized):
19+
""" Test the imports from a Magento Mock.
20+
"""
21+
22+
def setUp(self):
23+
super(TestMagentoSaleImport, self).setUp()
24+
self.payment_method = self.env['payment.method'].search(
25+
[('name', '=', 'checkmo')])
26+
self.payment_method.payment_term_id = False
27+
28+
def test_transaction_id_mapping(self):
29+
""" Test import of sale order with a payment transaction id"""
30+
backend_id = self.backend_id
31+
self.payment_method.transaction_id_path = 'payment.trans_id'
32+
data = magento_base_responses[SALE_ORDER_DATA_MOCK_KEY]
33+
data['payment']['trans_id'] = '123456'
34+
with mock_api(magento_base_responses):
35+
with mock_urlopen_image():
36+
import_record(self.session,
37+
'magento.sale.order',
38+
backend_id, 900000695)
39+
40+
order_model = self.env['magento.sale.order']
41+
mag_order_id = order_model.search([
42+
('backend_id', '=', backend_id),
43+
('magento_id', '=', '900000695'),
44+
])
45+
self.assertEqual(len(mag_order_id), 1)
46+
self.assertEqual(mag_order_id.transaction_id, '123456')
47+
48+
def test_transaction_id_mapping_1(self):
49+
""" Test import of sale order with wrong path to the payment
50+
transaction id"""
51+
backend_id = self.backend_id
52+
self.payment_method.transaction_id_path = 'payment.tra'
53+
data = magento_base_responses[SALE_ORDER_DATA_MOCK_KEY]
54+
data['payment']['trans_id'] = '123456'
55+
with mock_api(magento_base_responses):
56+
with mock_urlopen_image():
57+
import_record(self.session,
58+
'magento.sale.order',
59+
backend_id, 900000695)
60+
61+
order_model = self.env['magento.sale.order']
62+
mag_order_id = order_model.search([
63+
('backend_id', '=', backend_id),
64+
('magento_id', '=', '900000695'),
65+
])
66+
self.assertEqual(len(mag_order_id), 1)
67+
self.assertFalse(mag_order_id.transaction_id)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<openerp>
3+
<data>
4+
<record id="payment_method_view_form" model="ir.ui.view">
5+
<field name="name">sale_payment_method.payment_method.view_form (magentoerpconnect_transaction_id)</field>
6+
<field name="model">payment.method</field>
7+
<field name="inherit_id" ref="sale_payment_method.payment_method_view_form"/>
8+
<field name="arch" type="xml">
9+
<field name="journal_id" position="after">
10+
<field name="transaction_id_path" placeholder="payment.last_trans_id"/>
11+
</field>
12+
</field>
13+
</record>
14+
</data>
15+
</openerp>

0 commit comments

Comments
 (0)