예제 #1
0
    def get_seedoo_instance_uuid(self, cr, uid, context=None):
        instanceid = self.search(cr, uid, [], limit=1)
        if not instanceid:
            raise MissingError(_("Instance not found"))

        instance_id = self.browse(cr, uid, [instanceid[0]])
        if not instance_id:
            raise MissingError(_("Instance not found"))

        return instance_id.uuid
예제 #2
0
 def create(self, cr, uid, ids, data, context=None):
     pool = registry(cr.dbname)
     merger = PdfFileMerger()
     outfiles = []
     for p in pool.get(self.model).read(cr,uid,ids):
         outfiles.append(self.newfilename())
         sla = self.render(cr,uid,p,data.get('template') or self.template)
         if self.report_type == 'scribus_sla':
             os.unlink(outfiles[-1])
             return (sla.read(),'sla')
         command = "xvfb-run -a scribus-ng -ns -g %s -py %s -pa -o %s" % (sla.name,os.path.join(get_module_path('report_scribus'), 'scribus.py'),outfiles[-1])
         _logger.info(command)
         res = os.system(command)
         sla.close()
         if not os.path.exists(outfiles[-1]) or os.stat(outfiles[-1]).st_size == 0:
             raise MissingError('There are something wrong with the template or scribus installation')
         merger.append(PdfFileReader(file(outfiles[-1], 'rb')))
     outfile = tempfile.NamedTemporaryFile(mode='w+b',suffix='.pdf')
     merger.write(outfile.name)
     for filename in outfiles:
         os.unlink(filename)
     outfile.seek(0)
     pdf = outfile.read()
     outfile.close()
     return (pdf,'pdf')
예제 #3
0
    def get_edit_info_for_geo_column(self, cursor, uid, column, context=None):
        res = {}
        raster_obj = self.pool['geoengine.raster.layer']

        field = self._fields.get(column)
        if not field or not isinstance(field, geo_fields.GeoField):
            raise ValueError(
                _("%s column does not exists or is not a geo field") % column)
        view = self._get_geo_view(cursor, uid)
        raster_id = raster_obj.search(cursor,
                                      uid, [('view_id', '=', view.id),
                                            ('use_to_edit', '=', True)],
                                      context=context)
        if not raster_id:
            raster_id = raster_obj.search(cursor,
                                          uid, [('view_id', '=', view.id)],
                                          context=context)
        if not raster_id:
            raise MissingError(
                _('No raster layer for view %s') % (view.name, ))
        res['edit_raster'] = raster_obj.read(cursor,
                                             uid,
                                             raster_id[0],
                                             context=context)
        res['geo_type'] = field.geo_type
        res['srid'] = field.srid
        res['default_extent'] = view.default_extent
        return res
예제 #4
0
def init_postgis(cr):
    """ Initialize postgis
    Add PostGIS support to the database. PostGIS is a spatial database
    extender for PostgreSQL object-relational database. It adds support for
    geographic objects allowing location queries to be run in SQL.
    """
    cr.execute("""
        SELECT
            tablename
        FROM
            pg_tables
        WHERE
            tablename='spatial_ref_sys';
    """)
    check = cr.fetchone()
    if check:
        return {}
    try:
        cr.execute("""
        CREATE EXTENSION postgis;
        CREATE EXTENSION postgis_topology;
    """)
    except Exception:
        raise MissingError(
            "Error, can not automatically initialize spatial postgis support. "
            "Database user may have to be superuser and postgres/postgis "
            "extentions with their devel header have to be installed. "
            "If you do not want Odoo to connect with a super user "
            "you can manually prepare your database. To do this"
            "open a client to your database using a super user and run: \n"
            "CREATE EXTENSION postgis;\n"
            "CREATE EXTENSION postgis_topology;\n")
예제 #5
0
    def get_birthday_reminder_email_template(self):
        template = self.env.ref(
            'ap_hr_birthday_reminders.' +
            self.get_birthday_reminder_mail_template_name())
        if not template:
            raise MissingError(
                _('Birthday reminder mail template does not exist.'))

        return template
 def verify_attachment(self):
     if not crypto_install:
         raise MissingError("ERROR IMPORTING M2Crypto, if not installed, "
                            "please install it.\nGet it here:\n"
                            "https://pypi.python.org/pypi/M2Crypto")
     signature = self.signature_tested
     if self.force_signature:
         if not self.signature_tested:
             raise MissingError("Please set a key to test")
     else:
         signature = self.attachment_tested_id.signed_content
         if not signature:
             raise MissingError("This document have't been signed.")
     params = self.env['ir.config_parameter']
     def _get_key():
         signature_key = params.sudo().\
             get_param('attachment_signature_key',
                       default='')
         return signature_key
     def gimmepw(*args):
         signature_passphrase = params.sudo().\
             get_param('attachment_signature_passphrase',
                       default='')
         return str(signature_passphrase)
     key = _get_key()
     pkey = RSA.load_key(key, gimmepw)
     att = self.env['ir.attachment'].create({
                                             'name': 'File tested',
                                             'datas': self.datas,
                                             'datas_fname': 'File tested',
                                             'res_model': self._name,
                                             'res_id': self.id,
                                             })
     value = att.datas
     signature = base64.decodestring(signature)
     sha256_val = hashlib.sha256(value).digest()
     try:
         pkey.verify(sha256_val, signature)
         raise Warning(_("The signature is OK !\n"
                         "This document hasn't been changed."))
     except RSAError:
         raise Warning(_("Wrong signature !\nThe document has changed."))
예제 #7
0
 def update(self, params):
     claim = self.env['crm.claim'].search([
         ('partner_id', '=', self.partner.id),
         ('shopinvader_backend_id', '=', self.backend_record.id),
         ('id', '=', params['id'])
     ])
     if not claim:
         raise MissingError(_('Claim not found'))
     if params.get('add_message', ''):
         claim.message_post(body=params['add_message'],
                            type='comment',
                            subtype='mail.mt_comment',
                            content_subtype='plaintext',
                            author_id=self.partner.id)
     return {'data': self._to_json(claim)}
예제 #8
0
def set_gitlab_ci_conf(token, gitlab_url, runbot_domain, repo_id):
    if not token:
        raise MissingError(
            _("Gitlab repo requires an API token from a user with admin access to repo"
              ))
    domain, name = get_gitlab_params(gitlab_url.replace(':', '/'))
    url = GITLAB_CI_SETTINGS_URL % (domain, quote_plus(name))
    project_url = "http://%s/gitlab-ci/%s" % (runbot_domain, repo_id)
    data = {
        "token": token,
        "project_url": project_url,
    }
    headers = {
        "PRIVATE-TOKEN": token,
    }
    requests.put(url, data=data, headers=headers)
예제 #9
0
 def _prepare_claim(self, params):
     categ = self.env['crm.case.categ'].search([('id', '=',
                                                 params['subject_id'])])
     claim_type = self.env.ref('crm_claim_type.crm_claim_type_customer').id
     backend_id = self.backend_record.id
     vals = {
         'categ_id': params['subject_id'],
         'name': categ.name,
         'description': params['message'],
         'partner_id': self.partner.id,
         'claim_type': claim_type,
         'shopinvader_backend_id': backend_id,
         'claim_line_ids': []
     }
     vals = self.env['crm.claim'].play_onchanges(vals, ['partner_id'])
     order = False
     for line in params['sale_order_line']:
         if not line['qty']:
             continue
         so_line = self.env['sale.order.line'].search([
             ('id', '=', line['id']),
             ('order_id.partner_id', '=', self.partner.id),
             ('order_id.shopinvader_backend_id', '=', backend_id)
         ])
         if not so_line:
             raise MissingError(
                 _('The sale order line %s does not exist') % line['id'])
         if not order:
             order = so_line.order_id
             vals['ref'] = 'sale.order,%s' % order.id
         elif order != so_line.order_id:
             raise UserError(
                 _('All sale order lines must'
                   'come from the same sale order'))
         if order.invoice_ids and not vals.get('invoice_id', False):
             vals['invoice_id'] = order.invoice_ids[0].id
         vals['claim_line_ids'].append((0, 0, {
             'product_id':
             so_line.product_id.id,
             'product_returned_quantity':
             line['qty'],
             'claim_origin':
             'none'
         }))
     if not vals['claim_line_ids']:
         raise UserError(_('You have to select an item'))
     return vals
