Use context date as default pattern
issue11359 review417411003 (grafted from 3ca1623dd74c4c1a9aff760d2b43d5dabf82a1ee) --HG-- branch : 6.0
This commit is contained in:
1 parent
8327db6463
commit
604118a802
2 files changed
+30
No files matched your search
@@ -3,6 +3,7 @@
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class PriceList(metaclass=PoolMeta):
|
||||
@@ -21,6 +22,14 @@ class PriceList(metaclass=PoolMeta):
|
||||
def open_lines(cls, price_lists):
|
||||
pass
|
||||
|
||||
def compute(
|
||||
self, party, product, unit_price, quantity, uom, pattern=None):
|
||||
context = Transaction().context
|
||||
pattern = pattern.copy() if pattern is not None else {}
|
||||
pattern.setdefault('date', context.get('date'))
|
||||
return super().compute(
|
||||
party, product, unit_price, quantity, uom, pattern=pattern)
|
||||
|
||||
|
||||
class PriceListLine(metaclass=PoolMeta):
|
||||
__name__ = 'product.price_list.line'
|
||||
|
||||
@@ -11,6 +11,7 @@ from trytond.tests.test_tryton import suite as test_suite
|
||||
|
||||
from trytond.modules.company.tests import (
|
||||
create_company, set_company, CompanyTestMixin)
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class ProductPriceListDatesTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
@@ -75,6 +76,26 @@ class ProductPriceListDatesTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
None, None, Decimal(10), 1, None, pattern={'date': yesterday}),
|
||||
Decimal(9))
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list_with_context_date(self):
|
||||
"Test price list with context date"
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
tomorrow = today + datetime.timedelta(days=1)
|
||||
|
||||
price_list = self.create_price_list('start_date', tomorrow)
|
||||
|
||||
with Transaction().set_context(date=today):
|
||||
self.assertEqual(
|
||||
price_list.compute(None, None, Decimal(10), 1, None),
|
||||
Decimal(10))
|
||||
with Transaction().set_context(date=tomorrow):
|
||||
self.assertEqual(
|
||||
price_list.compute(None, None, Decimal(10), 1, None),
|
||||
Decimal(9))
|
||||
|
||||
|
||||
def suite():
|
||||
suite = test_suite()
|
||||
|
||||
Reference in new issue
Block a user