From 4952b96ff7ce2c369a48388b3e3242ca0067a00f Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 6 Sep 2013 11:57:26 +0200 Subject: [PATCH] [IMP] Add store on package company_id and add owner, add parent_left/right store bzr revid: jco@openerp.com-20130906095726-ozz6lohbujidgm23 --- addons/stock/procurement.py | 9 ++++----- addons/stock/stock.py | 26 +++++++++++++++++++++----- addons/stock/stock_view.xml | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index c9d89816983..fbc1fb69f83 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -173,7 +173,7 @@ class procurement_order(osv.osv): 'product_uom': product.uom_id.id, 'location_id': location_id, 'company_id': warehouse.company_id.id, - 'procure_method': 'make_to_order',} + } def create_automatic_op(self, cr, uid, context=None): """ @@ -204,7 +204,7 @@ class procurement_order(osv.osv): product = product_obj.browse(cr, uid, [product_read['id']], context=context)[0] if product.supply_method == 'buy': - location_id = warehouse.lot_input_id.id + location_id = warehouse.lot_stock_id.id elif product.supply_method == 'produce': location_id = warehouse.lot_stock_id.id else: @@ -212,8 +212,8 @@ class procurement_order(osv.osv): proc_id = proc_obj.create(cr, uid, self._prepare_automatic_op_procurement(cr, uid, product, warehouse, location_id, context=context), context=context) - self.signal_button_confirm(cr, uid, [proc_id]) - self.signal_button_check(cr, uid, [proc_id]) + self.assign(cr, uid, [proc_id]) + self.run(cr, uid, [proc_id]) return True def _get_orderpoint_date_planned(self, cr, uid, orderpoint, start_date, context=None): @@ -229,7 +229,6 @@ class procurement_order(osv.osv): 'company_id': orderpoint.company_id.id, 'product_uom': orderpoint.product_uom.id, 'location_id': orderpoint.location_id.id, - 'procure_method': 'make_to_order', 'origin': orderpoint.name} def _product_virtual_get(self, cr, uid, order_point): diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 6923044dc4e..5d3c79417e5 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1950,7 +1950,10 @@ class stock_package(osv.osv): """ _name = "stock.quant.package" _description = "Physical Packages" - _order = 'name' + _parent_name = "parent_id" + _parent_store = True + _parent_order = 'name' + _order = 'parent_left' def name_get(self, cr, uid, ids, context=None): res = self._complete_name(cr, uid, ids, 'complete_name', None, context=context) @@ -1985,16 +1988,20 @@ class stock_package(osv.osv): res.add(pack.parent_id.id) return list(res) + # TODO: Problem when package is empty! + # def _get_package_info(self, cr, uid, ids, name, args, context=None): default_company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id res = {}.fromkeys(ids, {'location_id': False, 'company_id': default_company_id}) for pack in self.browse(cr, uid, ids, context=context): if pack.quant_ids: res[pack.id]['location_id'] = pack.quant_ids[0].location_id.id + res[pack.id]['owner_id'] = pack.quant_ids[0].owner_id and pack.quant_ids[0].owner_id.id or False res[pack.id]['company_id'] = pack.quant_ids[0].company_id.id elif pack.children_ids: - res[pack.id]['location_id'] = pack.children_ids[0].location_id.id - res[pack.id]['company_id'] = pack.children_ids[0].company_id.id + res[pack.id]['location_id'] = pack.children_ids[0].location_id and pack.children_ids[0].location_id.id or False + res[pack.id]['owner_id'] = pack.children_ids[0].owner_id and pack.children_ids[0].owner_id.id or False + res[pack.id]['company_id'] = pack.children_ids[0].company_id and pack.children_ids[0].company_id.id or False return res _columns = { @@ -2006,12 +2013,21 @@ class stock_package(osv.osv): 'location_id': fields.function(_get_package_info, type='many2one', relation='stock.location', string='Location', multi="package", store={ 'stock.quant': (_get_packages, ['location_id'], 10), - 'stock.quant.package': (_get_packages_to_relocate, ['children_ids', 'quant_ids', 'parent_id'], 10), + 'stock.quant.package': (_get_packages_to_relocate, ['quant_ids', 'children_ids', 'parent_id'], 10), }, readonly=True), 'quant_ids': fields.one2many('stock.quant', 'package_id', 'Bulk Content'), 'parent_id': fields.many2one('stock.quant.package', 'Parent Package', help="The package containing this item"), 'children_ids': fields.one2many('stock.quant.package', 'parent_id', 'Contained Packages'), - 'company_id': fields.function(_get_package_info, type="many2one", relation='res.company', string='Company', multi="package"), + 'company_id': fields.function(_get_package_info, type="many2one", relation='res.company', string='Company', multi="package", + store={ + 'stock.quant': (_get_packages, ['company_id'], 10), + 'stock.quant.package': (_get_packages_to_relocate, ['quant_ids', 'children_ids', 'parent_id'], 10), + }, readonly=True), + 'owner_id': fields.function(_get_package_info, type='many2one', relation='res.partner', string='Owner', multi="package", + store={ + 'stock.quant': (_get_packages, ['owner_id'], 10), + 'stock.quant.package': (_get_packages_to_relocate, ['quant_ids', 'children_ids', 'parent_id'], 10), + }, readonly=True), } _defaults = { 'name': lambda self, cr, uid, context: self.pool.get('ir.sequence').get(cr, uid, 'stock.quant.package') or _('Unknown Pack') diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index f5f7f6532fb..928d6b2ca21 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -614,7 +614,7 @@ - + @@ -1725,6 +1725,7 @@ +