def _calc_dates(self, cr, uid, data, context):
    res = {}
    period_length = data["form"]["period_length"]
    if period_length <= 0:
        raise wizard.except_wizard(_("UserError"), _("You must enter a period length that cannot be 0 or below !"))
    start = datetime.date.fromtimestamp(time.mktime(time.strptime(data["form"]["date1"], "%Y-%m-%d")))
    start = DateTime(int(start.year), int(start.month), int(start.day))
    if data["form"]["direction_selection"] == "past":
        for i in range(5)[::-1]:
            stop = start - RelativeDateTime(days=period_length)
            res[str(i)] = {
                "name": str((5 - (i + 1)) * period_length) + "-" + str((5 - i) * period_length),
                "stop": start.strftime("%Y-%m-%d"),
                "start": stop.strftime("%Y-%m-%d"),
            }
            start = stop - RelativeDateTime(days=1)
    else:
        for i in range(5):
            stop = start + RelativeDateTime(days=period_length)
            res[str(5 - (i + 1))] = {
                "name": str((i) * period_length) + "-" + str((i + 1) * period_length),
                "start": start.strftime("%Y-%m-%d"),
                "stop": stop.strftime("%Y-%m-%d"),
            }
            start = stop + RelativeDateTime(days=1)
    return res
示例#2
0
def _calc_dates(self, cr, uid, data, context):
	res = {}
	period_length = data['form']['period_length']
	if period_length<=0:
		raise wizard.except_wizard('UserError', 'You must enter a period length that cannot be 0 or below !')
	start = datetime.date.fromtimestamp(time.mktime(time.strptime(data['form']['date1'],"%Y-%m-%d")))
	start = DateTime(int(start.year),int(start.month),int(start.day))
	if data['form']['direction_selection'] == 'past':
		for i in range(5)[::-1]:
			stop = start - RelativeDateTime(days=period_length)
			res[str(i)] = {
				'name' : str((5-(i+1))*period_length) + '-' + str((5-i)*period_length),
				
				'stop': start.strftime('%Y-%m-%d'),
				'start' : stop.strftime('%Y-%m-%d'),
				}
			start = stop - RelativeDateTime(days=1)
	else:
		for i in range(5):
			stop = start + RelativeDateTime(days=period_length)
			res[str(5-(i+1))] = {
				'name' : str((i)*period_length)+'-'+str((i+1)*period_length),
				'start': start.strftime('%Y-%m-%d'),
				'stop' : stop.strftime('%Y-%m-%d'),
				}
			start = stop + RelativeDateTime(days=1)
	return res
示例#3
0
    def _get_prod_stock_before(self, cr, uid, ids, name, arg, context={}):
        res = {}
        prod_obj = self.pool.get('product.product')

        loc_ids = 11
        for line in self.browse(cr, uid, ids, context=context):
            # print 'fechaxxx: ',line.name
            startf = datetime.datetime.fromtimestamp(
                time.mktime(time.strptime(line.name, "%Y-%m-%d:%H:%M:%S")))
            # print 'ffff: ',startf
            start = DateTime(int(startf.year), 1, 1)
            # end =
            # DateTime(int(startf.year),int(startf.month),int(startf.day))
            end = startf - datetime.timedelta(seconds=1)
            d1 = start.strftime('%Y-%m-%d %H:%M:%S')
            d2 = end.strftime('%Y-%m-%d %H:%M:%S')
            # print 'd1xxxxxxx: ',d1
            # print 'd2yyyyyyy: ',d2
            c = context.copy()
            c.update({'location': loc_ids, 'from_date': d1, 'to_date': d2})
            res.setdefault(line.id, 0.0)
            if line.product_id and line.product_id.id:
                prd = prod_obj.browse(cr, uid, line.product_id.id, context=c)
                res[line.id] = prd.qty_available
        return res
    def _get_prod_stock_before(self, cr, uid, ids, name, arg, context={}):
        res = {}
        prod_obj = self.pool.get('product.product')

        loc_ids = 11
        for line in self.browse(cr, uid, ids, context=context):
            # print 'fechaxxx: ',line.name
            startf = datetime.datetime.fromtimestamp(time.mktime(
                time.strptime(line.name, "%Y-%m-%d:%H:%M:%S")))
            # print 'ffff: ',startf
            start = DateTime(int(startf.year), 1, 1)
            # end =
            # DateTime(int(startf.year),int(startf.month),int(startf.day))
            end = startf - datetime.timedelta(seconds=1)
            d1 = start.strftime('%Y-%m-%d %H:%M:%S')
            d2 = end.strftime('%Y-%m-%d %H:%M:%S')
            # print 'd1xxxxxxx: ',d1
            # print 'd2yyyyyyy: ',d2
            c = context.copy()
            c.update({'location': loc_ids, 'from_date': d1, 'to_date': d2})
            res.setdefault(line.id, 0.0)
            if line.product_id and line.product_id.id:
                prd = prod_obj.browse(cr, uid, line.product_id.id, context=c)
                res[line.id] = prd.qty_available
        return res
    def _get_prod_stock(self, cr, uid, ids, name, arg, context={}):
        res = {}
        prod_obj = self.pool.get('product.product')

        loc_ids = 1
        for line in self.browse(cr, uid, ids, context=context):
            startf = datetime.date.fromtimestamp(time.mktime(time.strptime(line.name,"%Y-%m-%d")))
            start = DateTime(int(startf.year),1,1)
            end = DateTime(int(startf.year),int(startf.month),int(startf.day))
            d1 = start.strftime('%Y-%m-%d %H:%M:%S')
            d2 = end.strftime('%Y-%m-%d %H:%M:%S')
            c = context.copy()
            c.update({'location': loc_ids,'from_date':d1,'to_date':d2})
            res.setdefault(line.id, 0.0)
            if line.product_id and line.product_id.id:
                prd = prod_obj.browse(cr, uid, line.product_id.id,context=c)
                res[line.id] = prd.qty_available
        return res
    def action_print(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}

        data = {}
        data['ids'] = context.get('active_ids', [])
        data['model'] = context.get('active_model', 'ir.ui.menu')
        data['form'] = self.read(cr, uid, ids[0])
        form = data['form']
        if not form['u_check'] and not form['p_check'] and not form['c_check']:
            raise osv.except_osv(_('User Error'),
                                 _('You must check one box !'))
        res = {}
        period_length = data['form']['period_length']
        if period_length <= 0:
            raise osv.except_osv(
                _('UserError'),
                _('You must enter a period length that cannot be 0 or below !')
            )
        start = datetime.date.fromtimestamp(
            time.mktime(time.strptime(data['form']['date_start'], "%Y-%m-%d")))
        start = DateTime(int(start.year), int(start.month), int(start.day))

        for i in range(4)[::-1]:
            stop = start - RelativeDateTime(days=period_length)
            res[str(i)] = {
                'name':
                str((4 - (i + 1)) * period_length) + '-' + str(
                    (4 - i) * period_length),
                'stop':
                start.strftime('%Y-%m-%d'),
                'start':
                stop.strftime('%Y-%m-%d'),
            }
            start = stop - RelativeDateTime(days=1)

        data['form'].update(res)
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'profit.trial.cost',
            'datas': data
        }
def _data_save(self, cr, uid, data, context):
    form = data['form']
    if not form['u_check']  and not form['p_check'] and not form['c_check']:
        raise wizard.except_wizard(_('User Error'), _('You have to check one box !'))    
    res = {}
    period_length = data['form']['period_length']
    if period_length<=0:
        raise wizard.except_wizard(_('UserError'), _('You must enter a period length that cannot be 0 or below !'))
    start = datetime.date.fromtimestamp(time.mktime(time.strptime(data['form']['date_start'],"%Y-%m-%d")))
    start = DateTime(int(start.year),int(start.month),int(start.day))

    for i in range(4)[::-1]:
        stop = start - RelativeDateTime(days=period_length)
        res[str(i)] = {
            'name' : str((4-(i+1))*period_length) + '-' + str((4-i)*period_length),
            
            'stop': start.strftime('%Y-%m-%d'),
            'start' : stop.strftime('%Y-%m-%d'),
            }
        start = stop - RelativeDateTime(days=1)

    return res
示例#8
0
    def _get_stock_invoice(self, cr, uid, ids, name, arg, context={}):
        res = {}
        prod_obj = self.pool.get('product.product')

        loc_ids = 11
        for line in self.browse(cr, uid, ids, context=context):
            res.setdefault(line.id, 0.0)
            if line.date_inv:
                startf = datetime.datetime.fromtimestamp(
                    time.mktime(
                        time.strptime(line.date_inv, "%Y-%m-%d:%H:%M:%S")))
                start = DateTime(int(startf.year), 1, 1)
                end = startf - datetime.timedelta(seconds=1)
                d1 = start.strftime('%Y-%m-%d %H:%M:%S')
                d2 = end.strftime('%Y-%m-%d %H:%M:%S')
                c = context.copy()
                c.update({'location': loc_ids, 'from_date': d1, 'to_date': d2})
                if line.product_id and line.product_id.id:
                    prd = prod_obj.browse(cr,
                                          uid,
                                          line.product_id.id,
                                          context=c)
                    res[line.id] = prd.qty_available
        return res
示例#9
0
    def action_print(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}

        data = {}
        data['ids'] = context.get('active_ids', [])
        data['model'] = context.get('active_model', 'ir.ui.menu')
        data['form'] = self.read(cr, uid, ids[0])
        form = data['form']
        if not form['u_check'] and not form['p_check'] and not form['c_check']:
            raise osv.except_osv(_('User Error'), _(
                'You must check one box !'))
        res = {}
        period_length = data['form']['period_length']
        if period_length <= 0:
            raise osv.except_osv(_('UserError'), _(
                'You must enter a period length that cannot be 0 or below !'))
        start = datetime.date.fromtimestamp(time.mktime(
            time.strptime(data['form']['date_start'], "%Y-%m-%d")))
        start = DateTime(int(start.year), int(start.month), int(start.day))

        for i in range(4)[::-1]:
            stop = start - RelativeDateTime(days=period_length)
            res[str(i)] = {
                'name': str((4 - (i + 1)) * period_length) +
                '-' + str((4 - i) * period_length),

                'stop': start.strftime('%Y-%m-%d'),
                'start': stop.strftime('%Y-%m-%d'),
            }
            start = stop - RelativeDateTime(days=1)

        data['form'].update(res)
        return {'type': 'ir.actions.report.xml',
                'report_name': 'profit.trial.cost',
                'datas': data}
