Skip to content

Commit

Permalink
[IMP] show the date of the latest stock move along with that of the l…
Browse files Browse the repository at this point in the history
…atest inventory. Optimize SQL query. Let users filter inactive products or not.

https://launchpad.net/bugs/1291986
  • Loading branch information
Numerigraphe - Lionel Sausin authored and Stefan Rijnhart committed Jul 2, 2014
1 parent 4335f32 commit ac4016f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
21 changes: 13 additions & 8 deletions addons/stock/report/report_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ def unlink(self, cr, uid, ids, context=None):

class report_stock_lines_date(osv.osv):
_name = "report.stock.lines.date"
_description = "Dates of Inventories"
_description = "Dates of Inventories and latest Moves"
_auto = False
_order = "date"
_columns = {
'id': fields.integer('Inventory Line Id', readonly=True),
'id': fields.integer('Product Id', readonly=True),
'product_id': fields.many2one('product.product', 'Product', readonly=True, select=True),
'date': fields.datetime('Latest Inventory Date'),
'date': fields.datetime('Date of latest Inventory', readonly=True),
'move_date': fields.datetime('Date of latest Stock Move', readonly=True),
"active" : fields.boolean("Active", readonly=True),
}
def init(self, cr):
drop_view_if_exists(cr, 'report_stock_lines_date')
Expand All @@ -152,13 +154,16 @@ def init(self, cr):
select
p.id as id,
p.id as product_id,
max(s.date) as date
max(s.date) as date,
max(m.date) as move_date,
p.active as active
from
product_product p
left outer join stock_inventory_line l on (p.id=l.product_id)
left join stock_inventory s on (l.inventory_id=s.id)
and s.state = 'done'
where p.active='true'
left join (
stock_inventory_line l
inner join stock_inventory s on (l.inventory_id=s.id and s.state = 'done')
) on (p.id=l.product_id)
left join stock_move m on (m.product_id=p.id and m.state = 'done')
group by p.id
)""")

Expand Down
13 changes: 8 additions & 5 deletions addons/stock/report/report_stock_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<tree string="Dates of Inventories" create="false">
<field name="product_id"/>
<field name="date" />
<field name="move_date"/>
</tree>
</field>
</record>
Expand All @@ -31,12 +32,13 @@
<field name="name">report.stock.lines.date.search</field>
<field name="model">report.stock.lines.date</field>
<field name="arch" type="xml">
<search string="Dates of Inventories">
<search string="Dates of Inventories &amp; Moves">
<field name="date"/>
<filter icon="terp-accessories-archiver" name="stockable" string="Stockable" domain="[('product_id.type','=', 'product')]"/>
<filter icon="terp-accessories-archiver" string="Consumable" domain="[('product_id.type','=', 'consu')]"/>
<separator/>
<filter icon="terp-accessories-archiver-minus" string="Non Inv" domain="[('date','=', False)]"/>
<filter icon="terp-accessories-archiver-minus" string="No Inventory yet" domain="[('date','=', False)]"/>
<filter icon="terp-accessories-archiver-minus" string="No Stock Move yet" domain="[('move_date','=', False)]"/>
<field name="product_id"/>
</search>
</field>
Expand All @@ -46,22 +48,23 @@
<field name="name">report.stock.lines.date.form</field>
<field name="model">report.stock.lines.date</field>
<field name="arch" type="xml">
<form string="Dates of Inventories" version="7.0">
<form string="Dates of Inventories &amp; Moves" version="7.0">
<group>
<field name="product_id"/>
<field name="date"/>
<field name="move_date"/>
</group>
</form>
</field>
</record>

<record model="ir.actions.act_window" id="action_stock_line_date">
<field name="name">Last Product Inventories</field>
<field name="name">Latest Inventories &amp; Moves</field>
<field name="res_model">report.stock.lines.date</field>
<field name="view_type">form</field>
<field name="context">{'search_default_stockable':1}</field>
<field name="view_mode">tree,form</field>
<field name="help">Display the last inventories done on your products and easily sort them with specific filtering criteria. If you do frequent and partial inventories, you need this report in order to ensure that the stock of each product is controlled at least once a year.</field>
<field name="help">Display the latest Inventories and Moves done on your products and easily sort them with specific filtering criteria. If you do frequent and partial inventories, you need this report in order to ensure that the stock of each product is controlled at least once a year. This also lets you find out which products have seen little move lately and may deserve special measures (discounted sale, quality control...)</field>
</record>

<menuitem parent="next_id_61" action="action_stock_line_date" id="menu_report_stock_line_date" sequence="2"/>
Expand Down

0 comments on commit ac4016f

Please sign in to comment.