Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

ValueError: Expected singleton: Models_name(38, 39)

Subscriure's

Get notified when there's activity on this post

This question has been flagged
errorodoosingleton
3 Respostes
7472 Vistes
Avatar
Chaanto

Here is The problems


class Purchase(models.Model):

    _name = 'purchase'

    name = fields.Char(string="name")

    orderDate = fields.Date(string="Order Date")

    salesPerson = fields.Char(string="Sales Person", required=True)

    expiredDate = fields.Date(string="Expired Date", required=True)

    company = fields.Char(string="Company", related="customer_id.company", readonly=True)

    tax = fields.Float(string ="Tax")

    unTax = fields.Float(string="Untaxed", compute="_total_price")

    amount_total =  fields.Float(compute='_compute_amount_total', string="Total")

    orderNumber = fields.Char(string="Order Number")

    subpurchase_ids = fields.One2many('subpurchase', 'purchase_id', string="Purchase Lines")

    customer_id = fields.Many2one('customer', string='partner', required=True)

   

    

    state = fields.Selection([

            ('new', 'New'), 

            ('draft', 'Draft'),

            ('validate', 'Validated'),

            ('cancel', 'Cancelled')], 

            string='Status', required=False, readonly=True, copy=False, default='new')

    

    @api.onchange('tax', 'unTax')       

    @api.multi

    def _compute_amount_total(self):

        self.amount_total = self.unTax + self.tax

        

    @api.depends('subpurchase_ids', 'subpurchase_ids.amount') #tambah kalo butuh relasi tambahan

    @api.multi

    def _total_price(self):

        for purchase in self :

            total_price = 0

            for subpurchase in purchase.subpurchase_ids:

                total_price += subpurchase.amount

            purchase.unTax = total_price


class SubPurchase(models.Model):
    _name = 'subpurchase'

    category = fields.Char(string="Category", related="product_id.category", readonly=True)
    amount = fields.Float(compute='_compute_amount', string="Amount")
    quantity = fields.Integer(string="Quantity")
    codeItem = fields.Char(string="Code Item", readonly=True, related="product_id.codeItem")
    price = fields.Float(string="Item Price", readonly=True, related="product_id.price")
    sequence = fields.Char(string="Sequence")
    purchase_id = fields.Many2one('purchase', string="Customer")

 
    @api.multi
    @api.onchange('quantity', 'price')
    def _compute_amount(self):
        self.amount = self.quantity * self.price


i have an order lines so when i want add an item 2 or more the error come out ? how to fix this ?
example in order line i add an item Mouse 1 and save <= OKEY but when i add another item mouse 2 so there have a 2 item when i save this error come out 
1
Avatar
Descartar
Sudhir Arya (ERP Harbor Consulting Services)

Thanks to you all for answer this question

Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

I think you need to use a for loop in `_compute_amount_total` and `_compute_amount` methods.

Just give it a try and if this does not solve the issue, please post the traceback.

7
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

The Single ton error can be sorted out by iterating the self over a for loop or by using self.ensure_one() . In your code, at a first glance everything seems to be fine, you have iterated the self and the one2many lines. So will suggest you to cross check the code by putting the print statements in the code and see.

Suppose if any of the variables is getting the value as sale.order(38, 39), just a sample, then make sure that the value is then iterated over the loop such a way that we will get sale.order(38) and sale.order(39).

If you have the added the fields amount and amount_total in the Tree views, make sure that the corresponding compute function is also iterated over the for loop.


@api.onchange('tax', 'unTax')       
@api.multi
def _compute_amount_total(self):
for rec in self:
rec.amount_total = rec.unTax + rec.tax


Thanks

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
Error on Odoo setup
error odoo
Avatar
Avatar
Avatar
2
de febr. 23
9005
odoo server error
error odoo
Avatar
0
de set. 20
4050
Error while starting openerp-server ??
error odoo
Avatar
Avatar
2
de març 15
6753
How can i change my odoo domain name ? Solved
error odoo domainname
Avatar
Avatar
Avatar
Avatar
3
de set. 25
2811
problem backup Solved
error backup odoo
Avatar
Avatar
Avatar
3
de juny 24
7514
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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