From 5d335460fc8cda433390ca993f38fcf15acae53e Mon Sep 17 00:00:00 2001 From: Tran Anh Tuan Date: Mon, 11 Mar 2024 14:26:52 +0700 Subject: [PATCH 1/5] [IMP] shipment_advice: Add action on shipment advice to print delivery slip --- shipment_advice/__manifest__.py | 1 + shipment_advice/models/shipment_advice.py | 9 ++++++++ shipment_advice/tests/test_shipment_advice.py | 11 +++++++++ shipment_advice/views/shipment_advice.xml | 23 +++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/shipment_advice/__manifest__.py b/shipment_advice/__manifest__.py index 7d94b631..ec561187 100644 --- a/shipment_advice/__manifest__.py +++ b/shipment_advice/__manifest__.py @@ -21,6 +21,7 @@ "data/ir_sequence.xml", "data/queue_job_channel.xml", "data/queue_job_function.xml", + "report/reports.xml", "views/res_config_settings.xml", "views/shipment_advice.xml", "views/stock_picking.xml", diff --git a/shipment_advice/models/shipment_advice.py b/shipment_advice/models/shipment_advice.py index 0dd792a5..5264d753 100644 --- a/shipment_advice/models/shipment_advice.py +++ b/shipment_advice/models/shipment_advice.py @@ -528,3 +528,12 @@ def button_open_receptions_in_progress(self): action["views"][tree_view_index] = (view_tree.id, "tree") action["domain"] = [("id", "in", self.planned_picking_ids.ids)] return action + + def print_all_deliveryslip(self): + picking_type = self.env.ref("stock.picking_type_out") + pickings = self.mapped("loaded_picking_ids").filtered( + lambda p: p.picking_type_id == picking_type and p.state != "cancel" + ) + if pickings: + return self.env.ref("stock.action_report_delivery").report_action(pickings) + return {} diff --git a/shipment_advice/tests/test_shipment_advice.py b/shipment_advice/tests/test_shipment_advice.py index 01791f45..f7eb16d2 100644 --- a/shipment_advice/tests/test_shipment_advice.py +++ b/shipment_advice/tests/test_shipment_advice.py @@ -93,6 +93,17 @@ def test_shipment_advice_done_full(self): ) ) self.assertEqual(picking.state, "done") + # Print deliveryslip + action = self.shipment_advice_out.with_context( + discard_logo_check=True + ).print_all_deliveryslip() + self.assertEqual(action.get("type"), "ir.actions.report") + self.assertEqual(action.get("report_name"), "stock.report_deliveryslip") + self.assertEqual(action.get("report_type"), "qweb-pdf") + self.assertEqual( + action.get("context").get("active_ids"), + picking.ids, + ) def test_shipment_advice_done_backorder_policy_disabled(self): """Validating a shipment with no backorder policy should let partial diff --git a/shipment_advice/views/shipment_advice.xml b/shipment_advice/views/shipment_advice.xml index 0f1a0683..6a4d10ea 100644 --- a/shipment_advice/views/shipment_advice.xml +++ b/shipment_advice/views/shipment_advice.xml @@ -60,6 +60,20 @@ class="btn-secondary" states="cancel" /> +