diff --git a/addons/product/product.py b/addons/product/product.py index bc91ff2a949..ff4a380c5c0 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -178,10 +178,10 @@ class product_template(osv.osv): 'rental': fields.boolean('Rentable product'), 'categ_id': fields.many2one('product.category','Category', required=True, change_default=True), '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'), '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)'), '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."), diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index b01215ab595..ab86209540f 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -58,14 +58,15 @@ + + - diff --git a/addons/purchase/__init__.py b/addons/purchase/__init__.py index d0e7a81b176..c4dc0a0e54f 100644 --- a/addons/purchase/__init__.py +++ b/addons/purchase/__init__.py @@ -31,3 +31,4 @@ import partner import stock import wizard import report +import stock diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 822508bf712..955ea80fc86 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -93,7 +93,7 @@ class purchase_order(osv.osv): 'validator' : fields.many2one('res.users', 'Validated by', readonly=True), 'notes': fields.text('Notes'), '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), '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), @@ -231,7 +231,7 @@ class purchase_order(osv.osv): 'type': 'in', 'address_id': order.dest_address_id.id or order.partner_address_id.id, 'invoice_state': istate, - 'purchase_id': order.id + 'purchase_id': order.id, }) for order_line in order.order_line: if not order_line.product_id: @@ -250,7 +250,8 @@ class purchase_order(osv.osv): 'location_dest_id': dest, 'picking_id': picking_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: 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, 'invoiced':False, 'invoice_id':False, - 'picking_ids':[], + 'picking_ids':False, 'name': self.pool.get('ir.sequence').get(cr, uid, 'purchase.order'), }) return super(purchase_order, self).copy(cr, uid, id, default, context) diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index 2cfd521af5a..a0e616e6e6a 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -28,6 +28,16 @@ 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 # diff --git a/addons/stock/wizard/wizard_partial_picking.py b/addons/stock/wizard/wizard_partial_picking.py index 7a11a50636d..7407b884c73 100644 --- a/addons/stock/wizard/wizard_partial_picking.py +++ b/addons/stock/wizard/wizard_partial_picking.py @@ -56,8 +56,20 @@ def _get_moves(self, cr, uid, data, context): quantity = m.product_qty if m.state<>'assigned': quantity = 0 - _moves_arch_lst.append('\n' % (m.id,)) + _moves_arch_lst.append('' % (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)} + 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('' % (m.id,)) + _moves_fields['price%s' % m.id] = {'string': 'Unit Price', 'type': 'float', 'required': True, 'default': make_default(price)} + _moves_arch_lst.append('' % (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('') res.setdefault('moves', []).append(m.id) _moves_arch_lst.append('') _moves_arch.string = '\n'.join(_moves_arch_lst) @@ -78,6 +90,21 @@ def _do_split(self, cr, uid, data, context): too_few.append(move) else: 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: if not new_picking: