Merge lp:~camptocamp/openerp-connector-magento/7.0-copy-quotation-move-binding into lp:~openerp-connector-core-editors/openerp-connector-magento/7.0

Proposed by Guewen Baconnier @ Camptocamp
Status: Rejected
Rejected by: Guewen Baconnier @ Camptocamp
Proposed branch: lp:~camptocamp/openerp-connector-magento/7.0-copy-quotation-move-binding
Merge into: lp:~openerp-connector-core-editors/openerp-connector-magento/7.0
Diff against target: 171 lines (+126/-1)
3 files modified
magentoerpconnect/sale.py (+63/-1)
magentoerpconnect/tests/__init__.py (+2/-0)
magentoerpconnect/tests/test_sale_order.py (+61/-0)
To merge this branch: bzr merge lp:~camptocamp/openerp-connector-magento/7.0-copy-quotation-move-binding
Reviewer Review Type Date Requested Status
OpenERP Connector Core Editors Pending
Review via email: mp+226137@code.launchpad.net

Description of the change

When a sales order is canceled, when one uses the 'New Copy from Quotation' button,
the binding are moved from the old (canceled) order to the new one, so the
synchronizations now happen on the new order.

Warning: needs https://github.com/odoo/odoo/pull/1025 to be merged!

To post a comment you must log in.
1007. By Guewen Baconnier @ Camptocamp

remove unused imports

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Unmerged revisions

1007. By Guewen Baconnier @ Camptocamp

remove unused imports

1006. By Guewen Baconnier @ Camptocamp

When a sales order is canceled, when one uses the 'New Copy from Quotation' button,
the binding are moved from the old (canceled) order to the new one, so the
synchronizations now happen on the new order.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'magentoerpconnect/sale.py'
--- magentoerpconnect/sale.py 2014-05-26 11:25:41 +0000
+++ magentoerpconnect/sale.py 2014-07-09 14:04:57 +0000
@@ -128,6 +128,28 @@
128 default=default,128 default=default,
129 context=context)129 context=context)
130130
131 def copy_quotation(self, cr, uid, ids, context=None):
132 if isinstance(ids, (tuple, list)):
133 assert len(ids) == 1, "1 ID expected, got %s" % ids
134 if context is None:
135 context = {}
136 else:
137 context = context.copy()
138 context['__copy_from_quotation'] = True
139 result = super(sale_order, self).copy_quotation(cr, uid, ids,
140 context=context)
141 # link binding of the canceled order to the new order, so the
142 # operations done on the new order will be sync'ed with Magento
143 new_id = result['res_id']
144 binding_obj = self.pool['magento.sale.order']
145 binding_ids = binding_obj.search(cr, uid,
146 [('openerp_id', '=', ids[0])],
147 context=context)
148 binding_obj.write(cr, uid, binding_ids,
149 {'openerp_id': new_id},
150 context=context)
151 return result
152
131153
132class magento_sale_order_line(orm.Model):154class magento_sale_order_line(orm.Model):
133 _name = 'magento.sale.order.line'155 _name = 'magento.sale.order.line'
@@ -199,13 +221,53 @@
199 string="Magento Bindings"),221 string="Magento Bindings"),
200 }222 }
201223
224 def create(self, cr, uid, vals, context=None):
225 if context is None:
226 context= {}
227
228 old_line_id = None
229 if context.get('__copy_from_quotation'):
230 # when we are copying a sale.order from a canceled one,
231 # the id of the copied line is inserted in the vals
232 # in `copy_data`.
233 old_line_id = vals.pop('__copy_from_line_id', None)
234 new_id = super(sale_order_line, self).create(cr, uid, vals,
235 context=context)
236 if old_line_id:
237 # link binding of the canceled order lines to the new order
238 # lines, happens when we are using the 'New Copy of
239 # Quotation' button on a canceled sales order
240 binding_obj = self.pool['magento.sale.order.line']
241 binding_ids = binding_obj.search(
242 cr, uid,
243 [('openerp_id', '=', old_line_id)],
244 context=context)
245 if binding_ids:
246 binding_obj.write(cr, uid, binding_ids,
247 {'openerp_id': new_id},
248 context=context)
249 return new_id
250
202 def copy_data(self, cr, uid, id, default=None, context=None):251 def copy_data(self, cr, uid, id, default=None, context=None):
203 if default is None:252 if default is None:
204 default = {}253 default = {}
254 if context is None:
255 context= {}
256
205 default['magento_bind_ids'] = False257 default['magento_bind_ids'] = False
206 return super(sale_order_line, self).copy_data(cr, uid, id,258 data = super(sale_order_line, self).copy_data(cr, uid, id,
207 default=default,259 default=default,
208 context=context)260 context=context)
261 if context.get('__copy_from_quotation'):
262 # copy_data is called by `copy` of the sale.order which
263 # builds a dict for the full new sale order, so we lose the
264 # association between the old and the new line.
265 # Keep a trace of the old id in the vals that will be passed
266 # to `create`, from there, we'll be able to update the
267 # Magento bindings, modifying the relation from the old to
268 # the new line.
269 data['__copy_from_line_id'] = id
270 return data
209271
210272
211@magento273@magento
212274
=== modified file 'magentoerpconnect/tests/__init__.py'
--- magentoerpconnect/tests/__init__.py 2014-05-26 09:37:00 +0000
+++ magentoerpconnect/tests/__init__.py 2014-07-09 14:04:57 +0000
@@ -24,6 +24,7 @@
24import test_export_invoice24import test_export_invoice
25import test_import_product_image25import test_import_product_image
26import test_related_action26import test_related_action
27import test_sale_order
2728
2829
29fast_suite = [30fast_suite = [
@@ -35,4 +36,5 @@
35 test_export_invoice,36 test_export_invoice,
36 test_import_product_image,37 test_import_product_image,
37 test_related_action,38 test_related_action,
39 test_sale_order,
38]40]
3941
=== added file 'magentoerpconnect/tests/test_sale_order.py'
--- magentoerpconnect/tests/test_sale_order.py 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/tests/test_sale_order.py 2014-07-09 14:04:57 +0000
@@ -0,0 +1,61 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.addons.magentoerpconnect.unit.import_synchronizer import (
23 import_record)
24import openerp.tests.common as common
25from .common import (mock_api,
26 mock_urlopen_image)
27from .test_data import magento_base_responses
28from .test_synchronization import SetUpMagentoSynchronized
29
30DB = common.DB
31ADMIN_USER_ID = common.ADMIN_USER_ID
32
33
34class TestSaleOrder(SetUpMagentoSynchronized):
35
36 def test_sale_order_copy_quotation(self):
37 """ Copy a sales order with copy_quotation move bindings """
38 backend_id = self.backend_id
39 with mock_api(magento_base_responses):
40 with mock_urlopen_image():
41 import_record(self.session,
42 'magento.sale.order',
43 backend_id, 900000691)
44 MagentoOrder = self.registry('magento.sale.order')
45 MagentoLine = self.registry('magento.sale.order.line')
46 SaleOrder = self.registry('sale.order')
47 mag_order_ids = MagentoOrder.search(self.cr,
48 self.uid,
49 [('backend_id', '=', backend_id),
50 ('magento_id', '=', '900000691')])
51 self.assertEqual(len(mag_order_ids), 1)
52 mag_order = MagentoOrder.browse(self.cr, self.uid, mag_order_ids[0])
53 order = mag_order.openerp_id
54 action = SaleOrder.copy_quotation(self.cr, self.uid, [order.id])
55 new_id = action['res_id']
56 order.refresh()
57 self.assertFalse(order.magento_bind_ids)
58 mag_order.refresh()
59 self.assertEqual(mag_order.openerp_id.id, new_id)
60 for mag_line in mag_order.magento_order_line_ids:
61 self.assertEqual(mag_line.order_id.id, new_id)