Skip to content

Commit

Permalink
[IMP] stock_release_channel_shipment_advice: Add buttons on release c…
Browse files Browse the repository at this point in the history
…hannel kanban to print shipments and delivery slip
  • Loading branch information
tuantrantg committed Apr 8, 2024
1 parent 7c5b73e commit 514cec5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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()
Expand Down Expand Up @@ -131,3 +160,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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@
</div>
</t>
</xpath>
<xpath expr="//div[@name='dropdown-menu-right-panel']" position="inside">
<field name="is_action_print_shipment_allowed" invisible="1" />
<div role="menuitem" class="o_kanban_card_manage_title">
<span>Print</span>
</div>
<t t-if="record.is_action_print_shipment_allowed.raw_value">
<div role="menuitem">
<a
name="action_print_shipment"
type="object"
icon="fa-archive"
><span class="ms-2">Print Shipment</span></a>
</div>
</t>
<t t-if="record.is_action_print_shipment_allowed.raw_value">
<div role="menuitem">
<a
name="action_print_deliveryslip"
type="object"
icon="fa-truck"
><span class="ms-2">Print Deliveries</span></a>
</div>
</t>
</xpath>
</field>
</record>

Expand Down

0 comments on commit 514cec5

Please sign in to comment.