Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

UnboundLocalError: local variable 'potential' referenced before assignment

Odoberať

Get notified when there's activity on this post

This question has been flagged
1 Odpoveď
8990 Zobrazenia
Avatar
Bhaskar Reddy

below is my code showing unboundlocalerror 


@api.multi

    def action_apply(self):

        

        self.ensure_one()

        values = {

            'team_id': self.team_id.id,

        }


        if self.partner_id:

            values['partner_id'] = self.partner_id.id


        if self.name == 'merge':

            opportunities = self.with_context(active_test=False).potential_ids.merge_potential()

            if not opportunities.active:

                opportunities.write({'active': True, 'activity_type_id': False, 'lost_reason': False})

            if opportunities.type == "opportunity":

                values.update({'opportunity_ids': opportunities.ids, 'user_ids': [self.user_id.id]})

                self.with_context(active_ids=opportunities.ids)._convert_potential(values)

            elif not self._context.get('no_force_assignation') or not opportunities.user_id:

                values['user_id'] = self.user_id.id

                opportunities.write(values)

        else:

            opportunities = self.env['crm.lead'].browse(self._context.get('active_ids', []))

            potential = self.env['crm.potentials'].create(values)

            team_id = opportunities.team_id.id if opportunities.team_id else False

            customer = opportunities.partner_id if opportunities.partner_id else False

            values = {

                'planned_revenue': opportunities.planned_revenue,

                'probability': opportunities.probability,

                'name': opportunities.name,

                'partner_id': customer.id if customer else False,

                'type': 'potential',

                'date_open': fields.Datetime.now(),

                'email_from': customer and customer.email or opportunities.email_from,

                'phone': customer and customer.phone or opportunities.phone,

                'date_conversion': fields.Datetime.now(),

            }

            if not opportunities.stage_id:

                stage = opportunities._stage_find(team_id=team_id)

                values['stage_id'] = stage.id

                if stage:

                    values['probability'] = stage.probability

            potential = self.env['crm.potentials'].create(values)

        return potential.redirect_potential_view()



my error is:


Odoo Server Error
Traceback (most recent call last):
  File "D:\smoothtel\odoo\odoo\http.py", line 646, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "D:\smoothtel\odoo\odoo\http.py", line 307, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "D:\smoothtel\odoo\odoo\tools\pycompat.py", line 87, in reraise
    raise value
  File "D:\smoothtel\odoo\odoo\http.py", line 683, in dispatch
    result = self._call_function(**self.params)
  File "D:\smoothtel\odoo\odoo\http.py", line 339, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "D:\smoothtel\odoo\odoo\service\model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "D:\smoothtel\odoo\odoo\http.py", line 332, in checked_call
    result = self.endpoint(*a, **kw)
  File "D:\smoothtel\odoo\odoo\http.py", line 927, in __call__
    return self.method(*args, **kw)
  File "D:\smoothtel\odoo\odoo\http.py", line 512, in response_wrap
    response = f(*args, **kw)
  File "D:\smoothtel\odoo\addons\web\controllers\main.py", line 928, in call_button
    action = self._call_kw(model, method, args, {})
  File "D:\smoothtel\odoo\addons\web\controllers\main.py", line 916, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "D:\smoothtel\odoo\odoo\api.py", line 689, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "D:\smoothtel\odoo\odoo\api.py", line 680, in call_kw_multi
    result = method(recs, *args, **kwargs)
  File "D:\smoothtel\odoo\addons\crm\wizard\crm_opportunity_to_potential.py", line 158, in action_apply
    return potential.redirect_potential_view()
UnboundLocalError: local variable 'potential' referenced before assignment
0
Avatar
Zrušiť
Avatar
Hilar Andikkadavath
Best Answer


@api.multi

    def action_apply(self):

        self.ensure_one()

        values = {

            'team_id': self.team_id.id,

        }


        if self.partner_id:

            values['partner_id'] = self.partner_id.id


        if self.name == 'merge':

            opportunities = self.with_context(active_test=False).potential_ids.merge_potential()

            if not opportunities.active:

                opportunities.write({'active': True, 'activity_type_id': False, 'lost_reason': False})

            if opportunities.type == "opportunity":

                values.update({'opportunity_ids': opportunities.ids, 'user_ids': [self.user_id.id]})

                self.with_context(active_ids=opportunities.ids)._convert_potential(values)

            elif not self._context.get('no_force_assignation') or not opportunities.user_id:

                values['user_id'] = self.user_id.id

                opportunities.write(values)

        else:

            opportunities = self.env['crm.lead'].browse(self._context.get('active_ids', []))

            potential = self.env['crm.potentials'].create(values)

            team_id = opportunities.team_id.id if opportunities.team_id else False

            customer = opportunities.partner_id if opportunities.partner_id else False

            values = {

                'planned_revenue': opportunities.planned_revenue,

                'probability': opportunities.probability,

                'name': opportunities.name,

                'partner_id': customer.id if customer else False,

                'type': 'potential',

                'date_open': fields.Datetime.now(),

                'email_from': customer and customer.email or opportunities.email_from,

                'phone': customer and customer.phone or opportunities.phone,

                'date_conversion': fields.Datetime.now(),

            }

            if not opportunities.stage_id:

                stage = opportunities._stage_find(team_id=team_id)

                values['stage_id'] = stage.id

                if stage:

                    values['probability'] = stage.probability

        potential = self.env['crm.potentials'].create(values) # potential should be in scope, must have value

        if potential:

            return potential.redirect_potential_view()

        else:

            return [] # return or do any operation


1
Avatar
Zrušiť
Bhaskar Reddy
Autor

thanks

OdooBot
Welcome

On Mon, 11 Jun 2018, 1:06 p.m. Bhaskar Reddy, <bhaskar@sevate.com> wrote:

thanks

--
Bhaskar Reddy

Sent by Odoo S.A. using Odoo.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now