Odoo Help


Setting A Minimum Sales Order Price

Alex Gallien
on 8/13/14, 6:38 PM 1,278 views

Is there a module that would let me set a minumum price for a Sales Order? So if a total SO price is below a minumum the total will be set to the minumum? Would this be difficult to program into a custom module? Thanks.



| 5 4 7
Bikaner, India

OpenERP Devloper at SunARC Technology

On 8/14/14, 1:54 AM

In Sale order screen add extra Functional field  to calculate if a total SO price is below a minumum the total then calculate the Minumum Amout Diff = (Minimum Sale Order Price  - Total Sale Price).

In your custom module _inherit sale order line add Total Price field and method (default code from sale order).

And in the method addition add Total Sale Price + Minumum Amout Diff amout value.


Ben Olsen
On 8/13/14, 6:44 PM

I don't know if there's an existing module for it, but it would be fairly trivial to make a custom module that does something like this. You'd inherit from "sale.order" and overwrite the "write" function. How to make custom modules is a larger discussion, but a simple web search will bring up a few good tutorials.

EDIT: The details on this question are pretty vague, and there are different options for different approaches. The biggest question is, how do you want to make the total SO price larger, if it needs to be? In the sale module, the sale.order class calculates the "amount_total" in the "_amount_all" function. So the "amount_total" is really just the sum of the sales order lines. For me, that means if I want the SO total to meet a minimum price, I'll add an extra sale order line to make up the difference. Also, I assume that you want the SO total to be a minimum amount *when confirmed*, rather than on every save or every change of the SO. In that case, I'd make a custom module and override the "action_button_confirm" function, which is what gets called when the quotation is confirmed as a sale order, rather than write().

Here's my off-the-cuff suggestion (ugh, how do you make a codeblock in this stupid forum?):

    def action_button_confirm(self, cr, uid, ids, context=None):
        assert len(ids) == 1, 'This option should only be used for a single id at a time.'
    order = self.browse(cr, uid, ids[0])
    lacking = MINIMUM_SO_AMOUNT - order.amount_total
    if lacking > 0:
        # get my special product that is only used to make SO totals meet a minimum
        product_obj = self.pool.get('product.product')
        extra_res = product_obj.search(cr, uid, [('name', '=', 'MY_EXTRA_PROD')], context=context)
        extra_id = extra_res and extra_res[0]
        extra_prod = product_obj.browse(cr, uid, extra_id)
        # do a bunch of configuration of the product details here, with the price as what's lacking
        so_line_vals = {} # fill in this dictionary with details of the new SO line
        # don't forget to set this new SO line's sales order to the current SO
        so_line_vals['order_id'] =  order.id
        # add a sales order line with this product
        self.pool.get('sale.order.line').create(cr, uid, so_line_vals)
    # now you have an extra SO line to make up the difference
    # because the totals are all calculated fields, you should be good to go from here
        self.signal_workflow(cr, uid, ids, 'order_confirm')

        # redisplay the record as a sales order
        view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale', 'view_order_form')
        view_id = view_ref and view_ref[1] or False,
        return {
            'type': 'ir.actions.act_window',
            'name': _('Sales Order'),
            'res_model': 'sale.order',
            'res_id': ids[0],
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': view_id,
            'target': 'current',
            'nodestroy': True,

I am relatively comfortable making custom modules. OpenERP's syntax confuses me sometimes, but I have a pretty good grip on it at this point. Is it possible to override the total sales price? That is what I couldn't figure out.

Alex Gallien
on 8/13/14, 7:28 PM

I've edited my post with a more concrete suggestion, though I still left out the bits where you configure the product and sales order line details. Hopefully this puts you on the right track, though.

Ben Olsen
on 8/14/14, 11:44 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/13/14, 6:38 PM
Seen: 1278 times
Last updated: 3/16/15, 8:10 AM