Odoo Help

Welcome!

This community 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.

0

Minimum Sales Order Line Cost

By
Alex Gallien
on 1/7/15, 7:42 PM 705 views

I am working on creating a module that will allow a minimum price for a sales order line to be set, but am having some trouble getting it working. I started by defining a minimium lot charge value in product.product:

class ec_products(osv.Model):

    _inherit = 'product.product'

    _columns = {

        'x_min_lot_charge':fields.float('Min Lot Charge', size=64),

        }

Added it to the view without issue, so this code is working fine. I then inherited sale.order.line and and modified the _amount_line() method, which is where things aren't working. This is my code currently:

class sales_order_detail_field(osv.Model):

    _inherit = 'sale.order.line'

    def _amount_line(self, cr, uid, ids, field_name, arg, context=None):

        tax_obj = self.pool.get('account.tax')

        cur_obj = self.pool.get('res.currency')

        res = {}

        if context is None:

            context = {}

        for line in self.browse(cr, uid, ids, context=context):

            price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)

            taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id)

            ###  Min lot charge calc

            line_min = line.product_id.x_min_lot_charge

            if taxes['total'] < line_min:

                taxes['total']= line_min

            ###

            cur = line.order_id.pricelist_id.currency_id

            res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])

        return res

So basically I grab the minimum lot charge that is definied on the product page using line_min = line.product_id.x_min_lot_charge, then compare that to the calulated subtotal, taxes['total'], and set that value to the minimum charge if it is smaller. Seems pretty simple, but it isn't working. I tried removing the if statement to see if I could just set the subtotal to the value defined on the product, but that didn't work either. The subtotal field I am trying to modify is defined in sale.py as a functional field relating to the _amount_line method that I am editing above:

'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account'))

Any idea what I am doing wrong here? Any advice would be greatly appreciated!

I wanted to implement a minimum product quantity using the same approach. I have created a field, 'min_quantity' under product.product model. Do you have an idea on how I can set it as default in sale.order.line and ensure that it is the minimum value that a user can set?

Cyrus Waithaka
on 9/24/15, 7:22 AM
1

zbik

--zbik--
5951
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 1/8/15, 4:47 AM

Probably method sales_order_detail_field() is not called. You need to define again

'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account'))

in your module.

That's exactly it! Also I had to define the function before the _columns dictionary for it to work correctly. Thanks for your help zbik!

Alex Gallien
on 1/8/15, 12:43 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/7/15, 7:42 PM
Seen: 705 times
Last updated: 9/24/15, 7:22 AM