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

raise ValueError("Expected singleton: %s" % self) ValueError: Expected singleton: fashion.order.lines(216, 217)

Subscribe

Get notified when there's activity on this post

This question has been flagged
productionorder.lines
2 Replies
3307 Views
Avatar
Novan

from email.policy importdefault
from attr import fields

from odoo import models, fields, api
classFashionOrder(models.Model):

_name = 'fashion.order'#untuk lead

_rec_name = 'order_name'
customer_name = fields.Many2one('fashion.customer', string="Name")

order_name = fields.Char("Order Name", default="ORDER_")

notes = fields.Char("Notes")

order_line = fields.One2many('fashion.order.lines','order_id', string = "Order Lines")

totalorder_price = fields.Float(string="Total Order Price", readonly=True, store=True, compute="_compute_total_order_price")
state = fields.Selection([ ('lead', 'Lead'), ('ordered', 'Ordered'), ('paid', 'Paid') ], default='lead', string="Status", required=True)

def action_submit_order(self):

self.state = 'ordered'

view_ordered = self.env.ref('foodstore.action_fashion_order').read()[0]

view_ordered['domain'] = [('state', '=', 'ordered')]

view_ordered['target'] = 'main'

invoice_line_value = []

for line in self.order_line:

invoice_line_value.append((0,0, {'product_id': line.product_id.id, }))
order_rec = {'invoice_customer': self.customer_name.customername,'totalinvoice_price': self.totalorder_price,'state': self.state,'invoice_lines': invoice_line_value, }

order = self.env['fashion.invoice'].create(order_rec)
return view_ordered
def action_delete(self):

print('', self.order_name)

self.unlink()

view_orders = self.env.ref('foodstore.action_fashion_order').read()[0]

view_orders['target'] = 'main'
return view_orders
@api.depends('order_line.total_price')

def_compute_total_order_price(self):

current_price = 0

for product in self.order_line:

current_price += product.total_price

self.totalorder_price = current_price


classFashionOrderLines(models.Model):

_name = 'fashion.order.lines'
product_id = fields.Many2one('fashion.product', string="Product Name")

product_qty = fields.Integer(string = "Quantity", default="1")

order_id = fields.Many2one('fashion.order', string="Order ID")
order_code = fields.Char("Order Code", default="ORDER-")

price_id = fields.Float(related='product_id.price', string="Price")

sale_price = fields.Float(related='price_id', string="Sale Price", readonly=False)

total_price = fields.Float("Total Price", store=True, compute="action_calculate_price")

@api.depends('sale_price','product_qty')

def action_calculate_price(self):

total_prices = self.total_price

total_prices = self.sale_price * self.product_qty

self.total_price = total_prices


Here above is my code, when i add 2 product directly, then save it, this error is appear. Any idea how to solve it?

0
Avatar
Discard
Avatar
Jainesh Shah(Aktiv Software)
Best Answer

Hello Syah,

You haven't used for loop in "action_calculate_price" compute method in fashion.order.line. That is why it is showing an singleton error. Use for loop then it will work properly.

I hope This will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

0
Avatar
Discard
Avatar
Sam fayad
Best Answer

Hi, the matter is every model is a list of records, so if you are trying to change some field then you either have to check that one record is edited on a time, or you have to pass on each record, here is the solution for all of your functions in your code:

def action_calculate_price(self):

for record in self:

total_prices = record.total_price

total_prices = record.sale_price * record.product_qty

record.total_price = total_prices

or you just can do:

@api.depends('sale_price','product_qty')

def action_calculate_price(self):

self.ensure_one()

total_prices = self.total_price

total_prices = self.sale_price * self.product_qty

self.total_price = total_prices now you do like I wrote above for all of your functions in your code. I also suggest you to use more (if) , cause you might have issues like there is no price or quantity entered, so you might got error then, to avoid this I recommended you to us( if (exist) do)

0
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
How to automatically return surplus stock from Pre-Production to Stock after MO consumption?
production
Avatar
Avatar
Avatar
2
Sep 25
773
Workshop setup time
production
Avatar
Avatar
1
Jul 25
1008
Building a new order from previously purchased sales order lines V18
order.lines
Avatar
Avatar
Avatar
3
Mar 25
1679
Show three decimals in Sale Order line subtotals? Have changed currency precision to 3 decimal places (only fixes price and total, not subtotal)
order.lines
Avatar
2
Jan 25
4425
Odoo documentation - V10, manufacturing - routings in BoMs
production
Avatar
0
Apr 17
3153
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