Skip to content

Commit

Permalink
[IMP] stock_move_location
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Apr 4, 2024
1 parent 2d2ec7f commit 699ca1b
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions stock_move_location/wizard/stock_move_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ class StockMoveLocationWizard(models.TransientModel):
_name = "wiz.stock.move.location"
_description = "Wizard move location"

def _get_default_picking_type_id(self):
company_id = self.env.context.get("company_id") or self.env.user.company_id.id
return (
self.env["stock.picking.type"]
.search(
[
("code", "=", "internal"),
("warehouse_id.company_id", "=", company_id),
],
limit=1,
)
.id
)

origin_location_disable = fields.Boolean(
compute="_compute_readonly_locations",
help="technical field to disable the edition of origin location.",
Expand All @@ -53,7 +39,9 @@ def _get_default_picking_type_id(self):
string="Move Location lines",
)
picking_type_id = fields.Many2one(
comodel_name="stock.picking.type", default=_get_default_picking_type_id
compute="_compute_picking_type_id",
comodel_name="stock.picking.type",
readonly=False,
)
picking_id = fields.Many2one(
string="Connected Picking", comodel_name="stock.picking"
Expand All @@ -74,6 +62,34 @@ def _compute_readonly_locations(self):
rec.origin_location_disable = True
rec.destination_location_disable = True

@api.depends("origin_location_id")
def _compute_picking_type_id(self):
company_id = self.env.context.get("company_id") or self.env.user.company_id.id
domain = [
("code", "=", "internal"),
("warehouse_id.company_id", "=", company_id),
]
for rec in self:
rec.picking_type_id = (
self.env["stock.picking.type"]
.search(
domain,
limit=1,
)
.id
)
if rec.origin_location_id:
domain += [("default_location_src_id", "=", rec.origin_location_id.id)]
picking_type_id = (
self.env["stock.picking.type"]
.search(
domain,
limit=1,
)
.id
)
rec.picking_type_id = picking_type_id

@api.model
def default_get(self, fields):
res = super().default_get(fields)
Expand Down Expand Up @@ -137,6 +153,20 @@ def _prepare_wizard_move_lines(self, quants):

@api.onchange("origin_location_id")
def _onchange_origin_location_id(self):
if self.origin_location_id:
picking_type_id = (
self.env["stock.picking.type"]
.search(
[
("code", "=", "internal"),
("default_location_src_id", "=", self.origin_location_id.id),
("warehouse_id.company_id", "=", self.env.user.company_id.id),
],
limit=1,
)
.id
)
self.picking_type_id = picking_type_id
if not self.env.context.get("origin_location_disable", False):
self._clear_lines()

Expand Down

0 comments on commit 699ca1b

Please sign in to comment.