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

How to check the product type of the product in the sale.order.line?[odoo10]

Subscribe

Get notified when there's activity on this post

This question has been flagged
productsale.ordertypesource_code
7 Replies
7742 Views
Avatar
tyrion

I have to check the product type of each line in the sale.order.line before invoicing. So in the sale.py I have added the code under action_invoice_create(self, grouped=False, final=False) method (line 342 of source code).

But the code doesn't enter the print condition according to the product type. How to correct?

if group_key not in invoices:
 if 'product_id.product_tmpl_id.type' == 'service':
  print 'Service product'
     elif 'product_id.product_tmpl_id.type' == 'stockable':
         print 'Stockable product'      
     else:
         print 'Service product'

0
Avatar
Discard
Avatar
Mayank Gosai
Best Answer

Hello Naksha,

All you did is correct , you just need to correct your field name declaration as you code it in string.

Replace this 'product_id.product_tmpl_id.type' to product_id.product_tmpl_id.type.

Paste this code:

if group_key not in invoices:
  if product_id.product_tmpl_id.type == 'service':
   print 'Service product'
elif product_id.product_tmpl_id.type == 'stockable':
      print 'Stockable product'
  else:
  print 'Service product'

1
Avatar
Discard
tyrion
Author

But removing the single quotes just make Unresolved reference 'product_id'. I tried that in pycharm.

Mayank Gosai

Can you share your field declaration code ?

Your .py file.

tyrion
Author

@api.multi

def action_invoice_create(self, grouped=False, final=False):

"""

Create the invoice associated to the SO.

:param grouped: if True, invoices are grouped by SO id. If False, invoices are grouped by

(partner_invoice_id, currency)

:param final: if True, refunds will be generated if necessary

:returns: list of created invoices

"""

inv_obj = self.env['account.invoice']

precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')

invoices = {}

references = {}

for order in self:

group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id)

for line in order.order_line.sorted(key=lambda l: l.qty_to_invoice < 0):

if float_is_zero(line.qty_to_invoice, precision_digits=precision):

continue

if group_key not in invoices:

if group_key not in invoices:

if product_id.product_tmpl_id.type == 'service':

print 'Service product'

elif product_id.product_tmpl_id.type == 'stockable':

print 'Stockable product'

else:

print 'Consumable product'

inv_data = order._prepare_invoice()

invoice = inv_obj.create(inv_data)

references[invoice] = order

invoices[group_key] = invoice

elif group_key in invoices:

vals = {}

if order.name not in invoices[group_key].origin.split(', '):

vals['origin'] = invoices[group_key].origin + ', ' + order.name

if order.client_order_ref and order.client_order_ref not in invoices[group_key].name.split(', ') and order.client_order_ref != invoices[group_key].name:

vals['name'] = invoices[group_key].name + ', ' + order.client_order_ref

invoices[group_key].write(vals)

if line.qty_to_invoice > 0:

line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice)

elif line.qty_to_invoice < 0 and final:

line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice)

if references.get(invoices.get(group_key)):

if order not in references[invoices[group_key]]:

references[invoice] = references[invoice] | order

That is the source code from sale.py odoo 10 community edition(from line 324). I was trying my code directly there. (It's not the norm, just experimenting)

Mayank Gosai

Hi,

I think in the loop your are missing variable line.

Can you try with line.product_id.product_tmpl_id.type

Hope it helps,

Regards,

Mayank Gosai

Waleed Ali Mohsen

You modified the original sale.py file so you need to upgrade the sales app --> from Apps open sales app and upgrade it. give it a try

Avatar
airacobra
Best Answer

action_invoice_create method belogs to "sale.order" model.  product_id field belongs to "sale.order.line" model and is linked in "sale.order" by order_line field.

So you can not refer to product_id without appropriate prefix: line.product_id in this case while iterating by self.order_line.

Anyway  to avoid future headake you should write custom module instead of changing standrd one. 

рекомендую почитать доки по питону (https://docs.python.org).

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
What are the product types in Odoo 14? Solved
product type
Avatar
Avatar
Avatar
Avatar
3
May 23
9506
Sale order State update (Sale order > sale to invoice)
product sale.order
Avatar
Avatar
1
Jan 16
5398
How can I sell products with bundled usage and bill for excess consumption
product sale sale.order
Avatar
0
Jul 24
1911
How to get related field value from database ? Solved
product sale sale.order
Avatar
Avatar
1
Mar 24
15607
Product type file...add or edit types ?
product type add
Avatar
0
Mar 15
5384
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