[IMP] mrp: added stat button on MO to open Traceability Report
- Remove some reusable code in get_lines()
This commit is contained in:
committed by
Simon Lejeune
parent
523092e6f4
commit
827beb9662
@@ -56,6 +56,7 @@
|
||||
<field name="post_visible" invisible="1"/>
|
||||
<field name="unreserve_visible" invisible="1"/>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button name="%(stock.action_stock_report)d" icon="fa-arrow-up" class="oe_stat_button" string="Traceability Report" type="action" states="done" groups="stock.group_production_lot"/>
|
||||
<button name="%(action_mrp_workorder_production_specific)d" type="action" attrs="{'invisible': [('workorder_count', '=', 0)]}" class="oe_stat_button" icon="fa-play-circle-o">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="workorder_done_count" widget="statinfo" nolabel="1"/> / <field name="workorder_count" widget="statinfo" nolabel="1"/></span>
|
||||
|
||||
@@ -44,38 +44,31 @@ class MrpStockReport(models.TransientModel):
|
||||
@api.model
|
||||
def get_lines(self, line_id=None, **kw):
|
||||
context = dict(self.env.context)
|
||||
model = False
|
||||
model_id = False
|
||||
level = 1
|
||||
if kw:
|
||||
level = kw['level']
|
||||
model = kw['model_name']
|
||||
model_id = kw['model_id']
|
||||
model = kw and kw['model_name'] or context.get('model')
|
||||
rec_id = kw and kw['model_id'] or context.get('active_id')
|
||||
level = kw and kw['level'] or 1
|
||||
lines = []
|
||||
res = []
|
||||
move_line = self.env['stock.move.line']
|
||||
if context.get('active_id') and not context.get('model') or context.get('model') == 'stock.production.lot':
|
||||
move_ids = self.env['stock.move.line'].search([
|
||||
('lot_id', '=', context.get('active_id')),
|
||||
if rec_id and model in ('stock.production.lot', 'stock.move.line'):
|
||||
lines = self.env['stock.move.line'].search([
|
||||
('lot_id', '=', context.get('lot_id') or rec_id),
|
||||
('state', '=', 'done'),
|
||||
('move_id.returned_move_ids', '=', False),
|
||||
])
|
||||
res += self._lines(line_id, model_id=model_id, model='stock.move.line', level=level, obj_ids=move_ids)
|
||||
elif context.get('active_id') and context.get('model') == 'stock.picking':
|
||||
move_ids = self.env['stock.picking'].browse(context['active_id']).move_lines.mapped('move_line_ids').filtered(lambda m: m.lot_id and m.state == 'done')
|
||||
res = self._lines(line_id, model_id=model_id, model='stock.move.line', level=level, obj_ids=move_ids)
|
||||
elif context.get('active_id') and context.get('model') == 'stock.move.line':
|
||||
move_ids = self.env['stock.move.line'].search([
|
||||
('lot_id', '=', context.get('lot_id')),
|
||||
('state', '=', 'done'),
|
||||
('move_id.returned_move_ids', '=', False),
|
||||
])
|
||||
for line in move_ids:
|
||||
dummy, is_used = self._get_linked_move_lines(line)
|
||||
if is_used:
|
||||
move_line |= is_used
|
||||
res = self._lines(line_id, model_id=context.get('active_id'), model=context.get('model'), level=level, obj_ids=move_line)
|
||||
else:
|
||||
res = self._lines(line_id, model_id=model_id, model=model, level=level)
|
||||
if model == 'stock.move.line':
|
||||
for line in lines:
|
||||
dummy, is_used = self._get_linked_move_lines(line)
|
||||
if is_used:
|
||||
move_line |= is_used
|
||||
lines = move_line
|
||||
elif rec_id and model in ('stock.picking', 'mrp.production'):
|
||||
res = self.env[model].browse(rec_id)
|
||||
if model == 'stock.picking':
|
||||
lines = res.move_lines.mapped('move_line_ids').filtered(lambda m: m.lot_id and m.state == 'done')
|
||||
else:
|
||||
lines = res.move_finished_ids.mapped('move_line_ids').filtered(lambda m: m.lot_id and m.state == 'done')
|
||||
res = self._lines(line_id, model_id=rec_id, model=model, level=level, obj_ids=lines)
|
||||
final_vals = sorted(res, key=lambda v: v['date'], reverse=True)
|
||||
lines = self.final_vals_to_lines(final_vals, level)
|
||||
return lines
|
||||
|
||||
Reference in New Issue
Block a user