示例#10
0
def test_string_format():
    # Negative years
    t = DateTime(-1,1,1,12,34,56.78)
    assert str(t) == '-0001-01-01 12:34:56.78'

    # Rounding
    t = DateTime(2007,1,1,12,34,56.78)
    assert str(t) == '2007-01-01 12:34:56.78'
    t = DateTime(2011,1,1,12,34,3.42)
    # Note: 3.42 is stored as 3.4199999999999999
    assert str(t) == '2011-01-01 12:34:03.42', str(t)
    assert repr(t).find( '2011-01-01 12:34:03.42') > 0
    assert t.date == '2011-01-01'
    assert t.time == '12:34:03.42'
    t = DateTime(2011,1,1,12,34,3.425)
    # Note: 3.425 is stored as 3.4249999999999998
    assert str(t) == '2011-01-01 12:34:03.43', str(t)
    assert repr(t).find( '2011-01-01 12:34:03.43') > 0
    assert t.date == '2011-01-01'
    assert t.time == '12:34:03.43'
    t = DateTime(2011,1,1,12,34,56.1147)
    # Note: 56.1147 is stored as 56.114699999999999
    assert str(t) == '2011-01-01 12:34:56.11', str(t)
    assert repr(t).find( '2011-01-01 12:34:56.11') > 0
    assert t.date == '2011-01-01'
    assert t.time == '12:34:56.11'
    t = DateTime(2011,1,1,12,34,56.124449)
    # Note: 56.124449 is stored as 56.124448999999998
    assert str(t) == '2011-01-01 12:34:56.12', str(t)

    # Rounding at the end of a minute
    t = DateTimeFromAbsDateTime(733407, 86399)
    assert str(t) == '2008-12-31 23:59:59.00'
    t = DateTimeFromAbsDateTime(733407, 86399.9)
    assert str(t) == '2008-12-31 23:59:59.90'
    t = DateTimeFromAbsDateTime(733407, 86399.99)
    assert str(t) == '2008-12-31 23:59:59.99'
    assert repr(t).find('2008-12-31 23:59:59.99') > 0
    t = DateTimeFromAbsDateTime(733407, 86399.995)
    assert str(t) == '2008-12-31 23:59:59.99'
    assert repr(t).find('2008-12-31 23:59:59.99') > 0
    t = DateTimeFromAbsDateTime(733407, 86399.999)
    assert str(t) == '2008-12-31 23:59:59.99'
    assert repr(t).find('2008-12-31 23:59:59.99') > 0

    print 'String format ok.'

    # .strftime()
    t = DateTime(2015,6,30,23,59,59)
    assert t.strftime('%y-%m-%d') == '15-06-30'
    assert t.strftime('%Y-%m-%d') == '2015-06-30'
    assert t.strftime('%H:%M:%S') == '23:59:59'
    assert t.strftime('%Y-%m-%d %H:%M:%S') == '2015-06-30 23:59:59'

    # .strftime() and unsupported format codes
    try:
        assert t.strftime('%f') == '%f'
    except ValueError:
        # On Windows, a ValueError is raised
        print "Note: dt.strftime('%f') raises a ValueError on Windows"

    # .strftime() and % at the end of the format string
    try:
        assert t.strftime('%') == '%'
    except ValueError:
        # On Windows, a ValueError is raised
        print "Note: dt.strftime('%') raises a ValueError on Windows"

    # .strftime() with leap seconds
    t = DateTime(2015,6,30,23,59,60)
    try:
        assert t.strftime('%Y-%m-%d %H:%M:%S') == '2015-06-30 23:59:60'
    except ValueError:
        # On Windows, a ValueError is raised
        print "Note: dt.strftime('%c') raises a ValueError on Windows for leap seconds"
