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

How to correct a function onchange Odoo Community Version 12

Odoberať

Get notified when there's activity on this post

This question has been flagged
functionurgentonchangeodooV12
4 Replies
5533 Zobrazenia
Avatar
Ramla

Hi,

1- I want to recover the unit price and the unit of measurement of the product.

2- I want to compute : prix_total = quantite * prix_unitaire

Code py :

class ProductionVente(models.Model):
  _name = 'production.vente'
  _description ="Les ventes"
  _inherit = ['mail.thread']

  name = fields.Char(string='Référence', required=True, track_visibility='always')
  date = fields.Date(string='Date', required=True, track_visibility='onchange')
  client_id = fields.Many2one('res.partner', string='Client', required=True, track_visibility='onchange')
  article_id = fields.Many2one('product.product', string='Aliment', required=True, track_visibility='onchange')
  unite_mesure = fields.Char(string='Unité de mesure', readonly=True, compute='onchange_prix_unitaire_unite_mesure', track_visibility='onchange')
  quantite = fields.Integer(string='Quantité', required=True, track_visibility='onchange')
  prix_unitaire = fields.Float(string='Prix unitaire', readonly=True, compute='onchange_prix_unitaire_unite_mesure', track_visibility='onchange')
  prix_total = fields.Float(string='Prix total', readonly=True, compute='onchange_prix_total', track_visibility='onchange')
  cycle_id = fields.Many2one('production.cycle', string='Cycle', ondelete='cascade', readonly=True, track_visibility='onchange')
  
  _sql_constraints = [
('name_uniq', 'unique (name, date, client_id, article_id, cycle_id)', "La vente existe déjà !"),
]


  @ api.onchange ( 'article_id' )
  def onchange_prix_unitaire_unite_mesure ( self ):
    if self.article_id:
      a = self.env['product.product'].search([])
        self .prix_unitaire = a.lst_price
        self .unite_mesure = a.uom_id
  

  @ api.onchange ( 'quantite', 'prix_unitaire' )
  def onchange_prix_total ( self ):
    if self.quantite or self.prix_unitaire:
      self .prix_total = self.quantite * self.prix_unitaire


Erreur :

Erreur:

Odoo Server Error


Traceback (most recent call last):

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 757, in parse

    self._tags[rec.tag](rec, de, mode=mode)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 662, in _tag_record

    record = model.with_context(rec_context)._load_records([data], self.mode == 'update')

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3794, in _load_records

    data['record']._load_records_write(data['values'])

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3732, in _load_records_write

    self.write(values)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 66, in write

    res = super(IrActions, self).write(vals)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3269, in write

    self._write(store_vals)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3413, in _write

    self._validate_fields(vals)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 1108, in _validate_fields

    check(self)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 141, in _check_model

    raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)

odoo.exceptions.ValidationError: ("Nom de modèle 'production.vente' non valide dans la définition de l'action.", None)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 654, in _handle_exception

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

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 312, in _handle_exception

    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\pycompat.py", line 87, in reraise

    raise value

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 696, in dispatch

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

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 344, in _call_function

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

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\service\model.py", line 97, in wrapper

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

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 337, in checked_call

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

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 939, in __call__

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

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 517, in response_wrap

    response = f(*args, **kw)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\web\controllers\main.py", line 966, in call_button

    action = self._call_kw(model, method, args, {})

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\web\controllers\main.py", line 954, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\api.py", line 749, in call_kw

    return _call_kw_multi(method, model, args, kwargs)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\api.py", line 736, in _call_kw_multi

    result = method(recs, *args, **kwargs)

  File "<decorator-gen-67>", line 2, in button_immediate_upgrade

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_module.py", line 73, in check_and_log

    return method(self, *args, **kwargs)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_module.py", line 614, in button_immediate_upgrade

    return self._button_immediate_function(type(self).button_upgrade)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_module.py", line 553, in _button_immediate_function

    modules.registry.Registry.new(self._cr.dbname, update_module=True)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\modules\registry.py", line 86, in new

    odoo.modules.load_modules(registry._db, force_demo, status, update_module)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\modules\loading.py", line 417, in load_modules

    force, status, report, loaded_modules, update_module, models_to_check)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\modules\loading.py", line 313, in load_marked_modules

    perform_checks=perform_checks, models_to_check=models_to_check

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\modules\loading.py", line 222, in load_module_graph

    load_data(cr, idref, mode, kind='data', package=package, report=report)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\modules\loading.py", line 68, in load_data

    tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 801, in convert_file

    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 864, in convert_xml_import

    obj.parse(doc.getroot(), mode=mode)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 754, in parse

    self.parse(rec, mode)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 763, in parse

    exc_info[2]

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\pycompat.py", line 86, in reraise

    raise value.with_traceback(tb)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 757, in parse

    self._tags[rec.tag](rec, de, mode=mode)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\convert.py", line 662, in _tag_record

    record = model.with_context(rec_context)._load_records([data], self.mode == 'update')

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3794, in _load_records

    data['record']._load_records_write(data['values'])

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3732, in _load_records_write

    self.write(values)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 66, in write

    res = super(IrActions, self).write(vals)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3269, in write

    self._write(store_vals)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 3413, in _write

    self._validate_fields(vals)

  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 1108, in _validate_fields

    check(self)

  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 141, in _check_model

    raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)

