Use sale_uom as fallback uom to compute sale price

issue7855
review45821002
This commit is contained in:
Cédric Krier committed 2018-12-22 00:16:15 +01:00
1 parent 42a617f1c0
commit 8cc4fa18d6
3 files changed
+60 -2

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
* Use sale_uom as default for Product.get_sale_price
Version 5.0.0 - 2018-10-01
* Bug fixes (see mercurial logs for details)
* Add configured delay for processing sale
+4 -1
View File
@@ -94,7 +94,7 @@ class Product(metaclass=PoolMeta):
'''
Return the sale price for products and quantity.
It uses if exists from the context:
uom: the unit of measure
uom: the unit of measure or the sale uom of the product
currency: the currency id for the returned price
'''
pool = Pool()
@@ -123,6 +123,9 @@ class Product(metaclass=PoolMeta):
if uom and product.default_uom.category == uom.category:
prices[product.id] = Uom.compute_price(
product.default_uom, prices[product.id], uom)
else:
prices[product.id] = Uom.compute_price(
product.default_uom, prices[product.id], product.sale_uom)
if currency and user.company:
if user.company.currency != currency:
date = Transaction().context.get('sale_date') or today
+54 -1
View File
@@ -2,15 +2,68 @@
# this repository contains the full copyright notices and license terms.
import unittest
import doctest
from decimal import Decimal
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.tests.test_tryton import doctest_teardown, doctest_checker
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.modules.company.tests import create_company, set_company
from trytond.modules.account.tests import create_chart
class SaleTestCase(ModuleTestCase):
'Test Sale module'
module = 'sale'
@with_transaction()
def test_sale_price(self):
"Test sale price"
pool = Pool()
Account = pool.get('account.account')
Template = pool.get('product.template')
Product = pool.get('product.product')
Uom = pool.get('product.uom')
company = create_company()
with set_company(company):
create_chart(company)
receivable, = Account.search([
('kind', '=', 'receivable'),
('company', '=', company.id),
])
payable, = Account.search([
('kind', '=', 'payable'),
('company', '=', company.id),
])
kg, = Uom.search([('name', '=', 'Kilogram')])
g, = Uom.search([('name', '=', 'Gram')])
pound, = Uom.search([('name', '=', 'Pound')])
template, = Template.create([{
'name': 'Product',
'default_uom': g.id,
'sale_uom': kg.id,
'list_price': Decimal(5),
'products': [('create', [{}])],
}])
product, = template.products
prices = Product.get_sale_price([product], quantity=100)
self.assertEqual(prices, {product.id: Decimal(5000)})
prices = Product.get_sale_price([product], quantity=1500)
self.assertEqual(prices, {product.id: Decimal(5000)})
with Transaction().set_context(uom=pound.id):
prices = Product.get_sale_price([product], quantity=0.5)
self.assertEqual(prices, {product.id: Decimal('2267.96185')})
prices = Product.get_sale_price([product], quantity=1.5)
self.assertEqual(prices, {product.id: Decimal('2267.96185')})
def suite():
suite = trytond.tests.test_tryton.suite()