mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_orderpoint_purchase_link: Add smart-button on orderpoints
We provide a link from the orderpoint to the involved purchase orders. TT39644
This commit is contained in:
@@ -10,7 +10,10 @@
|
|||||||
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||||
"category": "Warehouse Management",
|
"category": "Warehouse Management",
|
||||||
"depends": ["stock_orderpoint_move_link", "purchase_stock"],
|
"depends": ["stock_orderpoint_move_link", "purchase_stock"],
|
||||||
"data": ["views/purchase_order_views.xml"],
|
"data": [
|
||||||
|
"views/purchase_order_views.xml",
|
||||||
|
"views/stock_warehouse_orderpoint_views.xml",
|
||||||
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"auto_install": True,
|
"auto_install": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com)
|
# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||||
|
# Copyright 2022 Tecnativa - Pedro M. Baeza
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import _, api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class StockWarehouseOrderpoint(models.Model):
|
class StockWarehouseOrderpoint(models.Model):
|
||||||
@@ -13,3 +14,17 @@ class StockWarehouseOrderpoint(models.Model):
|
|||||||
copy=False,
|
copy=False,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
|
purchase_count = fields.Integer(compute="_compute_purchase_count")
|
||||||
|
|
||||||
|
@api.depends("purchase_line_ids")
|
||||||
|
def _compute_purchase_count(self):
|
||||||
|
for record in self:
|
||||||
|
record.purchase_count = len(record.purchase_line_ids.order_id)
|
||||||
|
|
||||||
|
def button_view_purchases(self):
|
||||||
|
self.ensure_one()
|
||||||
|
orders = self.purchase_line_ids.order_id
|
||||||
|
action = self.env["ir.actions.act_window"]._for_xml_id("purchase.purchase_rfq")
|
||||||
|
action["display_name"] = _("Generated purchases")
|
||||||
|
action["domain"] = [("id", "in", orders.ids)]
|
||||||
|
return action
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ class TestOrderpointPurchaseLink(common.TransactionCase):
|
|||||||
"product_max_qty": 20.0,
|
"product_max_qty": 20.0,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
self.group_obj.run_scheduler()
|
||||||
|
|
||||||
def test_01_po_line_from_orderpoints(self):
|
def test_01_po_line_from_orderpoints(self):
|
||||||
"""Test that a PO line created/updated by two orderpoints keeps
|
"""Test that a PO line created/updated by two orderpoints keeps
|
||||||
the link with both of them."""
|
the link with both of them."""
|
||||||
self.group_obj.run_scheduler()
|
|
||||||
po_line = self.env["purchase.order.line"].search(
|
po_line = self.env["purchase.order.line"].search(
|
||||||
[("product_id", "=", self.tp1.id)]
|
[("product_id", "=", self.tp1.id)]
|
||||||
)
|
)
|
||||||
@@ -81,3 +81,12 @@ class TestOrderpointPurchaseLink(common.TransactionCase):
|
|||||||
# Each orderpoint must have required 20.0 units:
|
# Each orderpoint must have required 20.0 units:
|
||||||
self.assertEqual(po_line.product_qty, 40.0)
|
self.assertEqual(po_line.product_qty, 40.0)
|
||||||
self.assertEqual(len(po_line.orderpoint_ids), 2)
|
self.assertEqual(len(po_line.orderpoint_ids), 2)
|
||||||
|
|
||||||
|
def test_02_button_view_purchases(self):
|
||||||
|
po_line = self.env["purchase.order.line"].search(
|
||||||
|
[("product_id", "=", self.tp1.id)]
|
||||||
|
)
|
||||||
|
self.assertEqual(self.op1.purchase_count, 1)
|
||||||
|
self.assertEqual(self.op2.purchase_count, 1)
|
||||||
|
action = self.op1.button_view_purchases()
|
||||||
|
self.assertEqual(action["domain"], [("id", "in", [po_line.order_id.id])])
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<!-- Copyright 2022 Tecnativa - Pedro M. Baeza
|
||||||
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||||
|
<odoo>
|
||||||
|
<record id="view_warehouse_orderpoint_move_form" model="ir.ui.view">
|
||||||
|
<field name="name">stock.warehouse.orderpoint.form - PO smart-button</field>
|
||||||
|
<field name="model">stock.warehouse.orderpoint</field>
|
||||||
|
<field
|
||||||
|
name="inherit_id"
|
||||||
|
ref="stock_orderpoint_move_link.view_warehouse_orderpoint_move_form"
|
||||||
|
/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[@name='button_box']" position="inside">
|
||||||
|
<button
|
||||||
|
type="object"
|
||||||
|
name="button_view_purchases"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-shopping-cart"
|
||||||
|
attrs="{'invisible': [('purchase_count', '=', 0)]}"
|
||||||
|
>
|
||||||
|
<field string="Purchases" name="purchase_count" widget="statinfo" />
|
||||||
|
</button>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user