Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [10.0] connector_magento_payment_ref: Migration to 10.0 #259

Open
wants to merge 3 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions connector_magento_payment_ref/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.. 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


===================================
Connector Magento Payment Reference
===================================

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/10.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.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Laurent Mignon <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.
3 changes: 3 additions & 0 deletions connector_magento_payment_ref/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models
from . import components
25 changes: 25 additions & 0 deletions connector_magento_payment_ref/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- 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': 'https://github.com/OCA/connector-magento',
'category': 'Connector',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'component',
'connector',
'connector_magento',
'account_payment_mode',
'base_transaction_id',
'sale_automatic_workflow_payment_ref',
],
'data': [
'views/account_payment_mode.xml',
],
}
2 changes: 2 additions & 0 deletions connector_magento_payment_ref/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import sale_order_import_mapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo.addons.component.core import Component
from odoo.addons.connector.components.mapper import mapping


class SaleOrderImportMapper(Component):
_inherit = 'magento.sale.order.mapper'

@mapping
def payment(self, record):
vals = super(SaleOrderImportMapper, self).payment(record)
payment_mode_id = vals.get('payment_mode_id')
if payment_mode_id:
payment_mode = self.env['account.payment.mode'].browse(
payment_mode_id)
if payment_mode.transaction_id_path:
value = record
for key in payment_mode.transaction_id_path.split('.'):
value = value.get(key)
if not value:
break
vals['transaction_id'] = value
return vals
2 changes: 2 additions & 0 deletions connector_magento_payment_ref/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import account_payment_mode
15 changes: 15 additions & 0 deletions connector_magento_payment_ref/models/account_payment_mode.py
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 odoo import models, fields


class AccountPaymentMode(models.Model):
_inherit = 'account.payment.mode'

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.'))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions connector_magento_payment_ref/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_sale_order

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions connector_magento_payment_ref/tests/test_sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- 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 os.path import dirname, join
from odoo.addons.connector_magento.tests.common import MagentoSyncTestCase, \
recorder

CASSETTE_LIBRARY_DIR = join(dirname(__file__), 'fixtures/cassettes')


class TestSaleOrder(MagentoSyncTestCase):
""" Test the imports from a Magento Mock.
"""

def setUp(self):
super(TestSaleOrder, self).setUp()
self.payment_method = self.env['account.payment.mode'].search(
[('name', '=', 'checkmo')],
limit=1,
)

def _import_sale_order(self, increment_id, cassette=True):
return self._import_record('magento.sale.order',
increment_id, cassette=cassette)

def test_transaction_id_mapping(self):
""" Test import of sale order with a payment transaction id"""
self.payment_method.transaction_id_path = 'payment.transaction_id'
with recorder.use_cassette('import_sale_order_transaction_id',
cassette_library_dir=CASSETTE_LIBRARY_DIR):
binding = self._import_sale_order(100000201, cassette=False)
self.assertEqual(binding.transaction_id, '951')

def test_transaction_id_mapping_wrong_path(self):
""" Test import of sale order with a wrong path to the
transaction_id"""
self.payment_method.transaction_id_path = 'payment.trans'
with recorder.use_cassette('import_sale_order_transaction_id',
cassette_library_dir=CASSETTE_LIBRARY_DIR):
binding = self._import_sale_order(100000201, cassette=False)
self.assertEqual(binding.transaction_id, False)
13 changes: 13 additions & 0 deletions connector_magento_payment_ref/views/account_payment_mode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_payment_mode_form_view" model="ir.ui.view">
<field name="name">account_payment_mode.form.view (connector_magento_payment_ref)</field>
<field name="model">account.payment.mode</field>
<field name="inherit_id" ref="account_payment_mode.account_payment_mode_form"/>
<field name="arch" type="xml">
<field name="fixed_journal_id" position="after">
<field name="transaction_id_path" placeholder="payment.last_trans_id"/>
</field>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sale-workflow
server-tools
bank-payment
partner-contact
bank-statement-reconcile
1 change: 1 addition & 0 deletions setup/connector_magento_payment_ref/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/connector_magento_payment_ref/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)