Esempio n. 1
0
 def _check_payment_type_crypto(self):
     for rec in self:
         if rec.currency_id.inventoried and rec.payment_type == "transfer":
             raise exceptions.ValidationError(
                 _("You cannot make internal transfers using crypto "
                   "currencies."))
Esempio n. 2
0
    def validate_finishing_type(self):

        if not self.finishing_type:
            raise exceptions.ValidationError(
                'Finishing type Code Cannot Be Empty')
Esempio n. 3
0
    def validate_property_code(self):

        if not self.property_code:
            raise exceptions.ValidationError('Property Code Cannot Be Empty')
Esempio n. 4
0
    def validate_property_design(self):

        if not self.property_design:
            raise exceptions.ValidationError(
                'Property Design Code Cannot Be Empty')
Esempio n. 5
0
    def validate_built_up(self):

        if not self.built_up:
            raise exceptions.ValidationError('Built Cannot Be Empty')
Esempio n. 6
0
 def _check_use_webhooks_unique(self):
     if len(self.search([('use_webhooks', '=', True)])) > 1:
         raise exceptions.ValidationError(
             _('Only one backend can listen to webhooks'))
Esempio n. 7
0
 def _check_reference(self):
     for transaction in self.filtered(lambda tx: tx.state not in ('cancel', 'error')):
         if self.search_count([('reference', '=', transaction.reference)]) != 1:
             raise exceptions.ValidationError(_('The payment transaction reference must be unique!'))
     return True
Esempio n. 8
0
    def action_set_webstack_settings(self):
        self.ensure_one()
        bad_hosts = ['localhost', '127.0.0.1','.local']
        odoo_url = str(self.env['ir.config_parameter'].sudo().get_param('web.base.url'))
        odoo_port = len(odoo_url.split(':'))==3 and int(odoo_url.split(':')[2], 10) or 80
        odoo_protocol = odoo_url.split('//')[0]
        if any([odoo_url.find(bh) < 0 for bh in bad_hosts]):
            local_ip = get_local_ip()
            new_odoo_url =  f"{local_ip}"
            if odoo_url == new_odoo_url:
                raise exceptions.ValidationError(_('Your current setup not permit this operation. You need to do it manually. Please call your support team for more information!'))
            else:
                odoo_url = new_odoo_url
                _logger.info(f"After investigation, the system url is: {odoo_url}")
        odoo_url += '/hr/rfid/event'

        username = str(self.module_username) if self.module_username else ''
        password = str(self.module_password) if self.module_password else ''

        auth = base64.b64encode((username + ':' + password).encode())
        auth = auth.decode()
        req_headers = {"content-type": "application/json", "Authorization": "Basic " + str(auth)}
        host = str(self.last_ip)
        js_uart_conf = json.dumps([
            {
                "br": 9600,
                "db": 3,
                "fc": 0,
                "ft": 122,
                "port": 0,
                "pr": 0,
                "rt": False,
                "sb": 1,
                "usage": 0
            }, {
                "br": 9600,
                "db": 3,
                "fc": 0,
                "ft": 122,
                "port": 2,
                "pr": 0,
                "rt": False,
                "sb": 1,
                "usage": 1
            }
        ])

        config_params = 'sdk=1&stsd=1&sdts=1&stsu=' + odoo_url + '&prt=' \
                        + str(odoo_port) + '&hb=1&thb=60&br=1&odoo=1'
        try:
            if self.hw_version != '50.1':
                conn = http.client.HTTPConnection(str(host), 80, timeout=2)
                conn.request("POST", "/protect/uart/conf", js_uart_conf, req_headers)
                response = conn.getresponse()
                conn.close()
                code = response.getcode()
                body = response.read()
                if code != 200:
                    raise exceptions.ValidationError('While trying to setup /protect/uart/conf the module '
                                                     'returned code ' + str(code) + ' with body:\n' +
                                                     body.decode())

            conn = http.client.HTTPConnection(str(host), 80, timeout=2)
            conn.request("POST", "/protect/config.htm", config_params, req_headers)
            response = conn.getresponse()
            conn.close()
            code = response.getcode()
            body = response.read()
            if code != 200:
                raise exceptions.ValidationError('While trying to setup /protect/config.htm the module '
                                                 'returned code ' + str(code) + ' with body:\n' +
                                                 body.decode())
        except socket.timeout:
            raise exceptions.ValidationError('Could not connect to the module. '
                                             "Check if it is turned on or if it's on a different ip.")
        except (socket.error, socket.gaierror, socket.herror) as e:
            raise exceptions.ValidationError('Error while trying to connect to the module.'
                                             ' Information:\n' + str(e))
        self.key = None
        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'title': _('Setup the Module'),
                'message': _('Information sent to the Module. If everything is fine, the Module have to start '
                             'communication with this instance. The URL in use is http://{} on port {}.').format(odoo_url, odoo_port),
                'sticky': True,
            }}
