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 create sample sale order and sale order line in odoo?

Subscribe

Get notified when there's activity on this post

This question has been flagged
odooodooV8
2 Replies
23328 Views
Avatar
bhanukiran

I am trying to create a sample order in sales order.In the sample order form, products are sold to customers as complimentary copy(books in my case) without charging any money so I have created a separate sub-menu in sales menu.Here I take only product and quantity as input. Sample order number will be the next number from the sales order(like SO360).So I am fetching sales order number as parent_id in my inherited module.I am not able to create sale order line(data in order lines tab)

    class SaleOrder(models.Model):

    _inherit = 'sale.order'


    is_sample = fields.Boolean(string="Sample Order", default=False)

    parent_id = fields.Many2one('sale.order', string="Parent Sales Order")

    sample_ids = fields.One2many('sale.order', 'parent_id', string="Sample Orders")


    @api.model

    @api.returns('sale.order')

    def create(self, vals):

        if vals.get('is_sample', False) and vals.get('name', '/') == '/':

            IrSeq = self.env['ir.sequence']

            ref = IrSeq.next_by_code('sale.order.sample.ref') or '/'

            parent = self.search([('id', '=', vals.get('parent_id'))])

            vals['name'] = parent.name + ref

            vals['user_id'] = parent.user_id.id


        return super(SaleOrder, self).create(vals)


class SampleOrderWizard(models.TransientModel):

    _name = 'sale.order.sample.wizard'

    _description = 'Sample Sale Order Wizard'


    def _get_parent(self):

        res = False

        if self.env.context \

                and 'active_id' in list(self.env.context.iterkeys()):

            res = self.env.context['active_id']

            

        return res


    def _get_new_sale_line(self, orig_sale, orig_sale_line):

        """Internal function to get the fields of the sale order line. Modules

        enhancing this one should add their own fields to the return value."""


        res = {

            'order_id': orig_sale.id,

            'product_id': orig_sale_line.product.id,

            'name': orig_sale_line.name,

            'sequence': orig_sale_line.sequence,

            'price_unit': orig_sale_line.price_unit,

            'product_uom': orig_sale_line.product_uom.id,

            'product_uom_qty': orig_sale_line.qty or 1,

            'product_uos_qty': orig_sale_line.qty or 1,

        }

        self.env['sale.order.line'].create(res)


        return res


    def _get_order_lines(self, sale):

        res = []

        line_env = self.env['sale.order.sample.wizard.line']

        res = self._get_new_sale_line(sale, line_env)


        for line in sale.order_line:

            wizard_line = False

            for wzline in self.wizard_lines:

                if wzline.product == line.product_id:

                    wizard_line = wzline

                    break


            if wizard_line:

                res.append(

                    (0, 0, self._get_new_sale_line(sale, line, wizard_line))

                )


        return res


    def _get_wizard_lines(self):

        res = []

        if self._get_parent():

            SaleOrder = self.env['sale.order']

            parent = SaleOrder.search([('id', '=', self._get_parent())])

            for line in parent.order_line:

                res.append((0, 0,

                            {

                                'product': line.product_id,

                                'qty': 1,

                            }))

        return res


   


    @api.one

    def create_order(self):


        sale_vals = {

            'user_id': self.order.user_id.id,

            'partner_id': self.order.partner_id.id,

            'parent_id': self.order.id,

            'date_order': self.order_date,

            'client_order_ref': self.order.client_order_ref,

            'company_id': self.order.company_id.id,

            'is_sample': True,

            'order_line': self._get_order_lines(self.order)

        }

        self.env['sale.order'].create(sale_vals)


        return {'type': 'ir.actions.act_window_close'}


    order = fields.Many2one('sale.order', default=_get_parent, readonly=True)

    wizard_lines = fields.One2many('sale.order.sample.wizard.line', 'wizard', default=_get_wizard_lines)

    order_date = fields.Datetime(default=fields.Datetime.now())



class SampleOrderWizardLine(models.TransientModel):


    _name = 'sale.order.sample.wizard.line'

    _description = 'Sample Order Wizard Line'


    wizard = fields.Many2one('sale.order.sample.wizard')

    product = fields.Many2one('product.product',

                              domain=[('sale_ok', '=', True)])

    qty = fields.Float(string="Quantity", default=1.0, digits_compute=dp.get_precision('Product UoS'))

0
Avatar
Discard
Avatar
Mohammed Amal N
Best Answer

Existing order lines is a One2many relation to model sale.order.line, you can inherit it if you need to alter it
Or if you are trying to show another tree view below it you can add a One2many relation to that model in sale.order and from xml inherit sale order form view and add your one2many field

0
Avatar
Discard
Avatar
Synodica Solutions Pvt. Ltd.
Best Answer

\https://apps.odoo.com/apps/modules/13.0/pos_test_orders/

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
Add a button to a ValidationError
odoo odooV8
Avatar
Avatar
1
Nov 22
4290
How to get values of one record of a many2many relation displayed in a tree view when clicking on a button
odoo odooV8
Avatar
0
Jun 21
6820
How to pass string in wizard context
odoo odooV8
Avatar
0
Mar 21
3644
How to replace invoice number sequence by invoice id from database
odoo odooV8
Avatar
Avatar
2
May 18
4928
Writing value to One2many Field odoo 8
odoo odooV8
Avatar
Avatar
3
May 18
5950
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