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

Sale Order from Custom Module

Subscribe

Get notified when there's activity on this post

This question has been flagged
actioninvoicecreatecustomSO
10 Replies
10269 Views
Avatar
Gregory Gillis

I am making a custom module to track service tickets for a repair shop. I would like to be able to open the custom module tickets and be able to create a SO/Invoice from within the ticket so they are linked. 

ie. Custom brings item in for repair. While technician is working, they can add items required for the repair to the repair ticket and will update the sales order without changing screens. We can then use a button in the top corner to see the attached sales order and invoices. This way we just pull up a service ticket and can see what items are being used, what the customer owes, and what payments that have made on that specific ticket. 


I have tried mimicking code from the sales module as a template, but cannot get the custom module to make a sales order when our ticket is created so that they are linked-the repair ticket shows as source document for SO.

Using Odoo 12 Community, and coding manually without access to the Studio module. 

0
Avatar
Discard
Sehrish

To implement your changes you just need to know how to customize existing modules, have a look into: https://learnopenerp.tumblr.com/

Avatar
Jake Robinson
Best Answer

Hi Gregory, 

The easiest way would be to add three new fields on the ticket model:

A sale order many2one (Hook the create method to create a blank sale order when a ticket is created)

A sale order line many2many related to the sale orders order_line field.

An invoice many2many related to the sale orders invoice_ids field.

With these three fields you can show a link to the sale order and its invoices, as well as show and manipulate the sale orders order lines.

0
Avatar
Discard
Gregory Gillis
Author

The three fields you mentioned are easy enough and I can add those in. However, I am lost with "Hook the create method to create a blank sale order when a ticket is created". Any chance you can provide an example of that code? Thanks.

Jake Robinson

In the ticket model (assuming the ticket has a partner field called partner_id and the tickets sale field is call sale_order_id):

def create(self, vals):

res = super(TicketModelClass, self).create(vals)

res.sale_order_id = self.env['sale.order'].create({'partner_id': res.partner_id.id})

return res

Gregory Gillis
Author

I am now getting this error message when I applied that code. Here is snippet of my models.py:

sale_order_id = fields.Many2one('sale.order')

def create(self, vals):

res = super(TicketModelClass, self).create(vals)

res.sale_order_id = self.env['sale.order'].create({'partner_id': res.customer})

return res

sale_order_line = fields.Many2many(related="sale_order_id.order_line")

invoice_id = fields.Many2many(related="sale_order_id.invoice_ids")

(I am using 'customer' for the customer/partner in the model)

And here is the error I am getting when I refresh Odoo and reload the server:

2018-11-12 16:00:11,799 26612 ERROR coding werkzeug: Error on request:

Traceback (most recent call last):

File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 205, in run_wsgi

execute(self.server.app)

File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 193, in execute

application_iter = app(environ, start_response)

File "/mylocation/odoo12/odoo/service/server.py", line 339, in app

return self.app(e, s)

File "/mylocation/odoo12/odoo/service/wsgi_server.py", line 128, in application

return application_unproxied(environ, start_response)

File "/mylocation/odoo12/odoo/service/wsgi_server.py", line 117, in application_unproxied

result = odoo.http.root(environ, start_response)

File "/mylocation/odoo12/odoo/http.py", line 1317, in __call__

return self.dispatch(environ, start_response)

File "/mylocation/odoo12/odoo/http.py", line 1290, in __call__

return self.app(environ, start_wrapped)

File "/usr/local/lib/python3.6/site-packages/werkzeug/wsgi.py", line 599, in __call__

return self.app(environ, start_response)

File "/mylocation/odoo12/odoo/http.py", line 1489, in dispatch

response = self.get_response(httprequest, result, explicit_session)

File "/mylocation/odoo12/odoo/http.py", line 287, in __exit__

elif self.registry:

File "/mylocation/odoo12/odoo/http.py", line 378, in registry

return odoo.registry(self.db)

File "/mylocation/odoo12/odoo/__init__.py", line 78, in registry

return modules.registry.Registry(database_name)

