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