Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

ValueError: Expected singleton: Models_name(38, 39)

Subscribe

Get notified when there's activity on this post

This question has been flagged
errorodoosingleton
3 Replies
7473 Views
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
Discard
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
Discard
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Error on Odoo setup
error odoo
Avatar
Avatar
Avatar
2
Feb 23
9005
odoo server error
error odoo
Avatar
0
Sep 20
4050
Error while starting openerp-server ??
error odoo
Avatar
Avatar
2
Mar 15
6753
How can i change my odoo domain name ? Solved
error odoo domainname
Avatar
Avatar
Avatar
Avatar
3
Sep 25
2814
problem backup Solved
error backup odoo
Avatar
Avatar
Avatar
3
Jun 24
7514
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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