本文整理汇总了Python中trytond.tools.grouped_slice函数的典型用法代码示例。如果您正苦于以下问题:Python grouped_slice函数的具体用法?Python grouped_slice怎么用?Python grouped_slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grouped_slice函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write
def write(cls, *args):
pool = Pool()
Purchase = pool.get('purchase.purchase')
PurchaseLine = pool.get('purchase.line')
Sale = pool.get('sale.sale')
SaleLine = pool.get('sale.line')
super(ShipmentDrop, cls).write(*args)
cls._set_move_planned_date(sum(args[::2], []))
actions = iter(args)
for shipments, values in zip(actions, actions):
if values.get('state', '') not in ('done', 'cancel'):
continue
with Transaction().set_context(_check_access=False):
move_ids = [m.id for s in shipments for m in s.customer_moves]
sale_lines = []
for sub_moves in grouped_slice(move_ids):
sale_lines += SaleLine.search([
('moves', 'in', list(sub_moves)),
])
sales = list(set(l.sale for l in sale_lines or []))
Sale.process(sales)
move_ids = [m.id for s in shipments for m in s.supplier_moves]
purchase_lines = []
for sub_moves in grouped_slice(move_ids):
purchase_lines += PurchaseLine.search([
('moves', 'in', move_ids),
])
purchases = list(set(l.purchase for l in purchase_lines or []))
Purchase.process(purchases)
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:32,代码来源:stock.py
示例2: check_sled_period_closed
def check_sled_period_closed(cls, lots):
Period = Pool().get('stock.period')
Move = Pool().get('stock.move')
periods = Period.search([
('state', '=', 'closed'),
], order=[('date', 'DESC')], limit=1)
if not periods:
return
period, = periods
for lots in grouped_slice(lots):
lot_ids = [l.id for l in lots]
moves = Move.search([
('lot', 'in', lot_ids),
['OR', [
('effective_date', '=', None),
('planned_date', '<=', period.date),
],
('effective_date', '<=', period.date),
]], limit=1)
if moves:
move, = moves
cls.raise_user_error('period_closed_expiration_dates', {
'lot': move.lot.rec_name,
'move': move.rec_name,
})
开发者ID:kret0s,项目名称:tryton3_8,代码行数:25,代码来源:stock.py
示例3: validate_active
def validate_active(self):
#Deactivate mandate as unit mandate on canceled state
if (self.id > 0) and self.state=='canceled':
condoparties = Pool().get('condo.party').__table__()
condopayments = Pool().get('condo.payment').__table__()
cursor = Transaction().connection.cursor()
cursor.execute(*condopayments.select(condopayments.id,
where=(condopayments.sepa_mandate == self.id) & (
(condopayments.state == 'draft') | (condopayments.state == 'approved')),
))
ids = [ids for (ids,) in cursor.fetchall()]
if len(ids):
self.raise_user_error('Can\'t cancel mandate "%s".\nThere are %s payments in draft or approved state with this mandate!',
(self.identification, len(ids)))
cursor.execute(*condoparties.select(condoparties.id,
where=(condoparties.sepa_mandate == self.id)))
ids = [ids for (ids,) in cursor.fetchall()]
if len(ids):
self.raise_user_warning('warn_canceled_mandate',
'Mandate "%s" will be canceled as mean of payment in %d unit(s)/apartment(s)!', (self.identification, len(ids)))
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(condoparties.id, sub_ids)
# Use SQL to prevent double validate loop
cursor.execute(*condoparties.update(
columns=[condoparties.sepa_mandate],
values=[None],
where=red_sql))
开发者ID:malonp,项目名称:trytond-condominium_payment_sepa,代码行数:30,代码来源:payment.py
示例4: _get_duration_timesheet
def _get_duration_timesheet(works, invoiced):
pool = Pool()
TimesheetLine = pool.get('timesheet.line')
cursor = Transaction().cursor
line = TimesheetLine.__table__()
durations = {}
twork2work = dict((w.work.id, w.id) for w in works if w.work)
ids = twork2work.keys()
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(line.work, sub_ids)
if invoiced:
where = line.invoice_line != Null
else:
where = line.invoice_line == Null
cursor.execute(*line.select(line.work, Sum(line.duration),
where=red_sql & where,
group_by=line.work))
for twork_id, duration in cursor.fetchall():
if duration:
# SQLite uses float for SUM
if not isinstance(duration, datetime.timedelta):
duration = datetime.timedelta(seconds=duration)
durations[twork2work[twork_id]] = duration
return durations
开发者ID:kret0s,项目名称:tryton3_8,代码行数:25,代码来源:work.py
示例5: delete
def delete(cls, requests):
pool = Pool()
Sale = pool.get('sale.sale')
SaleLine = pool.get('sale.line')
sale_ids = list(set(r.origin.id for r in requests
if isinstance(r.origin, Sale)))
with Transaction().set_context(_check_access=False):
sale_lines = []
for sub_requests in grouped_slice(requests):
sale_lines.append(SaleLine.search([
('purchase_request', 'in',
[r.id for r in sub_requests]),
]))
sale_lines = list(chain(*sale_lines))
if sale_lines:
SaleLine.write(sale_lines, {
'purchase_request': None,
})
super(PurchaseRequest, cls).delete(requests)
if sale_ids:
with Transaction().set_context(_check_access=False):
Sale.process(Sale.browse(sale_ids))
开发者ID:kret0s,项目名称:tryton3_8,代码行数:26,代码来源:purchase.py
示例6: get_lastmodified
def get_lastmodified(cls, uri, cache=None):
pool = Pool()
object_name, object_id = cls._uri2object(uri, cache=cache)
if object_name == 'ir.attachment':
Model = pool.get(object_name)
if object_id:
if cache is not None:
cache.setdefault(Model.__name__, {})
ids = cache[Model.__name__].keys()
if object_id not in ids:
ids.append(object_id)
elif 'lastmodified' in cache[Model.__name__][object_id]:
return cache[Model.__name__][object_id][
'lastmodified']
else:
ids = [object_id]
res = None
cursor = Transaction().cursor
table = Model.__table__()
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(table.id, sub_ids)
cursor.execute(*table.select(table.id,
Extract('EPOCH',
Coalesce(table.write_date, table.create_date)),
where=red_sql))
for object_id2, date in cursor.fetchall():
if object_id2 == object_id:
res = date
if cache is not None:
cache[Model.__name__].setdefault(object_id2, {})
cache[Model.__name__][object_id2][
'lastmodified'] = date
if res is not None:
return res
return time.time()
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:35,代码来源:webdav.py
示例7: wait
def wait(cls, shipments):
pool = Pool()
PurchaseRequest = pool.get('purchase.request')
SaleLine = pool.get('sale.line')
Move = pool.get('stock.move')
requests = []
for sub_lines in grouped_slice([m.origin.id for s in shipments
for m in s.supplier_moves]):
requests += PurchaseRequest.search([
('purchase_line', 'in', list(sub_lines)),
])
pline2request = {r.purchase_line: r for r in requests}
sale_lines = SaleLine.search([
('purchase_request', 'in', [r.id for r in requests]),
])
request2sline = {sl.purchase_request: sl for sl in sale_lines}
to_save = []
for shipment in shipments:
for move in shipment.supplier_moves:
sale_line = request2sline[pline2request[move.origin]]
for move in sale_line.moves:
if (move.state not in ('cancel', 'done')
and not move.shipment
and move.from_location.type == 'drop'):
move.shipment = shipment
to_save.append(move)
Move.save(to_save)
cls._synchronize_moves(shipments)
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:30,代码来源:stock.py
示例8: generate
def generate(cls, pains):
pool = Pool()
Payment = pool.get('condo.payment')
payment = Payment.__table__()
cursor = Transaction().connection.cursor()
for pain in pains:
pids = [p.id for group in pain.groups for p in group.payments]
for sub_ids in grouped_slice(pids):
red_sql = reduce_ids(payment.id, sub_ids)
cursor.execute(*payment.update(
columns=[payment.state],
values=['approved'],
where=red_sql))
try:
tmpl = pain.get_sepa_template()
message = tmpl.generate(pain=pain,
datetime=datetime, normalize=unicodedata.normalize,
).filter(remove_comment).render()
pain.message = message
pain.save()
except:
Transaction().rollback()
cls.raise_user_error('generate_error', (pain.reference,pain.company.party.name))
else:
Transaction().commit()
开发者ID:malonp,项目名称:trytond-condominium_payment_sepa,代码行数:28,代码来源:payment.py
示例9: write
def write(cls, *args):
pool = Pool()
Lines = pool.get('timesheet.line')
actions = iter(args)
childs = []
for works, values in zip(actions, actions):
if not values.get('timesheet_available', True):
for sub_works in grouped_slice(works):
lines = Lines.search([
('work', 'in', [x.id for x in sub_works]),
], limit=1)
if lines:
cls.raise_user_error('change_timesheet_available',
lines[0].work.rec_name)
if not values.get('active', True):
childs += cls.search([
('parent', 'child_of', [w.id for w in works]),
])
super(Work, cls).write(*args)
if childs:
cls.write(childs, {
'active': False,
})
开发者ID:kret0s,项目名称:tryton3_8,代码行数:26,代码来源:work.py
示例10: get_pending_amount
def get_pending_amount(cls, agents, name):
pool = Pool()
Commission = pool.get('commission')
commission = Commission.__table__()
cursor = Transaction().connection.cursor()
ids = [a.id for a in agents]
amounts = dict.fromkeys(ids, None)
for sub_ids in grouped_slice(ids):
where = reduce_ids(commission.agent, sub_ids)
where &= commission.invoice_line == Null
query = commission.select(commission.agent, Sum(commission.amount),
where=where,
group_by=commission.agent)
cursor.execute(*query)
amounts.update(dict(cursor.fetchall()))
digits = cls.pending_amount.digits
exp = Decimal(str(10.0 ** -digits[1]))
for agent_id, amount in amounts.items():
if amount:
# SQLite uses float for SUM
if not isinstance(amount, Decimal):
amount = Decimal(str(amount))
amounts[agent_id] = amount.quantize(exp)
return amounts
开发者ID:coopengo,项目名称:commission,代码行数:25,代码来源:commission.py
示例11: __register__
def __register__(cls, module_name):
pool = Pool()
StatementLine = pool.get('account.statement.line')
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
super(Move, cls).__register__(module_name)
# Migration from 3.4:
# account.statement.line origin changed to account.statement
statement_line = StatementLine.__table__()
cursor.execute(*sql_table.join(statement_line,
condition=(
Concat(StatementLine.__name__ + ',', statement_line.id)
== sql_table.origin
)
).select(sql_table.id, statement_line.statement,
order_by=(sql_table.id, statement_line.statement)))
for statement_id, values in groupby(cursor.fetchall(), itemgetter(1)):
ids = [x[0] for x in values]
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(sql_table.id, sub_ids)
cursor.execute(*sql_table.update(
columns=[sql_table.origin],
values=['account.statement,%s' % statement_id],
where=red_sql))
开发者ID:coopengo,项目名称:account_statement,代码行数:26,代码来源:account.py
示例12: get_creationdate
def get_creationdate(cls, uri, cache=None):
Party = Pool().get('party.party')
party = Party.__table__()
party_id = cls.vcard(uri)
cursor = Transaction().cursor
if party_id is None:
raise DAV_NotFound
if party_id:
if cache is not None:
cache.setdefault('_contact', {})
ids = cache['_contact'].keys()
if party_id not in ids:
ids.append(party_id)
elif 'creationdate' in cache['_contact'][party_id]:
return cache['_contact'][party_id]['creationdate']
else:
ids = [party_id]
res = None
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(party.id, sub_ids)
cursor.execute(*party.select(party.id,
Extract('EPOCH', party.create_date),
where=red_sql))
for party_id2, date in cursor.fetchall():
if party_id2 == party_id:
res = date
if cache is not None:
cache['_contact'].setdefault(party_id2, {})
cache['_contact'][party_id2]['creationdate'] = date
if res is not None:
return res
return super(Collection, cls).get_creationdate(uri, cache=cache)
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:34,代码来源:webdav.py
示例13: __register__
def __register__(cls, module_name):
pool = Pool()
Move = pool.get('stock.move')
PurchaseLine = pool.get('purchase.line')
PurchaseRequest = pool.get('purchase.request')
SaleLine = pool.get('sale.line')
Location = pool.get('stock.location')
move = Move.__table__()
purchase_line = PurchaseLine.__table__()
purchase_request = PurchaseRequest.__table__()
sale_line = SaleLine.__table__()
location = Location.__table__()
cursor = Transaction().cursor
super(ShipmentDrop, cls).__register__(module_name)
# Migration from 3.6
cursor.execute(*location.select(Count(location.id),
where=(location.type == 'drop')))
has_drop_shipment, = cursor.fetchone()
if not has_drop_shipment:
drop_shipment = Location(name='Migration Drop Shipment',
type='drop', active=False)
drop_shipment.save()
drop_shipment_location = drop_shipment.id
move_sale_query = move.join(purchase_line,
condition=move.origin == Concat('purchase.line,',
purchase_line.id)
).join(purchase_request,
condition=purchase_request.purchase_line == purchase_line.id
).join(sale_line,
condition=sale_line.purchase_request == purchase_request.id
).select(
move.id, move.to_location, sale_line.id,
where=move.shipment.like('stock.shipment.drop,%'))
cursor.execute(*move_sale_query)
move_sales = cursor.fetchall()
for sub_move in grouped_slice(move_sales):
sub_ids = [s[0] for s in sub_move]
cursor.execute(*move.update(
columns=[move.to_location],
values=[drop_shipment_location],
where=move.id.in_(sub_ids)))
create_move = move.insert(values=move.select(
where=move.shipment.like('stock.shipment.drop,%')))
cursor.execute(*create_move)
for move_id, customer_location, line_id in move_sales:
cursor.execute(move.update(
columns=[move.origin, move.from_location,
move.to_location],
values=[Concat('sale.line,', str(line_id)),
drop_shipment_location, customer_location],
where=(move.id == move_id)))
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:58,代码来源:stock.py
示例14: transition_handle
def transition_handle(self):
pool = Pool()
Sale = pool.get('sale.sale')
SaleLine = pool.get('sale.line')
Purchase = pool.get('purchase.purchase')
PurchaseRequest = pool.get('purchase.request')
Move = pool.get('stock.move')
super(PurchaseHandleShipmentException, self).transition_handle()
sales = set()
moves = set()
to_recreate = set(self.ask.recreate_moves)
domain_moves = set(self.ask.domain_moves)
purchase = Purchase(Transaction().context['active_id'])
requests = []
for sub_lines in grouped_slice([pl.id for pl in purchase.lines]):
requests += PurchaseRequest.search([
('purchase_line', 'in', list(sub_lines)),
])
pline2request = {r.purchase_line: r for r in requests}
request2sline = {}
for sub_requests in grouped_slice(requests):
sale_lines = SaleLine.search([
('purchase_request', 'in', [r.id for r in sub_requests]),
])
request2sline.update({sl.purchase_request: sl
for sl in sale_lines})
for line in purchase.lines:
if not set(line.moves) & domain_moves:
continue
if not any(m in to_recreate for m in line.moves):
sale_line = request2sline[pline2request[line]]
moves.update({m for m in sale_line.moves
if (m.state != 'done'
and m.from_location.type == 'drop')})
sales.add(sale_line.sale)
if moves:
Move.cancel(list(moves))
if sales:
Sale.process(list(sales))
return 'end'
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:45,代码来源:purchase.py
示例15: get_receivable_payable
def get_receivable_payable(cls, parties, names):
'''
Function to compute receivable, payable (today or not) for party ids.
'''
result = {}
pool = Pool()
MoveLine = pool.get('account.move.line')
Account = pool.get('account.account')
User = pool.get('res.user')
Date = pool.get('ir.date')
cursor = Transaction().cursor
line = MoveLine.__table__()
account = Account.__table__()
for name in names:
if name not in ('receivable', 'payable',
'receivable_today', 'payable_today'):
raise Exception('Bad argument')
result[name] = dict((p.id, Decimal('0.0')) for p in parties)
user = User(Transaction().user)
if not user.company:
return result
company_id = user.company.id
line_query, _ = MoveLine.query_get(line)
amount = Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0))
for name in names:
code = name
today_where = Literal(True)
if name in ('receivable_today', 'payable_today'):
code = name[:-6]
today_where = ((line.maturity_date <= Date.today())
| (line.maturity_date == Null))
for sub_parties in grouped_slice(parties):
sub_ids = [p.id for p in sub_parties]
party_where = reduce_ids(line.party, sub_ids)
cursor.execute(*line.join(account,
condition=account.id == line.account
).select(line.party, amount,
where=(account.active
& (account.kind == code)
& (line.reconciliation == Null)
& (account.company == company_id)
& line_query
& party_where
& today_where
& (account.kind == code)),
group_by=line.party))
for party, value in cursor.fetchall():
# SQLite uses float for SUM
if not isinstance(value, Decimal):
value = Decimal(str(value))
result[name][party] = value
return result
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:57,代码来源:party.py
示例16: check_no_move
def check_no_move(cls, templates, error):
Move = Pool().get('stock.move')
for sub_templates in grouped_slice(templates):
moves = Move.search([
('product.template', 'in', [t.id for t in sub_templates]),
],
limit=1, order=[])
if moves:
cls.raise_user_error(error)
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:9,代码来源:product.py
示例17: _purchase_cost
def _purchase_cost(cls, works):
'Compute direct purchase cost'
pool = Pool()
Currency = pool.get('currency.currency')
PurchaseLine = pool.get('purchase.line')
InvoiceLine = pool.get('account.invoice.line')
Invoice = pool.get('account.invoice')
Company = pool.get('company.company')
cursor = Transaction().cursor
table = cls.__table__()
purchase_line = PurchaseLine.__table__()
invoice_line = InvoiceLine.__table__()
invoice = Invoice.__table__()
company = Company.__table__()
amounts = defaultdict(Decimal)
work_ids = [w.id for w in works]
work2currency = {}
iline2work = {}
for sub_ids in grouped_slice(work_ids):
where = reduce_ids(table.id, sub_ids)
cursor.execute(*table.join(purchase_line,
condition=purchase_line.work == table.id
).join(invoice_line,
condition=invoice_line.origin == Concat(
'purchase.line,', purchase_line.id)
).join(invoice,
condition=invoice_line.invoice == invoice.id
).select(invoice_line.id, table.id,
where=where & ~invoice.state.in_(['draft', 'cancel'])))
iline2work.update(cursor.fetchall())
cursor.execute(*table.join(company,
condition=table.company == company.id
).select(table.id, company.currency,
where=where))
work2currency.update(cursor.fetchall())
currencies = Currency.browse(set(work2currency.itervalues()))
id2currency = {c.id: c for c in currencies}
invoice_lines = InvoiceLine.browse(iline2work.keys())
for invoice_line in invoice_lines:
invoice = invoice_line.invoice
work_id = iline2work[invoice_line.id]
currency_id = work2currency[work_id]
currency = id2currency[currency_id]
if currency != invoice.currency:
with Transaction().set_context(date=invoice.currency_date):
amount = Currency.compute(invoice.currency,
invoice_line.amount, currency)
else:
amount = invoice_line.amount
amounts[work_id] += amount
return amounts
开发者ID:kret0s,项目名称:tryton3_8,代码行数:56,代码来源:work.py
示例18: draft
def draft(cls, periods):
for grouping in cls.groupings():
Cache = cls.get_cache(grouping)
caches = []
for sub_periods in grouped_slice(periods):
caches.append(Cache.search([
('period', 'in',
[p.id for p in sub_periods]),
], order=[]))
Cache.delete(list(chain(*caches)))
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:10,代码来源:period.py
示例19: delete
def delete(cls, categories):
pool = Pool()
Product_TariffCode = pool.get('product-customs.tariff.code')
products = [str(t) for t in categories]
super(Category, cls).delete(categories)
for products in grouped_slice(products):
product_tariffcodes = Product_TariffCode.search([
'product', 'in', list(products),
])
Product_TariffCode.delete(product_tariffcodes)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:12,代码来源:product.py
示例20: get_invoice_payment
def get_invoice_payment(cls, lines, name):
pool = Pool()
InvoicePaymentLine = pool.get('account.invoice-account.move.line')
ids = list(map(int, lines))
result = dict.fromkeys(ids, None)
for sub_ids in grouped_slice(ids):
payment_lines = InvoicePaymentLine.search([
('line', 'in', list(sub_ids)),
])
result.update({p.line.id: p.invoice.id for p in payment_lines})
return result
开发者ID:coopengo,项目名称:account_invoice,代码行数:12,代码来源:account.py
注:本文中的trytond.tools.grouped_slice函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论