Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(options):
db_name = options.database_name
pool = Pool(db_name)
with Transaction().start(db_name, 0, readonly=True):
pool.init()
with Transaction().start(db_name, 0) as transaction:
local = {
'pool': pool,
'transaction': transaction,
}
if sys.stdin.isatty():
console = Console(local, histsize=options.histsize)
banner = "Tryton %s, Python %s on %s" % (
__version__, sys.version, sys.platform)
kwargs = {}
if sys.version_info >= (3, 6):
kwargs['exitmsg'] = ''
console.interact(banner=banner, **kwargs)
for db_name in self.options.database_names:
if self.options.update:
with Transaction().start(db_name, 0) as transaction,\
transaction.connection.cursor() as cursor:
database = Database(db_name)
database.connect()
if not database.test():
raise Exception("'%s' is not a Tryton database!"
% db_name)
lang = Table('ir_lang')
cursor.execute(*lang.select(lang.code,
where=lang.translatable == True))
lang = [x[0] for x in cursor.fetchall()]
else:
lang = None
Pool(db_name).init(update=self.options.update, lang=lang)
for db_name in self.options.database_names:
if init[db_name]:
# try to read password from environment variable
# TRYTONPASSFILE, empty TRYTONPASSFILE ignored
passpath = os.getenv('TRYTONPASSFILE')
password = ''
if passpath:
try:
with open(passpath) as passfile:
password = passfile.readline()[:-1]
except Exception, err:
sys.stderr.write('Can not read password '
'from "%s": "%s"\n' % (passpath, err))
if not password:
def _credit(self):
pool = Pool()
PosSequence = pool.get('account.pos.sequence')
Date = pool.get('ir.date')
credit = super(Invoice, self)._credit()
credit.currency_rate = self.currency_rate
if self.type == 'in':
invoice_type, invoice_type_desc = INVOICE_CREDIT_AFIP_CODE[
str(int(self.tipo_comprobante))
]
credit.tipo_comprobante = invoice_type.rjust(3, '0')
credit.reference = None
return credit
credit.pos = self.pos
credit.invoice_date = Date.today()
invoice_type, invoice_type_desc = INVOICE_CREDIT_AFIP_CODE[
def _get_dav_resourcetype(self, uri):
dbname, dburi = self._get_dburi(uri)
if not dbname or not dburi:
return COLLECTION
pool = Pool(Transaction().cursor.database_name)
Collection = pool.get('webdav.collection')
try:
res = Collection.get_resourcetype(dburi, cache=CACHE)
except (DAV_Error, DAV_NotFound, DAV_Secret, DAV_Forbidden), exception:
self._log_exception(exception)
raise
except Exception, exception:
self._log_exception(exception)
raise DAV_Error(500)
return res
def get_target(self):
'Return the target Model'
return Pool().get(self.model_name)
def global_search(cls, text, limit, menu='ir.ui.menu'):
"""
Search on models for text including menu
Returns a list of tuple (ratio, model, model_name, id, name, icon)
The size of the list is limited to limit
"""
pool = Pool()
ModelAccess = pool.get('ir.model.access')
if not limit > 0:
raise ValueError('limit must be > 0: %r' % (limit,))
models = cls.search(['OR',
('global_search_p', '=', True),
('model', '=', menu),
])
access = ModelAccess.get_access([m.model for m in models])
s = StringMatcher()
if isinstance(text, bytes):
text = text.decode('utf-8')
s.set_seq2(text)
def generate():
def get_contentlength(cls, uri, cache=None):
pool = Pool()
Attachment = pool.get('ir.attachment')
object_name, object_id = cls._uri2object(uri, cache=cache)
if object_name == 'ir.attachment':
if cache is not None:
cache.setdefault('ir.attachment', {})
ids = cache['ir.attachment'].keys()
if object_id not in ids:
ids.append(object_id)
elif 'contentlength' in cache['ir.attachment'][object_id]:
return cache['ir.attachment'][object_id]['contentlength']
else:
ids = [object_id]
attachments = Attachment.browse(ids)
def delete(cls, domains):
pool = Pool()
super(ActionActWindowDomain, cls).delete(domains)
pool.get('ir.action.keyword')._get_keyword_cache.clear()
def send(cls, requests):
pool = Pool()
RequestHistory = pool.get('res.request.history')
to_create = []
for request in requests:
values = {
'request': request.id,
'act_from': request.act_from.id,
'act_to': request.act_to.id,
'body': request.body,
'state': request.state,
'subject': request.name,
'number_references': request.number_references,
'priority': request.priority,
}
if values['body'] and len(values['body']) > 128:
values['name'] = values['body'][:125] + '...'
else:
def model(self):
pool = Pool()
context = Transaction().context
if context.get('active_model'):
return pool.get(context['active_model'])