mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP][rma] add smart button for internal transfers
This commit is contained in:
@@ -25,6 +25,13 @@ class RmaOrder(models.Model):
|
||||
pickings |= line._get_in_pickings()
|
||||
rec.in_shipment_count = len(pickings)
|
||||
|
||||
def _compute_int_picking_count(self):
|
||||
for rec in self:
|
||||
pickings = self.env["stock.picking"]
|
||||
for line in rec.rma_line_ids:
|
||||
pickings |= line._get_int_pickings()
|
||||
rec.int_picking_count = len(pickings)
|
||||
|
||||
def _compute_out_shipment_count(self):
|
||||
for rec in self:
|
||||
pickings = self.env["stock.picking"]
|
||||
@@ -96,6 +103,9 @@ class RmaOrder(models.Model):
|
||||
in_shipment_count = fields.Integer(
|
||||
compute="_compute_in_shipment_count", string="# of Shipments"
|
||||
)
|
||||
int_picking_count = fields.Integer(
|
||||
compute="_compute_int_picking_count", string="# of Internal Transfers"
|
||||
)
|
||||
out_shipment_count = fields.Integer(
|
||||
compute="_compute_out_shipment_count", string="# of Outgoing Shipments"
|
||||
)
|
||||
@@ -185,6 +195,14 @@ class RmaOrder(models.Model):
|
||||
shipments |= line._get_in_pickings()
|
||||
return self._view_shipments(result, shipments)
|
||||
|
||||
def action_view_int_pickings(self):
|
||||
action = self.env.ref("stock.action_picking_tree_all")
|
||||
result = action.sudo().read()[0]
|
||||
shipments = self.env["stock.picking"]
|
||||
for line in self.rma_line_ids:
|
||||
shipments |= line._get_int_pickings()
|
||||
return self._view_shipments(result, shipments)
|
||||
|
||||
def action_view_out_shipments(self):
|
||||
action = self.env.ref("stock.action_picking_tree_all")
|
||||
result = action.sudo().read()[0]
|
||||
|
||||
@@ -58,6 +58,16 @@ class RmaOrderLine(models.Model):
|
||||
pickings |= move.picking_id
|
||||
return pickings
|
||||
|
||||
@api.model
|
||||
def _get_int_pickings(self):
|
||||
pickings = self.env["stock.picking"]
|
||||
for move in self.move_ids:
|
||||
first_usage = move._get_first_usage()
|
||||
last_usage = move._get_last_usage()
|
||||
if last_usage == "internal" and first_usage == "internal":
|
||||
pickings |= move.picking_id
|
||||
return pickings
|
||||
|
||||
@api.model
|
||||
def _get_out_pickings(self):
|
||||
pickings = self.env["stock.picking"]
|
||||
@@ -75,6 +85,11 @@ class RmaOrderLine(models.Model):
|
||||
pickings = line._get_in_pickings()
|
||||
line.in_shipment_count = len(pickings)
|
||||
|
||||
def _compute_int_picking_count(self):
|
||||
for line in self:
|
||||
pickings = line._get_int_pickings()
|
||||
line.int_picking_count = len(pickings)
|
||||
|
||||
def _compute_out_shipment_count(self):
|
||||
for line in self:
|
||||
pickings = line._get_out_pickings()
|
||||
@@ -301,6 +316,9 @@ class RmaOrderLine(models.Model):
|
||||
in_shipment_count = fields.Integer(
|
||||
compute="_compute_in_shipment_count", string="# of Shipments"
|
||||
)
|
||||
int_picking_count = fields.Integer(
|
||||
compute="_compute_int_picking_count", string="# of Internal Transfers"
|
||||
)
|
||||
out_shipment_count = fields.Integer(
|
||||
compute="_compute_out_shipment_count", string="# of Deliveries"
|
||||
)
|
||||
@@ -709,6 +727,21 @@ class RmaOrderLine(models.Model):
|
||||
result["res_id"] = shipments.ids[0]
|
||||
return result
|
||||
|
||||
def action_view_int_pickings(self):
|
||||
action = self.env.ref("stock.action_picking_tree_all")
|
||||
result = action.sudo().read()[0]
|
||||
shipments = self.env["stock.picking"]
|
||||
for line in self:
|
||||
shipments |= line._get_int_pickings()
|
||||
# choose the view_mode accordingly
|
||||
if len(shipments) != 1:
|
||||
result["domain"] = "[('id', 'in', " + str(shipments.ids) + ")]"
|
||||
elif len(shipments) == 1:
|
||||
res = self.env.ref("stock.view_picking_form", False)
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = shipments.ids[0]
|
||||
return result
|
||||
|
||||
def action_view_out_shipments(self):
|
||||
action = self.env.ref("stock.action_picking_tree_all")
|
||||
result = action.sudo().read()[0]
|
||||
|
||||
@@ -109,6 +109,20 @@
|
||||
string="Shipments"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_int_pickings"
|
||||
class="oe_stat_button"
|
||||
icon="fa-truck"
|
||||
groups="stock.group_stock_user"
|
||||
attrs="{'invisible': [('int_picking_count', '=', 0)]}"
|
||||
>
|
||||
<field
|
||||
name="int_picking_count"
|
||||
widget="statinfo"
|
||||
string="Internal Transfers"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_out_shipments"
|
||||
@@ -123,12 +137,6 @@
|
||||
string="Deliveries"
|
||||
/>
|
||||
</button>
|
||||
<!--Move this button to rma_account-->
|
||||
<!--<button type="object" name="action_view_invoice"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
string="Origin Inv">
|
||||
</button>-->
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_rma_lines"
|
||||
|
||||
@@ -210,6 +210,20 @@
|
||||
string="Shipments"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_int_pickings"
|
||||
class="oe_stat_button"
|
||||
icon="fa-truck"
|
||||
groups="stock.group_stock_user"
|
||||
attrs="{'invisible': [('int_picking_count', '=', 0)]}"
|
||||
>
|
||||
<field
|
||||
name="int_picking_count"
|
||||
widget="statinfo"
|
||||
string="Internal Transfers"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_out_shipments"
|
||||
|
||||
Reference in New Issue
Block a user