[IMP] stock{_account}: add reference opening magic in list view
The move line form view is too technical for the average user so instead we can to auto-magically open the reference document instead (picking or MO only for now). We do the same with stock valuation layers as well, but this feature will not be available until its custom JS is converted to OWL "product moves" part of b2b task: 2882539 closes odoo/odoo#97109 Related: odoo/enterprise#29974 Related: odoo/upgrade#3819 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
@@ -551,3 +551,15 @@ class StockMove(models.Model):
|
||||
if 'manufacture' in self.product_id._get_rules_from_location(self.location_id).mapped('action'):
|
||||
date -= relativedelta(days=self.company_id.manufacturing_lead)
|
||||
return date
|
||||
|
||||
def action_open_reference(self):
|
||||
res = super().action_open_reference()
|
||||
source = self.production_id or self.raw_material_production_id
|
||||
if source and source.check_access_rights('read', raise_exception=False):
|
||||
return {
|
||||
'res_model': source._name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [[False, "form"]],
|
||||
'res_id': source.id,
|
||||
}
|
||||
return res
|
||||
|
||||
@@ -2122,3 +2122,22 @@ class StockMove(models.Model):
|
||||
result[out] = (-remaining, False)
|
||||
|
||||
return result
|
||||
|
||||
def action_open_reference(self):
|
||||
""" Open the form view of the move's reference document, if one exists, otherwise open form view of self
|
||||
"""
|
||||
self.ensure_one()
|
||||
source = self.picking_id
|
||||
if source and source.check_access_rights('read', raise_exception=False):
|
||||
return {
|
||||
'res_model': source._name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [[False, "form"]],
|
||||
'res_id': source.id,
|
||||
}
|
||||
return {
|
||||
'res_model': self._name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [[False, "form"]],
|
||||
'res_id': self.id,
|
||||
}
|
||||
|
||||
@@ -847,3 +847,16 @@ class StockMoveLine(models.Model):
|
||||
'restrict_partner_id': self.picking_id.owner_id.id,
|
||||
'company_id': self.picking_id.company_id.id,
|
||||
}
|
||||
|
||||
def action_open_reference(self):
|
||||
self.ensure_one()
|
||||
if self.move_id:
|
||||
action = self.move_id.action_open_reference()
|
||||
if action['res_model'] != 'stock.move':
|
||||
return action
|
||||
return {
|
||||
'res_model': self._name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [[False, "form"]],
|
||||
'res_id': self.id,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<field name="name">stock.move.line.tree</field>
|
||||
<field name="model">stock.move.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Move Lines" create="0" default_order="date desc">
|
||||
<tree string="Move Lines" create="0" default_order="date desc" action="action_open_reference" type="object">
|
||||
<field name="location_usage" invisible="1"/>
|
||||
<field name="location_dest_usage" invisible="1"/>
|
||||
<field name="date"/>
|
||||
|
||||
@@ -62,3 +62,16 @@ class StockValuationLayer(models.Model):
|
||||
if 'unit_cost' in fields:
|
||||
fields.remove('unit_cost')
|
||||
return super().read_group(domain, fields, groupby, offset, limit, orderby, lazy)
|
||||
|
||||
def action_open_reference(self):
|
||||
self.ensure_one()
|
||||
if self.stock_move_id:
|
||||
action = self.move_id.action_open_reference()
|
||||
if action['res_model'] != 'stock.move':
|
||||
return action
|
||||
return {
|
||||
'res_model': self._name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [[False, "form"]],
|
||||
'res_id': self.id,
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
<field name="model">stock.valuation.layer</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree default_order="create_date desc, id desc" create="0"
|
||||
import="0" js_class="inventory_report_list">
|
||||
import="0" js_class="inventory_report_list"
|
||||
action="action_open_reference" type="object">
|
||||
<field name="create_date" string="Date" />
|
||||
<field name="reference"/>
|
||||
<field name="product_id" />
|
||||
|
||||
Reference in New Issue
Block a user