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 order_line.product_uom.id != order_line.product_id.uom_id.id:
                checke_tax *= order_line.product_uom.factor / order_line.product_id.uom_id.factor
            if order.currency_id.id != order.company_id.currency_id.id:
                #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, order.currency_id.id, order.company_id.currency_id.id, checke_tax, round=False, context=context)
            res = []
            move_template = {
                'name': order_line.name or '',
                'product_id': order_line.product_id.id,
                'product_uom': order_line.product_uom.id,
                'product_uos': order_line.product_uom.id,
                'date': order.date_order,
                'date_expected': fields.date.date_to_datetime(self, cr, uid, order_line.date_planned, context),
                'location_id': order.partner_id.property_stock_supplier.id,
                'location_dest_id': order.location_id.id,
                'picking_id': picking_id,
                'partner_id': order.dest_address_id.id,
                'move_dest_id': False,
                'state': 'draft',
                'purchase_line_id': order_line.id,
                'company_id': order.company_id.id,
                'checke_tax': checke_tax,
                'picking_type_id': order.picking_type_id.id,
                'group_id': group_id,
                'procurement_id': False,
                'origin': order.name,
                'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [x.id for x in order.picking_type_id.warehouse_id.route_ids])] or [],
                'warehouse_id':order.picking_type_id.warehouse_id.id,
                '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_uom.id, procurement.product_qty, to_uom_id=order_line.product_uom.id)
                tmp = move_template.copy()
                tmp.update({
                    'product_uom_qty': min(procurement_qty, diff_quantity),
                    'product_uos_qty': min(procurement_qty, diff_quantity),
                    'move_dest_id': procurement.move_dest_id.id,  #move destination is same as procurement destination
                    'group_id': procurement.group_id.id or group_id,  #move group is same as group of procurements if it exists, otherwise take another group
                    'procurement_id': procurement.id,
                    '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)
                res.append(tmp)
            #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
                res.append(move_template)
            return res
        _columns = {
        'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines',
                                          states={'approved':[('readonly',True)],
                                                  'done':[('readonly',True)]},
                                                  copy=True),
        }

    from openerp.osv import fields, osv from openerp.tools.translate 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 = move.product_id.product_tmpl_id.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 {}, force_company=move.company_id.id) product_obj.write(cr, SUPERUSER_ID, [product.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': fields.property(type = '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
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: