fix setup
This commit is contained in:
parent
a05df151f4
commit
6aa964e4df
|
@ -4,11 +4,10 @@
|
|||
import calendar
|
||||
from decimal import Decimal
|
||||
from trytond.pool import Pool
|
||||
from trytond.model import Workflow, ModelView, ModelSQL, fields
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.wizard import Wizard, StateView, Button, StateAction, StateReport
|
||||
from trytond.report import Report
|
||||
from sql import Null, Literal, Column, With
|
||||
# from trytond.report import Report
|
||||
from sql import Null, Literal, With
|
||||
from sql.aggregate import Sum, Min
|
||||
from sql.conditionals import Case
|
||||
from trytond.transaction import Transaction
|
||||
|
@ -16,16 +15,9 @@ from trytond.i18n import lazy_gettext
|
|||
from itertools import tee, zip_longest
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from sql.functions import CurrentTimestamp, DateTrunc, Extract, Trunc
|
||||
from sql.operators import Concat
|
||||
from sql.operators import Concat, Between
|
||||
from .goal import KIND, TYPE
|
||||
|
||||
type_dict = {
|
||||
'monthly': Extract('MONTH', ''),
|
||||
'bimonthly': Trunc((Extract('MONTH', '')+1)/2),
|
||||
'quarterly': Extract('QUARTER', ''),
|
||||
'annual': Extract('YEAR', ''),
|
||||
}
|
||||
|
||||
_ZERO = Decimal(0)
|
||||
|
||||
|
||||
|
@ -65,106 +57,6 @@ class Abstract(ModelSQL):
|
|||
lazy_gettext("sale.msg_sale_reporting_currency_digits")),
|
||||
'get_currency_digits')
|
||||
|
||||
@classmethod
|
||||
def table_query(cls):
|
||||
from_item, tables, withs = cls._joins()
|
||||
print(from_item.select(*cls._columns(tables, withs),
|
||||
where=cls._where(tables, withs),
|
||||
group_by=cls._group_by(tables, withs),
|
||||
with_=withs.values()))
|
||||
return from_item.select(*cls._columns(tables, withs),
|
||||
where=cls._where(tables, withs),
|
||||
group_by=cls._group_by(tables, withs),
|
||||
with_=withs.values())
|
||||
|
||||
@classmethod
|
||||
def _joins(cls):
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
Currency = pool.get('currency.currency')
|
||||
Line = pool.get('account.invoice.line')
|
||||
Invoice = pool.get('account.invoice')
|
||||
|
||||
tables = {}
|
||||
tables['line'] = line = Line.__table__()
|
||||
tables['line.invoice'] = invoice = Invoice.__table__()
|
||||
tables['line.invoice.company'] = company = Company.__table__()
|
||||
|
||||
withs = {}
|
||||
currency_invoice = With(query=Currency.currency_rate_sql())
|
||||
withs['currency_invoice'] = currency_invoice
|
||||
currency_company = With(query=Currency.currency_rate_sql())
|
||||
withs['currency_company'] = currency_company
|
||||
|
||||
from_item = (line
|
||||
.join(invoice, condition=line.invoice == invoice.id)
|
||||
.join(currency_invoice,
|
||||
condition=(invoice.currency == currency_invoice.currency)
|
||||
& (currency_invoice.start_date <= invoice.invoice_date)
|
||||
& ((currency_invoice.end_date == Null)
|
||||
| (currency_invoice.end_date >= invoice.invoice_date))
|
||||
)
|
||||
.join(company, condition=invoice.company == company.id)
|
||||
.join(currency_company,
|
||||
condition=(company.currency == currency_company.currency)
|
||||
& (currency_company.start_date <= invoice.invoice_date)
|
||||
& ((currency_company.end_date == Null)
|
||||
| (currency_company.end_date >= invoice.invoice_date))
|
||||
))
|
||||
return from_item, tables, withs
|
||||
|
||||
@classmethod
|
||||
def _columns(cls, tables, withs):
|
||||
line = tables['line']
|
||||
invoice = tables['line.invoice']
|
||||
currency_company = withs['currency_company']
|
||||
currency_invoice = withs['currency_invoice']
|
||||
|
||||
quantity = line.quantity
|
||||
amount_achieved = cls.amount_achieved.sql_cast(
|
||||
Sum(quantity * line.unit_price
|
||||
* currency_company.rate / currency_invoice.rate))
|
||||
return [
|
||||
cls._column_id(tables, withs).as_('id'),
|
||||
Literal(0).as_('create_uid'),
|
||||
CurrentTimestamp().as_('create_date'),
|
||||
cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
|
||||
cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
|
||||
invoice.company.as_('company'),
|
||||
amount_achieved.as_('amount_achieved'),
|
||||
Sum(quantity).as_('quantity'),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _column_id(cls, tables, withs):
|
||||
line = tables['line']
|
||||
return Min(line.id)
|
||||
|
||||
@classmethod
|
||||
def _group_by(cls, tables, withs):
|
||||
invoice = tables['line.invoice']
|
||||
return [invoice.company]
|
||||
|
||||
@classmethod
|
||||
def _having(cls, tables, withs):
|
||||
having = (0 == 0)
|
||||
return having
|
||||
|
||||
@classmethod
|
||||
def _where(cls, tables, withs):
|
||||
context = Transaction().context
|
||||
invoice = tables['line.invoice']
|
||||
|
||||
where = invoice.company == context.get('company')
|
||||
where &= invoice.state.in_(cls._invoice_states())
|
||||
from_date = context.get('from_date')
|
||||
if from_date:
|
||||
where &= invoice.invoice_date >= from_date
|
||||
to_date = context.get('to_date')
|
||||
if to_date:
|
||||
where &= invoice.invoice_date <= to_date
|
||||
return where
|
||||
|
||||
# @classmethod
|
||||
# def _column_amount_achieved(cls, tables, withs, sign):
|
||||
# move = tables['move']
|
||||
|
@ -174,10 +66,6 @@ class Abstract(ModelSQL):
|
|||
# sign * cls.revenue.sql_cast(move.quantity) * move.unit_price
|
||||
# * currency_company.rate / currency.rate))
|
||||
|
||||
@classmethod
|
||||
def _invoice_states(cls):
|
||||
return ['posted', 'paid', 'validated']
|
||||
|
||||
@property
|
||||
def time_series_all(self):
|
||||
delta = self._period_delta()
|
||||
|
@ -318,56 +206,130 @@ class GoalIndicatorMixin(object):
|
|||
period = fields.Numeric('Period')
|
||||
year_period = fields.Char('Year Period')
|
||||
|
||||
@classmethod
|
||||
def table_query(cls):
|
||||
from_item, tables, withs = cls._joins()
|
||||
|
||||
return from_item.select(*cls._columns(tables, withs),
|
||||
where=cls._where(tables, withs),
|
||||
group_by=cls._group_by(tables, withs),
|
||||
with_=withs.values())
|
||||
|
||||
@classmethod
|
||||
def _joins(cls):
|
||||
from_item, tables, withs = super(GoalIndicatorMixin, cls)._joins()
|
||||
pool = Pool()
|
||||
Indicator = pool.get('sale.indicator')
|
||||
GoalLine = pool.get('sale.goal.line')
|
||||
Goal = pool.get('sale.goal')
|
||||
Company = pool.get('company.company')
|
||||
Currency = pool.get('currency.currency')
|
||||
Line = pool.get('account.invoice.line')
|
||||
Invoice = pool.get('account.invoice')
|
||||
# Goal = pool.get('sale.goal')
|
||||
Product = pool.get('product.product')
|
||||
TemplateCategory = pool.get('product.template-product.category.all')
|
||||
|
||||
tables['line.product'] = product = Product.__table__()
|
||||
tables['line.product.template_category'] = template_category = TemplateCategory.__table__()
|
||||
tables = {}
|
||||
tables['sale.indicator'] = indicator = Indicator.__table__()
|
||||
tables['sale.goal.line'] = goal_line = GoalLine.__table__()
|
||||
tables['sale.goal'] = goal = Goal.__table__()
|
||||
invoice = tables['line.invoice']
|
||||
line = tables['line']
|
||||
# tables['sale.goal'] = goal = Goal.__table__()
|
||||
tables['line'] = line = Line.__table__()
|
||||
tables['line.invoice'] = invoice = Invoice.__table__()
|
||||
tables['line.invoice.company'] = company = Company.__table__()
|
||||
tables['line.product'] = product = Product.__table__()
|
||||
tables['line.product.template_category'] = template_category = TemplateCategory.__table__()
|
||||
|
||||
withs = {}
|
||||
currency_invoice = With(query=Currency.currency_rate_sql())
|
||||
withs['currency_invoice'] = currency_invoice
|
||||
currency_company = With(query=Currency.currency_rate_sql())
|
||||
withs['currency_company'] = currency_company
|
||||
|
||||
context = Transaction().context
|
||||
condition_between = Between(invoice.invoice_date, goal_line.start_date, goal_line.end_date)
|
||||
|
||||
kind = context['kind']
|
||||
from_item = (goal_line.join(indicator, condition=goal_line.id == indicator.goal_line))
|
||||
|
||||
if kind == 'salesman':
|
||||
from_item = (from_item
|
||||
.join(indicator, condition=indicator.salesman == invoice.salesman))
|
||||
.join(invoice, condition=(indicator.salesman == invoice.salesman) & (condition_between))
|
||||
.join(line, condition=invoice.id == line.invoice))
|
||||
elif kind == 'category':
|
||||
from_item = (from_item
|
||||
.join(product, condition=line.product == product.id)
|
||||
.join(template_category,
|
||||
condition=product.template == template_category.template)
|
||||
.join(indicator,
|
||||
condition=indicator.category == template_category.id))
|
||||
.join(template_category, condition=indicator.category == template_category.id)
|
||||
.join(product, condition=product.template == template_category.template)
|
||||
.join(line, condition=product.id == line.product)
|
||||
.join(invoice, condition=((line.invoice == invoice.id) & condition_between)))
|
||||
elif kind == 'product':
|
||||
from_item = (from_item
|
||||
.join(indicator, condition=indicator.product == line.product))
|
||||
from_item = (from_item
|
||||
.join(goal_line, condition=goal_line.id == indicator.goal_line))
|
||||
.join(line, condition=indicator.product == line.product)
|
||||
.join(invoice, condition=(line.invoice == invoice.id)
|
||||
& condition_between))
|
||||
|
||||
from_item=(from_item.join(currency_invoice,
|
||||
condition=(invoice.currency == currency_invoice.currency)
|
||||
& (currency_invoice.start_date <= invoice.invoice_date)
|
||||
& ((currency_invoice.end_date == Null)
|
||||
| (currency_invoice.end_date >= invoice.invoice_date)))
|
||||
.join(company, condition=invoice.company == company.id)
|
||||
.join(currency_company,
|
||||
condition=(company.currency == currency_company.currency)
|
||||
& (currency_company.start_date <= invoice.invoice_date)
|
||||
& ((currency_company.end_date == Null)
|
||||
| (currency_company.end_date >= invoice.invoice_date))
|
||||
))
|
||||
return from_item, tables, withs
|
||||
|
||||
@classmethod
|
||||
def _columns(cls, tables, withs):
|
||||
indicator = tables['sale.indicator']
|
||||
line = tables['line']
|
||||
invoice = tables['line.invoice']
|
||||
indicator = tables['sale.indicator']
|
||||
currency_company = withs['currency_company']
|
||||
currency_invoice = withs['currency_invoice']
|
||||
type_year_period = cls.year_period.sql_type().base
|
||||
columns_ = [
|
||||
|
||||
quantity = line.quantity
|
||||
amount_achieved = cls.amount_achieved.sql_cast(
|
||||
Sum(quantity * line.unit_price
|
||||
* currency_company.rate / currency_invoice.rate))
|
||||
return [
|
||||
# cls._column_id(tables, withs).as_('id'),
|
||||
indicator.id.as_('id'),
|
||||
indicator.id.as_('indicator'),
|
||||
Literal(0).as_('create_uid'),
|
||||
CurrentTimestamp().as_('create_date'),
|
||||
cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
|
||||
cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
|
||||
invoice.company.as_('company'),
|
||||
Extract('YEAR', invoice.invoice_date).as_('year'),
|
||||
cls._column_date(tables, withs).as_('period'),
|
||||
Concat(Extract('YEAR', invoice.invoice_date).cast(type_year_period),
|
||||
cls._column_date(tables, withs).cast(type_year_period)).as_('year_period'),
|
||||
indicator.amount.as_('amount_target'),
|
||||
Concat(Extract('YEAR', invoice.invoice_date).cast(type_year_period), cls._column_date(tables, withs).cast(type_year_period)).as_('year_period')
|
||||
]
|
||||
return super(GoalIndicatorMixin, cls)._columns(tables, withs) + columns_
|
||||
amount_achieved.as_('amount_achieved'),
|
||||
Sum(quantity).as_('quantity'),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _where(cls, tables, withs):
|
||||
context = Transaction().context
|
||||
invoice = tables['line.invoice']
|
||||
goal_line = tables['sale.goal.line']
|
||||
|
||||
type = context.get('type')
|
||||
where = invoice.company == context.get('company')
|
||||
where &= invoice.state.in_(cls._invoice_states())
|
||||
where &= goal_line.type == type
|
||||
from_date = context.get('from_date')
|
||||
|
||||
if from_date:
|
||||
where &= goal_line.start_date >= from_date
|
||||
where &= invoice.invoice_date >= from_date
|
||||
to_date = context.get('to_date')
|
||||
if to_date:
|
||||
where &= goal_line.end_date <= to_date
|
||||
where &= invoice.invoice_date <= to_date
|
||||
return where
|
||||
|
||||
@classmethod
|
||||
def _column_date(cls, tables, withs):
|
||||
|
@ -391,41 +353,23 @@ class GoalIndicatorMixin(object):
|
|||
indicator = tables['sale.indicator']
|
||||
invoice = tables['line.invoice']
|
||||
type_year_period = cls.year_period.sql_type().base
|
||||
group_by_ = [
|
||||
group_by = [
|
||||
indicator.id,
|
||||
Extract('YEAR', invoice.invoice_date),
|
||||
cls._column_date(tables, withs),
|
||||
indicator.amount.as_('amount_target'),
|
||||
indicator.amount,
|
||||
invoice.company,
|
||||
Concat(Extract('YEAR', invoice.invoice_date).cast(type_year_period), cls._column_date(tables, withs).cast(type_year_period))
|
||||
]
|
||||
return super(GoalIndicatorMixin, cls)._group_by(tables, withs) + group_by_
|
||||
return group_by
|
||||
|
||||
@classmethod
|
||||
def _having(cls, tables, withs):
|
||||
having = super(GoalIndicatorMixin, cls)._having(tables, withs)
|
||||
|
||||
having &= (0 == 0)
|
||||
return having
|
||||
def _invoice_states(cls):
|
||||
return ['posted', 'paid', 'validated']
|
||||
|
||||
# def get_rec_name(self, name):
|
||||
# return self.indicator.rec_name
|
||||
|
||||
@classmethod
|
||||
def _where(cls, tables, withs):
|
||||
where = super(GoalIndicatorMixin, cls)._where(tables, withs)
|
||||
context = Transaction().context
|
||||
invoice = tables['line.invoice']
|
||||
|
||||
where = invoice.company == context.get('company')
|
||||
where &= invoice.state.in_(cls._invoice_states())
|
||||
from_date = context.get('from_date')
|
||||
if from_date:
|
||||
where &= invoice.invoice_date >= from_date
|
||||
to_date = context.get('to_date')
|
||||
if to_date:
|
||||
where &= invoice.invoice_date <= to_date
|
||||
return where
|
||||
|
||||
|
||||
class GoalIndicator(GoalIndicatorMixin, Abstract, ModelView):
|
||||
"Goal Reporting per Indicator"
|
||||
|
|
BIN
sale_daily.ods
BIN
sale_daily.ods
Binary file not shown.
29
setup.py
29
setup.py
|
@ -6,10 +6,7 @@ from setuptools import setup
|
|||
import re
|
||||
import os
|
||||
import io
|
||||
try:
|
||||
from configparser import ConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import ConfigParser
|
||||
from configparser import ConfigParser
|
||||
|
||||
MODULE = 'sale_goal'
|
||||
PREFIX = 'trytonpsk'
|
||||
|
@ -90,25 +87,13 @@ setup(name=name,
|
|||
'Intended Audience :: Financial and Insurance Industry',
|
||||
'Intended Audience :: Legal Industry',
|
||||
'License :: OSI Approved :: GNU General Public License (GPL)',
|
||||
'Natural Language :: Bulgarian',
|
||||
'Natural Language :: Catalan',
|
||||
'Natural Language :: Chinese (Simplified)',
|
||||
'Natural Language :: Czech',
|
||||
'Natural Language :: Dutch',
|
||||
'Natural Language :: English',
|
||||
'Natural Language :: French',
|
||||
'Natural Language :: German',
|
||||
'Natural Language :: Hungarian',
|
||||
'Natural Language :: Italian',
|
||||
'Natural Language :: Portuguese (Brazilian)',
|
||||
'Natural Language :: Russian',
|
||||
'Natural Language :: Slovenian',
|
||||
'Natural Language :: Spanish',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Programming Language :: Python :: 3.7',
|
||||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.9',
|
||||
'Programming Language :: Python :: Implementation :: CPython',
|
||||
'Programming Language :: Python :: Implementation :: PyPy',
|
||||
'Topic :: Office/Business',
|
||||
|
@ -125,8 +110,4 @@ setup(name=name,
|
|||
test_suite='tests',
|
||||
test_loader='trytond.test_loader:Loader',
|
||||
tests_require=tests_require,
|
||||
use_2to3=True,
|
||||
convert_2to3_doctests=[
|
||||
'tests/scenario.rst',
|
||||
],
|
||||
)
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree keyword_open="1">
|
||||
<field name="indicator" expand="1"/>
|
||||
<!-- <field name="year"/> -->
|
||||
<!-- <field name="period"/>
|
||||
<field name="year_period"/> -->
|
||||
<field name="amount_target" sum="Target Amount" symbol="currency"/>
|
||||
<field name="amount_achieved" sum="Achieved Amount" symbol="currency"/>
|
||||
<!-- <field name="percentage" sum="%" /> -->
|
||||
|
|
Loading…
Reference in New Issue