summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTWA <twa@odoo.com>2018-08-14 13:46:00 +0200
committerPierre Masereel <pim@odoo.com>2018-08-21 22:25:26 +0200
commit326e48a112f86c16e14be816ce7165a27a23709d (patch)
treebdd2d08e5ee06151bc3a4e423748db74603e0794
parentc9f899b99a633b38614f7689e56d56f5342ba590 (diff)
[IMP] purchase_stock, sale_stock : Show stat button instead of m2m widget
On stock production lot, we show stat buttons redirecting to purchase orders and sale orders where the lot has been used instead of showing Many2many in the form view. TASK-ID: 1873101
-rw-r--r--addons/purchase_stock/models/stock.py8
-rw-r--r--addons/purchase_stock/views/stock_production_lot_views.xml21
-rw-r--r--addons/sale_stock/models/stock.py8
-rw-r--r--addons/sale_stock/views/stock_production_lot_views.xml21
4 files changed, 36 insertions, 22 deletions
diff --git a/addons/purchase_stock/models/stock.py b/addons/purchase_stock/models/stock.py
index f4dbe1baa25..80d5027178e 100644
--- a/addons/purchase_stock/models/stock.py
+++ b/addons/purchase_stock/models/stock.py
@@ -190,6 +190,7 @@ class ProductionLot(models.Model):
_inherit = 'stock.production.lot'
purchase_order_ids = fields.Many2many('purchase.order', string="Purchase Orders", compute='_compute_purchase_order_ids', readonly=True, store=False)
+ purchase_order_count = fields.Integer('Purchase order count', compute='_compute_purchase_order_ids')
@api.depends('name')
def _compute_purchase_order_ids(self):
@@ -200,3 +201,10 @@ class ProductionLot(models.Model):
]).mapped('move_id').filtered(
lambda move: move.picking_id.location_id.usage == 'supplier' and move.state == 'done')
lot.purchase_order_ids = stock_moves.mapped('purchase_line_id.order_id')
+ lot.purchase_order_count = len(stock_moves)
+
+ def action_view_po(self):
+ self.ensure_one()
+ action = self.env.ref('purchase.purchase_form_action').read()[0]
+ action['domain'] = [('id', 'in', self.mapped('purchase_order_ids.id'))]
+ return action
diff --git a/addons/purchase_stock/views/stock_production_lot_views.xml b/addons/purchase_stock/views/stock_production_lot_views.xml
index 9371b84ce28..23ae5678bd3 100644
--- a/addons/purchase_stock/views/stock_production_lot_views.xml
+++ b/addons/purchase_stock/views/stock_production_lot_views.xml
@@ -5,17 +5,16 @@
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form"/>
<field name="arch" type="xml">
- <xpath expr="//group[@name='main_group']" position="after">
- <group>
- <field name="purchase_order_ids" widget="many2many" readonly="True">
- <tree>
- <field name="name"/>
- <field name="partner_id"/>
- <field name="date_order"/>
- <field name="state" invisible="1"/>
- </tree>
- </field>
- </group>
+ <xpath expr="//div[hasclass('oe_button_box')]/button" position="before">
+ <button class="oe_stat_button" name="action_view_po"
+ type="object" icon="fa-shopping-cart" attrs="{'invisible': [('purchase_order_count', '=', 0)]}" help="Purchase Orders">
+ <div class="o_field_widget o_stat_info">
+ <span class="o_stat_value">
+ <field name="purchase_order_count" widget="statinfo" nolabel="1" class="mr4"/>
+ </span>
+ <span class="o_stat_text">Purchase Orders</span>
+ </div>
+ </button>
</xpath>
</field>
</record>
diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py
index a07a479f8fc..cad005b4f36 100644
--- a/addons/sale_stock/models/stock.py
+++ b/addons/sale_stock/models/stock.py
@@ -103,6 +103,7 @@ class ProductionLot(models.Model):
_inherit = 'stock.production.lot'
sale_order_ids = fields.Many2many('sale.order', string="Sales Orders", compute='_compute_sale_order_ids')
+ sale_order_count = fields.Integer('Sale order count', compute='_compute_sale_order_ids')
@api.depends('name')
def _compute_sale_order_ids(self):
@@ -113,3 +114,10 @@ class ProductionLot(models.Model):
]).mapped('move_id').filtered(
lambda move: move.picking_id.location_dest_id.usage == 'customer' and move.state == 'done')
lot.sale_order_ids = stock_moves.mapped('sale_line_id.order_id')
+ lot.sale_order_count = len(stock_moves)
+
+ def action_view_so(self):
+ self.ensure_one()
+ action = self.env.ref('sale.action_orders').read()[0]
+ action['domain'] = [('id', 'in', self.mapped('sale_order_ids.id'))]
+ return action
diff --git a/addons/sale_stock/views/stock_production_lot_views.xml b/addons/sale_stock/views/stock_production_lot_views.xml
index e919bb81b9f..82b5ac9fb69 100644
--- a/addons/sale_stock/views/stock_production_lot_views.xml
+++ b/addons/sale_stock/views/stock_production_lot_views.xml
@@ -5,17 +5,16 @@
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form"/>
<field name="arch" type="xml">
- <xpath expr="//group[@name='main_group']" position="after">
- <group>
- <field name="sale_order_ids" widget="many2many" readonly="True">
- <tree>
- <field name="name"/>
- <field name="partner_id"/>
- <field name="confirmation_date"/>
- <field name="state" invisible="1"/>
- </tree>
- </field>
- </group>
+ <xpath expr="//div[hasclass('oe_button_box')]/button" position="before">
+ <button class="oe_stat_button" name="action_view_so"
+ type="object" icon="fa-pencil-square-o" attrs="{'invisible': [('sale_order_count', '=', 0)]}" help="Sale Orders">
+ <div class="o_field_widget o_stat_info">
+ <span class="o_stat_value">
+ <field name="sale_order_count" widget="statinfo" nolabel="1" class="mr4"/>
+ </span>
+ <span class="o_stat_text">Sale Orders</span>
+ </div>
+ </button>
</xpath>
</field>
</record>