Use context date as default pattern
issue11359 review417411003
This commit is contained in:
1 parent
307b8e4dd1
commit
fd0b6619c2
2 files changed
+30
No files matched your search
@@ -3,6 +3,7 @@
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
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'
|
||||
|
||||
@@ -8,6 +8,7 @@ from trytond.modules.company.tests import (
|
||||
CompanyTestMixin, create_company, set_company)
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class ProductPriceListDatesTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
@@ -72,5 +73,25 @@ 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))
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
Reference in new issue
Block a user