Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Sociale media-marketing
    • E-mailmarketing
    • Sms-marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

How to change many2many field route_ids value?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
many2manymanufactureBuymto
4 Antwoorden
8284 Weergaven
Avatar
lemonjin2000@yahoo.com.hk

Hi Guys,

I have been working for my below code for few days, but still can't get it work. What I intended to do is when one select raw-material product type (customized field) in Product Create section, Buy route will be selected. On the other hand, select "Finish Good", Manufacture and MTO route will be selected. The below codes does the half because it doesn't clear the previous selected value when switch from Raw-Material to Finish Good. The previous filled up value still remain. Please help! Thx so much.

@ api.onchange ('custom_product_type')

    def _onchange_custom_product_type (self):

        if self.custom_product_type:

            self.warehouse = self.env.ref ('stock.warehouse0')

            route_manufacture = self.env.ref ('stock.warehouse0'). manufacture_pull_id.route_id.id

            route_mto = self.env.ref ('stock.warehouse0'). mto_pull_id.route_id.id

            buy_route = self.env.ref ('stock.warehouse0'). buy_pull_id.route_id.id

             if self.custom_product_type == 'RM':

                self.sale_ok = False

                self.purchase_ok = True

                self.update ({'route_ids': [(6, 0, [buy_route])]})

            elif self.custom_product_type == 'FG' or self.custom_product_type == 'HG':

                self.sale_ok = True

                self.purchase_ok = False

                self.update ({'route_ids': [(6, 0, [route_manufacture, route_mto])]})

0
Avatar
Annuleer
Avatar
faOtools
Beste antwoord

Just a few comments regarding.

1. Why have you chosen to use @api.onchange for that purpose? It is triggered only when the field is manually changed on the form. Moreover, it is not ideal to change many2many fields.

2. Basically, in onchange you are not obliged to work with m2m/o2m operators (at least at Odoo version > 11). So, if I’m not mistaken you may do self.route_ids = self.env.ref('stock.warehouse0').manufacture_pull_id.route_id

3. Continuing the point 1: it is much more efficient to work with inverse of the field ‘custom_product_type’ since in inverse the record is already saved. I would offer something like:

def _inverse_custom_product_type(self):
    warehouse = self.env.ref('stock.warehouse0')
    fhg_routes = []
    buy_routes = []
    if warehouse:
        fhg_routes = (warehouse.manufacture_pull_id.route_id + warehouse.mto_pull_id.route_id).ids
        buy_routes = warehouse.buy_pull_id.route_id.ids
    for product in self:
        res_route_ids = []
        if product.custom_product_type ==  'RM':
            res_route_ids = buy_routes
        elif product.custom_product_type in  ['FG', 'HG']:
            res_route_ids = fhg_routes
        product.route_ids = [(6, 0, res_route_ids)]
custom_product_type = fields.Selection(
    [
        ("RM", "Raw MAterial"),
        ("FG", "Finished Good"),
        ("HG", "whatever it means")
    ],
    inverse=_inverse_custom_product_type,
)


0
Avatar
Annuleer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Beste antwoord

Hi,

Try the following

self.update({'route_ids': [(5,), (6, 0, [route_manufacture, route_mto])]})

Hope it helps

1
Avatar
Annuleer
Avatar
Adnier Rosello
Beste antwoord

Hi, did you try: self.route_ids = [(6, 0, [route_manufacture, route_mto])]

0
Avatar
Annuleer
Avatar
lemonjin2000@yahoo.com.hk
Auteur Beste antwoord

@Adnier, thx for your response, but it doesn't work. I tried.


@Odoo Tools, thx for your response, your code is much better than mine. I will have a try and let you know if it works. Yes, you are correct, api.change won't be able to change many2many vaule. Actually, I found out my original work after save. Althought previous selected value doesn't change in the "form" only, it does change after press "Save". Your code looks more reasonable and sophisticate.
0
Avatar
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
MTO-BUY Routing in inventory have been switch
inventory routing Buy mto
Avatar
1
aug. 19
1265
How to config product as make to stock to generate purchase order for zero stocks items? Opgelost
stock purchase_order manufacture make_to_order Buy
Avatar
Avatar
Avatar
Avatar
3
dec. 24
13886
Buy and manufacture route options selected simultaneously Opgelost
inventory variants manufacture Buy routes
Avatar
Avatar
Avatar
2
okt. 24
4625
How to configure to take from stock and manufacture the left quantity
inventory rules manufacture routes mto
Avatar
Avatar
Avatar
2
aug. 21
6125
MTO on the manufacturing, draft MO from the Sales Order
mto
Avatar
Avatar
Avatar
2
mrt. 24
2948
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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