diff --git a/partner_stock_risk/tests/test_partner_stock_risk.py b/partner_stock_risk/tests/test_partner_stock_risk.py index d3ccd89f5..56209b98a 100644 --- a/partner_stock_risk/tests/test_partner_stock_risk.py +++ b/partner_stock_risk/tests/test_partner_stock_risk.py @@ -2,37 +2,75 @@ # © 2016 Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.tests.common import TransactionCase +from openerp import exceptions +from openerp.tests.common import SavepointCase -class TestPartnerStocklRisk(TransactionCase): - def setUp(self): - super(TestPartnerStocklRisk, self).setUp() - self.partner = self.env['res.partner'].create({ +class TestPartnerStocklRisk(SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestPartnerStocklRisk, cls).setUpClass() + cls.partner = cls.env['res.partner'].create({ 'name': 'Partner test', 'customer': True, }) - self.product = self.env.ref('product.product_product_36') - self.quant = self.env['stock.quant'].create({ + cls.product = cls.env.ref('product.product_product_36') + cls.quant = cls.env['stock.quant'].create({ 'qty': 100, - 'location_id': self.env.ref('stock.stock_location_stock').id, - 'product_id': self.product.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, + 'product_id': cls.product.id, }) - self.picking = self.env['stock.picking'].create({ - 'picking_type_id': self.env.ref('stock.picking_type_out').id, - 'location_id': self.env.ref('stock.stock_location_stock').id, + cls.picking = cls.env['stock.picking'].create({ + 'picking_type_id': cls.env.ref('stock.picking_type_out').id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, 'location_dest_id': - self.env.ref('stock.stock_location_customers').id, + cls.env.ref('stock.stock_location_customers').id, + 'partner_id': cls.partner.id, }) - self.move = self.env['stock.move'].create({ + cls.move = cls.env['stock.move'].create({ 'name': '/', - 'picking_id': self.picking.id, - 'product_uom': self.product.uom_id.id, - 'location_id': self.env.ref('stock.stock_location_stock').id, + 'picking_id': cls.picking.id, + 'product_uom_qty': 10, + 'product_uom': cls.product.uom_id.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, 'location_dest_id': - self.env.ref('stock.stock_location_customers').id, - 'product_id': self.product.id, + cls.env.ref('stock.stock_location_customers').id, + 'product_id': cls.product.id, }) + cls.env.user.lang = 'en_US' - def test_stock_move(self): + def test_stock_move_ok(self): self.move.action_done() + + def test_stock_move_error(self): + self.partner.risk_exception = True + self.move.partner_id = self.partner + with self.assertRaises(exceptions.UserError): + self.move.action_done() + + def test_stock_picking_ok(self): + self.picking.action_assign() + self.picking.force_assign() + self.picking.action_confirm() + + def test_stock_picking_error(self): + self.partner.risk_exception = True + res = self.picking.action_assign() + self.assertEqual(res['name'], 'Partner risk exceeded') + res = self.picking.force_assign() + self.assertEqual(res['name'], 'Partner risk exceeded') + res = self.picking.action_confirm() + self.assertEqual(res['name'], 'Partner risk exceeded') + + def test_do_new_transfer_ok(self): + self.picking.action_assign() + self.picking.pack_operation_product_ids[:1].qty_done = 5 + self.picking.do_new_transfer() + + def test_do_new_transfer_error(self): + self.picking.action_assign() + self.picking.pack_operation_product_ids[:1].qty_done = 5 + self.partner.risk_exception = True + res = self.picking.do_new_transfer() + self.assertEqual(res['name'], 'Partner risk exceeded')