diff --git a/addons/auction/auction.py b/addons/auction/auction.py
index 979f2c6cf42..1687980c029 100644
--- a/addons/auction/auction.py
+++ b/addons/auction/auction.py
@@ -481,10 +481,8 @@ class auction_lots(osv.osv):
def name_search(self, cr, user, name, args=None, operator='ilike', context={}):
if not args:
args = []
- try:
- ids = self.search(cr, user, [('obj_num','=',int(name))] + args)
- except:
- ids = []
+
+ ids = self.search(cr, user, [('obj_num','=',int(name))] + args)
if not ids:
ids = self.search(cr, user, [('name',operator,name)] + args)
return self.name_get(cr, user, ids)
diff --git a/addons/stock/wizard/stock_change_standard_price.py b/addons/stock/wizard/stock_change_standard_price.py
index 576c82f224e..50892c6fdc6 100644
--- a/addons/stock/wizard/stock_change_standard_price.py
+++ b/addons/stock/wizard/stock_change_standard_price.py
@@ -27,28 +27,79 @@ class change_standard_price(osv.osv_memory):
_description = "Change Standard Price"
_columns = {
'new_price': fields.float('Price', required=True),
+
+ 'property_stock_account_input':fields.many2one('account.account', 'Stock Input Account', required=True),
+ 'property_stock_account_output':fields.many2one('account.account', 'Stock Output Account', required=True),
+ 'property_stock_journal':fields.many2one('account.journal', 'Stock journal', required=True),
+
+# 'property_stock_account_input': fields.property('account.account',
+# type='many2one', relation='account.account',
+# string='Stock Input Account', method=True, view_load=True,
+# help='This account will be used, instead of the default one, to value input stock'),
+# 'property_stock_account_output': fields.property('account.account',
+# type='many2one', relation='account.account',
+# string='Stock Output Account', method=True, view_load=True,
+# help='This account will be used, instead of the default one, to value output stock'),
+#
+# 'property_stock_journal': fields.property('account.journal',
+# relation='account.journal', type='many2one',
+# string='Stock journal', method=True, view_load=True,
+# required = True,
+# help="This journal will be used for the accounting move generated by stock move"),
+
+ 'enable_acc':fields.boolean('Enable Related Account',),
}
def default_get(self, cr, uid, fields, context):
"""
- To get default values for the object.
-
- @param self: The object pointer.
- @param cr: A database cursor
- @param uid: ID of the user currently logged in
- @param fields: List of fields for which we want default values
- @param context: A standard dictionary
-
- @return: A dictionary which of fields with values.
+ To get default values for the object.
+
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param fields: List of fields for which we want default values
+ @param context: A standard dictionary
+
+ @return: A dictionary which of fields with values.
"""
-
+ product_obj = self.pool.get('product.product').browse(cr, uid, context.get('active_id', False))
res = super(change_standard_price, self).default_get(cr, uid, fields, context=context)
- price = self.pool.get('product.product').browse(cr, uid, context.get('active_id', False))
+
+ stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False
+ if not stock_input_acc:
+ stock_input_acc = product_obj.categ_id.property_stock_account_input_categ and product_obj.categ_id.property_stock_account_input_categ.id or False
+
+ stock_output_acc = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id or False
+ 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
+
+ price = product_obj.standard_price
+ journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False
+
if 'new_price' in fields:
- res.update({'new_price':price.standard_price})
+ res.update({'new_price': price})
+ if 'property_stock_account_input' in fields:
+ res.update({'property_stock_account_input': stock_input_acc})
+ if 'property_stock_account_output' in fields:
+ res.update({'property_stock_account_output': stock_output_acc})
+ if 'property_stock_journal' in fields:
+ res.update({'property_stock_journal': journal_id})
+ if 'enable_acc' in fields:
+ res.update({'enable_acc': True})
+
+
return res
+ def onchange_price(self, cr, uid, ids, new_price, context = {}):
+ product_obj = self.pool.get('product.product').browse(cr, uid, context.get('active_id', False))
+ price = product_obj.standard_price
+ diff = price - new_price
+ if diff > 0 :
+ return {'value' : {'enable_acc':False}}
+ else :
+ return {'value' : {'enable_acc':True}}
+
def change_price(self, cr, uid, ids, context):
"""
Changes the Standard Price of Product.
@@ -73,39 +124,36 @@ class change_standard_price(osv.osv_memory):
data_obj = self.pool.get('ir.model.data')
res = self.browse(cr, uid, ids)
- new_price = res[0].new_price
+
loc_ids = location_obj.search(cr, uid, [('account_id','<>',False),('usage','=','internal')])
+
+ new_price = res[0].new_price
+ stock_output_acc = res[0].property_stock_account_output.id
+ stock_input_acc = res[0].property_stock_account_input.id
+ journal_id = res[0].property_stock_journal.id
+
move_ids = []
for location in location_obj.browse(cr, uid, loc_ids):
c = context.copy()
- c.update({'location':location.id})
+ c.update({'location': location.id})
+ c.update({'compute_child': False})
+
product = prod_obj.browse(cr, uid, rec_id, context=c)
qty = product.qty_available
diff = product.standard_price - new_price
- assert diff, _("Do not found any different between standard price and 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
- stock_input_acc = product.property_stock_account_input and product.property_stock_account_input.id or False
- if not stock_input_acc:
- stock_input_acc = product.categ_id.property_stock_account_input_categ and product.categ_id.property_stock_account_input_categ.id or False
- stock_output_acc = product.property_stock_account_output and product.property_stock_account_output.id or False
- if not stock_output_acc:
- stock_output_acc = product.categ_id.property_stock_account_output_categ and product.categ_id.property_stock_account_output_categ.id or False
-
-
- journal_id = product.categ_id.property_stock_journal and product.categ_id.property_stock_journal.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 journal_id, _('Stock Journal is not specified in Product Category')
assert company_id, _('Company is not specified in Location')
move_id = move_obj.create(cr, uid, {
'journal_id': journal_id,
'company_id': company_id
})
- move_ids.append(move_id)
+
+ move_ids.append(move_id)
if diff > 0:
- assert stock_input_acc, _('Stock Input Account is not specified for Product: %s' %(product.name))
-
amount_diff = qty * diff
move_line_obj.create(cr, uid, {
'name': product.name,
@@ -117,23 +165,21 @@ class change_standard_price(osv.osv_memory):
'name': location.name,
'account_id': location_account,
'credit': amount_diff,
- 'move_id': move_id,
+ 'move_id': move_id
})
elif diff < 0:
- assert stock_output_acc, _('Stock Output Account is not specified for Product: %s' %(product.name))
-
amount_diff = qty * -diff
move_line_obj.create(cr, uid, {
'name': product.name,
'account_id': stock_output_acc,
'credit': amount_diff,
- 'move_id': move_id,
+ 'move_id': move_id
})
move_line_obj.create(cr, uid, {
'name': location.name,
'account_id': location_account,
'debit': amount_diff,
- 'move_id': move_id,
+ 'move_id': move_id
})
prod_obj.write(cr, uid, rec_id, {'standard_price': new_price})
diff --git a/addons/stock/wizard/stock_change_standard_price_view.xml b/addons/stock/wizard/stock_change_standard_price_view.xml
index 38ba579848d..8c418cef0ea 100644
--- a/addons/stock/wizard/stock_change_standard_price_view.xml
+++ b/addons/stock/wizard/stock_change_standard_price_view.xml
@@ -7,8 +7,14 @@
form