Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits: 59a06c99 by Cédric Krier at 2023-04-11T00:30:00+02:00 Convert product cost datetime in UTC from the company timezone Closes #12026 - - - - - 1 changed file: - modules/stock/product.py Changes: ===================================== modules/stock/product.py ===================================== @@ -20,6 +20,7 @@ from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, If, PYSONEncoder from trytond.tools import decistmt, grouped_slice +from trytond.tools import timezone as tz from trytond.transaction import Transaction, without_check_access from trytond.wizard import ( Button, StateAction, StateTransition, StateView, Wizard) @@ -216,6 +217,8 @@ @classmethod def get_cost_value(cls, products, name): + pool = Pool() + Company = pool.get('company.company') cost_values = {p.id: None for p in products} context = {} trans_context = Transaction().context @@ -223,6 +226,18 @@ # Use the last cost_price of the day context['_datetime'] = datetime.datetime.combine( trans_context['stock_date_end'], datetime.time.max) + company = trans_context.get('company') + if company: + company = Company(company) + if company.timezone: + timezone = tz.ZoneInfo(company.timezone) + try: + context['_datetime'] = ( + context['_datetime'] + .replace(tzinfo=timezone) + .astimezone(tz.UTC)) + except OverflowError: + pass # The date could be before the product creation products = [p for p in products if p.create_date <= context['_datetime']] View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/commit/59a06c99ac7c82cc8d739db6b9ccb230dccc82ed -- View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/commit/59a06c99ac7c82cc8d739db6b9ccb230dccc82ed You're receiving this email because of your account on foss.heptapod.net.