Leonardo Pistone - camptocamp has proposed merging lp:~camptocamp/sale-wkfl/7.0-add-dropshipping-merge-check-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-add-dropshipping-merge-check-lep/+merge/216420 -- https://code.launchpad.net/~camptocamp/sale-wkfl/7.0-add-dropshipping-merge-check-lep/+merge/216420 Your team Sale Core Editors is requested to review the proposed merge of lp:~camptocamp/sale-wkfl/7.0-add-dropshipping-merge-check-lep into lp:sale-wkfl.
=== modified file 'sale_dropshipping/purchase.py' --- sale_dropshipping/purchase.py 2013-11-08 13:18:10 +0000 +++ sale_dropshipping/purchase.py 2014-04-18 09:08:14 +0000 @@ -20,6 +20,7 @@ # ############################################################################## from openerp.osv import fields, orm +from openerp.tools.translate import _ class purchase_order_line(orm.Model): @@ -110,3 +111,37 @@ 'sale_id': purchase.sale_id and purchase.sale_id.id}, context=context) return res + + @staticmethod + def _check_merge_dropshipping(orders): + + def _all_dropshipping(orders): + return all(o.sale_flow == 'direct_delivery' for o in orders) + + def _mixed_dropshipping(orders): + return ( + any(o.sale_flow == 'direct_delivery' for o in orders) and + any(o.sale_flow != 'direct_delivery' for o in orders)) + + def _same_customer(orders): + customers = [o.sale_id.partner_id for o in orders] + return len(set(customers)) == 1 + + if _all_dropshipping(orders) and not _same_customer(orders): + raise orm.except_orm( + _('Error'), + _('Cannot merge dropshipping purchase orders if the customer ' + 'is not the same') + ) + elif _mixed_dropshipping(orders): + raise orm.except_orm( + _('Error'), + _('Cannot merge orders in dropshipping mode with orders ' + 'that are not') + ) + + def do_merge(self, cr, uid, order_ids, context=None): + orders = self.browse(cr, uid, order_ids, context=context) + self._check_merge_dropshipping(orders) + super(purchase_order, self).do_merge(cr, uid, order_ids, + context=context) === 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-18 09:08:14 +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-18 09:08:14 +0000 @@ -0,0 +1,39 @@ +import unittest2 +from mock import Mock + +from ..purchase import purchase_order +from openerp.osv import orm + + +class TestMergePO(unittest2.TestCase): + + def setUp(self): + super(TestMergePO, self).setUp() + self.po1 = Mock() + self.po2 = Mock() + + def test_no_dropshipping(self): + self.po1.sale_flow = self.po2.sale_flow = 'normal' + purchase_order._check_merge_dropshipping([self.po1, self.po2]) + # nothing to check: I expect the method not to raise + + def test_one_dropshipping_one_not(self): + self.po1.sale_flow = 'normal' + self.po2.sale_flow = 'direct_delivery' + with self.assertRaises(orm.except_orm): + purchase_order._check_merge_dropshipping([self.po1, self.po2]) + + def test_two_dropshipping_different_customers(self): + self.po1.sale_flow = self.po2.sale_flow = 'direct_delivery' + self.po1.sale_id.partner_id = 1 + self.po2.sale_id.partner_id = 2 + + with self.assertRaises(orm.except_orm): + purchase_order._check_merge_dropshipping([self.po1, self.po2]) + + def test_two_dropshipping_same_customer(self): + self.po1.sale_flow = self.po2.sale_flow = 'direct_delivery' + self.po1.sale_id.partner_id = self.po2.sale_id.partner_id = 1 + + purchase_order._check_merge_dropshipping([self.po1, self.po2]) + # nothing to check: I expect the method not to raise
-- Mailing list: https://launchpad.net/~openerp-community-reviewer Post to : openerp-community-reviewer@lists.launchpad.net Unsubscribe : https://launchpad.net/~openerp-community-reviewer More help : https://help.launchpad.net/ListHelp