Skip to content

Commit

Permalink
[UPD] ssi_stock
Browse files Browse the repository at this point in the history
* Penambahan mekanisme untuk filter source dan destination loc pd picking berdasarkan location type
  • Loading branch information
andhit-r committed Jul 3, 2024
1 parent 879c33a commit 4b3dcc4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
58 changes: 56 additions & 2 deletions ssi_stock/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class StockPicking(models.Model):
allowed_source_location_ids = fields.Many2many(
string="Allowed Source Locations",
comodel_name="stock.location",
related="picking_type_id.allowed_source_location_ids",
compute="_compute_allowed_source_location_ids",
related=False,
store=False,
)
allowed_destination_location_ids = fields.Many2many(
string="Allowed Destination Locations",
comodel_name="stock.location",
related="picking_type_id.allowed_destination_location_ids",
compute="_compute_allowed_destination_location_ids",
related=False,
store=False,
)
allowed_product_category_ids = fields.Many2many(
Expand Down Expand Up @@ -94,6 +96,58 @@ def _compute_policy(self):
_super = super(StockPicking, self)
_super._compute_policy()

@api.depends(
"picking_type_id",
)
def _compute_allowed_source_location_ids(self):
Location = self.env["stock.location"]
for record in self:
result = []
if record.picking_type_id:
ptype = record.picking_type_id
result += ptype.allowed_source_location_ids.ids

for loc_type in ptype.allowed_source_location_type_ids:
criteria = False
if loc_type.is_warehouse_location and ptype.warehouse_id:
criteria = [
("type_id", "=", loc_type.id),
("warehouse_id", "=", ptype.warehouse_id.id),
]
elif not loc_type.is_warehouse_location:
criteria = [
("type_id", "=", loc_type.id),
]
if criteria:
result += Location.search(criteria).ids
record.allowed_source_location_ids = result

@api.depends(
"picking_type_id",
)
def _compute_allowed_destination_location_ids(self):
Location = self.env["stock.location"]
for record in self:
result = []
if record.picking_type_id:
ptype = record.picking_type_id
result += ptype.allowed_destination_location_ids.ids

for loc_type in ptype.allowed_destination_location_type_ids:
criteria = False
if loc_type.is_warehouse_location and ptype.warehouse_id:
criteria = [
("type_id", "=", loc_type.id),
("warehouse_id", "=", ptype.warehouse_id.id),
]
elif not loc_type.is_warehouse_location:
criteria = [
("type_id", "=", loc_type.id),
]
if criteria:
result += Location.search(criteria).ids
record.allowed_destination_location_ids = result

@api.model
def _get_policy_field(self):
res = super(StockPicking, self)._get_policy_field()
Expand Down
14 changes: 14 additions & 0 deletions ssi_stock/models/stock_picking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ class StockPickingType(models.Model):
column1="picking_type_id",
column2="location_id",
)
allowed_source_location_type_ids = fields.Many2many(
string="Allowed Source Location Types",
comodel_name="location_type",
relation="rel_picking_type_2_source_location_type",
column1="picking_type_id",
column2="location_type_id",
)
allowed_destination_location_type_ids = fields.Many2many(
string="Allowed Destination Location Types",
comodel_name="location_type",
relation="rel_picking_type_2_destination_location_type",
column1="picking_type_id",
column2="location_type_id",
)
allowed_product_category_ids = fields.Many2many(
string="Allowed Product Categories",
comodel_name="product.category",
Expand Down
8 changes: 8 additions & 0 deletions ssi_stock/views/stock_picking_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,20 @@
</xpath>
<xpath expr="//field[@name='default_location_src_id']" position="after">
<field name="allowed_source_location_ids" widget="many2many_tags" />
<field
name="allowed_source_location_type_ids"
widget="many2many_tags"
/>
</xpath>
<xpath expr="//field[@name='default_location_dest_id']" position="after">
<field
name="allowed_destination_location_ids"
widget="many2many_tags"
/>
<field
name="allowed_destination_location_type_ids"
widget="many2many_tags"
/>
</xpath>
<xpath expr="//sheet/group[2]" position="after">
<group name="product" string="Product">
Expand Down

0 comments on commit 4b3dcc4

Please sign in to comment.