From 19b2c67f797e8852f92c2a47f045b7ba39f6bc00 Mon Sep 17 00:00:00 2001 From: Tran Anh Tuan Date: Tue, 12 Mar 2024 09:31:28 +0700 Subject: [PATCH 1/3] [IMP] stock_release_channel_shipment_advice: Add buttons on release channel kanban to print shipments and delivery slip --- .../models/stock_release_channel.py | 41 +++++++++++++++++++ .../views/stock_release_channel.xml | 37 +++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/stock_release_channel_shipment_advice/models/stock_release_channel.py b/stock_release_channel_shipment_advice/models/stock_release_channel.py index bdfc19ea8a4..c1ad5c6e30d 100644 --- a/stock_release_channel_shipment_advice/models/stock_release_channel.py +++ b/stock_release_channel_shipment_advice/models/stock_release_channel.py @@ -29,6 +29,35 @@ class StockReleaseChannel(models.Model): comodel_name="stock.dock", domain='[("warehouse_id", "=", warehouse_id)]' ) warehouse_id = fields.Many2one(inverse="_inverse_warehouse_id") + shipment_advice_to_print_ids = fields.One2many( + "shipment.advice", compute="_compute_shipment_advice_to_print_ids" + ) + is_action_print_shipment_allowed = fields.Boolean( + compute="_compute_is_action_print_shipment_allowed" + ) + + @api.depends("shipment_advice_ids") + def _compute_shipment_advice_to_print_ids(self): + for rec in self: + rec.shipment_advice_to_print_ids = fields.first( + rec.shipment_advice_ids.filtered(lambda r: r.state == "done").sorted( + "id", reverse=True + ) + ) + + @api.model + def _get_print_shipment_allowed_states(self): + return ["locked"] + + def _compute_is_action_print_shipment_allowed(self): + allowed_states = self._get_print_shipment_allowed_states() + for rec in self: + rec.is_action_print_shipment_allowed = ( + rec.state in allowed_states + and rec.shipment_advice_to_print_ids + and True + or False + ) def button_show_shipment_advice(self): self.ensure_one() @@ -132,3 +161,15 @@ def _check_warehouse(self): def _onchange_check_warehouse(self): self.ensure_one() self._check_warehouse() + + def action_print_shipment(self): + if self.shipment_advice_to_print_ids: + return self.env.ref( + "shipment_advice.action_report_shipment_advice" + ).report_action(self.shipment_advice_to_print_ids) + return {} + + def action_print_deliveryslip(self): + if self.shipment_advice_to_print_ids: + return self.shipment_advice_to_print_ids.print_all_deliveryslip() + return {} diff --git a/stock_release_channel_shipment_advice/views/stock_release_channel.xml b/stock_release_channel_shipment_advice/views/stock_release_channel.xml index 3ca91574657..91449c8cd6f 100644 --- a/stock_release_channel_shipment_advice/views/stock_release_channel.xml +++ b/stock_release_channel_shipment_advice/views/stock_release_channel.xml @@ -18,6 +18,19 @@ groups="stock.group_stock_manager" attrs="{'invisible': [('can_plan_shipment', '=', False)]}" /> +