← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/sale-wkfl/7.0-dropshipping-merge-po-lep into lp:sale-wkfl

 

Leonardo Pistone - camptocamp has proposed merging lp:~camptocamp/sale-wkfl/7.0-dropshipping-merge-po-lep into lp:sale-wkfl.

Requested reviews:
  Sale Core Editors (sale-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/sale-wkfl/7.0-dropshipping-merge-po-lep/+merge/216756
-- 
https://code.launchpad.net/~camptocamp/sale-wkfl/7.0-dropshipping-merge-po-lep/+merge/216756
Your team Sale Core Editors is requested to review the proposed merge of lp:~camptocamp/sale-wkfl/7.0-dropshipping-merge-po-lep into lp:sale-wkfl.
=== modified file 'sale_dropshipping/__openerp__.py'
--- sale_dropshipping/__openerp__.py	2014-03-21 16:32:11 +0000
+++ sale_dropshipping/__openerp__.py	2014-04-22 17:14:29 +0000
@@ -25,6 +25,7 @@
  "website": "http://www.openerp.com";,
  "category": "Generic Modules/Purchase",
  "depends": ["purchase",
+             "purchase_group_hooks",
              "sale_stock"],
  "description": """
 Makes it better to deal with purchases with known sale schemes, specially the following case:

=== modified file 'sale_dropshipping/purchase.py'
--- sale_dropshipping/purchase.py	2013-11-08 13:18:10 +0000
+++ sale_dropshipping/purchase.py	2014-04-22 17:14:29 +0000
@@ -110,3 +110,14 @@
                          'sale_id': purchase.sale_id and purchase.sale_id.id},
                         context=context)
         return res
+
+    def _key_fields_for_grouping(self):
+        """Do not merge orders that have different destination addresses."""
+        field_list = super(purchase_order, self)._key_fields_for_grouping()
+        return field_list + ['dest_address_id']
+
+    def _initial_merged_order_data(self, order):
+        """Populate the destination address in the merged order."""
+        res = super(purchase_order, self)._initial_merged_order_data(order)
+        res['dest_address_id'] = order.dest_address_id
+        return res

=== added directory 'sale_dropshipping/tests'
=== added file 'sale_dropshipping/tests/__init__.py'
--- sale_dropshipping/tests/__init__.py	1970-01-01 00:00:00 +0000
+++ sale_dropshipping/tests/__init__.py	2014-04-22 17:14:29 +0000
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Author: Leonardo Pistone
+#    Copyright 2014 Camptocamp SA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import test_merge_po
+
+checks = [
+    test_merge_po,
+]

=== added file 'sale_dropshipping/tests/test_merge_po.py'
--- sale_dropshipping/tests/test_merge_po.py	1970-01-01 00:00:00 +0000
+++ sale_dropshipping/tests/test_merge_po.py	2014-04-22 17:14:29 +0000
@@ -0,0 +1,35 @@
+from mock import Mock
+
+from openerp.tests.common import BaseCase
+from openerp.osv.orm import browse_record
+
+
+class TestGroupOrders(BaseCase):
+
+    def setUp(self):
+        super(TestGroupOrders, self).setUp()
+        self.order1 = Mock()
+        self.order2 = Mock()
+        # I have to use the registry to get an instance of a model. I cannot
+        # use the class constructor because that is modified to return nothing.
+        self.po = self.registry('purchase.order')
+
+    def test_two_orders_different_destination_addresses(self):
+        """Orders with the same partner, location, pricelist, but different
+        destination addresses should not be merged.
+
+        We do not care about the order lines here.
+        """
+        self.order1.partner_id = self.order2.partner_id = Mock(
+            spec=browse_record, id=1)
+        self.order1.location_id = self.order2.location_id = Mock(
+            spec=browse_record, id=2)
+        self.order1.pricelist_id = self.order2.pricelist_id = Mock(
+            spec=browse_record, id=3)
+        self.order1.order_line = self.order2.order_line = []
+
+        self.order1.dest_address_id = Mock(spec=browse_record, id=5)
+        self.order2.dest_address_id = Mock(spec=browse_record, id=6)
+
+        grouped = self.po._group_orders([self.order1, self.order2])
+        self.assertEqual(grouped, {}, u'These orders should not be merged')


Follow ups