From dac1cb78beb3e92269ecfb44d48484735dec2224 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 30 Apr 2013 16:04:45 +0200 Subject: [PATCH] [IMP] product valuation field as multi-company bzr revid: jco@openerp.com-20130430140445-fymwzfv6c7ayg1mj --- addons/product/product.py | 2 +- addons/stock/product.py | 4 ++-- addons/stock/stock.py | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index bb15aedd397..b77135a9c2d 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -319,7 +319,7 @@ class product_template(osv.osv): 'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True, help="Default Unit of Measure used for all stock operation."), 'uom_po_id': fields.many2one('product.uom', 'Purchase Unit of Measure', required=True, help="Default Unit of Measure used for purchase orders. It must be in the same category than the default unit of measure."), 'uos_id' : fields.many2one('product.uom', 'Unit of Sale', - help='Sepcify a unit of measure here if invoicing is made in another unit of measure than inventory. Keep empty to use the default unit of measure.'), + help='Specify a unit of measure here if invoicing is made in another unit of measure than inventory. Keep empty to use the default unit of measure.'), 'uos_coeff': fields.float('Unit of Measure -> UOS Coeff', digits_compute= dp.get_precision('Product UoS'), help='Coefficient to convert default Unit of Measure to Unit of Sale\n' ' uos = uom * coeff'), diff --git a/addons/stock/product.py b/addons/stock/product.py index b13192c8805..348aea51238 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -456,8 +456,8 @@ class product_product(osv.osv): 'track_outgoing': fields.boolean('Track Outgoing Lots', help="Forces to specify a Serial Number for all moves containing this product and going to a Customer Location"), 'location_id': fields.dummy(string='Location', relation='stock.location', type='many2one'), 'warehouse_id': fields.dummy(string='Warehouse', relation='stock.warehouse', type='many2one'), - 'valuation':fields.selection([('manual_periodic', 'Periodical (manual)'), - ('real_time','Real Time (automated)'),], 'Inventory Valuation', + 'valuation':fields.property('', type='selection', selection = [('manual_periodic', 'Periodical (manual)'), + ('real_time','Real Time (automated)'),], string = 'Inventory Valuation', help="If real-time valuation is enabled for a product, the system will automatically write journal entries corresponding to stock moves." \ "The inventory variation account set on the product category will represent the current inventory value, and the stock input and stock output account will hold the counterpart moves for incoming and outgoing products." , required=True), diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 8ce998335f4..9d3e3946b62 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1630,6 +1630,14 @@ class stock_move(osv.osv): raise osv.except_osv(_('Error'), _('You cannot move product %s to a location of type view %s.')% (record.product_id.name, record.location_dest_id.name)) return True + def _check_company_location(self, cr, uid, ids, context=None): + for record in self.browse(cr, uid, ids, context=context): + if record.location_id.company_id and (record.company_id.id != record.location_id.company_id.id): + raise osv.except_osv(_('Error'), _('The company of the source location %s and the company of the stock move should be the same') % record.location_id.name) + if record.location_dest_id.company_id and (record.company_id.id != record.location_dest_id.company_id.id): + raise osv.except_osv(_('Error'), _('The company of the destination location %s and the company of the stock move should be the same') % record.location_dest_id.name) + return True + _constraints = [ (_check_tracking, 'You must assign a serial number for this product.', @@ -1638,7 +1646,9 @@ class stock_move(osv.osv): ['location_id','location_dest_id']), (_check_product_lot, 'You try to assign a lot which is not from the same product.', - ['prodlot_id'])] + ['prodlot_id']), + (_check_company_location, 'You cannot use a location from another company. ', + ['company_id', 'location_id', 'location_dest_id'])] def _default_location_destination(self, cr, uid, context=None): """ Gets default address of partner for destination location @@ -1667,6 +1677,11 @@ class stock_move(osv.osv): location_xml_id = 'stock_location_customers' if location_xml_id: location_model, location_id = mod_obj.get_object_reference(cr, uid, 'stock', location_xml_id) + if location_id: + location_company = self.pool.get("stock.location").browse(cr, uid, location_id, context=context).company_id + user_company = self.pool.get("res.users").browse(cr, uid, uid, context=context).company_id.id + if location_company and location_company.id != user_company: + location_id = False return location_id def _default_location_source(self, cr, uid, context=None): @@ -1696,6 +1711,11 @@ class stock_move(osv.osv): location_xml_id = 'stock_location_stock' if location_xml_id: location_model, location_id = mod_obj.get_object_reference(cr, uid, 'stock', location_xml_id) + if location_id: + location_company = self.pool.get("stock.location").browse(cr, uid, location_id, context=context).company_id + user_company = self.pool.get("res.users").browse(cr, uid, uid, context=context).company_id.id + if location_company and location_company.id != user_company: + location_id = False return location_id def _default_destination_address(self, cr, uid, context=None): @@ -1915,6 +1935,16 @@ class stock_move(osv.osv): location_dest_id = 'stock_location_customers' source_location = mod_obj.get_object_reference(cr, uid, 'stock', location_source_id) dest_location = mod_obj.get_object_reference(cr, uid, 'stock', location_dest_id) + #Check companies + user_company = self.pool.get("res.users").browse(cr, uid, uid, context=context).company_id.id + if source_location: + location_company = self.pool.get("stock.location").browse(cr, uid, source_location[1], context=context).company_id + if location_company and location_company.id != user_company: + source_location = False + if dest_location: + location_company = self.pool.get("stock.location").browse(cr, uid, dest_location[1], context=context).company_id + if location_company and location_company.id != user_company: + dest_location = False return {'value':{'location_id': source_location and source_location[1] or False, 'location_dest_id': dest_location and dest_location[1] or False}} def onchange_date(self, cr, uid, ids, date, date_expected, context=None): @@ -2269,7 +2299,10 @@ class stock_move(osv.osv): to real_time valuation tracking, and the source or destination location is a transit location or is outside of the company. """ - if move.product_id.valuation == 'real_time': # FIXME: product valuation should perhaps be a property? + ctx = context.copy() + ctx['force_company'] = move.company_id.id + valuation = self.pool.get("product.product").browse(cr, uid, move.product_id.id, context=ctx).valuation + if valuation == 'real_time': if context is None: context = {} src_company_ctx = dict(context,force_company=move.location_id.company_id.id)