示例#11
0
def _data_save(self, cr, uid, data, context):
    form = data['form']
    pool = pooler.get_pool(cr.dbname)
    prod_obj = pool.get('product.product')
    line_inv_obj = pool.get('report.profit.invoice')
    inv_ids = []
    res = {}
    
    
    cost_obj = pool.get('costo.inicial')
    inv_obj = pool.get('account.invoice')
    if form['state']=='bydate':
        inv_ids = inv_obj.search(cr,uid,[('date_invoice','>=',form['date_start']), ('date_invoice','<=',form['date_end'])])

    if form['state']=='byinvoice':
        inv_ids.append(form['invoice_id'])

    if form['state']=='some':
        if form['invoice_ids'] and form['invoice_ids'][0]:
            inv_ids.extend(form['invoice_ids'][0][2])

    if form['state']=='none':
        inv_ids = inv_obj.search(cr,uid,[])


    if inv_ids:
        inv_obj.button_reset_cost(cr, uid, inv_ids, context)

    il_ids = line_inv_obj.search(cr,uid,[])

    if il_ids:
        cr.execute('SELECT DISTINCT product_id FROM report_profit_invoice WHERE id in ('+','.join(map(str,il_ids))+')')
        prd_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
        for p_id in prd_ids:
            res[p_id] = []

        for line in line_inv_obj.browse(cr, uid, il_ids):
            dct = {}
            lst_tmp = []
            elem = False
            cost_ids = cost_obj.search(cr,uid,[('default_code','=',line.product_id.default_code)])
            if cost_ids:
                if len(cost_ids)==1:
                    elem=cost_ids[0]
                else:
                    raise wizard.except_wizard('Error','Codigo duplicado en csv importado')

            dct={
                'fecha': line.name,
                'costo': line.acc_cost,
                'cant': line.quantity,
                'tipo': line.invoice_id.type,
                'fact': line.invoice_id.id,
                'comp': line.move_id.id,
                'prod': line.product_id.id,
                'linea': line.line_id.id,
                'exist': line.stock,                
                'elem': elem
            }

            lst_tmp = res[line.product_id.id]
            lst_tmp.append(dct)
            res[line.product_id.id] = lst_tmp
               


    for pd_id in res.keys():
        dct = {}
        lst_tmp = []
        startf = datetime.date.fromtimestamp(time.mktime(time.strptime(time.strftime('%Y-%m-%d'),"%Y-%m-%d")))
        start = DateTime(int(startf.year),1,1)
        d1 = start.strftime('%Y-%m-%d')
        if res[pd_id] and res[pd_id][0]['elem']:
            c_ini = cost_obj.browse(cr, uid, res[pd_id][0]['elem'])
            dct={
                'fecha': d1,
                'costo': float(c_ini.standard_price.replace(',','')) or 0.0,
                'cant': float(c_ini.product_qty.replace(',','')) or 0.0,
                'tipo': u'cos_ini'
            }
            lst_tmp = res[pd_id]
            lst_tmp.append(dct)
            res[pd_id] = lst_tmp


    print 'ressssss: ',res            
    return {}
示例#12
0
文件: test.py 项目: shahwangithub/lib
assert int(d1 + d2) == 0
assert int(d2 + d1) == 0
assert int(d1 - d2) == 86400 * 2, d1 - d2
assert int(d2 - d1) == -86400 * 2, d2 - d1

try:
    d2 * d1
except TypeError:
    pass
else:
    raise TypeError('DateTimeDelta*DateTimeDelta should not work')

# .strftime()
d = DateTimeDelta(30, 1, 2, 3)
assert d.strftime('%d %H:%M:%S') == '30 01:02:03'

# .strftime() and days out of typical month range
d = DateTimeDelta(32, 1, 2, 3)
try:
    assert d.strftime('%d %H:%M:%S') == '32 01:02:03'
except ValueError:
    # On Windows, a ValueError is raised
    print "Note: dtd.strftime('%S') raises a ValueError on Windows with day > 31"

# .strftime() and unsupported format codes
d = DateTimeDelta(30, 1, 2, 3)
try:
    assert d.strftime('%f') == '%f'
except ValueError:
    # On Windows, a ValueError is raised
assert int(d1 + d2) == 0
assert int(d2 + d1) == 0
assert int(d1 - d2) == 86400 * 2, d1 - d2
assert int(d2 - d1) == -86400 * 2, d2 - d1

try:
    d2 * d1
except TypeError:
    pass
else:
    raise TypeError('DateTimeDelta*DateTimeDelta should not work')

# .strftime()
d = DateTimeDelta(30,1,2,3)
assert d.strftime('%d %H:%M:%S') == '30 01:02:03'

# .strftime() and days out of typical month range
d = DateTimeDelta(32,1,2,3)
try:
    assert d.strftime('%d %H:%M:%S') == '32 01:02:03'
except ValueError:
    # On Windows, a ValueError is raised
    print "Note: dtd.strftime('%S') raises a ValueError on Windows with day > 31"

# .strftime() and unsupported format codes
d = DateTimeDelta(30,1,2,3)
try:
    assert d.strftime('%f') == '%f'
except ValueError:
    # On Windows, a ValueError is raised