Add fulfillment month
This commit is contained in:
parent
e4777b8f60
commit
38141a32c0
|
@ -43,5 +43,13 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="in_thousands">True</field>
|
||||
</record>
|
||||
|
||||
<record model="dash.report" id="dash_report_fulfillment_month_year">
|
||||
<field name="name">Goal Month</field>
|
||||
<field name="model">sale.sale</field>
|
||||
<field name="type">card_info</field>
|
||||
<field name="method">report_fulfillment_goal_month</field>
|
||||
<field name="in_thousands">True</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
60
sale.py
60
sale.py
|
@ -753,7 +753,6 @@ class Sale(metaclass=PoolMeta):
|
|||
|
||||
res = {
|
||||
'value': sum(values),
|
||||
'selector': selector,
|
||||
'header_meta': fiscalyear.name,
|
||||
'desc': 'In thousands',
|
||||
'desc_meta': currency.code,
|
||||
|
@ -790,6 +789,65 @@ class Sale(metaclass=PoolMeta):
|
|||
}
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def report_fulfillment_goal_month(cls, args, ctx=None):
|
||||
# Dash Report
|
||||
pool = Pool()
|
||||
Currency = pool.get('currency.currency')
|
||||
Period = pool.get('account.period')
|
||||
GoalPeriod = pool.get('goal.period')
|
||||
Goal = pool.get('goal')
|
||||
currency_id = Transaction().context.get('currency')
|
||||
if args.get('currency'):
|
||||
currency_id = args.get('currency')
|
||||
|
||||
currency = Currency(currency_id)
|
||||
today = date.today()
|
||||
|
||||
_date = today
|
||||
moment = args.get('moment', None)
|
||||
if moment == 'previous':
|
||||
_date = today - timedelta(days=31)
|
||||
|
||||
dates = {
|
||||
'start_date': _date,
|
||||
'end_date': _date
|
||||
}
|
||||
|
||||
period, = Period.search([
|
||||
('start_date', '<=', _date),
|
||||
('end_date', '>=', _date),
|
||||
])
|
||||
|
||||
month = period.start_date.strftime("%b")
|
||||
dates = {'period': period}
|
||||
|
||||
goals = GoalPeriod.search([
|
||||
('goal.kind', '=', 'sales'),
|
||||
('period', '=', period.id),
|
||||
], limit=1)
|
||||
|
||||
goal = goals[0] if goals else {}
|
||||
|
||||
sales = cls._get_sales_report(dates, currency_id, True)
|
||||
fulfillment = 0
|
||||
value = 0
|
||||
if goal:
|
||||
value = goal.total_amount / 1000
|
||||
if sales:
|
||||
fulfillment = round((sales * 100) / value, 2)
|
||||
print(sales, goal.total_amount, fulfillment)
|
||||
|
||||
month = _date.strftime("%b %Y")
|
||||
res = {
|
||||
'value': value,
|
||||
'args': {'legend': f'{fulfillment}%'},
|
||||
'header_meta': month,
|
||||
'desc': 'In thousands',
|
||||
'desc_meta': currency.code,
|
||||
}
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def report_fulfillment_goal_year(cls, args, ctx=None):
|
||||
pool = Pool()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=6.0.13
|
||||
version=6.0.14
|
||||
depends:
|
||||
party
|
||||
product
|
||||
|
|
Loading…
Reference in New Issue