This commit is contained in:
oscar alvarez 2023-03-18 11:34:55 -05:00
parent 4f2b2e6cca
commit f891b2ab31
1 changed files with 37 additions and 21 deletions

58
sale.py
View File

@ -604,10 +604,14 @@ class Sale(metaclass=PoolMeta):
Currency = pool.get('currency.currency') Currency = pool.get('currency.currency')
res = {} res = {}
today = date.today() today = date.today()
# today = today - timedelta(days=30) _date = today
moment = args.get('moment', None)
if moment == 'previous':
_date = today - timedelta(days=30)
periods = Period.search([ periods = Period.search([
('start_date', '<=', today), ('start_date', '<=', _date),
('end_date', '>=', today), ('end_date', '>=', _date),
('type', '=', 'standard') ('type', '=', 'standard')
]) ])
if not periods: if not periods:
@ -628,7 +632,7 @@ class Sale(metaclass=PoolMeta):
dates = {'period': period} dates = {'period': period}
value = cls._get_sales_report(dates, currency_id, in_thousands=True) value = cls._get_sales_report(dates, currency_id, in_thousands=True)
month_name = today.strftime("%b %Y") month_name = _date.strftime("%b %Y")
res = { res = {
'value': value, 'value': value,
'selector': selector, 'selector': selector,
@ -645,10 +649,14 @@ class Sale(metaclass=PoolMeta):
Fiscalyear = pool.get('account.fiscalyear') Fiscalyear = pool.get('account.fiscalyear')
Currency = pool.get('currency.currency') Currency = pool.get('currency.currency')
today = date.today() today = date.today()
# today = today - timedelta(days=30) moment = args.get('moment', None)
_date = today
if moment == 'previous':
_date = today - timedelta(days=365)
fiscalyear, = Fiscalyear.search([ fiscalyear, = Fiscalyear.search([
('start_date', '<=', today), ('start_date', '<=', _date),
('end_date', '>=', today), ('end_date', '>=', _date),
], limit=1) ], limit=1)
if not fiscalyear: if not fiscalyear:
return {} return {}
@ -687,10 +695,14 @@ class Sale(metaclass=PoolMeta):
Fiscalyear = pool.get('account.fiscalyear') Fiscalyear = pool.get('account.fiscalyear')
Currency = pool.get('currency.currency') Currency = pool.get('currency.currency')
today = date.today() today = date.today()
# today = today - timedelta(days=30) moment = args.get('moment', None)
_date = today
if moment == 'previous':
_date = today - timedelta(days=365)
fiscalyear, = Fiscalyear.search([ fiscalyear, = Fiscalyear.search([
('start_date', '<=', today), ('start_date', '<=', _date),
('end_date', '>=', today), ('end_date', '>=', _date),
], limit=1) ], limit=1)
if not fiscalyear: if not fiscalyear:
return {} return {}
@ -736,18 +748,20 @@ class Sale(metaclass=PoolMeta):
currency = Currency(currency_id) currency = Currency(currency_id)
today = date.today() today = date.today()
_date = today
moment = args.get('moment', None)
if moment == 'previous':
_date = today - timedelta(days=1)
dates = { dates = {
'start_date': today, 'start_date': _date,
'end_date': today 'end_date': _date
} }
yesterday = str(today - timedelta(days=1))
selector = {yesterday: 'yesterday'}
values = cls._get_sales_report(dates, currency_id, True) values = cls._get_sales_report(dates, currency_id, True)
res = { res = {
'value': values, 'value': values,
'selector': selector, 'header_meta': str(_date),
'header_meta': str(today),
'desc': 'In thousands', 'desc': 'In thousands',
'desc_meta': currency.code, 'desc_meta': currency.code,
} }
@ -758,12 +772,15 @@ class Sale(metaclass=PoolMeta):
pool = Pool() pool = Pool()
Fiscalyear = pool.get('account.fiscalyear') Fiscalyear = pool.get('account.fiscalyear')
Goal = pool.get('goal') Goal = pool.get('goal')
# Currency = pool.get('currency.currency')
today = date.today() today = date.today()
# today = today - timedelta(days=30) _date = today
moment = args.get('moment', None)
if moment == 'previous':
_date = today - timedelta(days=365)
fiscalyear, = Fiscalyear.search([ fiscalyear, = Fiscalyear.search([
('start_date', '<=', today), ('start_date', '<=', _date),
('end_date', '>=', today), ('end_date', '>=', _date),
], limit=1) ], limit=1)
if not fiscalyear: if not fiscalyear:
return {} return {}
@ -774,7 +791,6 @@ class Sale(metaclass=PoolMeta):
currency_id = args.get('currency') currency_id = args.get('currency')
# currency = Currency(currency_id) # currency = Currency(currency_id)
values = [] values = []
labels = [] labels = []
for p in periods: for p in periods: