diff --git a/addons/product/product.py b/addons/product/product.py
index 18c9e6ded8d..407125c841d 100644
--- a/addons/product/product.py
+++ b/addons/product/product.py
@@ -209,7 +209,15 @@ class product_category(osv.osv):
'child_id': fields.one2many('product.category', 'parent_id', string='Child Categories'),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Category Type'),
+ 'property_stock_variation': fields.property(
+ 'account.account',
+ type='many2one',
+ relation='account.account',
+ string="Stock variation Account",
+ method=True,
+ view_load=True,),
}
+
_defaults = {
'type' : lambda *a : 'normal',
@@ -457,6 +465,9 @@ class product_product(osv.osv):
'price_extra': fields.float('Variant Price Extra', digits_compute=dp.get_precision('Sale Price')),
'price_margin': fields.float('Variant Price Margin', digits_compute=dp.get_precision('Sale Price')),
'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'),
+ 'valuation':fields.selection([('manual_periodic','Manual Periodic Valuation'),
+ ('real_time','Real Time valuation'),
+ ('','')],'Valuation'),
}
def onchange_uom(self, cursor, user, ids, uom_id,uom_po_id):
diff --git a/addons/product/product_data.xml b/addons/product/product_data.xml
index ce2cc1ee632..646d9ea4219 100644
--- a/addons/product/product_data.xml
+++ b/addons/product/product_data.xml
@@ -135,6 +135,11 @@ parameter) will see those record just disappear.
Stock Weight
2
-
+
+ property_stock_variation
+
+
+
+
diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml
index fde77cc43e8..f2479b420f4 100644
--- a/addons/product/product_view.xml
+++ b/addons/product/product_view.xml
@@ -147,6 +147,7 @@
+
@@ -215,6 +216,7 @@
+
diff --git a/addons/stock/product.py b/addons/stock/product.py
index 83e36b9d078..bac29d57673 100644
--- a/addons/stock/product.py
+++ b/addons/stock/product.py
@@ -26,6 +26,7 @@ from tools.translate import _
class product_product(osv.osv):
_inherit = "product.product"
+
def get_product_accounts(self, cr, uid, product_id, context={}):
""" To get the stock input account, stock output account and stock journal related to product.
@param product_id: product id
@@ -41,14 +42,15 @@ class product_product(osv.osv):
if not stock_output_acc:
stock_output_acc = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id or False
+
journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False
res = {}
res.update({'stock_account_input': stock_input_acc})
res.update({'stock_account_output': stock_output_acc})
res.update({'stock_journal': journal_id})
-
return res
+
def do_change_standard_price(self, cr, uid, ids, datas, context={}):
"""
Changes the Standard Price of Product and creates an account move accordingly.
@@ -67,10 +69,12 @@ class product_product(osv.osv):
stock_output_acc = datas.get('stock_output_account', False)
stock_input_acc = datas.get('stock_input_account', False)
journal_id = datas.get('stock_journal', False)
-
+ property_obj=self.pool.get('ir.property')
+ product_obj=self.browse(cr,uid,ids)[0]
+ account_variation = product_obj.categ_id.property_stock_variation
move_ids = []
for rec_id in ids:
- loc_ids = location_obj.search(cr, uid, [('account_id','<>',False),('usage','=','internal')])
+ loc_ids = location_obj.search(cr, uid,[('usage','=','internal')])
for location in location_obj.browse(cr, uid, loc_ids):
c = context.copy()
c.update({
@@ -83,7 +87,8 @@ class product_product(osv.osv):
diff = product.standard_price - new_price
assert diff, _("Could not find any difference between standard price and new price!")
if qty:
- location_account = location.account_id and location.account_id.id or False
+ location_account = account_variation and account_variation.id or False
+
company_id = location.company_id and location.company_id.id or False
assert location_account, _('Inventory Account is not specified for Location: %s' % (location.name))
assert company_id, _('Company is not specified in Location')
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 4eaf97be6d6..635231fcca5 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -152,7 +152,7 @@ class stock_location(osv.osv):
'stock_real': fields.function(_product_qty_available, method=True, type='float', string='Real Stock', multi="stock"),
'stock_virtual': fields.function(_product_qty_available, method=True, type='float', string='Virtual Stock', multi="stock"),
- 'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type', '!=', 'view')]),
+ #'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type', '!=', 'view')]),
'location_id': fields.many2one('stock.location', 'Parent Location', select=True, ondelete='cascade'),
'child_ids': fields.one2many('stock.location', 'location_id', 'Contains'),
@@ -916,6 +916,7 @@ class stock_picking(osv.osv):
like partner_id, address_id, delivery_date, delivery moves with product_id, product_qty, uom
"""
res = {}
+
move_obj = self.pool.get('stock.move')
delivery_obj = self.pool.get('stock.delivery')
product_obj = self.pool.get('product.product')
@@ -1565,90 +1566,88 @@ class stock_move(osv.osv):
#
acc_src = None
acc_dest = None
- if move.location_id.account_id:
- acc_src = move.location_id.account_id.id
- if move.location_dest_id.account_id:
- acc_dest = move.location_dest_id.account_id.id
- if acc_src or acc_dest:
- test = [('product.product', move.product_id.id)]
- if move.product_id.categ_id:
- test.append( ('product.category', move.product_id.categ_id.id) )
- if not acc_src:
- acc_src = move.product_id.product_tmpl_id.\
- property_stock_account_input.id
+ if move.product_id.valuation=='real_time':
+ journal_id = move.product_id.categ_id.property_stock_journal and move.product_id.categ_id.property_stock_journal.id or False
+ if(move.location_id.usage=='internal' and move.location_dest_id.usage=='internal' and move.location_id.company_id.id!=move.location_dest_id.company_id.id) or ( move.location_id.usage=='internal' or move.location_dest_id.usage=='internal'):
+ test = [('product.product', move.product_id.id)]
+ if move.product_id.categ_id:
+ test.append( ('product.category', move.product_id.categ_id.id) )
if not acc_src:
- acc_src = move.product_id.categ_id.\
- property_stock_account_input_categ.id
- if not acc_src:
- raise osv.except_osv(_('Error!'),
- _('There is no stock input account defined ' \
- 'for this product: "%s" (id: %d)') % \
- (move.product_id.name,
- move.product_id.id,))
- if not acc_dest:
- acc_dest = move.product_id.product_tmpl_id.\
- property_stock_account_output.id
- if not acc_dest:
- acc_dest = move.product_id.categ_id.\
- property_stock_account_output_categ.id
+ acc_src = move.product_id.product_tmpl_id.\
+ property_stock_account_input.id
+ if not acc_src:
+ acc_src = move.product_id.categ_id.\
+ property_stock_account_input_categ.id
+ if not acc_src:
+ raise osv.except_osv(_('Error!'),
+ _('There is no stock input account defined ' \
+ 'for this product: "%s" (id: %d)') % \
+ (move.product_id.name,
+ move.product_id.id,))
if not acc_dest:
+ acc_dest = move.product_id.product_tmpl_id.\
+ property_stock_account_output.id
+ if not acc_dest:
+ acc_dest = move.product_id.categ_id.\
+ property_stock_account_output_categ.id
+ if not acc_dest:
+ raise osv.except_osv(_('Error!'),
+ _('There is no stock output account defined ' \
+ 'for this product: "%s" (id: %d)') % \
+ (move.product_id.name,
+ move.product_id.id,))
+ if not move.product_id.categ_id.property_stock_journal.id:
raise osv.except_osv(_('Error!'),
- _('There is no stock output account defined ' \
- 'for this product: "%s" (id: %d)') % \
- (move.product_id.name,
- move.product_id.id,))
- if not move.product_id.categ_id.property_stock_journal.id:
- raise osv.except_osv(_('Error!'),
- _('There is no journal defined '\
- 'on the product category: "%s" (id: %d)') % \
- (move.product_id.categ_id.name,
- move.product_id.categ_id.id,))
- journal_id = move.product_id.categ_id.property_stock_journal.id
- if acc_src != acc_dest:
- ref = move.picking_id and move.picking_id.name or False
- default_uom = move.product_id.uom_id.id
- date = time.strftime('%Y-%m-%d')
- q = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
- if move.product_id.cost_method == 'average' and move.price_unit:
- amount = q * move.price_unit
- # Base computation on valuation price type
- else:
- company_id = move.company_id.id
- context['currency_id'] = move.company_id.currency_id.id
- pricetype = price_type_obj.browse(cr,uid,move.company_id.property_valuation_price_type.id)
- amount_unit = move.product_id.price_get(pricetype.field, context)[move.product_id.id]
- amount = amount_unit * q or 1.0
- # amount = q * move.product_id.standard_price
-
- partner_id = False
- if move.picking_id:
- partner_id = move.picking_id.address_id and (move.picking_id.address_id.partner_id and move.picking_id.address_id.partner_id.id or False) or False
- lines = [
- (0, 0, {
- 'name': move.name,
- 'quantity': move.product_qty,
- 'product_id': move.product_id and move.product_id.id or False,
- 'credit': amount,
- 'account_id': acc_src,
- 'ref': ref,
- 'date': date,
- 'partner_id': partner_id}),
- (0, 0, {
- 'name': move.name,
- 'product_id': move.product_id and move.product_id.id or False,
- 'quantity': move.product_qty,
- 'debit': amount,
- 'account_id': acc_dest,
- 'ref': ref,
- 'date': date,
- 'partner_id': partner_id})
- ]
- move_obj.create(cr, uid, {
- 'name': move.name,
- 'journal_id': journal_id,
- 'line_id': lines,
- 'ref': ref,
- })
+ _('There is no journal defined '\
+ 'on the product category: "%s" (id: %d)') % \
+ (move.product_id.categ_id.name,
+ move.product_id.categ_id.id,))
+ journal_id = move.product_id.categ_id.property_stock_journal.id
+ if acc_src != acc_dest:
+ ref = move.picking_id and move.picking_id.name or False
+ default_uom = move.product_id.uom_id.id
+ date = time.strftime('%Y-%m-%d')
+ q = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
+ if move.product_id.cost_method == 'average' and move.price_unit:
+ amount = q * move.price_unit
+ # Base computation on valuation price type
+ else:
+ company_id = move.company_id.id
+ context['currency_id'] = move.company_id.currency_id.id
+ pricetype = price_type_obj.browse(cr,uid,move.company_id.property_valuation_price_type.id)
+ amount_unit = move.product_id.price_get(pricetype.field, context)[move.product_id.id]
+ amount = amount_unit * q or 1.0
+ # amount = q * move.product_id.standard_price
+
+ partner_id = False
+ if move.picking_id:
+ partner_id = move.picking_id.address_id and (move.picking_id.address_id.partner_id and move.picking_id.address_id.partner_id.id or False) or False
+ lines = [
+ (0, 0, {
+ 'name': move.name,
+ 'quantity': move.product_qty,
+ 'product_id': move.product_id and move.product_id.id or False,
+ 'credit': amount,
+ 'account_id': acc_src,
+ 'ref': ref,
+ 'date': date,
+ 'partner_id': partner_id}),
+ (0, 0, {
+ 'name': move.name,
+ 'product_id': move.product_id and move.product_id.id or False,
+ 'quantity': move.product_qty,
+ 'debit': amount,
+ 'account_id': acc_dest,
+ 'ref': ref,
+ 'date': date,
+ 'partner_id': partner_id})
+ ]
+ move_obj.create(cr, uid, {
+ 'name': move.name,
+ 'journal_id': journal_id,
+ 'line_id': lines,
+ 'ref': ref,
+ })
tracking_lot = False
if context:
tracking_lot = context.get('tracking_lot', False)
@@ -2160,6 +2159,7 @@ class stock_picking_move_wizard(osv.osv_memory):
def action_move(self, cr, uid, ids, context=None):
move_obj = self.pool.get('stock.move')
picking_obj = self.pool.get('stock.picking')
+ account_move_obj = self.pool.get('account.move')
for act in self.read(cr, uid, ids):
move_lines = move_obj.browse(cr, uid, act['move_ids'])
for line in move_lines:
diff --git a/addons/stock/stock_demo.xml b/addons/stock/stock_demo.xml
index 10a24cb7a15..65553e9fc2b 100644
--- a/addons/stock/stock_demo.xml
+++ b/addons/stock/stock_demo.xml
@@ -37,7 +37,7 @@
Shelf 2
-
+
Sub Products
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index eb68117e698..7eab6aa8c3e 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -407,7 +407,7 @@
-
+
diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py
index eba095718cd..022488cfc43 100644
--- a/addons/stock/wizard/stock_partial_picking.py
+++ b/addons/stock/wizard/stock_partial_picking.py
@@ -163,7 +163,7 @@ class stock_partial_picking(osv.osv_memory):
res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')})
for pick in pick_obj.browse(cr, uid, context.get('active_ids', [])):
if 'partner_id' in fields:
- res.update({'partner_id': pick.address_id.partner_id.id})
+ res.update({'partner_id': pick.address_id.partner_id and pick.address_id.partner_id.id or False })
if 'address_id' in fields:
res.update({'address_id': pick.address_id.id})
for m in pick.move_lines: