Exemple #1
0
    def testModelHref(self):
        "Test model href"
        pool = Pool()
        UrlObject = pool.get('test.urlobject')
        db_name = Transaction().database.name

        self.assertEqual(UrlObject.__href__,
            '%s/#%s/model/test.urlobject' % (
                http_host(), urllib.parse.quote(db_name)))

        self.assertEqual(UrlObject(1).__href__,
            '%s/#%s/model/test.urlobject/1' % (
                http_host(), urllib.parse.quote(db_name)))
Exemple #2
0
    def testWizardHref(self):
        "Test wizard href"
        pool = Pool()
        UrlWizard = pool.get('test.test_wizard', type='wizard')
        db_name = Transaction().database.name

        self.assertEqual(UrlWizard.__href__,
            '%s/#%s/wizard/test.test_wizard' % (
                http_host(), urllib.parse.quote(db_name)))
Exemple #3
0
 def get_context(cls, records, data):
     pool = Pool()
     Lang = pool.get('ir.lang')
     context = super(EmailResetPassword, cls).get_context(records, data)
     lang = Lang.get()
     context['host'] = host()
     context['http_host'] = http_host()
     context['database'] = Transaction().database.name
     context['expire'] = lang.strftime(records[0].password_reset_expire,
                                       format=lang.date + ' %H:%M:%S')
     return context
Exemple #4
0
 def get_context(cls, records, header, data):
     context = super().get_context(records, header, data)
     context['host'] = host()
     context['http_host'] = http_host()
     context['database'] = Transaction().database.name
     expire_delay = (records[0].password_reset_expire -
                     datetime.datetime.now())
     # Use a precision of minutes
     expire_delay = datetime.timedelta(days=expire_delay.days,
                                       minutes=round(expire_delay.seconds /
                                                     60))
     context['expire_delay'] = expire_delay
     return context
    def prepare(cls, data):
        pool = Pool()
        Template = pool.get('product.template')
        Product = pool.get('product.product')
        Move = pool.get('stock.move')
        Location = pool.get('stock.location')
        Company = pool.get('company.company')

        try:
            Production = pool.get('production')
        except:
            Production = None
        try:
            Lot = pool.get('stock.lot')
        except:
            Lot = None

        move = Move.__table__()
        cursor = Transaction().connection.cursor()

        t_context = Transaction().context
        company_id = t_context.get('company')
        from_date = data.get('from_date') or datetime.min.date()
        to_date = data.get('to_date') or datetime.max.date()
        warehouse = Location(data.get('warehouse'))

        parameters = {}
        parameters['from_date'] = from_date
        parameters['to_date'] = to_date
        parameters['warehouse'] = warehouse.rec_name
        parameters['show_date'] = True if data.get('from_date') else False
        parameters['production'] = True if Production else False
        parameters['lot'] = True if Lot else False
        parameters['base_url'] = '%s/#%s' % (http_host(),
                                             Transaction().database.name)
        parameters['company'] = DualRecord(Company(company_id))

        # Locations
        locations = [
            l.id
            for l in Location.search([('parent', 'child_of', [warehouse.id])])
        ]
        location_suppliers = [
            l.id for l in Location.search([('type', '=', 'supplier')])
        ]
        location_customers = [
            l.id for l in Location.search([('type', '=', 'customer')])
        ]
        location_lost_founds = [
            l.id for l in Location.search([('type', '=', 'lost_found')])
        ]
        if Production:
            location_productions = [
                l.id for l in Location.search([('type', '=', 'production')])
            ]

        keys = ()
        if data.get('model') == 'product.template':
            grouping = ('product', )
            for template in Template.browse(data['ids']):
                for product in template.products:
                    keys += ((product, None), )
        elif data.get('model') == 'product.product':
            grouping = ('product', )
            for product in Product.browse(data['ids']):
                keys += ((product, None), )
        elif data.get('model') == 'stock.lot':
            grouping = ('product', 'lot')
            Lot = pool.get('stock.lot')
            for lot in Lot.browse(data['ids']):
                keys += ((lot.product, lot), )

        def compute_quantites(sql_where):
            Uom = Pool().get('product.uom')

            query = move.select(move.id.as_('move_id'),
                                where=sql_where,
                                order_by=move.effective_date.desc)
            cursor.execute(*query)
            move_ids = [m[0] for m in cursor.fetchall()]
            moves = Move.browse(move_ids)
            total = sum([
                Uom.compute_qty(m.uom, m.quantity, m.product.default_uom, True)
                for m in moves
            ])
            moves = [DualRecord(m) for m in moves]
            return total, moves

        records = []
        for key in keys:
            product = key[0]
            lot = key[1]

            # Initial stock
            context = {}
            context['stock_date_end'] = from_date
            with Transaction().set_context(context):
                pbl = Product.products_by_location(
                    [warehouse.id],
                    with_childs=True,
                    grouping_filter=([product.id], ),
                    grouping=grouping)
            key = ((warehouse.id, product.id, lot.id) if lot else
                   (warehouse.id, product.id))
            initial_stock = pbl.get(key, 0)

            sql_common_where = ((move.product == product.id)
                                & (move.effective_date >= from_date)
                                & (move.effective_date <= to_date)
                                & (move.state == 'done') &
                                (move.company == company_id))
            if lot:
                sql_common_where &= (move.lot == lot.id)

            # supplier_incommings from_location = supplier
            sql_where = (sql_common_where
                         & (move.from_location.in_(location_suppliers))
                         & (move.to_location.in_(locations)))
            supplier_incommings_total, supplier_incommings = compute_quantites(
                sql_where)

            # supplier_returns: to_location = supplier
            sql_where = (sql_common_where
                         & (move.to_location.in_(location_suppliers))
                         & (move.from_location.in_(locations)))
            supplier_returns_total, supplier_returns = compute_quantites(
                sql_where)

            # customer_outgoing: to_location = customer
            sql_where = (sql_common_where
                         & (move.to_location.in_(location_customers))
                         & (move.from_location.in_(locations)))
            customer_outgoings_total, customer_outgoings = compute_quantites(
                sql_where)

            # customer_return: from_location = customer
            sql_where = (sql_common_where
                         & (move.from_location.in_(location_customers))
                         & (move.to_location.in_(locations)))
            customer_returns_total, customer_returns = compute_quantites(
                sql_where)

            production_outs_total = 0
            production_ins_total = 0
            if Production:
                # production_outs: to_location = production
                sql_where = (sql_common_where
                             & (move.from_location.in_(location_productions))
                             & (move.to_location.in_(locations)))
                production_outs_total, production_outs = compute_quantites(
                    sql_where)

                # production_ins: from_location = production
                sql_where = (sql_common_where
                             & (move.to_location.in_(location_productions))
                             & (move.from_location.in_(locations)))
                production_ins_total, production_ins = compute_quantites(
                    sql_where)

            # inventory
            sql_where = (sql_common_where
                         & (move.from_location.in_(location_lost_founds))
                         & (move.to_location.in_(locations)))
            lost_found_from_total, lost_found_from = compute_quantites(
                sql_where)

            sql_where = (sql_common_where
                         & (move.to_location.in_(location_lost_founds))
                         & (move.from_location.in_(locations)))
            lost_found_to_total, lost_found_to = compute_quantites(sql_where)

            # Entries from outside warehouse
            locations_in_out = (locations + location_lost_founds +
                                location_suppliers + location_customers)
            if Production:
                locations_in_out += location_productions

            sql_where = (sql_common_where
                         & (~move.from_location.in_(locations_in_out))
                         & (move.to_location.in_(locations)))
            in_to_total, in_to = compute_quantites(sql_where)

            # Outputs from our warehouse
            sql_where = (sql_common_where
                         & (move.from_location.in_(locations))
                         & (~move.to_location.in_(locations_in_out)))
            out_to_total, out_to = compute_quantites(sql_where)

            records.append({
                'product':
                DualRecord(product),
                'lot':
                DualRecord(lot),
                'initial_stock':
                initial_stock,
                'supplier_incommings_total':
                supplier_incommings_total,
                'supplier_incommings':
                supplier_incommings,
                'supplier_returns_total':
                (-supplier_returns_total if supplier_returns_total else 0),
                'supplier_returns':
                supplier_returns,
                'customer_outgoings_total':
                (-customer_outgoings_total if customer_outgoings_total else 0),
                'customer_outgoings':
                customer_outgoings,
                'customer_returns_total':
                customer_returns_total,
                'customer_returns':
                customer_returns,
                'production_outs_total':
                (production_outs_total if Production else 0),
                'production_outs':
                production_outs if Production else 0,
                'production_ins_total':
                (-production_ins_total if Production else 0),
                'production_ins':
                production_ins if Production else 0,
                'lost_found_total':
                lost_found_from_total - lost_found_to_total,
                'lost_found_from_total':
                lost_found_from_total,
                'lost_found_from':
                lost_found_from,
                'lost_found_to_total':
                (-lost_found_to_total if lost_found_to_total else 0),
                'lost_found_to':
                lost_found_to,
                'in_to_total':
                in_to_total if in_to_total else 0,
                'in_to':
                in_to,
                'out_to_total':
                -out_to_total if out_to_total else 0,
                'out_to':
                out_to,
                'total':
                (initial_stock + supplier_incommings_total +
                 (-supplier_returns_total) + (-customer_outgoings_total) +
                 customer_returns_total + production_outs_total +
                 (-production_ins_total) +
                 (lost_found_from_total - lost_found_to_total) + in_to_total +
                 (-out_to_total)),
            })
        return records, parameters
Exemple #6
0
import logging
import string
from urllib.parse import quote, urljoin

from sql.aggregate import Count

from trytond.config import config
from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import Pool
from trytond.tools import grouped_slice, reduce_ids
from trytond.transaction import Transaction
from trytond.url import http_host
from trytond.wsgi import Base64Converter

ALPHABET = string.digits + string.ascii_lowercase
URL_BASE = config.get('web', 'shortener_base', default=http_host())
logger = logging.getLogger(__name__)


class ShortenedURL(ModelSQL, ModelView):
    "Short URL"
    __name__ = 'web.shortened_url'

    shortened_url = fields.Function(fields.Char("Shortened URL"), 'get_url')
    redirect_url = fields.Char("Redirect URL", readonly=True, required=True)
    record = fields.Reference("Record", selection='get_models', readonly=True)
    method = fields.Selection('get_methods', "Method", readonly=True)
    count = fields.Function(fields.Integer("Click Count"), 'get_count')

    @classmethod
    def get_url(cls, shortened_urls, name):
Exemple #7
0
from trytond.pool import Pool
from trytond.pyson import Eval
from trytond.report import Report, get_email
from trytond.sendmail import SMTPDataManager, sendmail_transactional
from trytond.tools import grouped_slice
from trytond.tools.email_ import set_from_header
from trytond.transaction import Transaction
from trytond.url import http_host
from trytond.wizard import Button, StateTransition, StateView, Wizard

from .exceptions import TemplateError

if not config.get('html', 'plugins-marketing.email.message-content'):
    config.set('html', 'plugins-marketing.email.message-content', 'fullpage')

URL_BASE = config.get('marketing', 'email_base', default=http_host())
URL_OPEN = urljoin(URL_BASE, '/m/empty.gif')


def _formataddr(name, email):
    if name:
        name = str(Header(name, 'utf-8'))
    return formataddr((name, email))


def _add_params(url, **params):
    parts = urlsplit(url)
    query = parse_qsl(parts.query)
    for key, value in sorted(params.items()):
        query.append((key, value))
    parts = list(parts)
    def prepare(cls, data):
        pool = Pool()
        Product = pool.get('product.product')
        Company = pool.get('company.company')
        Production = pool.get('production')

        try:
            Lot = pool.get('stock.lot')
        except:
            Lot = None

        t_context = Transaction().context
        company_id = t_context.get('company')
        from_date = data.get('from_date') or datetime.min.date()
        to_date = data.get('to_date') or datetime.max.date()

        requested_product = Product(data['product'])
        direction = data['direction']
        lot = Lot(data['lot']) if data.get('lot') else None

        parameters = {}
        parameters['direction'] = direction
        parameters['from_date'] = from_date
        parameters['to_date'] = to_date
        parameters['show_date'] = bool(data.get('from_date'))
        parameters['requested_product'] = requested_product
        parameters['lot'] = Lot(data['lot']) if data.get('lot') else None
        parameters['base_url'] = '%s/#%s' % (http_host(),
                                             Transaction().database.name)
        parameters['company'] = Company(company_id)

        records = OrderedDict()

        if direction == 'backward':
            domain = [
                ('outputs.product', '=', requested_product),
                ('outputs.effective_date', '>=', from_date),
                ('outputs.effective_date', '<=', to_date),
                ('outputs.state', '=', 'done'),
                ('company', '=', company_id),
            ]
            if lot:
                domain += [('outputs.lot', '=', lot)]
        else:
            domain = [
                ('inputs.product', '=', requested_product),
                ('inputs.effective_date', '>=', from_date),
                ('inputs.effective_date', '<=', to_date),
                ('inputs.state', '=', 'done'),
                ('company', '=', company_id),
            ]
            if lot:
                domain += [('inputs.lot', '=', lot)]

        productions = Production.search(domain)

        records = {}
        for production in productions:
            res = production.mass_balance_report_data(requested_product,
                                                      direction, lot)

            for key, values in res.items():
                if not records.get(key):
                    records.setdefault(key, {})
                for k, v in values.items():
                    if k.endswith('_uom'):
                        records[key][k] = v
                    elif k in records[key]:
                        records[key][k] += v
                    else:
                        records[key][k] = v
        return records, parameters