Add average price
bzr revid: ced-988d63a062f858f1ffc47f729a7601b5b444bb52
This commit is contained in:
parent
bc438037fd
commit
2c4a050ab9
|
@ -178,10 +178,10 @@ class product_template(osv.osv):
|
||||||
'rental': fields.boolean('Rentable product'),
|
'rental': fields.boolean('Rentable product'),
|
||||||
'categ_id': fields.many2one('product.category','Category', required=True, change_default=True),
|
'categ_id': fields.many2one('product.category','Category', required=True, change_default=True),
|
||||||
'list_price': fields.float('List Price'),
|
'list_price': fields.float('List Price'),
|
||||||
'standard_price': fields.float('Standard Price', required=True, digit=(12,6)),
|
'standard_price': fields.float('Cost Price', required=True, digit=(12,6)),
|
||||||
'volume': fields.float('Volume'),
|
'volume': fields.float('Volume'),
|
||||||
'weight': fields.float('Weight'),
|
'weight': fields.float('Weight'),
|
||||||
'cost_method': fields.selection([('standard','Standard Price'), ('pmp','PMP (Not implemented!)'), ('fifo','FIFO')], 'Costing Method', required=True),
|
'cost_method': fields.selection([('standard','Standard Price'), ('average','Average Price')], 'Costing Method', required=True),
|
||||||
'warranty': fields.float('Warranty (months)'),
|
'warranty': fields.float('Warranty (months)'),
|
||||||
'sale_ok': fields.boolean('Can be sold', help="Determine if the product can be visible in the list of product within a selection from a sale order line."),
|
'sale_ok': fields.boolean('Can be sold', help="Determine if the product can be visible in the list of product within a selection from a sale order line."),
|
||||||
'purchase_ok': fields.boolean('Can be Purchased', help="Determine if the product is visible in the list of products within a selection from a purchase order line."),
|
'purchase_ok': fields.boolean('Can be Purchased', help="Determine if the product is visible in the list of products within a selection from a purchase order line."),
|
||||||
|
|
|
@ -58,14 +58,15 @@
|
||||||
<field name="warranty"/>
|
<field name="warranty"/>
|
||||||
<field name="rental" select="1"/>
|
<field name="rental" select="1"/>
|
||||||
<field name="list_price"/>
|
<field name="list_price"/>
|
||||||
|
<newline/>
|
||||||
<field name="standard_price"/>
|
<field name="standard_price"/>
|
||||||
|
<field name="cost_method"/>
|
||||||
<!--
|
<!--
|
||||||
<field name="price_margin"/>
|
<field name="price_margin"/>
|
||||||
<field name="price_extra"/>
|
<field name="price_extra"/>
|
||||||
-->
|
-->
|
||||||
<field name="uos_id" />
|
<field name="uos_id" />
|
||||||
<field name="uos_coeff" />
|
<field name="uos_coeff" />
|
||||||
<field name="cost_method"/>
|
|
||||||
<newline />
|
<newline />
|
||||||
<field name="seller_ids" colspan="4" select="1" nolabel="1" widget="one2many_list"/>
|
<field name="seller_ids" colspan="4" select="1" nolabel="1" widget="one2many_list"/>
|
||||||
</page>
|
</page>
|
||||||
|
|
|
@ -31,3 +31,4 @@ import partner
|
||||||
import stock
|
import stock
|
||||||
import wizard
|
import wizard
|
||||||
import report
|
import report
|
||||||
|
import stock
|
||||||
|
|
|
@ -93,7 +93,7 @@ class purchase_order(osv.osv):
|
||||||
'validator' : fields.many2one('res.users', 'Validated by', readonly=True),
|
'validator' : fields.many2one('res.users', 'Validated by', readonly=True),
|
||||||
'notes': fields.text('Notes'),
|
'notes': fields.text('Notes'),
|
||||||
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True),
|
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True),
|
||||||
'picking_ids': fields.one2many('stock.picking', 'purchase_id', 'Picking List', readonly=True, help="This is the list of picking list that have been generated for this invoice"),
|
'picking_ids': fields.one2many('stock.picking', 'purchase_id', 'Picking List', readonly=True, help="This is the list of picking list that have been generated for this purchase"),
|
||||||
'shipped':fields.boolean('Received', readonly=True, select=True),
|
'shipped':fields.boolean('Received', readonly=True, select=True),
|
||||||
'invoiced':fields.boolean('Invoiced & Paid', readonly=True, select=True),
|
'invoiced':fields.boolean('Invoiced & Paid', readonly=True, select=True),
|
||||||
'invoice_method': fields.selection([('manual','Manual'),('order','From order'),('picking','From picking')], 'Invoicing method', required=True),
|
'invoice_method': fields.selection([('manual','Manual'),('order','From order'),('picking','From picking')], 'Invoicing method', required=True),
|
||||||
|
@ -231,7 +231,7 @@ class purchase_order(osv.osv):
|
||||||
'type': 'in',
|
'type': 'in',
|
||||||
'address_id': order.dest_address_id.id or order.partner_address_id.id,
|
'address_id': order.dest_address_id.id or order.partner_address_id.id,
|
||||||
'invoice_state': istate,
|
'invoice_state': istate,
|
||||||
'purchase_id': order.id
|
'purchase_id': order.id,
|
||||||
})
|
})
|
||||||
for order_line in order.order_line:
|
for order_line in order.order_line:
|
||||||
if not order_line.product_id:
|
if not order_line.product_id:
|
||||||
|
@ -250,7 +250,8 @@ class purchase_order(osv.osv):
|
||||||
'location_dest_id': dest,
|
'location_dest_id': dest,
|
||||||
'picking_id': picking_id,
|
'picking_id': picking_id,
|
||||||
'move_dest_id': order_line.move_dest_id.id,
|
'move_dest_id': order_line.move_dest_id.id,
|
||||||
'state': 'assigned'
|
'state': 'assigned',
|
||||||
|
'purchase_line_id': order_line.id,
|
||||||
})
|
})
|
||||||
if order_line.move_dest_id:
|
if order_line.move_dest_id:
|
||||||
self.pool.get('stock.move').write(cr, uid, [order_line.move_dest_id.id], {'location_id':order.location_id.id})
|
self.pool.get('stock.move').write(cr, uid, [order_line.move_dest_id.id], {'location_id':order.location_id.id})
|
||||||
|
@ -265,7 +266,7 @@ class purchase_order(osv.osv):
|
||||||
'shipped':False,
|
'shipped':False,
|
||||||
'invoiced':False,
|
'invoiced':False,
|
||||||
'invoice_id':False,
|
'invoice_id':False,
|
||||||
'picking_ids':[],
|
'picking_ids':False,
|
||||||
'name': self.pool.get('ir.sequence').get(cr, uid, 'purchase.order'),
|
'name': self.pool.get('ir.sequence').get(cr, uid, 'purchase.order'),
|
||||||
})
|
})
|
||||||
return super(purchase_order, self).copy(cr, uid, id, default, context)
|
return super(purchase_order, self).copy(cr, uid, id, default, context)
|
||||||
|
|
|
@ -28,6 +28,16 @@
|
||||||
|
|
||||||
from osv import osv, fields
|
from osv import osv, fields
|
||||||
|
|
||||||
|
class stock_move(osv.osv):
|
||||||
|
_inherit = 'stock.move'
|
||||||
|
_columns = {
|
||||||
|
'purchase_line_id': fields.many2one('purchase.order.line', 'Purchase Order Line', ondelete='set null', select=True),
|
||||||
|
}
|
||||||
|
_defaults = {
|
||||||
|
'purchase_line_id': lambda *a:False
|
||||||
|
}
|
||||||
|
stock_move()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Inherit of picking to add the link to the PO
|
# Inherit of picking to add the link to the PO
|
||||||
#
|
#
|
||||||
|
|
|
@ -56,8 +56,20 @@ def _get_moves(self, cr, uid, data, context):
|
||||||
quantity = m.product_qty
|
quantity = m.product_qty
|
||||||
if m.state<>'assigned':
|
if m.state<>'assigned':
|
||||||
quantity = 0
|
quantity = 0
|
||||||
_moves_arch_lst.append('<field name="move%s" />\n<newline />' % (m.id,))
|
_moves_arch_lst.append('<field name="move%s" />' % (m.id,))
|
||||||
_moves_fields['move%s' % m.id] = {'string' : '%s - %s' % (m.product_id.code, m.product_id.name), 'type' : 'float', 'required' : True, 'default' : make_default(quantity)}
|
_moves_fields['move%s' % m.id] = {'string' : '%s - %s' % (m.product_id.code, m.product_id.name), 'type' : 'float', 'required' : True, 'default' : make_default(quantity)}
|
||||||
|
if (pick.type == 'in') and (m.product_id.cost_method == 'average'):
|
||||||
|
price=0
|
||||||
|
if hasattr(m, 'purchase_line_id') and m.purchase_line_id:
|
||||||
|
price=m.purchase_line_id.price_unit
|
||||||
|
currency=0
|
||||||
|
if hasattr(pick, 'purchase_id') and pick.purchase_id:
|
||||||
|
currency=pick.purchase_id.pricelist_id.currency_id.id
|
||||||
|
_moves_arch_lst.append('<group><field name="price%s"/>' % (m.id,))
|
||||||
|
_moves_fields['price%s' % m.id] = {'string': 'Unit Price', 'type': 'float', 'required': True, 'default': make_default(price)}
|
||||||
|
_moves_arch_lst.append('<field name="currency%d"/></group>' % (m.id,))
|
||||||
|
_moves_fields['currency%s' % m.id] = {'string': 'Currency', 'type': 'many2one', 'relation': 'res.currency', 'required': True, 'default': make_default(currency)}
|
||||||
|
_moves_arch_lst.append('<newline/>')
|
||||||
res.setdefault('moves', []).append(m.id)
|
res.setdefault('moves', []).append(m.id)
|
||||||
_moves_arch_lst.append('</form>')
|
_moves_arch_lst.append('</form>')
|
||||||
_moves_arch.string = '\n'.join(_moves_arch_lst)
|
_moves_arch.string = '\n'.join(_moves_arch_lst)
|
||||||
|
@ -78,6 +90,21 @@ def _do_split(self, cr, uid, data, context):
|
||||||
too_few.append(move)
|
too_few.append(move)
|
||||||
else:
|
else:
|
||||||
too_many.append(move)
|
too_many.append(move)
|
||||||
|
if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
|
||||||
|
product_obj = pooler.get_pool(cr.dbname).get('product.product')
|
||||||
|
currency_obj = pooler.get_pool(cr.dbname).get('res.currency')
|
||||||
|
users_obj = pooler.get_pool(cr.dbname).get('res.users')
|
||||||
|
|
||||||
|
product = product_obj.browse(cr, uid, [move.product_id.id])[0]
|
||||||
|
user = users_obj.browse(cr, uid, [uid])[0]
|
||||||
|
|
||||||
|
qty = data['form']['move%s' % move.id]
|
||||||
|
price = data['form']['price%s' % move.id]
|
||||||
|
currency = data['form']['currency%s' % move.id]
|
||||||
|
|
||||||
|
new_price = currency_obj.compute(cr, uid, currency, user.company_id.currency_id.id, price)
|
||||||
|
new_std_price = ((product.standard_price * product.qty_available) + (new_price * qty))/(product.qty_available + qty)
|
||||||
|
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
|
||||||
|
|
||||||
for move in too_few:
|
for move in too_few:
|
||||||
if not new_picking:
|
if not new_picking:
|
||||||
|
|
Loading…
Reference in New Issue