From 38141a32c0f032635b366f8dd587c46976d08ba3 Mon Sep 17 00:00:00 2001 From: oscar alvarez Date: Thu, 4 May 2023 12:59:07 -0500 Subject: [PATCH] Add fulfillment month --- reports.xml | 8 +++++++ sale.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-- tryton.cfg | 2 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/reports.xml b/reports.xml index 933e59d..8565e0a 100644 --- a/reports.xml +++ b/reports.xml @@ -43,5 +43,13 @@ this repository contains the full copyright notices and license terms. --> True + + Goal Month + sale.sale + card_info + report_fulfillment_goal_month + True + + diff --git a/sale.py b/sale.py index 78c7931..f4d8841 100644 --- a/sale.py +++ b/sale.py @@ -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() diff --git a/tryton.cfg b/tryton.cfg index 6996956..31a1a36 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=6.0.13 +version=6.0.14 depends: party product