File "/mylocation/odoo12/odoo/modules/registry.py", line 62, in __new__

return cls.new(db_name)

File "/mylocation/odoo12/odoo/modules/registry.py", line 86, in new

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

File "/mylocation/odoo12/odoo/modules/loading.py", line 422, in load_modules

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

File "/mylocation/odoo12/odoo/modules/loading.py", line 318, in load_marked_modules

perform_checks=perform_checks, models_to_check=models_to_check

File "/mylocation/odoo12/odoo/modules/loading.py", line 196, in load_module_graph

registry.setup_models(cr)

File "/mylocation/odoo12/odoo/modules/registry.py", line 267, in setup_models

model._setup_fields()

File "/mylocation/odoo12/odoo/models.py", line 2596, in _setup_fields

field.setup_full(self)

File "/mylocation/odoo12/odoo/fields.py", line 483, in setup_full

self._setup_related_full(model)

File "/mylocation/odoo12/odoo/fields.py", line 534, in _setup_related_full

raise TypeError("Type of related field %s is inconsistent with %s" % (self, field))

TypeError: Type of related field repaircenter.ticket.sale_order_line is inconsistent with sale.order.order_line - - -

Gregory Gillis
Author

If I comment out the sale_order_line, Odoo loads, but whenever I create a new ticket, I get the following error:

TypeError: create() missing 1 required positional argument: 'vals'

I have tried changing the customer and partner_id but didn't make a difference.

Jake Robinson

Two issues, the first is that I forgot to add the @api.model on the create method. This just goes on the line above def create...

The second is that the many2many fields need a comodel. In the many2one, the 'sale.order' you have written tells the system that that many2one is for sale orders. You need to do the same for the many2manys. Use comodel_name='sale.order.line' and comodel_name='account.invoice' in their definitions.

Gregory Gillis
Author

I am now getting this error: TypeError: create() got an unexpected keyword argument 'context'

Here is the updated code:

sale_order_line = fields.Many2many('sale.order.line')

invoices_id = fields.Many2one('account.invoice')

sale_order_id = fields.Many2one('sale.order')

@api.model

def create(self):

res = super(RepairTicket, self).create(vals)

res.sale_order_id = self.env['sale.order'].create({'partner_id': res.partner_id.id})

return res

sale_order_line_id = fields.Many2many('sale.order.line')

invoice_id = fields.Many2many(related="sale_order_id.invoice_ids")

If I change the @api.model to @api.multi, I get this error instead:

NameError: name 'vals' is not defined

Gregory Gillis
Author

EDIT: I realized I as missing vals from the def create(self, vals). I added it back in and am back to this error:

TypeError: create() missing 1 required positional argument: 'vals'

Avatar
Gregory Gillis
Author Best Answer

After fiddling some more,  I was able to make some headway. I am able to create a new sales order whenever I create a new ticket in my custom module using the following code.

    sale_order_id = fields.Many2one('sale.order')
@api.model
def create(self, vals):
res = super(RepairTicket, self).create(vals)
res.sale_order_id = self.env['sale.order'].create({'partner_id': res.partner_id, 'origin':res.id})
return res
(Note, I had to add a new field: partner_id=fields.Integer(related="customer.id") to get the id number form my customer field. I also added in the ticket number to show as the source document in the order.)
However, I cannot get it to pull in the sale order lines. Whenever I use any of the code above for sale_order_line or sale.order.line it prevents odoo from starting when I reboot. Need to be able to edit/view sale order lines on the same screen if possible. Thanks.

-1
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
Custom invoice template per client
invoice custom template
Avatar
Avatar
Avatar
2
Sep 24
12332
Error Findings
invoice error create
Avatar
0
Nov 23
2045
Strip string from a field with defined separator in invoice report
invoice custom reports
Avatar
0
Mar 22
2
Error creating an invoice
invoice error create
Avatar
Avatar
1
Apr 20
4256
How to pass custom field value from account.invoice to account.invoice.line on Create() method? Solved
invoice field custom
Avatar
1
Nov 19
6781
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