Esempio n. 9
0
    def get_controllers(self):
        controllers = None
        for ws in self:
            if ws.behind_nat or not ws.active:
                continue
            host = str(ws.last_ip)
            try:
                response = requests.get(f'http://{host}/config.json', timeout=2)
                if response.status_code != 200:
                    raise exceptions.ValidationError('Webstack sent us http code {}'
                                                     ' when 200 was expected.'.format(response.status_code))
                js = response.json()
                controllers = js['sdk']['devFound']
                if ws.name == f"Module {ws.serial}":
                    ws.name = f"Module {ws.serial} ({js['netConfig']['Host_Name']})"
                if not isinstance(controllers, int):
                    raise exceptions.ValidationError('Webstack gave us bad data when requesting /config.json')

                for dev in range(controllers):
                    response = requests.get(f'http://{host}/sdk/status.json?dev={dev}')

                    if response.status_code != 200:
                        raise exceptions.ValidationError('Webstack sent us http code {} when 200 was expected'
                                                         ' while requesting /sdk/details.json?dev={}'
                                                         .format(response.status_code, dev))
                    try:
                        ctrl_js = response.json()
                    except Exception as e:
                        _logger.error(str(e))
                        continue
                    if not self.env['hr.rfid.ctrl'].search_count(
                            [('ctrl_id', '=', ctrl_js['dev']['devID']), ('webstack_id', '=', ws.id)]):
                        controller = self.env['hr.rfid.ctrl'].sudo().create([{
                            'name': 'Controller',
                            'ctrl_id': ctrl_js['dev']['devID'],
                            'webstack_id': ws.id,
                        }])
                        controller.read_controller_information_cmd()
            except socket.timeout:
                raise exceptions.ValidationError('Could not connect to the webstack at ' + host)
            except(socket.error, socket.gaierror, socket.herror) as e:
                raise exceptions.ValidationError('Unexpected error:\n' + str(e))
            except KeyError as __:
                raise exceptions.ValidationError('Information returned by the webstack at '
                                                 + host + ' invalid')
        if controllers:
            return self.with_context(xml_id='hr_rfid_ctrl_action').return_action_to_open()
        else:
            return {
                    'type': 'ir.actions.client',
                    'tag': 'display_notification',
                    'params': {
                        'title': _('Reading controllers from the Module'),
                        'message': _('No controllers detected in the Module or the Module is Archived'),
                        # 'links': [{
                        #     'label': production.name,
                        #     'url': f'#action={action.id}&id={production.id}&model=mrp.production'
                        # }],
                        'type': 'warning',
                        'sticky': False,
                    }}
Esempio n. 10
0
 def _check_is_exempted(self):
     for record in self:
         if record.is_exempted and not record.is_subject_to:
             raise exceptions.ValidationError(
                 _("TicketBAI Invoice %s: Exempted taxes are Subject to taxes."
                   ) % record.tbai_invoice_id.name)
Esempio n. 11
0
 def check_issue_quantity(self):
     if self.quantity > (self.requested_quantity - self.issued_quantity):
         raise exceptions.ValidationError(
             "Error! Issue quantity more than requested")
Esempio n. 12
0
 def _check_not_subject_to_cause(self):
     for record in self:
         if not record.is_subject_to and not record.not_subject_to_cause:
             raise exceptions.ValidationError(
                 _("TicketBAI Invoice %s: Tax Not subject to cause is required."
                   ) % record.tbai_invoice_id.name)
Esempio n. 13
0
 def _check_price_not_negative(self):
     for r in self:
         if r.price < 0.00:
             raise exceptions.ValidationError(
                 "El precio no puede ser negativo")
Esempio n. 14
0
 def _check_python_code(self):
     for song in self.filtered('python_code'):
         msg = test_python_expr(expr=self.python_code.strip(), mode="exec")
         if msg:
             raise exceptions.ValidationError(msg)
Esempio n. 15
0
 def _instructor_not_attendees(self):
     for record in self:
         if record.instructor_id and record.instructor_id in record.attendee_ids:
             raise exceptions.ValidationError(
                 _("A session's instructor can't be an attendee"))
Esempio n. 16
0
 def _verify_pin(self):
     for employee in self:
         if employee.pin and not employee.pin.isdigit():
             raise exceptions.ValidationError(
                 _("The PIN must be a sequence of digits."))
Esempio n. 17
0
 def _cont(selfs):
     for r in selfs:
         if r.maitre_id in r.participant_ids:
             raise exceptions.ValidationError("Le maitre est parmi les participants")
 def _check_settle_integrity(self):
     for record in self:
         if any(record.mapped('settled')):
             raise exceptions.ValidationError(
                 _("You can't modify a settled line"), )
Esempio n. 19
0
 def _check_instructor_not_in_attendees(self):
     for r in self:
         if r.instructor_id and r.instructor_id in r.attendee_ids:
             raise exceptions.ValidationError(
                 _("A session's instructor can't be an attendee"))
Esempio n. 20
0
 def check_cmnd(self):
     if not self.cmnd:
         raise exceptions.ValidationError("Please fill your People ID!")
