Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

 4 Answer(s)

  • This is exactly what i want to do created an other solution... hope it will help others ... in this code I calculated 'standard_price' aka cost price when costing method is set to average from an other filed name as checke_tax in purchase order...

    class purchase_order(osv.osv):
        _inherit ='purchase.order'
    def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, group_id, context=None):
            ''' prepare the stock move data from the PO line. This function returns a list of dictionary ready to be used in stock.move's create()'''
            product_uom = self.pool.get('product.uom')
            checke_tax = order_line.checke_tax
            if !=
                checke_tax *= order_line.product_uom.factor / order_line.product_id.uom_id.factor
            if !=
                #we don't round the price_unit, as we may want to store the standard price with more digits than allowed by the currency
                checke_tax = self.pool.get('res.currency').compute(cr, uid,,, checke_tax, round=False, context=context)
            res = []
            move_template = {
                'name': or '',
                'date': order.date_order,
                'date_expected':, cr, uid, order_line.date_planned, context),
                'picking_id': picking_id,
                'move_dest_id': False,
                'state': 'draft',
                'checke_tax': checke_tax,
                'group_id': group_id,
                'procurement_id': False,
                'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [ for x in order.picking_type_id.warehouse_id.route_ids])] or [],
                'invoice_state': order.invoice_method == 'picking' and '2binvoiced' or 'none',
    diff_quantity = order_line.product_qty
            for procurement in order_line.procurement_ids:
                procurement_qty = product_uom._compute_qty(cr, uid,, procurement.product_qty,
                tmp = move_template.copy()
                    'product_uom_qty': min(procurement_qty, diff_quantity),
                    'product_uos_qty': min(procurement_qty, diff_quantity),
                    'move_dest_id':,  #move destination is same as procurement destination
                    'group_id': or group_id,  #move group is same as group of procurements if it exists, otherwise take another group
                    'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='2binvoiced' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale
                    'propagate': procurement.rule_id.propagate,
                diff_quantity -= min(procurement_qty, diff_quantity)
            #if the order line has a bigger quantity than the procurement it was for (manually changed or minimal quantity), then
            #split the future stock move in two because the route followed may be different.
            if float_compare(diff_quantity, 0.0, precision_rounding=order_line.product_uom.rounding) > 0:
                move_template['product_uom_qty'] = diff_quantity
                move_template['product_uos_qty'] = diff_quantity
            return res
        _columns = {
        'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines',

    from openerp.osv import fields, osv from import _ from openerp import SUPERUSER_ID, api import logging _logger = logging.getLogger(__name__) class stock_move(osv.osv): _inherit = "stock.move" def action_done(self, cr, uid, ids, context=None): self.product_price_update_before_done(cr, uid, ids, context=context) res = super(stock_move, self).action_done(cr, uid, ids, context=context) return res def product_price_update_before_done(self, cr, uid, ids, context=None): product_obj = self.pool.get('product.product') tmpl_dict = {} for move in self.browse(cr, uid, ids, context=context): #adapt standard price on incomming moves if the product cost_method is 'average' if (move.location_id.usage == 'supplier') and (move.product_id.cost_method == 'average'): product = move.product_id prod_tmpl_id = qty_available = move.product_id.product_tmpl_id.qty_available if tmpl_dict.get(prod_tmpl_id): product_avail = qty_available + tmpl_dict[prod_tmpl_id] else: tmpl_dict[prod_tmpl_id] = 0 product_avail = qty_available if product_avail <= 0: new_std_price = move.checke_tax else: # Get the standard price amount_unit = product.standard_price new_std_price = ((amount_unit * product_avail) + (move.checke_tax * move.product_qty)) / (product_avail + move.product_qty) tmpl_dict[prod_tmpl_id] += move.product_qty # Write the standard price, as SUPERUSER_ID because a warehouse manager may not have the right to write on products ctx = dict(context or {}, product_obj.write(cr, SUPERUSER_ID, [], {'standard_price': new_std_price}, context=ctx) _columns = { 'checke_tax': fields.float('Unit Price', help="Technical field used to record the product cost set by the user during a picking confirmation (when costing method used is 'average price' or 'real'). Value given in company currency and in product uom."), # as it's a technical field, we intentionally don't provide the digits attribute }

  • hello ehtisham faisal, I did not clearly understand your problem but you can use this class purchase_order_line and override this function def _amount_line(self, cr, uid, ids, prop, arg, context=None): and add your custom fields here to calculate in total amount.

  • 'standard_price': = 'float', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product template used for standard stock valuation in accounting and used as a base price on purchase orders. " "Expressed in the default unit of measure of the product.", groups="base.group_user", string="Cost Price"),

    this field is calculated form line.price_unit when cost method is set to average in products all i want is that instead of it is calculated from price_unit it calculate from my custom field

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: