-
-
Notifications
You must be signed in to change notification settings - Fork 212
[8.0] Migration of magentorepconnect_order_comment #174
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
base: 8.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' | ||
| * 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). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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, | ||
|
|
@@ -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 | ||
|
|
@@ -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' | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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 | ||
|
|
@@ -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'], | ||
|
|
||
There was a problem hiding this comment.
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