예제 #10
0
    def sign_attachment(self):
        if not crypto_install:
            raise MissingError("ERROR IMPORTING M2Crypto, if not installed, "
                               "please install it.\nGet it here:\n"
                               "https://pypi.python.org/pypi/M2Crypto")
        params = self.env['ir.config_parameter']

        def _get_key():
            signature_key = params.sudo().\
                get_param('attachment_signature_key',
                          default='')
            return signature_key

        def gimmepw(*args):
            signature_passphrase = params.sudo().\
                get_param('attachment_signature_passphrase',
                          default='')
            return str(signature_passphrase)

        key = _get_key()
        pkey = RSA.load_key(key, gimmepw)
        value = self.datas
        sha256_val = hashlib.sha256(value).digest()
        signature = pkey.sign(sha256_val)
        file_name = self.datas_fname + '.signature'
        self.signature_id = self.create({
            'name':
            file_name,
            'datas':
            base64.encodestring(base64.encodestring(signature)),
            'datas_fname':
            file_name,
            'res_model':
            self._name,
            'res_id':
            self.id,
            'is_signature':
            True,
        }).id
예제 #11
0
    def _get_quants(self, line):
        obj_data = self.env['ir.model.data']
        quants = []
        move_obj = self.env['stock.move']
        if line.invoice_id.type == 'in_invoice':
            stock_loc_input = obj_data.xmlid_to_res_id(
                'stock.stock_location_company')  #input location
            move = move_obj.search(
                [('product_id', '=', line.product_id.id),
                 ('purchase_line_id', '=', line.purchase_line_id.id),
                 ('location_dest_id', '=', stock_loc_input),
                 ('state', '=', 'done')],
                limit=1)
        elif line.invoice_id.type in ('out_invoice', 'out_refund'):
            so = self.env['sale.order'].search([('invoice_ids', 'in',
                                                 [line.invoice_id.id])])
            loc_stock = self.env.ref('stock.stock_location_stock')
            loc_output = self.env.ref('stock.stock_location_output')
            move = self.env['stock.move'].search(
                [('product_id', '=', line.product_id.id),
                 ('location_id', '=', loc_stock.id),
                 ('location_dest_id', '=', loc_output.id),
                 ('picking_id', 'in', so.picking_ids.ids)],
                limit=1)

        if move:
            quants = move.quant_ids | move.reserved_quant_ids
            if quants:
                dsoft_cod = quants[0].dsoft_cod
                if line.invoice_id.type == 'in_invoice':
                    #if there are more than one quants (initial quant splitted),
                    # then they have to have the same dsoft_cod, there is no other possibility
                    quant_with_different_codes = filter(
                        lambda x: x.dsoft_cod != dsoft_cod, quants)
                    if len(quant_with_different_codes) > 0:
                        raise MissingError(
                            "Eroare la identificarea cantitatilor.")

                elif line.invoice_id.type in ('out_invoice', 'out_refund'):
                    quant_with_no_dsoft_pret_achiz = filter(
                        lambda x: x.cost == 0, quants)
                    if len(quant_with_no_dsoft_pret_achiz) > 0:
                        raise MissingError(
                            "Eroare la identificarea cantitatilor. Una din cantitati are pretul de achizitie 0."
                        )
                    sum_quants = sum([qnt.qty for qnt in quants])
                    if sum_quants < line.quantity:
                        raise MissingError(
                            "Eroare la identificarea cantitatilor. Cantitati insuficiente in magazie."
                        )
            else:
                if line.invoice_id.type == 'out_invoice':
                    raise MissingError(
                        "Produsul -- %s -- nu s-a transferat la iesire" %
                        line.product_id.name)

        elif line.product_id.name not in [
                'TOTAL-F', 'DSOFT_TRANSPORT1', 'DSOFT_TRANSPORT2'
        ]:
            if line.invoice_id.type == 'in_invoice':
                raise MissingError(
                    "Produsul -- %s -- nu s-a transferat la intrare" %
                    line.product_id.name)
            elif line.invoice_id.type == 'out_invoice':
                raise MissingError(
                    "Produsul -- %s -- nu s-a transferat la iesire" %
                    line.product_id.name)

        return quants
예제 #12
0
    def get_seedoo_instance_uuid(self):
        instance_id = self.search([], limit=1)
        if not instance_id:
            raise MissingError(_("Instance not found"))

        return instance_id.uuid
예제 #13
0
    def get_seedoo_instance(self, cr, uid, context=None):
        instanceid = self.search(cr, uid, [], limit=1)
        if not instanceid:
            raise MissingError(_("Instance not found"))

        return instanceid
예제 #14
0
파일: utils.py 프로젝트: feketemihai/dsoft
 def default_cont_service(self):
     dsoft_default_cont = self.get_dsoft_sys_param('param_dsoft_accounts_default_cont_service')
     if dsoft_default_cont:
         default_odoo = self.env['account.account'].search([('code', 'like', dsoft_default_cont + '%')])
         return default_odoo and default_odoo[0].id
     raise MissingError('Eroare cont dsoft default.')