Add fulfillment month

This commit is contained in:
oscar alvarez 2023-05-04 12:59:07 -05:00
parent e4777b8f60
commit 38141a32c0
3 changed files with 69 additions and 3 deletions

View File

@ -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>

62
sale.py
View File

@ -364,7 +364,7 @@ class Sale(metaclass=PoolMeta):
user = User(ctx.get('user'))
shop = Shop(args['shop']['id'])
attribs_del = ['id', 'amount', 'unit_price_w_tax', 'total_amount', 'discount']
attribs_del = ['id', 'amount', 'unit_price_w_tax', 'total_amount', 'discount']
for v in args['lines']:
keys = v.keys()
for k in attribs_del:
@ -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()

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.13
version=6.0.14
depends:
party
product