odoo.tools.convert.ParseError: "Nom de modèle 'production.vente' non valide dans la définition de l'action.

None" while parsing file:/c:/program files (x86)/odoo 12.0/server/odoo/addons/production/views/cycle_views.xml:230, near

<record model="ir.actions.act_window" id="production_vente_list_action">

      <field name="name">Les ventes</field>

      <field name="context">{'default_cycle_id': active_id}</field>

      <field name="domain">[('cycle_id', '=', active_id)]</field>

      <field name="res_model">production.vente</field>

    </record>

-1
Avatar
Zrušiť
Ramla
Autor

class ProductionVente(models.Model):

_name = 'production.vente'

_description ="Les ventes"

_inherit = ['mail.thread']

name = fields.Char(string='Référence', required=True, track_visibility='always')

date = fields.Date(string='Date', required=True, track_visibility='onchange')

client_id = fields.Many2one('res.partner', string='Client', required=True, track_visibility='onchange')

article_id = fields.Many2one('product.product', string='Article', required=True, track_visibility='onchange')

#unite_mesure = fields.Char(string='Unité de mesure', store=True, related='article_id.uom_name', track_visibility='onchange')

quantite = fields.Integer(string='Quantité', required=True, track_visibility='onchange')

prix_unitaire = fields.Float(string='Prix unitaire', store=True, related='article_id.lst_price', track_visibility='onchange')

prix_total = fields.Float(string='Prix total', readonly=True, compute='onchange_prix_total', track_visibility='onchange')

cycle_id = fields.Many2one('production.cycle', string='Cycle', ondelete='cascade', readonly=True, track_visibility='onchange')

_sql_constraints = [

('name_uniq', 'unique (name, cycle_id)', "La référence de la vente existe déjà !"),

]

#Calculer le prix_total = quantite * prix_unitaire

@ api.onchange ( 'quantite', 'prix_unitaire' )

def onchange_prix_total ( self ):

if self.quantite or self.prix_unitaire:

self .prix_total = self.quantite * self.prix_unitaire

Avatar
Ramla
Autor Best Answer
class ProductionVente(models.Model):
  _name = 'production.vente'
  _description ="Les ventes"
  _inherit = ['mail.thread']

  name = fields.Char(string='Référence', required=True, track_visibility='always')
  date = fields.Date(string='Date', required=True, track_visibility='onchange')
  client_id = fields.Many2one('res.partner', string='Client', required=True, track_visibility='onchange')
  article_id = fields.Many2one('product.product', string='Article', required=True, track_visibility='onchange')
  #unite_mesure = fields.Char(string='Unité de mesure', store=True, related='article_id.uom_name', track_visibility='onchange')
  quantite = fields.Integer(string='Quantité', required=True, track_visibility='onchange')
  prix_unitaire = fields.Float(string='Prix unitaire', store=True, related='article_id.lst_price', track_visibility='onchange')
  prix_total = fields.Float(string='Prix total', readonly=True, compute='onchange_prix_total', track_visibility='onchange')
  cycle_id = fields.Many2one('production.cycle', string='Cycle', ondelete='cascade', readonly=True, track_visibility='onchange')
  
  _sql_constraints = [
('name_uniq', 'unique (name, cycle_id)', "La référence de la vente existe déjà !"),
]
  
  #Calculer le prix_total = quantite * prix_unitaire
  @ api.onchange ( 'quantite', 'prix_unitaire' )
  def onchange_prix_total ( self ):
    if self.quantite or self.prix_unitaire:
      self .prix_total = self.quantite * self.prix_unitaire
0
Avatar
Zrušiť
Avatar
Hilar Andikkadavath
Best Answer

Please restart your server or check your init file where the model is added or not. The error says the corresponding model is not found or loaded. Possibly it's not updated in your DB.

0
Avatar
Zrušiť
Avatar
SLIFE AFRICA
Best Answer

Hello,

1. Be sure to have imported your model python file in __.init__.py file

2.  If the import is done, make sure to don't have bad indentation in your model python file

Hoping that it can help you

0
Avatar
Zrušiť
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
Related Posts Replies Zobrazenia Aktivita
How to correct the function onchange : compute age Odoo Community 12
function urgent onchange odooV12
Avatar
Avatar
Avatar
2
máj 19
4407
How to correct a function onchange Odoo Community Version 12 Solved
function urgent onchange odooV12
Avatar
Avatar
Avatar
2
apr 19
4905
How to compute the sum of the values Odoo Community 12 ?
function urgent onchange compute odooV12
Avatar
Avatar
1
apr 19
5621
Function Onchange Odoo Community Version 12
function python urgent onchange odooV12
Avatar
0
apr 19
4418
How to create a function onchange Odoo Community Version 12 Solved
function python urgent odooV12
Avatar
Avatar
1
apr 19
9939
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