Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Grant portal access automatically when contact is created

Naroči se

Get notified when there's activity on this post

This question has been flagged
automatedportal-userodoo.shv12
4 Odgovori
12067 Prikazi
Avatar
Chris Leray

HI, 


I am trying to create an automated action in order to automatically grant portal access to a new contact. 

As right now if you create a new contact from the POS they don't have access to the website so they have to create a new account and then contacts are duplicated.

Maybe there is better to do it than automated action?

thanks, 

0
Avatar
Opusti
Avatar
Paresh Wagh
Best Answer

Hi Chris:

Using an automated action is the simplest and most elegant way of doing this.

EDIT:

Create an automated action on the Contact (res.partner) model with a Trigger Condition of On Creation and Action To Do of Execute Python Code

Put the following code in the Python Code field:

# Ensure an email address has been entered so that it can be used for the login
if not record.email:
    raise Warning("Please enter an email address.")

x_group_portal_user = env.ref('base.group_portal')
env['res.users'].create([{'name': record.name,
                          'login': record.email,
                          'partner_id': record.id,
                          'company_id': env.company.id, 
                          'groups_id': [(6, 0, [x_group_portal_user.id])],
                          }],)

1
Avatar
Opusti
Chris Leray
Avtor

thanks for your message. I have tried to create this automated action but it still does now work. I am not sure about the loving there and python code I should add ?

any chance u can help?

thanks

Paresh Wagh

Hi Chris: I have edited my post and added the details.

Chris Leray
Avtor

awesome, thanks a lot, it works perfectly. I just add to remove the 'company_id': env.company.id,

but all good.

Chris Leray
Avtor

Actually I realized that with this script it also publish the contact on the website which I don't want to.

I want to grant them the access but don't want to publish the contact on the website if that make sense.

I had a look at my group and it looks like my grant port is id = 9 and not 6. I changed it to 9 but then it does now work.

I think this is not the same group, what am i missing here?

sorry, thanks a lot

Paresh Wagh

Hi Chris:

The (6,0,...) part is the syntax for populating one2many/many2many fields. The "6" indicates that the existing groups assigned to this user need to be removed and replaced with the portal user group. If you need more groups to be assigned to the user, you will need to add their ref ids to the array of group ids on the right.

Here's a link to the documentation (you will have to scroll down a bit to the one2many.many2many part):

https://www.odoo.com/documentation/13.0/reference/orm.html#create-update

Regarding the question about the Contact getting published to the website, when I try this out in my environment, the Contact is not getting automatically published. There must be something else in your environment that is triggering off the publish.

You can try to get around this by adding the following line at the end of the code (after the create).

record['is_published'] = False

This will reset the published flag to False even if it gets set to True somewhere else.

NOTE: You may want to use this as a last resort only if you cannot find what is automatically triggering the publish.

Chris Leray
Avtor

ok I see, this is really helpful thanks a lot. I will try to understand where is this coming from

thanks ,

Cherry Rose Sanchez

hi can you add a condition, wherein portal access will be granted only if the contact has that information. otherwise, it will skip. example: a custom field "portal_user" is true before granting portal access upon creation? and does it work if odoo bot created the contact via website?

Avatar
Luke Austin
Best Answer

I'm using this ina  slightly different context - ie on sales order confirmation, so I need to check if theuser has already been granted portal access.

I've tried a few things, like:

if not record.partner_id.has_group('base.portal_users'):

Which doesn't work, because it's addressing the partner, not the user but I can't see how to get from record to the user group. How would you add a conditional to exclude existing portal users from this code? 

0
Avatar
Opusti
Avatar
MUHAMMAD Imran
Best Answer

Just do simplify,

In wizard just replace your apply button with following button

<button name="1174" type="action" string="Apply"/>

here name is the id of your server action. 

In server action you can add the code like,

for rec in records:

  for userin rec.user_ids:

    user['in_portal'] = True

 rec.action_apply()

Video : https://youtu.be/Mjr-RpITSC0

0
Avatar
Opusti
Diego Riera Diaz

Hi Muhammad,

I am new to Odoo dev. Looking at your video and in V15. Did you create a new server action or updated an existing one ?

Thanks you !

Diego

Avatar
Chris TRINGHAM
Best Answer

Paresh's solution works, and will automatically create portal access for all contacts, so you might want to add "Apply On": Customer Rank is set

 [["customer_rank","!=",False]]
One other suggestion.  If you create customers through the normal Odoo user interface (and not POS), there is an action to "add portal access" (you can do this for multiple customers from the list view or for individual customers using the Form View).


This image has an empty alt attribute; its file name is grant-portal-access-list-view.jpg

This image has an empty alt attribute; its file name is grant-portal-access.jpg
0
Avatar
Opusti
Chris Leray
Avtor

great thanks a lot for your help:) all good

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Add a Mailing contact automatically to a mailing list Solved
python automated mailing odoo.sh v12
Avatar
Avatar
Avatar
Avatar
Avatar
12
apr. 24
14507
Automated action with python expression Solved
action python automated odoo.sh v12
Avatar
Avatar
6
mar. 24
10688
How to code Automated Action to update a ManytoOne custom field to match source field?
automated v12
Avatar
Avatar
2
jul. 19
6632
[v12] adding field to res_partner breaks odoo.sh instance Solved
odoo.sh v12 upgrad
Avatar
Avatar
3
avg. 21
4549
How to access sudo on Odoo.sh? v12
sudouser odoo.sh v12
Avatar
Avatar
3
avg. 19
10479
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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