[REF]
bzr revid: mra@mra-laptop-20100706115632-ar3g22cjjqfo331i
This commit is contained in:
parent
11284af16d
commit
c47792af54
|
@ -25,5 +25,4 @@ import product
|
|||
import report
|
||||
import wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
|
@ -15,7 +15,7 @@
|
|||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
@ -23,29 +23,27 @@ from osv import fields, osv
|
|||
import ir
|
||||
|
||||
class res_partner(osv.osv):
|
||||
_name = 'res.partner'
|
||||
_inherit = 'res.partner'
|
||||
_columns = {
|
||||
'property_stock_customer': fields.property(
|
||||
'stock.location',
|
||||
type='many2one',
|
||||
relation='stock.location',
|
||||
string="Customer Location",
|
||||
type='many2one',
|
||||
relation='stock.location',
|
||||
string="Customer Location",
|
||||
method=True,
|
||||
view_load=True,
|
||||
help="This stock location will be used, instead of the default one, as the destination location for goods you send to this partner"),
|
||||
|
||||
'property_stock_supplier': fields.property(
|
||||
'stock.location',
|
||||
type='many2one',
|
||||
relation='stock.location',
|
||||
string="Supplier Location",
|
||||
type='many2one',
|
||||
relation='stock.location',
|
||||
string="Supplier Location",
|
||||
method=True,
|
||||
view_load=True,
|
||||
help="This stock location will be used, instead of the default one, as the source location for goods you receive from the current partner"),
|
||||
}
|
||||
|
||||
res_partner()
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -22,45 +22,46 @@
|
|||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class product_product(osv.osv):
|
||||
_inherit = "product.product"
|
||||
|
||||
def get_product_accounts(self, cr, uid, product_id, context=None):
|
||||
""" To get the stock input account, stock output account and stock journal related to product.
|
||||
@param product_id: product id
|
||||
@param product_id: product id
|
||||
@return: dictionary which contains information regarding stock input account, stock output account and stock journal
|
||||
"""
|
||||
product_obj = self.pool.get('product.product').browse(cr, uid, product_id, context)
|
||||
|
||||
stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False
|
||||
if context is None:
|
||||
context = {}
|
||||
product_obj = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
|
||||
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
|
||||
|
||||
journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False
|
||||
account_variation = product_obj.categ_id.property_stock_variation and product_obj.categ_id.property_stock_variation.id or False
|
||||
|
||||
|
||||
return {
|
||||
'stock_account_input': stock_input_acc,
|
||||
'stock_account_output': stock_output_acc,
|
||||
'stock_journal': journal_id,
|
||||
'stock_account_input': stock_input_acc,
|
||||
'stock_account_output': stock_output_acc,
|
||||
'stock_journal': journal_id,
|
||||
'property_stock_variation': account_variation
|
||||
}
|
||||
}
|
||||
|
||||
def do_change_standard_price(self, cr, uid, ids, datas, context={}):
|
||||
""" Changes the Standard Price of Product and creates an account move accordingly.
|
||||
@param datas : dict. contain default datas like new_price, stock_output_account, stock_input_account, stock_journal
|
||||
@param context: A standard dictionary
|
||||
@return:
|
||||
|
||||
"""
|
||||
@param context: A standard dictionary
|
||||
@return:
|
||||
|
||||
"""
|
||||
location_obj = self.pool.get('stock.location')
|
||||
move_obj = self.pool.get('account.move')
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
|
||||
new_price = datas.get('new_price', 0.0)
|
||||
stock_output_acc = datas.get('stock_output_account', False)
|
||||
|
@ -71,7 +72,7 @@ class product_product(osv.osv):
|
|||
account_variation = product_obj.categ_id.property_stock_variation
|
||||
account_variation_id = account_variation and account_variation.id or False
|
||||
if not account_variation_id: raise osv.except_osv(_('Error!'), _('Variation Account is not specified for Product Category: %s' % (product_obj.categ_id.name)))
|
||||
move_ids = []
|
||||
move_ids = []
|
||||
loc_ids = location_obj.search(cr, uid,[('usage','=','internal')])
|
||||
for rec_id in ids:
|
||||
for location in location_obj.browse(cr, uid, loc_ids):
|
||||
|
@ -79,14 +80,14 @@ class product_product(osv.osv):
|
|||
c.update({
|
||||
'location': location.id,
|
||||
'compute_child': False
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
product = self.browse(cr, uid, rec_id, context=c)
|
||||
qty = product.qty_available
|
||||
diff = product.standard_price - new_price
|
||||
diff = product.standard_price - new_price
|
||||
if not diff: raise osv.except_osv(_('Error!'), _("Could not find any difference between standard price and new price!"))
|
||||
if qty:
|
||||
company_id = location.company_id and location.company_id.id or False
|
||||
company_id = location.company_id and location.company_id.id or False
|
||||
if not company_id: raise osv.except_osv(_('Error!'), _('Company is not specified in Location'))
|
||||
#
|
||||
# Accounting Entries
|
||||
|
@ -100,10 +101,10 @@ class product_product(osv.osv):
|
|||
(product.categ_id.name,
|
||||
product.categ_id.id,))
|
||||
move_id = move_obj.create(cr, uid, {
|
||||
'journal_id': journal_id,
|
||||
'journal_id': journal_id,
|
||||
'company_id': company_id
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
move_ids.append(move_id)
|
||||
|
||||
|
||||
|
@ -120,7 +121,7 @@ class product_product(osv.osv):
|
|||
'for this product: "%s" (id: %d)') % \
|
||||
(product.name,
|
||||
product.id,))
|
||||
amount_diff = qty * diff
|
||||
amount_diff = qty * diff
|
||||
move_line_obj.create(cr, uid, {
|
||||
'name': product.name,
|
||||
'account_id': stock_input_acc,
|
||||
|
@ -133,7 +134,7 @@ class product_product(osv.osv):
|
|||
'credit': amount_diff,
|
||||
'move_id': move_id
|
||||
})
|
||||
elif diff < 0:
|
||||
elif diff < 0:
|
||||
if not stock_output_acc:
|
||||
stock_output_acc = product.product_tmpl_id.\
|
||||
property_stock_account_output.id
|
||||
|
@ -158,13 +159,15 @@ class product_product(osv.osv):
|
|||
'account_id': account_variation_id,
|
||||
'debit': amount_diff,
|
||||
'move_id': move_id
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
self.write(cr, uid, rec_id, {'standard_price': new_price})
|
||||
|
||||
return move_ids
|
||||
|
||||
def view_header_get(self, cr, user, view_id, view_type, context):
|
||||
def view_header_get(self, cr, user, view_id, view_type, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(product_product, self).view_header_get(cr, user, view_id, view_type, context)
|
||||
if res: return res
|
||||
if (context.get('location', False)):
|
||||
|
@ -280,12 +283,14 @@ class product_product(osv.osv):
|
|||
res[prod_id] -= amount
|
||||
return res
|
||||
|
||||
def _product_available(self, cr, uid, ids, field_names=None, arg=False, context={}):
|
||||
def _product_available(self, cr, uid, ids, field_names=None, arg=False, context=None):
|
||||
""" Finds the incoming and outgoing quantity of product.
|
||||
@return: Dictionary of values
|
||||
"""
|
||||
if not field_names:
|
||||
field_names = []
|
||||
if context is None:
|
||||
context = {}
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = {}.fromkeys(field_names, 0.0)
|
||||
|
@ -323,7 +328,7 @@ class product_product(osv.osv):
|
|||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
res = super(product_product,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
|
||||
if context == None:
|
||||
if context is None:
|
||||
context = {}
|
||||
if ('location' in context) and context['location']:
|
||||
location_info = self.pool.get('stock.location').browse(cr, uid, context['location'])
|
||||
|
@ -348,7 +353,7 @@ class product_product(osv.osv):
|
|||
if location_info.usage == 'inventory':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = _('Future P&L')
|
||||
if fields.get('qty_available'):
|
||||
if fields.get('qty_available'):
|
||||
res['fields']['qty_available']['string'] = _('P&L Qty')
|
||||
|
||||
if location_info.usage == 'procurement':
|
||||
|
@ -362,10 +367,9 @@ class product_product(osv.osv):
|
|||
res['fields']['virtual_available']['string'] = _('Future Productions')
|
||||
if fields.get('qty_available'):
|
||||
res['fields']['qty_available']['string'] = _('Produced Qty')
|
||||
|
||||
return res
|
||||
product_product()
|
||||
|
||||
product_product()
|
||||
|
||||
class product_template(osv.osv):
|
||||
_name = 'product.template'
|
||||
|
@ -407,10 +411,12 @@ class product_template(osv.osv):
|
|||
string='Stock Output Account', method=True, view_load=True,
|
||||
help='This account will be used, instead of the default one, to value output stock'),
|
||||
}
|
||||
|
||||
product_template()
|
||||
|
||||
|
||||
class product_category(osv.osv):
|
||||
|
||||
_inherit = 'product.category'
|
||||
_columns = {
|
||||
'property_stock_journal': fields.property('account.journal',
|
||||
|
@ -425,14 +431,14 @@ class product_category(osv.osv):
|
|||
type='many2one', relation='account.account',
|
||||
string='Stock Output Account', method=True, view_load=True,
|
||||
help='This account will be used to value the output stock'),
|
||||
'property_stock_variation': fields.property('account.account',
|
||||
'property_stock_variation': fields.property('account.account',
|
||||
type='many2one',
|
||||
relation='account.account',
|
||||
string="Stock Variation Account",
|
||||
method=True, view_load=True,
|
||||
method=True, view_load=True,
|
||||
help="This account will be used in product when valuation type is real-time valuation ",),
|
||||
}
|
||||
|
||||
product_category()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue