[WIP] Replace quants report with report based on stock.quant instead of separate SQL view
bzr revid: jco@openerp.com-20130722161533-tkzuetmfk64exq8m
This commit is contained in:
parent
a3cc2f8fdc
commit
8a1c3b8139
|
@ -13,8 +13,6 @@ access_stock_production_lot_user,stock.production.lot user,stock.model_stock_pro
|
|||
access_stock_production_lot_manager,stock.production.lot manager,stock.model_stock_production_lot,mrp.group_mrp_manager,1,0,0,0
|
||||
access_mrp_repair_line_user,mrp.repair.line user,model_mrp_repair_line,mrp.group_mrp_user,1,1,1,1
|
||||
access_mrp_repair_line_manager,mrp.repair.line manager,model_mrp_repair_line,mrp.group_mrp_manager,1,0,0,0
|
||||
access_stock_production_lot_revision_manager,stock.production.lot.revision manager,stock.model_stock_production_lot_revision,mrp.group_mrp_manager,1,0,0,0
|
||||
access_stock_production_lot_revision_user,stock.production.lot.revision user,stock.model_stock_production_lot_revision,mrp.group_mrp_user,1,1,1,1
|
||||
access_product_price_type_manager,product.price.type manager,product.model_product_price_type,mrp.group_mrp_manager,1,0,0,0
|
||||
access_product_price_type_user,product.price.type,product.model_product_price_type,mrp.group_mrp_user,1,1,1,1
|
||||
access_account_tax_user,account.tax,account.model_account_tax,mrp.group_mrp_user,1,1,1,1
|
||||
|
|
|
|
@ -24,13 +24,14 @@ from openerp.osv import fields,osv
|
|||
from openerp.addons.decimal_precision import decimal_precision as dp
|
||||
|
||||
# FP Note: TODO: drop this table and use the stock.move table instead
|
||||
class report_stock_inventory(osv.osv):
|
||||
_name = "report.stock.inventory"
|
||||
class stock_quant(osv.osv):
|
||||
_inherit = "stock.quant"
|
||||
_description = "Stock Statistics"
|
||||
_auto = False
|
||||
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
|
||||
res = super(report_stock_inventory, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)
|
||||
res = super(stock_quant, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)
|
||||
product_obj = self.pool.get("product.product")
|
||||
if 'inventory_value' in fields:
|
||||
for line in res:
|
||||
if '__domain' in line:
|
||||
lines = self.search(cr, uid, line['__domain'], context=context)
|
||||
|
@ -58,7 +59,7 @@ class report_stock_inventory(osv.osv):
|
|||
prods = product_obj.browse(cr, uid, proddict[prodelem].keys(), context=ctx)
|
||||
for prod in prods:
|
||||
prodbrow[(prodelem, prod.id)] = prod
|
||||
# use prodbrow and existing value on the report lines to calculate the inventory_value on the report lines
|
||||
# use prodbrow and existing value on quants to calculate the inventory_value on the report lines
|
||||
for line in lines:
|
||||
ctx = context.copy()
|
||||
ctx['force_company'] = line.company_id.id
|
||||
|
@ -70,37 +71,7 @@ class report_stock_inventory(osv.osv):
|
|||
return prodbrow[(line.company_id.id, line.product_id.id)].standard_price * line.product_qty
|
||||
|
||||
_columns = {
|
||||
'product_id':fields.many2one('product.product', 'Product', readonly=True),
|
||||
'product_categ_id':fields.many2one('product.category', 'Product Category', readonly=True),
|
||||
'location_id': fields.many2one('stock.location', 'Location', readonly=True),
|
||||
'lot_id': fields.many2one('stock.production.lot', 'Lot', readonly=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', readonly=True),
|
||||
'product_qty':fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), help="Qty Remaining", readonly=True),
|
||||
'value' : fields.float('Total Value', digits_compute=dp.get_precision('Account'), required=True),
|
||||
'scrap_location': fields.boolean('scrap'),
|
||||
'inventory_value': fields.function(_calc_moves, string="Inventory Value", type='float', readonly=True),
|
||||
'location_type': fields.selection([('supplier', 'Supplier Location'), ('view', 'View'), ('internal', 'Internal Location'), ('customer', 'Customer Location'), ('inventory', 'Inventory'), ('procurement', 'Procurement'), ('production', 'Production'), ('transit', 'Transit Location for Inter-Companies Transfers')], 'Location Source Type'),
|
||||
}
|
||||
def init(self, cr):
|
||||
tools.drop_view_if_exists(cr, 'report_stock_inventory')
|
||||
cr.execute("""
|
||||
CREATE OR REPLACE view report_stock_inventory AS (
|
||||
SELECT
|
||||
sq.id as id,
|
||||
sq.in_date as date,
|
||||
sq.location_id as location_id,
|
||||
sq.product_id as product_id,
|
||||
pt.categ_id as product_categ_id,
|
||||
location.scrap_location as scrap_location,
|
||||
sq.company_id,
|
||||
sq.lot_id as lot_id,
|
||||
sq.cost * sq.qty as value,
|
||||
sq.qty as product_qty,
|
||||
location.usage as location_type
|
||||
FROM stock_quant sq
|
||||
LEFT JOIN stock_location location ON (sq.location_id = location.id)
|
||||
LEFT JOIN product_template pt ON (sq.product_id=pt.id)
|
||||
);
|
||||
""")
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -10,66 +10,50 @@
|
|||
groups="group_stock_manager"/>
|
||||
|
||||
<!-- Inventory Control -->
|
||||
<record id="view_stock_inventory_tree" model="ir.ui.view">
|
||||
<field name="name">report.stock.inventory.tree</field>
|
||||
<field name="model">report.stock.inventory</field>
|
||||
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="view_stock_quant_tree_value">
|
||||
<field name="name">stock.quant.tree</field>
|
||||
<field name="model">stock.quant</field>
|
||||
<field eval="12" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Inventory Analysis" create="false">
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="location_type" invisible="1"/>
|
||||
<field name="location_id" invisible="1"/>
|
||||
<field name="product_categ_id" invisible="1"/>
|
||||
<field name="product_id" invisible="1"/>
|
||||
<field name="lot_id" invisible="1"/>
|
||||
<field name="product_qty" sum="Total Quantity in Stock"/>
|
||||
<field name="inventory_value" sum="Total Inventory Value"/>
|
||||
<tree string="Quants">
|
||||
<field name="product_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="location_id"/>
|
||||
<field name="in_date"/>
|
||||
<field name="inventory_value"/>
|
||||
<field name="reservation_id" invisible='1'/>
|
||||
<field name="propagated_from_id" invisible='1'/>
|
||||
<field name="company_id" invisible='1'/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_stock_inventory_graph" model="ir.ui.view">
|
||||
<field name="name">report.stock.inventory.graph</field>
|
||||
<field name="model">report.stock.inventory</field>
|
||||
|
||||
<record model="ir.ui.view" id="view_stock_quant_graph_value">
|
||||
<field name="name">stock.quant.graph</field>
|
||||
<field name="model">stock.quant</field>
|
||||
<field eval="12" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<graph string="Inventory Analysis" type="bar">
|
||||
<graph string="Quants">
|
||||
<field name="product_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="location_id"/>
|
||||
<field name="inventory_value"/>
|
||||
|
||||
</graph>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_stock_inventory_search" model="ir.ui.view">
|
||||
<field name="name">report.stock.inventory.search</field>
|
||||
<field name="model">report.stock.inventory</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Inventory Analysis">
|
||||
<filter icon="terp-go-home" name="location_type_internal" string="Internal" domain="[('location_type','=','internal')]"/>
|
||||
<field name="product_id" default_focus="1"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="location_id" filter_domain="[('location_id', 'child_of', self)]"/>
|
||||
<group expand="0" string="Extended Filters...">
|
||||
<field name="product_categ_id" />
|
||||
<field name="lot_id"/>
|
||||
<field name="location_type"/>
|
||||
<filter icon="terp-go-home" name="location_type_scrap" string="Scrap" domain="[('scrap_location','=','True')]"/>
|
||||
</group>
|
||||
<group expand="1" string="Group By..." >
|
||||
<filter name="group_product_categ_id" string="Product Category" icon="terp-stock_symbol-selection" context="{'group_by':'product_categ_id'}"/>
|
||||
<filter name="group_product" string="Product" icon="terp-accessories-archiver" context="{'group_by':'product_id'}"/>
|
||||
<filter name="group_lot" string="Lot" icon="terp-accessories-archiver" context="{'group_by':'lot_id'}"/>
|
||||
<filter name="group_company" string="Company" groups="base.group_multi_company" icon="terp-go-home" context="{'group_by':'company_id'}"/>
|
||||
<filter name="group_location" string="Location" icon="terp-go-home" context="{'group_by':'location_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_stock_inventory_report" model="ir.actions.act_window">
|
||||
<field name="name">Inventory Valuation</field>
|
||||
<field name="res_model">report.stock.inventory</field>
|
||||
<field name="res_model">stock.quant</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,graph</field>
|
||||
<field name="search_view_id" eval="False"/>
|
||||
<field name="view_mode">tree,graph,form</field>
|
||||
<field name="view_id" ref="view_stock_quant_tree_value"/>
|
||||
<field name="context">{'search_default_real':1, 'search_default_inmovesremaining':1 ,'group_by':['company_id', 'product_id'], 'group_by_no_leaf':0}</field>
|
||||
<field name="help">Inventory Analysis allows you to easily check and analyse your company stock levels. Sort and group by selection criteria in order to better analyse and manage your company activities.</field>
|
||||
</record>
|
||||
|
|
|
@ -1597,7 +1597,7 @@
|
|||
<field name="package_id"/>
|
||||
<field name="lot_id"/>
|
||||
<group expand='0' string='Filters'>
|
||||
<filter string="Internal Locations" domain="[('location_id.usage,'=', 'internal')]"/>
|
||||
<filter string="Internal Locations" domain="[('location_id.usage','=', 'internal')]"/>
|
||||
</group>
|
||||
<group expand='0' string='Group by...'>
|
||||
<filter name="productgroup" string='Product' context="{'group_by' : 'product_id'}"/>
|
||||
|
|
|
@ -62,6 +62,14 @@ class stock_location(osv.osv):
|
|||
class stock_quant(osv.osv):
|
||||
_inherit = "stock.quant"
|
||||
|
||||
|
||||
def _get_inventory_value(self, cr, uid, line, prodbrow, context=None):
|
||||
#TODO: what in case of partner_id
|
||||
if prodbrow[(line.company_id.id, line.product_id.id)].cost_method in ('real'):
|
||||
return line.cost
|
||||
return super(stock_quant, self)._get_inventory_value(cr, uid, line, prodbrow, context=context)
|
||||
|
||||
|
||||
# FP Note: this is where we should post accounting entries for adjustment
|
||||
def _price_update(self, cr, uid, quant, newprice, context=None):
|
||||
super(stock_quant, self)._price_update(cr, uid, quant, newprice, context=context)
|
||||
|
@ -533,12 +541,6 @@ class stock_move(osv.osv):
|
|||
# return True
|
||||
|
||||
|
||||
class report_stock_inventory(osv.osv):
|
||||
_inherit = "report.stock.inventory"
|
||||
|
||||
def _get_inventory_value(self, cr, uid, line, prodbrow, context=None):
|
||||
if prodbrow[(line.company_id.id, line.product_id.id)].cost_method in ('real'):
|
||||
return line.value
|
||||
return super(report_stock_inventory, self)._get_inventory_value(cr, uid, line, prodbrow, context=context)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue