[REF] product: migrate yml test cases to unit test cases.
This commit is contained in:
committed by
Thibault Delavallée
parent
1b4f96cf40
commit
f771ed2ca2
@@ -47,10 +47,6 @@ Print product labels with barcode.
|
||||
'data/product_demo.xml',
|
||||
'data/product_image_demo.xml',
|
||||
],
|
||||
'test': [
|
||||
'test/product_pricelist_demo.yml',
|
||||
'test/product_pricelist.yml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
-
|
||||
In order to check the calculation of price of the products according to pricelist,
|
||||
-
|
||||
I check sale price of Assemble Computer
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
context.update({'pricelist': ref("customer_pricelist"), 'quantity':1})
|
||||
product = self.browse(cr, uid, ref("product_product_4"), context=context)
|
||||
assert float_compare(product.price, (product.lst_price-product.lst_price*(0.10)), precision_digits=2) == 0, "Wrong sale price: Assemble Computer."
|
||||
-
|
||||
I check sale price of Laptop.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
product = self.browse(cr, uid, ref("product_delivery_01"), context=context)
|
||||
assert float_compare(product.price, product.lst_price + 1, precision_digits=2) == 0, "Wrong sale price: Laptop."
|
||||
-
|
||||
I check sale price of IT component.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
product = self.browse(cr, uid, ref("product_product_7"), context=context)
|
||||
assert float_compare(product.price, product.lst_price, precision_digits=2) == 0, "Wrong sale price: IT component."
|
||||
-
|
||||
I check sale price of IT component if more than 3 Unit.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
context.update({'quantity':5})
|
||||
product = self.browse(cr, uid, ref("product_product_25"), context=context)
|
||||
assert float_compare(product.price, product.lst_price-product.lst_price*(0.05), precision_digits=2) == 0, "Wrong sale price: IT component if more than 3 Unit."
|
||||
-
|
||||
I check sale price of LCD Monitor.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
context.update({'quantity':1})
|
||||
product = self.browse(cr, uid, ref("product_product_6"), context=context)
|
||||
assert float_compare(product.price, product.lst_price, precision_digits=2) == 0, "Wrong sale price: LCD Monitor."
|
||||
-
|
||||
I check sale price of LCD Monitor on end of year.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
context.update({'quantity':1, 'date': '2011-12-31'})
|
||||
product = self.browse(cr, uid, ref("product_product_6"), context=context)
|
||||
assert float_compare(product.price, product.lst_price-product.lst_price*(0.30), precision_digits=2) == 0, "Wrong sale price: LCD Monitor on end of year."
|
||||
-
|
||||
I check cost price of LCD Monitor.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
product = self.browse(cr, uid, ref("product_product_6"), context=context)
|
||||
partner = self.pool.get('res.partner').browse(cr, uid, ref('base.res_partner_4'), context=context)
|
||||
assert float_compare(product._select_seller(partner_id=partner, quantity=1.0).price, 790, precision_digits=2) == 0, "Wrong cost price: LCD Monitor."
|
||||
-
|
||||
I check cost price of LCD Monitor if more than 3 Unit.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
from openerp.tools import float_compare
|
||||
product = self.browse(cr, uid, ref("product_product_6"), context=context)
|
||||
partner = self.pool.get('res.partner').browse(cr, uid, ref('base.res_partner_4'), context=context)
|
||||
assert float_compare(product._select_seller(partner_id=partner, quantity=3.0).price, 785, precision_digits=2) == 0, "Wrong cost price: LCD Monitor if more than 3 Unit."
|
||||
-
|
||||
I print the sale prices report.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
ctx = {'model': 'product.product', 'date': '2011-12-30', 'active_ids': [ref('product.product_product_3'), ref('product.product_product_4'), ref('product.product_product_5'), ref('product.product_product_6')]}
|
||||
data_dict = {
|
||||
'qty1': 1,
|
||||
'qty2': 5,
|
||||
'qty3': 10,
|
||||
'qty4': 15,
|
||||
'qty5': 30,
|
||||
'price_list':ref('customer_pricelist'),
|
||||
}
|
||||
from openerp.tools import test_reports
|
||||
test_reports.try_report_action(cr, uid, 'action_product_price_list',wiz_data=data_dict, context=ctx, our_module='product')
|
||||
@@ -1,42 +0,0 @@
|
||||
-
|
||||
!record {model: product.product, id: product_product_4}:
|
||||
uom_id: product_uom_unit
|
||||
categ_id: product_category_5
|
||||
-
|
||||
!record {model: product.pricelist, id: customer_pricelist}:
|
||||
name: Customer Pricelist
|
||||
item_ids:
|
||||
- name: Default pricelist
|
||||
compute_price: 'formula'
|
||||
base: 'pricelist'
|
||||
base_pricelist_id: list0
|
||||
- name: 10% Discount on Assemble Computer
|
||||
applied_on : '1_product'
|
||||
sequence: 1
|
||||
product_id: product_product_4
|
||||
compute_price: 'formula'
|
||||
base: 'list_price'
|
||||
price_discount: 10
|
||||
- name: 1 surchange on Laptop
|
||||
applied_on : '1_product'
|
||||
sequence: 1
|
||||
product_id: product_delivery_01
|
||||
compute_price: 'formula'
|
||||
base: 'list_price'
|
||||
price_surcharge: 1
|
||||
- name: 5% Discount on all Computer related products
|
||||
applied_on : '2_product_category'
|
||||
sequence: 4
|
||||
min_quantity: 2
|
||||
compute_price: 'formula'
|
||||
base: 'list_price'
|
||||
categ_id: product_category_5
|
||||
price_discount: 5
|
||||
- name: 30% Discount on all products
|
||||
applied_on : '0_product_variant'
|
||||
date_start: 2011-12-27
|
||||
date_end: 2011-12-31
|
||||
compute_price: 'formula'
|
||||
price_discount: 30
|
||||
sequence: 1
|
||||
base: 'list_price'
|
||||
@@ -1 +1,4 @@
|
||||
from . import common, test_variants, test_uom, test_pricelist
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_variants, test_uom, test_pricelist, test_product_pricelist
|
||||
|
||||
@@ -1,109 +1,102 @@
|
||||
from openerp.tests.common import TransactionCase
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestPricelist(TransactionCase):
|
||||
"""Tests for unit of measure conversion"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestPricelist, self).setUp()
|
||||
cr, uid, context = self.cr, self.uid, {}
|
||||
self.ir_model_data = self.registry('ir.model.data')
|
||||
self.product_product = self.registry('product.product')
|
||||
self.product_pricelist = self.registry('product.pricelist')
|
||||
self.uom = self.registry('product.uom')
|
||||
|
||||
self.usb_adapter_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_delivery_01')[1]
|
||||
self.datacard_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_delivery_02')[1]
|
||||
self.unit_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_uom_unit')[1]
|
||||
self.dozen_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_uom_dozen')[1]
|
||||
self.tonne_id = self.ir_model_data.xmlid_to_res_id(cr, uid, 'product.product_uom_ton')
|
||||
self.kg_id = self.ir_model_data.xmlid_to_res_id(cr, uid, 'product.product_uom_kgm')
|
||||
self.datacard = self.env.ref('product.product_delivery_02')
|
||||
self.usb_adapter = self.env.ref('product.product_delivery_01')
|
||||
self.uom_ton = self.env.ref('product.product_uom_ton')
|
||||
self.uom_unit_id = self.ref('product.product_uom_unit')
|
||||
self.uom_dozen_id = self.ref('product.product_uom_dozen')
|
||||
self.uom_kgm_id = self.ref('product.product_uom_kgm')
|
||||
|
||||
self.public_pricelist_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'list0')[1]
|
||||
self.sale_pricelist_id = self.product_pricelist.create(cr, uid, {
|
||||
self.public_pricelist = self.env.ref('product.list0')
|
||||
self.sale_pricelist_id = self.env['product.pricelist'].create({
|
||||
'name': 'Sale pricelist',
|
||||
'item_ids': [(0, 0, {
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price', # based on public price
|
||||
'base': 'list_price', # based on public price
|
||||
'price_discount': 10,
|
||||
'product_id': self.usb_adapter_id,
|
||||
'product_id': self.usb_adapter.id,
|
||||
'applied_on': '0_product_variant',
|
||||
}), (0, 0, {
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price', # based on public price
|
||||
'base': 'list_price', # based on public price
|
||||
'price_surcharge': -0.5,
|
||||
'product_id': self.datacard_id,
|
||||
'product_id': self.datacard.id,
|
||||
'applied_on': '0_product_variant',
|
||||
})]
|
||||
}, context=context)
|
||||
})
|
||||
|
||||
def test_10_discount(self):
|
||||
# Make sure the price using a pricelist is the same than without after
|
||||
# applying the computation manually
|
||||
cr, uid, context = self.cr, self.uid, {}
|
||||
context = {}
|
||||
|
||||
public_context = dict(context, pricelist=self.public_pricelist_id)
|
||||
pricelist_context = dict(context, pricelist=self.sale_pricelist_id)
|
||||
public_context = dict(context, pricelist=self.public_pricelist.id)
|
||||
pricelist_context = dict(context, pricelist=self.sale_pricelist_id.id)
|
||||
|
||||
usb_adapter_without_pricelist = self.product_product.browse(cr, uid, self.usb_adapter_id, context=public_context)
|
||||
usb_adapter_with_pricelist = self.product_product.browse(cr, uid, self.usb_adapter_id, context=pricelist_context)
|
||||
usb_adapter_without_pricelist = self.usb_adapter.with_context(public_context)
|
||||
usb_adapter_with_pricelist = self.usb_adapter.with_context(pricelist_context)
|
||||
self.assertEqual(usb_adapter_with_pricelist.price, usb_adapter_without_pricelist.price*0.9)
|
||||
|
||||
datacard_without_pricelist = self.product_product.browse(cr, uid, self.datacard_id, context=public_context)
|
||||
datacard_with_pricelist = self.product_product.browse(cr, uid, self.datacard_id, context=pricelist_context)
|
||||
datacard_without_pricelist = self.datacard.with_context(public_context)
|
||||
datacard_with_pricelist = self.datacard.with_context(pricelist_context)
|
||||
self.assertEqual(datacard_with_pricelist.price, datacard_without_pricelist.price-0.5)
|
||||
|
||||
# Make sure that changing the unit of measure does not break the unit
|
||||
# price (after converting)
|
||||
unit_context = dict(context,
|
||||
pricelist=self.sale_pricelist_id,
|
||||
uom=self.unit_id)
|
||||
dozen_context = dict(context,
|
||||
pricelist=self.sale_pricelist_id,
|
||||
uom=self.dozen_id)
|
||||
unit_context = dict(context, pricelist=self.sale_pricelist_id.id, uom=self.uom_unit_id)
|
||||
dozen_context = dict(context, pricelist=self.sale_pricelist_id.id, uom=self.uom_dozen_id)
|
||||
|
||||
usb_adapter_unit = self.product_product.browse(cr, uid, self.usb_adapter_id, context=unit_context)
|
||||
usb_adapter_dozen = self.product_product.browse(cr, uid, self.usb_adapter_id, context=dozen_context)
|
||||
usb_adapter_unit = self.usb_adapter.with_context(unit_context)
|
||||
usb_adapter_dozen = self.usb_adapter.with_context(dozen_context)
|
||||
self.assertAlmostEqual(usb_adapter_unit.price*12, usb_adapter_dozen.price)
|
||||
datacard_unit = self.product_product.browse(cr, uid, self.datacard_id, context=unit_context)
|
||||
datacard_dozen = self.product_product.browse(cr, uid, self.datacard_id, context=dozen_context)
|
||||
datacard_unit = self.datacard.with_context(unit_context)
|
||||
datacard_dozen = self.datacard.with_context(dozen_context)
|
||||
# price_surcharge applies to product default UoM, here "Units", so surcharge will be multiplied
|
||||
self.assertAlmostEqual(datacard_unit.price*12, datacard_dozen.price)
|
||||
|
||||
def test_20_pricelist_uom(self):
|
||||
# Verify that the pricelist rules are correctly using the product's default UoM
|
||||
# as reference, and return a result according to the target UoM (as specific in the context)
|
||||
cr, uid = self.cr, self.uid
|
||||
kg, tonne = self.kg_id, self.tonne_id
|
||||
|
||||
kg, tonne = self.uom_kgm_id, self.uom_ton.id
|
||||
tonne_price = 100
|
||||
|
||||
# make sure 'tonne' resolves down to 1 'kg'.
|
||||
self.uom.write(cr, uid, tonne, {'rounding': 0.001})
|
||||
self.uom_ton.write({'rounding': 0.001})
|
||||
# setup product stored in 'tonnes', with a discounted pricelist for qty > 3 tonnes
|
||||
spam_id = self.product_product.copy(cr, uid, self.usb_adapter_id,
|
||||
{ 'name': '1 tonne of spam',
|
||||
'uom_id': self.tonne_id,
|
||||
'uom_po_id': self.tonne_id,
|
||||
'list_price': tonne_price,
|
||||
'type': 'consu',
|
||||
})
|
||||
spam_id = self.usb_adapter.copy({
|
||||
'name': '1 tonne of spam',
|
||||
'uom_id': self.uom_ton.id,
|
||||
'uom_po_id': self.uom_ton.id,
|
||||
'list_price': tonne_price,
|
||||
'type': 'consu'
|
||||
})
|
||||
|
||||
self.registry('product.pricelist.item').create(cr, uid, {
|
||||
'pricelist_id': self.public_pricelist_id,
|
||||
'sequence': 10,
|
||||
'applied_on': '0_product_variant',
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price', # based on public price
|
||||
'min_quantity': 3, # min = 3 tonnes
|
||||
'price_surcharge': -10, # -10 EUR / tonne
|
||||
'product_id': spam_id, })
|
||||
pricelist_id = self.public_pricelist_id
|
||||
self.env['product.pricelist.item'].create({
|
||||
'pricelist_id': self.public_pricelist.id,
|
||||
'sequence': 10,
|
||||
'applied_on': '0_product_variant',
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price', # based on public price
|
||||
'min_quantity': 3, # min = 3 tonnes
|
||||
'price_surcharge': -10, # -10 EUR / tonne
|
||||
'product_id': spam_id.id
|
||||
})
|
||||
pricelist = self.public_pricelist
|
||||
|
||||
def test_unit_price(qty, uom, expected_unit_price):
|
||||
spam = self.product_product.browse(cr, uid, spam_id, {'uom': uom})
|
||||
unit_price = self.registry('product.pricelist').get_product_price(cr, uid, [pricelist_id],
|
||||
spam, qty, False,
|
||||
context={'uom': uom})
|
||||
self.assertAlmostEqual(unit_price, expected_unit_price)
|
||||
spam = spam_id.with_context({'uom': uom})
|
||||
unit_price = pricelist.with_context({'uom': uom}).get_product_price(spam, qty, False)
|
||||
self.assertAlmostEqual(unit_price, expected_unit_price, msg='Computed unit price is wrong')
|
||||
|
||||
# Test prices - they are *per unit*, the quantity is only here to match the pricelist rules!
|
||||
test_unit_price(2, kg, tonne_price / 1000.0)
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tools import float_compare, test_reports
|
||||
|
||||
|
||||
class TestProductPricelist(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestProductPricelist, self).setUp()
|
||||
self.ProductPricelist = self.env['product.pricelist']
|
||||
self.res_partner_4 = self.env.ref('base.res_partner_4')
|
||||
self.computer_SC234 = self.env.ref("product.product_product_3")
|
||||
self.ipad_retina_display = self.env.ref('product.product_product_4')
|
||||
self.custom_computer_kit = self.env.ref("product.product_product_5")
|
||||
self.ipad_mini = self.env.ref("product.product_product_6")
|
||||
self.apple_in_ear_headphones = self.env.ref("product.product_product_7")
|
||||
self.laptop_E5023 = self.env.ref('product.product_delivery_01')
|
||||
self.laptop_S3450 = self.env.ref("product.product_product_25")
|
||||
self.category_5_id = self.ref('product.product_category_5')
|
||||
self.uom_unit_id = self.ref('product.product_uom_unit')
|
||||
self.list0 = self.ref('product.list0')
|
||||
|
||||
self.ipad_retina_display.write({'uom_id': self.uom_unit_id, 'categ_id': self.category_5_id})
|
||||
self.customer_pricelist = self.ProductPricelist.create({
|
||||
'name': 'Customer Pricelist',
|
||||
'item_ids': [(0, 0, {
|
||||
'name': 'Default pricelist',
|
||||
'compute_price': 'formula',
|
||||
'base': 'pricelist',
|
||||
'base_pricelist_id': self.list0
|
||||
}), (0, 0, {
|
||||
'name': '10% Discount on Assemble Computer',
|
||||
'applied_on': '1_product',
|
||||
'sequence': 1,
|
||||
'product_id': self.ipad_retina_display.id,
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price',
|
||||
'price_discount': 10
|
||||
}), (0, 0, {
|
||||
'name': '1 surchange on Laptop',
|
||||
'applied_on': '1_product',
|
||||
'sequence': 4,
|
||||
'product_id': self.laptop_E5023.id,
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price',
|
||||
'price_surcharge': 1
|
||||
}), (0, 0, {
|
||||
'name': '5% Discount on all Computer related products',
|
||||
'applied_on': '2_product_category',
|
||||
'sequence': 1,
|
||||
'min_quantity': 2,
|
||||
'compute_price': 'formula',
|
||||
'base': 'list_price',
|
||||
'categ_id': self.category_5_id,
|
||||
'price_discount': 5
|
||||
}), (0, 0, {
|
||||
'name': '30% Discount on all products',
|
||||
'applied_on': '0_product_variant',
|
||||
'date_start': '2011-12-27',
|
||||
'date_end': '2011-12-31',
|
||||
'compute_price': 'formula',
|
||||
'price_discount': 30,
|
||||
'sequence': 1,
|
||||
'base': 'list_price'
|
||||
})]
|
||||
})
|
||||
|
||||
def test_10_calculation_price_of_products_pricelist(self):
|
||||
"""Test calculation of product price based on pricelist"""
|
||||
# I check sale price of iPad Retina Display
|
||||
context = {}
|
||||
context.update({'pricelist': self.customer_pricelist.id, 'quantity': 1})
|
||||
ipad_retina_display = self.ipad_retina_display.with_context(context)
|
||||
msg = "Wrong sale price: iPad Retina Display. should be %s instead of %s" % (ipad_retina_display.price, (ipad_retina_display.lst_price-ipad_retina_display.lst_price*(0.10)))
|
||||
self.assertEqual(float_compare(ipad_retina_display.price, (ipad_retina_display.lst_price-ipad_retina_display.lst_price*(0.10)), precision_digits=2), 0, msg)
|
||||
|
||||
# I check sale price of Laptop.
|
||||
laptop_E5023 = self.laptop_E5023.with_context(context)
|
||||
msg = "Wrong sale price: Laptop. should be %s instead of %s" % (laptop_E5023.price, (laptop_E5023.lst_price + 1))
|
||||
self.assertEqual(float_compare(laptop_E5023.price, laptop_E5023.lst_price + 1, precision_digits=2), 0, msg)
|
||||
|
||||
# I check sale price of IT component.
|
||||
apple_headphones = self.apple_in_ear_headphones.with_context(context)
|
||||
msg = "Wrong sale price: IT component. should be %s instead of %s" % (apple_headphones.price, apple_headphones.lst_price)
|
||||
self.assertEqual(float_compare(apple_headphones.price, apple_headphones.lst_price, precision_digits=2), 0, msg)
|
||||
|
||||
# I check sale price of IT component if more than 3 Unit.
|
||||
context.update({'quantity': 5})
|
||||
laptop_S3450 = self.laptop_S3450.with_context(context)
|
||||
msg = "Wrong sale price: IT component if more than 3 Unit. should be %s instead of %s" % (laptop_S3450.price, (laptop_S3450.lst_price-laptop_S3450.lst_price*(0.05)))
|
||||
self.assertEqual(float_compare(laptop_S3450.price, laptop_S3450.lst_price-laptop_S3450.lst_price*(0.05), precision_digits=2), 0, msg)
|
||||
|
||||
# I check sale price of LCD Monitor.
|
||||
context.update({'quantity': 1})
|
||||
ipad_mini = self.ipad_mini.with_context(context)
|
||||
msg = "Wrong sale price: LCD Monitor. should be %s instead of %s" % (ipad_mini.price, ipad_mini.lst_price)
|
||||
self.assertEqual(float_compare(ipad_mini.price, ipad_mini.lst_price, precision_digits=2), 0, msg)
|
||||
|
||||
# I check sale price of LCD Monitor on end of year.
|
||||
context.update({'quantity': 1, 'date': '2011-12-31'})
|
||||
ipad_mini = self.ipad_mini.with_context(context)
|
||||
msg = "Wrong sale price: LCD Monitor on end of year. should be %s instead of %s" % (ipad_mini.price, ipad_mini.lst_price-ipad_mini.lst_price*(0.30))
|
||||
self.assertEqual(float_compare(ipad_mini.price, ipad_mini.lst_price-ipad_mini.lst_price*(0.30), precision_digits=2), 0, msg)
|
||||
|
||||
# I check cost price of LCD Monitor.
|
||||
context.update({'quantity': 1, 'date': False, 'partner_id': self.res_partner_4.id})
|
||||
ipad_mini = self.ipad_mini.with_context(context)
|
||||
partner = self.res_partner_4.with_context(context)
|
||||
msg = "Wrong cost price: LCD Monitor. should be 790 instead of %s" % ipad_mini._select_seller(partner_id=partner, quantity=1.0).price
|
||||
self.assertEqual(float_compare(ipad_mini._select_seller(partner_id=partner, quantity=1.0).price, 790, precision_digits=2), 0, msg)
|
||||
|
||||
# I check cost price of LCD Monitor if more than 3 Unit.
|
||||
context.update({'quantity': 3})
|
||||
ipad_mini = self.ipad_mini.with_context(context)
|
||||
partner = self.res_partner_4.with_context(context)
|
||||
msg = "Wrong cost price: LCD Monitor if more than 3 Unit.should be 785 instead of %s" % ipad_mini._select_seller(partner_id=partner, quantity=3.0).price
|
||||
self.assertEqual(float_compare(ipad_mini._select_seller(partner_id=partner, quantity=3.0).price, 785, precision_digits=2), 0, msg)
|
||||
|
||||
# I print the sale prices report.
|
||||
ctx = {'active_model': 'product.product', 'date': '2011-12-30', 'active_ids': [self.computer_SC234.id, self.ipad_retina_display.id, self.custom_computer_kit.id, self.ipad_mini.id]}
|
||||
data_dict = {
|
||||
'qty1': 1,
|
||||
'qty2': 5,
|
||||
'qty3': 10,
|
||||
'qty4': 15,
|
||||
'qty5': 30,
|
||||
'price_list': self.customer_pricelist.id,
|
||||
}
|
||||
test_reports.try_report_action(self.cr, self.uid, 'action_product_price_list', wiz_data=data_dict, context=ctx, our_module='product')
|
||||
@@ -1,29 +1,25 @@
|
||||
from openerp.tests.common import TransactionCase
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestUom(TransactionCase):
|
||||
"""Tests for unit of measure conversion"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestUom, self).setUp()
|
||||
self.product = self.registry('product.product')
|
||||
self.uom = self.registry('product.uom')
|
||||
self.imd = self.registry('ir.model.data')
|
||||
self.uom_gram = self.env.ref('product.product_uom_gram')
|
||||
self.uom_kgm = self.env.ref('product.product_uom_kgm')
|
||||
self.uom_ton = self.env.ref('product.product_uom_ton')
|
||||
self.uom_unit = self.env.ref('product.product_uom_unit')
|
||||
self.uom_dozen = self.env.ref('product.product_uom_dozen')
|
||||
self.categ_unit_id = self.ref('product.product_uom_categ_unit')
|
||||
|
||||
def test_10_conversion(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
gram_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_gram')[1]
|
||||
kg_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_kgm')[1]
|
||||
kg = self.registry['product.uom'].browse(cr, uid, [kg_id])
|
||||
tonne_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_ton')[1]
|
||||
tonne = self.registry['product.uom'].browse(cr, uid, [tonne_id])
|
||||
unit_id = self.imd.get_object_reference(cr, uid, 'product','product_uom_unit')[1]
|
||||
unit = self.registry['product.uom'].browse(cr, uid, [unit_id])
|
||||
dozen_id = self.imd.get_object_reference(cr, uid, 'product','product_uom_dozen')[1]
|
||||
|
||||
qty = self.uom._compute_quantity(cr, uid, [gram_id], 1020000, tonne)
|
||||
qty = self.uom_gram._compute_quantity(1020000, self.uom_ton)
|
||||
self.assertEquals(qty, 1.02, "Converted quantity does not correspond.")
|
||||
|
||||
price = self.uom._compute_price(cr, uid, [gram_id], 2, tonne)
|
||||
price = self.uom_gram._compute_price(2, self.uom_ton)
|
||||
self.assertEquals(price, 2000000.0, "Converted price does not correspond.")
|
||||
|
||||
# If the conversion factor for Dozens (1/12) is not stored with sufficient precision,
|
||||
@@ -31,28 +27,23 @@ class TestUom(TransactionCase):
|
||||
# and the Unit rounding will round that up to 13.
|
||||
# This is a partial regression test for rev. 311c77bb, which is further improved
|
||||
# by rev. fa2f7b86.
|
||||
qty = self.uom._compute_quantity(cr, uid, [dozen_id], 1, unit)
|
||||
qty = self.uom_dozen._compute_quantity(1, self.uom_unit)
|
||||
self.assertEquals(qty, 12.0, "Converted quantity does not correspond.")
|
||||
|
||||
# Regression test for side-effect of commit 311c77bb - converting 1234 Grams
|
||||
# into Kilograms should work even if grams are rounded to 1.
|
||||
self.uom.write(cr, uid, gram_id, {'rounding': 1})
|
||||
qty = self.uom._compute_quantity(cr, uid, [gram_id], 1234, kg)
|
||||
self.uom_gram.write({'rounding': 1})
|
||||
qty = self.uom_gram._compute_quantity(1234, self.uom_kgm)
|
||||
self.assertEquals(qty, 1.234, "Converted quantity does not correspond.")
|
||||
|
||||
def test_20_rounding(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
unit_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_unit')[1]
|
||||
categ_unit_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_categ_unit')[1]
|
||||
|
||||
score_id = self.uom.create(cr, uid, {
|
||||
product_uom = self.env['product.uom'].create({
|
||||
'name': 'Score',
|
||||
'factor_inv': 20,
|
||||
'uom_type': 'bigger',
|
||||
'rounding': 1.0,
|
||||
'category_id': categ_unit_id
|
||||
'category_id': self.categ_unit_id
|
||||
})
|
||||
score = self.uom.browse(cr, uid, score_id)
|
||||
|
||||
qty = self.uom._compute_quantity(cr, uid, [unit_id], 2, score)
|
||||
qty = self.uom_unit._compute_quantity(2, product_uom)
|
||||
self.assertEquals(qty, 1, "Converted quantity should be rounded up.")
|
||||
|
||||
@@ -15,7 +15,6 @@ class TestVariants(common.TestProductCommon):
|
||||
return res
|
||||
|
||||
def test_variants_creation_mono(self):
|
||||
print '-------------------------------'
|
||||
test_template = self.env['product.template'].create({
|
||||
'name': 'Sofa',
|
||||
'uom_id': self.uom_unit.id,
|
||||
@@ -25,14 +24,12 @@ class TestVariants(common.TestProductCommon):
|
||||
'value_ids': [(4, self.size_attr_value_s.id)],
|
||||
})]
|
||||
})
|
||||
print '-------------------------------'
|
||||
|
||||
# produced variants: one variant, because mono value
|
||||
self.assertEqual(len(test_template.product_variant_ids), 1)
|
||||
self.assertEqual(test_template.product_variant_ids.attribute_value_ids, self.size_attr_value_s)
|
||||
|
||||
def test_variants_creation_mono_double(self):
|
||||
print '-------------------------------'
|
||||
test_template = self.env['product.template'].create({
|
||||
'name': 'Sofa',
|
||||
'uom_id': self.uom_unit.id,
|
||||
@@ -45,14 +42,12 @@ class TestVariants(common.TestProductCommon):
|
||||
'value_ids': [(4, self.size_attr_value_s.id)],
|
||||
})]
|
||||
})
|
||||
print '-------------------------------'
|
||||
|
||||
# produced variants: one variant, because only 1 combination is possible
|
||||
self.assertEqual(len(test_template.product_variant_ids), 1)
|
||||
self.assertEqual(test_template.product_variant_ids.attribute_value_ids, self.size_attr_value_s + self.prod_attr1_v2)
|
||||
|
||||
def test_variants_creation_mono_multi(self):
|
||||
print '-------------------------------'
|
||||
test_template = self.env['product.template'].create({
|
||||
'name': 'Sofa',
|
||||
'uom_id': self.uom_unit.id,
|
||||
@@ -65,7 +60,6 @@ class TestVariants(common.TestProductCommon):
|
||||
'value_ids': [(4, self.size_attr_value_s.id), (4, self.size_attr_value_m.id)],
|
||||
})]
|
||||
})
|
||||
print '-------------------------------'
|
||||
|
||||
# produced variants: two variants, simple matrix
|
||||
self.assertEqual(len(test_template.product_variant_ids), 2)
|
||||
@@ -78,7 +72,6 @@ class TestVariants(common.TestProductCommon):
|
||||
self.assertEqual(len(products), 1)
|
||||
|
||||
def test_variants_creation_matrix(self):
|
||||
print '-------------------------------'
|
||||
test_template = self.env['product.template'].create({
|
||||
'name': 'Sofa',
|
||||
'uom_id': self.uom_unit.id,
|
||||
@@ -91,7 +84,6 @@ class TestVariants(common.TestProductCommon):
|
||||
'value_ids': [(4, self.size_attr_value_s.id), (4, self.size_attr_value_m.id), (4, self.size_attr_value_l.id)],
|
||||
})]
|
||||
})
|
||||
print '-------------------------------'
|
||||
|
||||
# produced variants: value matrix : 2x3 values
|
||||
self.assertEqual(len(test_template.product_variant_ids), 6)
|
||||
@@ -105,7 +97,6 @@ class TestVariants(common.TestProductCommon):
|
||||
self.assertEqual(len(products), 1)
|
||||
|
||||
def test_variants_creation_multi_update(self):
|
||||
print '-------------------------------'
|
||||
test_template = self.env['product.template'].create({
|
||||
'name': 'Sofa',
|
||||
'uom_id': self.uom_unit.id,
|
||||
@@ -118,11 +109,9 @@ class TestVariants(common.TestProductCommon):
|
||||
'value_ids': [(4, self.size_attr_value_s.id), (4, self.size_attr_value_m.id)],
|
||||
})]
|
||||
})
|
||||
print '-------------------------------'
|
||||
size_attribute_line = test_template.attribute_line_ids.filtered(lambda line: line.attribute_id == self.size_attr)
|
||||
test_template.write({
|
||||
'attribute_line_ids': [(1, size_attribute_line.id, {
|
||||
'value_ids': [(4, self.size_attr_value_l.id)],
|
||||
})]
|
||||
})
|
||||
print '-------------------------------'
|
||||
|
||||
Reference in New Issue
Block a user