Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing-
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

How to Automatically Assign SKU (internal reference code) to Products depending on attributes?

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
automatedvariantskuv14AutomatedActions
1 Antworten
7060 Ansichten
Avatar
James Camfield

I want to automatically assign a SKU (internal reference code) to products depending on if they have the attribute "Organic". If Variants are created I want them only to be given an SKU if they have the attribute "Organic.



My current automated Action:

Model: Product

Active: True

Trigger: On Creation & Update

Trigger Fields:

Before Update Domain: Match all records

Apply on:     Product Attributes > Values > Value = "Organic

                     Internal Reference is not set

                     Product Category > Name = "Food"

Action To Do : Update the Record

Data to write:

                      Field: Internal Reference (product.product)

                      Evaluation Type : Python expression

                      Value: env['ir.sequence'].next_by_code('organic_sku')



When I create a product and give it many variants, all of the variants are given SKUs even though only one of the variants had organic. 

(example the variants: (product1, organic, blue), (product2, conventional, red) and (product3, conventional, green) will all be given an SKU even though only product1 is organic). 


How can it give each variant an SKU only if that variant is Organic?


Thanks for the Help

James Camfield

Odoo 14.0+e (Enterprise Edition)

0
Avatar
Verwerfen
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Beste Antwort

I think you need to write a python code in the server action.

Create a server action with Action "To Do='Execute Python Code'" and add the following code:

for prod in records:
for tmp_attr_val in prod.product_template_attribute_value_ids:
if tmp_attr_val.attribute_id.name == 'Organic':
prod.default_code = env['ir.sequence'].next_by_code('organic_sku')





4
Avatar
Verwerfen
James Camfield
Autor

Thanks for responding!

I tried using your code, but it wouldn't let me save and had this error message:

forbidden opcode(s) in "# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# To return an action, assign: action = {...}\n\nfor prod in records:\n for tmp_attr_val in prod.product_template_attribute_value_ids:\n if tmp_attr_val.attribute_id.name == 'Organic':\n #prod.write({'default_code' : env['ir.sequence'].next_by_code('organic_sku') })\n prod.default_code = env['ir.sequence'].next_by_code('organic_sku')": STORE_ATTR

I think it didnt allows the = on the last line

So I replaced it with

prod.write({'default_code' : env['ir.sequence'].next_by_code('organic_sku') })

Unfourtunately it gave this error when the model was 'Product Template':

Error:

Odoo Server Error

Traceback (most recent call last):

File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch

result = request.dispatch()

File "/home/odoo/src/odoo/odoo/http.py", line 683, in dispatch

result = self._call_function(**self.params)

File "/home/odoo/src/odoo/odoo/http.py", line 359, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper

return f(dbname, *args, **kwargs)

File "/home/odoo/src/odoo/odoo/http.py", line 347, in checked_call

result = self.endpoint(*a, **kw)

File "/home/odoo/src/odoo/odoo/http.py", line 912, in __call__

return self.method(*args, **kw)

File "/home/odoo/src/odoo/odoo/http.py", line 531, in response_wrap

response = f(*args, **kw)

File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1745, in run

result = action.run()

File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 632, in run

res = runner(run_self, eval_context=eval_context)

File "/home/odoo/src/odoo/addons/website/models/ir_actions.py", line 61, in _run_action_code_multi

res = super(ServerAction, self)._run_action_code_multi(eval_context)

File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 501, in _run_action_code_multi

safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action'

File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 346, in safe_eval

raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))

Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "/home/odoo/src/odoo/odoo/http.py", line 639, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/home/odoo/src/odoo/odoo/http.py", line 315, in _handle_exception

raise exception.with_traceback(None) from new_cause

ValueError: <class 'TypeError'>: "'NoneType' object is not iterable" while evaluating

"# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# To return an action, assign: action = {...}\n\nfor prod in records:\n for tmp_attr_val in prod.product_template_attribute_value_ids:\n if tmp_attr_val.attribute_id.name == 'Organic':\n prod.write({'default_code' : env['ir.sequence'].next_by_code('organic_sku') })\n #prod.default_code = env['ir.sequence'].next_by_code('organic_sku')"

When I used 'Product' as the model nothing happened

What is the soloution?

Thanks for your help!!!

Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
Automated Actions: Send Payment Receipt to Customers
automated actions v14 AutomatedActions
Avatar
0
Sept. 23
3774
Automated Action on Odoo activity deadline
automated AutomatedActions
Avatar
Avatar
1
Feb. 24
2736
Automated Action sending emails for first time only Gelöst
automated AutomatedActions
Avatar
Avatar
2
Jan. 24
3113
Create Auto Activity for old customers
v14 AutomatedActions
Avatar
0
Okt. 21
3205
Automated task creation in sales after make to order production is finished
automated AutomatedActions
Avatar
0
Mai 21
2555
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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