mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 12:06:57 -06:00
Merge pull request #141 from hbrunn/8.0-document_ocr
[8.0] document_ocr: green runbot
This commit is contained in:
commit
bb53504363
@ -8,6 +8,7 @@
|
|||||||
<field name="model">ir.attachment</field>
|
<field name="model">ir.attachment</field>
|
||||||
<field name="function">_ocr_cron</field>
|
<field name="function">_ocr_cron</field>
|
||||||
<field name="numbercall">-1</field>
|
<field name="numbercall">-1</field>
|
||||||
|
<field name="args">(100,)</field>
|
||||||
</record>
|
</record>
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
@ -18,7 +18,7 @@ class IrAttachment(models.Model):
|
|||||||
def _index(self, data, datas_fname, file_type):
|
def _index(self, data, datas_fname, file_type):
|
||||||
mimetype, content = super(IrAttachment, self)._index(
|
mimetype, content = super(IrAttachment, self)._index(
|
||||||
data, datas_fname, file_type)
|
data, datas_fname, file_type)
|
||||||
if not content or content == 'image':
|
if mimetype and (not content or content == 'image'):
|
||||||
has_synchr_param = self.env['ir.config_parameter'].get_param(
|
has_synchr_param = self.env['ir.config_parameter'].get_param(
|
||||||
'document_ocr.synchronous', 'False') == 'True'
|
'document_ocr.synchronous', 'False') == 'True'
|
||||||
has_force_flag = self.env.context.get('document_ocr_force')
|
has_force_flag = self.env.context.get('document_ocr_force')
|
||||||
@ -42,7 +42,7 @@ class IrAttachment(models.Model):
|
|||||||
else:
|
else:
|
||||||
image_data = StringIO()
|
image_data = StringIO()
|
||||||
try:
|
try:
|
||||||
Image.open(StringIO(data)).save(image_data, 'tiff',
|
Image.open(StringIO(data)).save(image_data, 'png',
|
||||||
dpi=(dpi, dpi))
|
dpi=(dpi, dpi))
|
||||||
except IOError:
|
except IOError:
|
||||||
_logger.exception('Failed to OCR image')
|
_logger.exception('Failed to OCR image')
|
||||||
@ -70,10 +70,10 @@ class IrAttachment(models.Model):
|
|||||||
return StringIO(stdout)
|
return StringIO(stdout)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _ocr_cron(self):
|
def _ocr_cron(self, limit=0):
|
||||||
for this in self.with_context(document_ocr_force=True).search([
|
for this in self.with_context(document_ocr_force=True).search([
|
||||||
('index_content', '=', _MARKER_PHRASE),
|
('index_content', '=', _MARKER_PHRASE),
|
||||||
]):
|
], limit=limit):
|
||||||
if not this.datas:
|
if not this.datas:
|
||||||
continue
|
continue
|
||||||
file_type, index_content = this._index(
|
file_type, index_content = this._index(
|
||||||
|
Loading…
Reference in New Issue
Block a user