Skip to content
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
62 changes: 62 additions & 0 deletions magentoerpconnect_order_comment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License

Sale order comments synchronisation
===================================

Extension for **Magento Connector**

Features
--------

* Import sale comments in the same time than 'sale order'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the same time as

* Move messages from canceled order to replacing sale order (edited sale
order in magento)
* Export messages from OpenERP sale order to Magento comment
* Export of moved messages to Magento

Settings / options
------------------

* Ability to require Magento to send email to customer for each comment
received. Unactive by default (Connectors/Magento/Store menu).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inactive


.. 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
<https://github.com/OCA/
connector-magento/issues/new?body=module:%20
magentoerpconnect_order_comment%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

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

* David BEAL
* Hugo Santos <[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.
25 changes: 1 addition & 24 deletions magentoerpconnect_order_comment/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,6 @@
'author': "Akretion,Odoo Community Association (OCA)",
'license': 'AGPL-3',
'website': 'http://www.odoo-magento-connector.com',
'description': """
Sale order comments synchronisation
===================================

Extension for **Magento Connector**

Features
--------

* Import sale comments in the same time than 'sale order'
* Move messages from canceled order to replacing sale order (edited sale
order in magento)
* Export messages from OpenERP sale order to Magento comment
* Export of moved messages to Magento

Settings / options
------------------

* Ability to require Magento to send email to customer for each comment
received. Unactive by default (Connectors/Magento/Store menu).


""",
'images': [],
'demo': [],
'external_dependencies': {
Expand All @@ -58,6 +35,6 @@
'data': [
'magento_model_view.xml',
],
'installable': False,
'installable': True,
'application': False,
}
20 changes: 7 additions & 13 deletions magentoerpconnect_order_comment/magento_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools.translate import _
from openerp import models, fields


class magento_store(orm.Model):
class MagentoStore(models.Model):
_inherit = 'magento.store'

_columns = {
'send_sale_comment_mail': fields.boolean(
'Send email notification on sale comment',
help=_("Require Magento to send email on 'sale order comment' "
"based on 'send a message' case (not 'log a note')")),
}

_defaults = {
'send_sale_comment_mail': False,
}
send_sale_comment_mail = fields.Boolean(
'Send email notification on sale comment',
help="Require Magento to send email on 'sale order comment' "
"based on 'send a message' case (not 'log a note')",
default=False)
145 changes: 61 additions & 84 deletions magentoerpconnect_order_comment/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools.translate import _
from openerp import models, fields, api, _
from openerp.addons.connector.event import (
on_record_write,
on_record_create)
Expand All @@ -41,26 +40,24 @@
from bs4 import BeautifulSoup


class mail_message(orm.Model):
class MailMessage(models.Model):
_inherit = "mail.message"

_columns = {
'magento_sale_bind_ids': fields.one2many(
'magento.sale.comment',
'openerp_id',
string="Magento Bindings"),
}
magento_sale_bind_ids = fields.One2many(
'magento.sale.comment',
'openerp_id',
string="Magento Bindings")


@on_record_create(model_names='mail.message')
def create_mail_message(session, model_name, record_id, vals):
if session.context.get('connector_no_export'):
if session.env.context.get('connector_no_export'):
return
if vals.get('model') == 'sale.order' and vals.get('subtype_id'):
order = session.browse('sale.order', vals['res_id'])
order = session.env['sale.order'].browse(vals['res_id'])
for mag_sale in order.magento_bind_ids:
store = mag_sale.storeview_id.store_id
session.create('magento.sale.comment', {
session.env['magento.sale.comment'].create({
'openerp_id': record_id,
'subject': _('Sent to Magento'),
'is_visible_on_front': True,
Expand All @@ -69,7 +66,7 @@ def create_mail_message(session, model_name, record_id, vals):
})


class magento_sale_order(orm.Model):
class MagentoSaleOrder(models.Model):
"""Allow to have a relation between
magento.sale.order and magento.sale.comment
like you have a relation between
Expand All @@ -78,15 +75,13 @@ class magento_sale_order(orm.Model):
"""
_inherit = 'magento.sale.order'

_columns = {
'magento_order_comment_ids': fields.one2many(
'magento.sale.comment',
'magento_sale_order_id',
'Magento Sale comments'),
}
magento_order_comment_ids = fields.One2many(
'magento.sale.comment',
'magento_sale_order_id',
'Magento Sale comments')


class magento_sale_comment(orm.Model):
class MagentoSaleComment(models.Model):
_name = 'magento.sale.comment'
_inherit = 'magento.binding'
_description = 'Magento Sale Comment'
Expand All @@ -96,66 +91,47 @@ class magento_sale_comment(orm.Model):
"sale comment on Magento. \nPlease refer to the Magento " \
"documentation for details. "

def _get_comments_from_order(self, cr, uid, ids, context=None):
return self.pool['magento.sale.comment'].search(
cr, uid, [('magento_sale_order_id', 'in', ids)], context=context)

_columns = {
'openerp_id': fields.many2one(
'mail.message',
string='Sale Comment',
required=True,
ondelete='cascade'),
'magento_sale_order_id': fields.many2one(
'magento.sale.order',
'Magento Sale Order',
required=True,
ondelete='cascade',
select=True),
'is_customer_notified': fields.boolean(
'Customer notified',
help=MAGENTO_HELP),
'is_visible_on_front': fields.boolean(
'Visible on front',
help=MAGENTO_HELP),
'status': fields.char(
'Order status',
size=64,
help=MAGENTO_HELP),
'backend_id': fields.related(
'magento_sale_order_id', 'backend_id',
type='many2one',
relation='magento.backend',
string='Magento Backend',
store={
'magento.sale.comment': (
lambda self, cr, uid, ids, c=None:
ids,
['magento_sale_order_id'],
10),
'magento.sale.order': (
_get_comments_from_order,
['backend_id'],
20),
},
readonly=True),
'storeid': fields.char(
'Store id',
help=MAGENTO_HELP),
}

def create(self, cr, uid, vals, context=None):
openerp_id = fields.Many2one(
'mail.message',
string='Sale Comment',
required=True,
ondelete='cascade')
magento_sale_order_id = fields.Many2one(
'magento.sale.order',
'Magento Sale Order',
required=True,
ondelete='cascade',
select=True)
is_customer_notified = fields.Boolean(
'Customer notified',
help=MAGENTO_HELP)
is_visible_on_front = fields.Boolean(
'Visible on front',
help=MAGENTO_HELP)
status = fields.Char(
'Order status',
size=64,
help=MAGENTO_HELP)
backend_id = fields.Many2one(
'magento.backend', related='magento_sale_order_id.backend_id',
string='Magento Backend',
store=True,
readonly=True)
storeid = fields.Char(
'Store id',
help=MAGENTO_HELP)

@api.model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the create method, you need to apply the @api.returns('self', lambda value: value.id) decorator for backwards compatibility with old API overrides of this method (you know, just in case...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was sure it was inherited. This comment would tend to confirm that, but it could be wrong https://github.com/odoo/odoo/blob/9.0/openerp/api.py#L77
Had you ever had issues with that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right: I can't seem to reproduce any such issues with a quick test. Thanks for the pointer!

def create(self, vals):
if 'res_id' not in vals:
info = self.pool['magento.sale.order'].read(
cr, uid, vals['magento_sale_order_id'],
['openerp_id'],
context=context)
info = self.env['magento.sale.order'].browse(
vals['magento_sale_order_id'])
vals.update({
'res_id': info['openerp_id'][0],
'res_id': info.openerp_id.id,
'model': 'sale.order',
})
return super(magento_sale_comment, self).create(
cr, uid, vals, context=context)
'backend_id': info.backend_id.id
})
return super(MagentoSaleComment, self).create(vals)


@magento(replacing=sale.SaleOrderCommentImportMapper)
Expand Down Expand Up @@ -231,17 +207,18 @@ class SaleOrderMoveComment(sale.SaleOrderMoveComment):
def move(self, binding):
"""magento messages from canceled (edit) order
are moved to the new order"""
mag_message_ids = self.session.search('magento.sale.comment', [
mag_messages = self.session.env['magento.sale.comment'].search([
('model', '=', 'sale.order'),
('magento_sale_order_id', '!=', False),
('res_id', '=', binding.parent_id)])
mag_sale_order_ids = self.session.search('magento.sale.order', [
('openerp_id', '=', binding.openerp_id.id)])
('res_id', '=', binding.parent_id.id)])
mag_sale_order = self.session.env['magento.sale.order'].search([
('openerp_id', '=', binding.openerp_id.id)
], limit=1)
vals = {
'res_id': binding.openerp_id.id,
'magento_id': False,
'magento_sale_order_id': mag_sale_order_ids[0]}
self.session.write('magento.sale.comment', mag_message_ids, vals)
'magento_sale_order_id': mag_sale_order.id}
mag_messages.write(vals)


@magento
Expand All @@ -263,7 +240,7 @@ def _create(self, data):
""" Create the Magento record """
# special check on data before export
self._validate_create_data(data) # you may inherit in your own module
adapter = self.get_connector_unit_for_model(
adapter = self.unit_for(
GenericAdapter,
'magento.sale.order')
return adapter.add_comment(data['order_increment'],
Expand Down
7 changes: 0 additions & 7 deletions magentoerpconnect_order_comment/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@
##############################################################################

from . import test_synchronization

fast_suite = [
]

checks = [
test_synchronization,
]