Esempio n. 21
0
 def _check_authorize_state(self):
     failed_tx = self.filtered(lambda tx: tx.state == 'authorized' and tx.acquirer_id.provider not in self.env['payment.acquirer']._get_feature_support()['authorize'])
     if failed_tx:
         raise exceptions.ValidationError(_('The %s payment acquirers are not allowed to manual capture mode!' % failed_tx.mapped('acquirer_id.name')))
Esempio n. 22
0
File: nivel.py Progetto: vagali/sge
 def _verificar_nivel_academico(self):
     if (len(self.nivel_academico) < 3):
         raise exceptions.ValidationError("Nivel academico minimo longitud 4 caracteres.")
Esempio n. 23
0
    def validate_price(self):

        if not self.price or self.price == 0:
            raise exceptions.ValidationError('Price Cannot Be Empty or 0')
Esempio n. 24
0
File: nivel.py Progetto: vagali/sge
 def _verificar_espeificacion(self):
     if len(self.espeificacion) < 3:
         raise exceptions.ValidationError("Especificacion minimo longitud 4 caracteres.")
Esempio n. 25
0
    def validate_property_status(self):

        if not self.property_status:
            raise exceptions.ValidationError(
                'Property status Code Cannot Be Empty')
Esempio n. 26
0
File: nivel.py Progetto: vagali/sge
 def _verificar_descripcion_nivel(self):
     if self.descripcion and (len(self.descripcion) < 3):
         raise exceptions.ValidationError("Descripcion minimo longitud 4 caracteres.")
Esempio n. 27
0
    def get_number_comment_bar_user(self):

        if len(self.comments) > 1:
            raise exceptions.ValidationError('Not Vaild to add other Comment')
Esempio n. 28
0
 def _check_adult(self):
     if self.age < 18:
         raise exceptions.ValidationError(
             "You aren't adult, your age is: %s" % self.age)
Esempio n. 29
0
    def validate_region(self):

        if not self.region:
            raise exceptions.ValidationError('Region Code Cannot Be Empty')
Esempio n. 30
0
    def sync_merchant_marakez(self):
        for rec in self:
            marakez_api_rec = self.env['marakez.server.api'].sudo().search(
                [], limit=1)
            if marakez_api_rec and marakez_api_rec.name:
                token_id = ''
                token = self.env['jwt.authentication']
                token_rec = token.sudo().search([], limit=1)
                if token_rec:
                    token_id = token_rec.token
                url = marakez_api_rec.name + 'erp_merchantregister'
                name = (rec.client_id and rec.client_id.name).split(' ', 1)
                firstname = name[0]
                lastname = name[1] if len(name) > 1 else ''
                citycode = self.env['city.city'].sudo().search([
                    ('name', '=', rec.city),
                    ('country_id', '=', rec.country_id.id),
                    ('state_id', '=', rec.state_id and rec.state_id.id)
                ])
                citycode = citycode.code if citycode else ''
                onboarddate = datetime.strptime(
                    rec.create_date, '%Y-%m-%d %H:%M:%S').strftime('%d/%m/%Y')
                payload = {
                    "sellercode": rec.request_no,
                    "sellertype": rec.plan_id and rec.plan_id.name,
                    "companyname": rec.company,
                    "companylogo":
                    "https://rukminim1.flixcart.com/image/300/300/jepzrm80/shoe/a/z/e/nm001-8-newport-black-original-imaf3chapbgyrk2h.jpeg?q=70",
                    "phoneno": rec.contact_no,
                    "firstname": firstname,
                    "lastname": lastname,
                    "email": rec.client_email,
                    "address1": rec.street1,
                    "address2": rec.street2,
                    "countrycode": rec.country_id and rec.country_id.code,
                    "statecode": rec.state_id and rec.state_id.code,
                    "citycode": citycode,
                    "pincode": "",
                    "iban": rec.client_bank_iban,
                    "bankname": rec.client_bank_id and rec.client_bank_id.name,
                    "accountno": rec.client_bank_acc,
                    "accountname": "current",
                    "onboarddate": onboarddate,
                    "category": ["MI2000", "MI200001"]
                }

                data = json.dumps(payload)
                headers = {
                    'content-type': "application/json",
                    'Authorization': "Bearer " + token_id,
                }
                print "############payload", payload
                print "##########headers", headers
                # response = requests.request("POST", url, data=data, headers=headers)
                # if response and response.status_code == 200:
                #     response = json.loads(response.text)
                #     print "##########response1",response
                #     if response['status'] == 'fail':
                #         response = requests.request("PUT", url, data=data, headers=headers)
                #         print "###########response2",response.text
                # else:
                #     token_rec.get_jwt_authentication()
                #     headers = {
                #         'content-type': "application/json",
                #         'Authorization': "Bearer "+token_rec.token,
                #     }
                #     response = requests.request("POST", url, data=data, headers=headers)
                #     if response and response.status_code == 200:
                #         response = json.loads(response.text)
                #         print "##############response2",response
                #         if response['status'] == 'fail':
                #             response = requests.request("PUT", url, data=data, headers=headers)
                #             print "#########updating record",response
            else:
                raise exceptions.ValidationError(
                    _("Please add marakez server API url."))
        return True