예제 #1
0
    def setUp(self):
        super().setUp()
        self._user = self.env['res.users'].create({
            'name': "Bylan",
            'login': '******',
            'password': '******',
            'tz': 'Australia/Eucla',
        })

        # needs a fake request in order to call methods protected with check_identity
        fake_req = DotDict({
            # various things go and access request items
            'httprequest':
            DotDict({
                'environ': {
                    'REMOTE_ADDR': 'localhost'
                },
                'cookies': {},
            }),
            # bypass check_identity flow
            'session': {
                'identity-check-last': time.time()
            }
        })
        _request_stack.push(fake_req)
        self.addCleanup(_request_stack.pop)
예제 #2
0
 def setUp(self):
     super().setUp()
     # needs a fake request in order to call methods protected with check_identity
     fake_req = DotDict({
         # various things go and access request items
         'httprequest': DotDict({
             'environ': {'REMOTE_ADDR': 'localhost'},
             'cookies': {},
         }),
         # bypass check_identity flow
         'session': {'identity-check-last': time.time()}
     })
     _request_stack.push(fake_req)
     self.addCleanup(_request_stack.pop)
예제 #3
0
파일: tools.py 프로젝트: zizou4426/odoo
 def __init__(self, env, **kw):
     app = MockObject(
         routing={
             'type': 'http',
             'website': True,
             'multilang': kw.get('multilang', True),
         })
     app.get_db_router = app.bind = app.match = app
     if not kw.get('routing', True):
         app.match = werkzeugRaiseNotFound
     self.request = DotDict({
         'context': kw.get('context', {}),
         'db': None,
         'env': env,
         'httprequest': {
             'path': '/hello/',
             'app': app,
         },
         'redirect': werkzeug.utils.redirect,
         'session': {
             'geoip': {
                 'country_code': kw.get('country_code'),
             },
             'debug': False,
             'sale_order_id': kw.get('sale_order_id'),
         },
         'website': kw.get('website'),
     })
     odoo.http._request_stack.push(self.request)
    def _get_grouping_info(self):
        grouping_forecast = []
        for key, _pickings in self._grouped_pickings():
            partner = self.env["res.partner"].browse()
            carrier = self.env["delivery.carrier"].browse()
            partner_id, carrier_id = key[:2]
            if partner_id:
                partner = partner.browse(partner_id)
            if carrier_id:
                carrier = carrier.browse(carrier_id)

            pickings = tuple(_pickings)
            grouping_forecast.append(
                DotDict({
                    "partner": partner,
                    "carrier": carrier,
                    "pickings": pickings,
                    "has_todo": len(pickings) > 1,
                }))
        discarded = self.discarded_picking_ids
        return {
            "grouping_forecast": grouping_forecast,
            "discarded_pickings": discarded,
            "something_todo": any([x["has_todo"] for x in grouping_forecast]),
        }
예제 #5
0
def _as_validation_error(env, exc):
    """ Return the IntegrityError encapsuled in a nice ValidationError """

    unknown = _('Unknown')
    for _name, rclass in env.registry.items():
        if exc.diag.table_name == rclass._table:
            model = rclass
            field = model._fields.get(exc.diag.column_name)
            break
    else:
        model = DotDict({'_name': unknown.lower(), '_description': unknown})
        field = DotDict({'name': unknown.lower(), 'string': unknown})

    if exc.pgcode == errorcodes.NOT_NULL_VIOLATION:
        return ValidationError(_(
            "The operation cannot be completed:\n"
            "- Create/update: a mandatory field is not set.\n"
            "- Delete: another model requires the record being deleted."
            " If possible, archive it instead.\n\n"
            "Model: %(model_name)s (%(model_tech_name)s)\n"
            "Field: %(field_name)s (%(field_tech_name)s)\n",
            model_name=model._description,
            model_tech_name=model._name,
            field_name=field.string,
            field_tech_name=field.name,
        ))

    if exc.pgcode == errorcodes.FOREIGN_KEY_VIOLATION:
        return ValidationError(_(
            "The operation cannot be completed: another model requires "
            "the record being deleted. If possible, archive it instead.\n\n"
            "Model: %(model_name)s (%(model_tech_name)s)\n"
            "Constraint: %(constraint)s\n",
            model_name=model._description,
            model_tech_name=model._name,
            constraint=exc.diag.constraint_name,
        ))

    if exc.diag.constraint_name in env.registry._sql_constraints:
        return ValidationError(_(
            "The operation cannot be completed: %s",
            translate_sql_constraint(env.cr, exc.diag.constraint_name, env.context['lang'])
        ))

    return ValidationError(_("The operation cannot be completed: %s", exc.args[0]))
예제 #6
0
 def get_pricelist_available(self, show_visible=False, website_id=1, country_code=None, website_sale_current_pl=None):
     request = DotDict({
         'website': self.env['website'].browse(website_id),
         'session': {
             'geoip': {
                 'country_code': country_code,
             },
             'website_sale_current_pl': website_sale_current_pl,
         },
     })
     return self.env['website']._get_pricelist_available(request, show_visible)
예제 #7
0
    def __init__(self, env, **kw):
        app = MockObject(
            routing={
                'type': 'http',
                'website': True,
                'multilang': kw.get('multilang', True),
            })
        app.get_db_router = app.bind = app.match = app
        if not kw.get('routing', True):
            app.match = werkzeugRaiseNotFound

        lang = kw.get('lang')
        if not lang:
            lang_code = kw.get('context',
                               {}).get('lang',
                                       env.context.get('lang', 'en_US'))
            lang = env['res.lang']._lang_get(lang_code)

        context = kw.get('context', {})
        context.setdefault('lang', lang_code)

        self.request = DotDict({
            'context': context,
            'db': None,
            'env': env,
            'httprequest': {
                'path': '/hello/',
                'app': app,
                'environ': {
                    'REMOTE_ADDR': '127.0.0.1',
                },
                'cookies': kw.get('cookies', {}),
            },
            'lang': lang,
            'redirect': werkzeug.utils.redirect,
            'session': {
                'geoip': {
                    'country_code': kw.get('country_code'),
                },
                'debug': False,
                'sale_order_id': kw.get('sale_order_id'),
            },
            'website': kw.get('website'),
        })
        odoo.http._request_stack.push(self.request)