123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- # -*- coding: utf-8 -*-
- # Copyright 2017 OpenSynergy Indonesia
- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
- from openerp.tests.common import TransactionCase
- from openerp.exceptions import Warning as UserError
- class TestOnchangeProductBarcode(TransactionCase):
- def setUp(self, *args, **kwargs):
- super(TestOnchangeProductBarcode, self).setUp(*args, **kwargs)
- # Objects
- self.wiz = self.env['sale.order.barcode']
- self.obj_sale_order_line =\
- self.env['sale.order.line']
- # Data
- self.data_so = self.env['sale.order'].create({
- 'partner_id': self.env.ref('base.res_partner_1').id,
- })
- self.product_1 =\
- self.env.ref('product.product_product_25')
- self.product_2 =\
- self.env.ref('product.product_product_30')
- self.product_3 =\
- self.env.ref('product.product_product_3')
- self.uom_unit =\
- self.env.ref('product.product_uom_unit')
- self.uom_dozen =\
- self.env.ref('product.product_uom_dozen')
- def test_error_product_no_ean_13(self):
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- new.product_barcode = 0000000000000
- res = new.product_barcode_onchange()
- self.assertEquals(
- 'No product found with this code as '
- 'EAN13 or product is not for sale. You should select '
- 'the right product manually.',
- res['warning']['message']
- )
- def test_error_product_duplicate_ean(self):
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- self.product_1.ean13 = 8998989300155
- self.product_2.ean13 = 8998989300155
- new.product_barcode = 8998989300155
- res = new.product_barcode_onchange()
- self.assertIsNotNone(
- res['warning']['message']
- )
- def test_error_more_than_1_line(self):
- order_line = [
- (0, 0, {
- 'product_id': self.product_1.id,
- 'product_uom_qty': 5,
- }),
- (0, 0, {
- 'product_id': self.product_1.id,
- 'product_uom_qty': 1,
- }),
- ]
- self.data_so.update({
- 'order_line': order_line
- })
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- self.product_1.ean13 = 8998989300155
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 20.0
- msg = ("More than 1 line found")
- with self.assertRaises(UserError) as error:
- new.save()
- self.assertEqual(error.exception.message, msg)
- def test_product_barcode_condition_1(self):
- # CONDITION
- # 1. type = INSERT
- # 2. Uom Lines = Uom Wizard
- # 3. Using single product
- self.product_1.ean13 = 8998989300155
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- new.type = 'insert'
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 5.0
- new.save()
- new.type = 'insert'
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 9.0
- new.save()
- line_1 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_1.id)
- ])
- self.assertEqual(line_1.product_uom_qty, 14.0)
- def test_product_barcode_condition_2(self):
- # CONDITION
- # 1. type = INSERT
- # 2. Uom Lines != Uom Wizard
- # 3. Using single product
- self.product_2.ean13 = 8996001600382
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- new.type = 'insert'
- new.product_barcode = 8996001600382
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 1.0
- new.save()
- new.type = 'insert'
- new.product_barcode = 8996001600382
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 2.0
- new.product_uom_id = self.uom_dozen.id
- new.save()
- line_1 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_2.id)
- ])
- self.assertEqual(line_1.product_uom_qty, 25.0)
- def test_product_barcode_condition_3(self):
- # CONDITION
- # 1. type = UPDATE
- # 2. Uom Lines = Uom Wizard
- # 3. Using single product
- self.product_1.ean13 = 8998989300155
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- new.type = 'insert'
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 1.0
- new.save()
- new.type = 'update'
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 2.0
- new.save()
- line_1 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_1.id)
- ])
- self.assertEqual(line_1.product_uom_qty, 2.0)
- def test_product_barcode_condition_4(self):
- # CONDITION
- # 1. type = UPDATE
- # 2. Uom Lines != Uom Wizard
- # 3. Using single product
- self.product_3.ean13 = 8998666000903
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- new.type = 'insert'
- new.product_barcode = 8998666000903
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 4.0
- new.save()
- new.type = 'update'
- new.product_barcode = 8998666000903
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 1.0
- new.product_uom_id = self.uom_dozen.id
- new.save()
- line_1 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_3.id)
- ])
- self.assertEqual(line_1.product_uom_qty, 12.0)
- def test_product_barcode_condition_5(self):
- # CONDITION
- # 1. type = UPDATE & INSERT
- # 2. Uom Lines != Uom Wizard & Uom Lines = Uom Wizard
- # 3. Using multiple product
- self.product_1.ean13 = 8998989300155
- self.product_2.ean13 = 8996001600382
- self.product_3.ean13 = 8998666000903
- new = self.wiz.with_context(
- active_model="sale.order",
- active_id=self.data_so.id
- ).new()
- new.type = 'insert'
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 3.0
- new.save()
- new.type = 'insert'
- new.product_barcode = 8996001600382
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 10.0
- new.save()
- new.type = 'insert'
- new.product_barcode = 8998666000903
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 8.0
- new.save()
- new.type = 'update'
- new.product_barcode = 8998989300155
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 13.0
- new.save()
- new.type = 'insert'
- new.product_barcode = 8996001600382
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 10.0
- new.save()
- new.type = 'update'
- new.product_barcode = 8998666000903
- new.product_barcode_onchange()
- new.product_id_onchange()
- new.product_qty = 10.0
- new.product_uom_id = self.uom_dozen.id
- new.save()
- line_1 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_1.id)
- ])
- self.assertEqual(line_1.product_uom_qty, 13.0)
- line_2 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_2.id)
- ])
- self.assertEqual(line_2.product_uom_qty, 20.0)
- line_3 = self.obj_sale_order_line.search([
- ('order_id', '=', self.data_so.id),
- ('product_id', '=', self.product_3.id)
- ])
- self.assertEqual(line_3.product_uom_qty, 120.0)
|