Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions stock_ux/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ def _compute_origin_description(self):

@api.constrains("quantity")
def _check_quantity(self):
# TODO: Odoo BTL - lock for AR
precision = self.env["decimal.precision"].precision_get("Product Unit of Measure")
if any(self.filtered(lambda x: x.scrapped)):
return
moves = self.filtered(
lambda x: x.picking_id.picking_type_id.block_additional_quantity
and float_compare(x.product_uom_qty, x.quantity, precision_digits=precision) == -1
)
if not moves:
return

# Si lo ejecuta el superusuario (scheduler), revertir el cambio y loguear
if self.env.is_superuser():
for move in moves:
# Revertir el cambio de quantity
move.quantity = move.product_uom_qty
move.picking_id.message_post(
body=_(
"Se intentó transferir una cantidad mayor a la demanda inicial en el movimiento %s durante la ejecución automática (scheduler). El sistema ignoró el cambio y mantuvo la cantidad original."
if self.env.company.country_code == 'AR':
precision = self.env["decimal.precision"].precision_get("Product Unit of Measure")
if any(self.filtered(lambda x: x.scrapped)):
return
moves = self.filtered(
lambda x: x.picking_id.picking_type_id.block_additional_quantity
and float_compare(x.product_uom_qty, x.quantity, precision_digits=precision) == -1
)
if not moves:
return

# Si lo ejecuta el superusuario (scheduler), revertir el cambio y loguear
if self.env.is_superuser():
for move in moves:
# Revertir el cambio de quantity
move.quantity = move.product_uom_qty
move.picking_id.message_post(
body=_(
"Se intentó transferir una cantidad mayor a la demanda inicial en el movimiento %s durante la ejecución automática (scheduler). El sistema ignoró el cambio y mantuvo la cantidad original."
)
% move.display_name
)
% move.display_name
)
return
return

# Comportamiento normal: raise si corresponde
raise ValidationError(_("You can not transfer more than the initial demand!"))
# Comportamiento normal: raise si corresponde
raise ValidationError(_("You can not transfer more than the initial demand!"))

def action_view_linked_record(self):
"""This function returns an action that display existing sales order
Expand All @@ -98,27 +98,27 @@ def action_view_linked_record(self):
def default_get(self, fields_list):
# We override the default_get to make stock moves created when the picking
# was confirmed , this way restrict to add more quantity that initial demand
# TODO: Odoo BTL - lock for AR
defaults = super().default_get(fields_list)
if self.env.context.get("default_picking_id"):
picking_id = self.env["stock.picking"].browse(self.env.context["default_picking_id"])
if picking_id.state == "confirmed":
defaults["state"] = "confirmed"
defaults["product_uom_qty"] = 0.0
defaults["additional"] = True
if self.env.company.country_code == 'AR':
if self.env.context.get("default_picking_id"):
picking_id = self.env["stock.picking"].browse(self.env.context["default_picking_id"])
if picking_id.state == "confirmed":
defaults["state"] = "confirmed"
defaults["product_uom_qty"] = 0.0
defaults["additional"] = True
return defaults

@api.constrains("state")
def check_cancel(self):
# TODO: Odoo BTL - lock for AR
if self._context.get("cancel_from_order") or self.env.is_superuser():
return
if self.filtered(
lambda x: x.picking_id
and x.state == "cancel"
and not self.env.user.has_group("stock_ux.allow_picking_cancellation")
):
raise ValidationError("Only User with 'Picking cancelation allow' rights can cancel pickings")
if self.env.company.country_code == 'AR':
if self._context.get("cancel_from_order") or self.env.is_superuser():
return
if self.filtered(
lambda x: x.picking_id
and x.state == "cancel"
and not self.env.user.has_group("stock_ux.allow_picking_cancellation")
):
raise ValidationError("Only User with 'Picking cancelation allow' rights can cancel pickings")

def _merge_moves(self, merge_into=False):
# 22/04/2024: Agregamos esto porque sino al intentar confirmar compras con usuarios sin permisos, podia pasar que salga la constrain de arriba (check_cancel)
Expand Down Expand Up @@ -146,17 +146,17 @@ def create(self, vals_list):

@api.depends("state", "picking_id")
def _compute_is_initial_demand_editable(self):
# TODO: Odoo BTL - lock for AR
super(StockMove, self)._compute_is_initial_demand_editable()
for move in self:
if move.picking_id.picking_type_id.block_additional_quantity and move.picking_id.state != "draft":
move.is_initial_demand_editable = False
if self.env.company.country_code == 'AR':
for move in self:
if move.picking_id.picking_type_id.block_additional_quantity and move.picking_id.state != "draft":
move.is_initial_demand_editable = False

def _trigger_assign(self):
"""To avoid to check_quantity_available when an assing in move is trigger we
send a context that checks if the assign comes from this method
"""
# TODO: Odoo BTL - lock for AR
if not self.env.context.get("trigger_assign"):
return super().with_context(trigger_assign=True)._trigger_assign()
if self.env.company.country_code == 'AR':
if not self.env.context.get("trigger_assign"):
return super().with_context(trigger_assign=True)._trigger_assign()
return super()._trigger_assign()
94 changes: 47 additions & 47 deletions stock_ux/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,53 @@ class StockMoveLine(models.Model):

@api.depends_context("location")
def _compute_product_uom_qty_location(self):
# TODO: Odoo BTL - lock for AR
location = self._context.get("location")
if not location:
self.update({"product_uom_qty_location": 0.0})
return False
# because now we use location_id to select location, we have compelte
# location name. If y need we can use some code of
# _get_domain_locations on stock/product.py
location_name = location[0]
if isinstance(location[0], int):
location_name = self.env["stock.location"].browse(location[0]).name
locations = self.env["stock.location"].search([("complete_name", "ilike", location_name)])
for rec in self:
product_uom_qty_location = rec.quantity
if rec.location_id in locations:
# if location is source and destiny, then 0
product_uom_qty_location = 0.0 if rec.location_dest_id in locations else -rec.quantity
rec.product_uom_qty_location = product_uom_qty_location
rec.product_uom_qty_location = 0.0
if self.env.company.country_code == 'AR':
location = self._context.get("location")
if not location:
self.update({"product_uom_qty_location": 0.0})
return False
# because now we use location_id to select location, we have compelte
# location name. If y need we can use some code of
# _get_domain_locations on stock/product.py
location_name = location[0]
if isinstance(location[0], int):
location_name = self.env["stock.location"].browse(location[0]).name
locations = self.env["stock.location"].search([("complete_name", "ilike", location_name)])
for rec in self:
product_uom_qty_location = rec.quantity
if rec.location_id in locations:
# if location is source and destiny, then 0
product_uom_qty_location = 0.0 if rec.location_dest_id in locations else -rec.quantity
rec.product_uom_qty_location = product_uom_qty_location

@api.constrains("quantity")
def _check_manual_lines(self):
# TODO: Odoo BTL - lock for AR
if self._context.get("put_in_pack", False):
return
invalid_lines = self.filtered(
lambda x: not x.location_id.should_bypass_reservation()
and x.picking_id.picking_type_id.block_manual_lines
and x._check_quantity_available() < 0
)
if not invalid_lines:
return

# Si lo ejecuta el superusuario (odoobot), revertir el cambio y loguear
if self.env.is_superuser():
for line in invalid_lines:
# Revertir el cambio de quantity
line.quantity = max(0, line._check_quantity_available() + line.quantity)
if line.picking_id:
line.picking_id.message_post(
body=_(
"Se intentó transferir una cantidad mayor al stock disponible en la línea %s durante la ejecución automática (odoobot/scheduler). El sistema ignoró el cambio y mantuvo la cantidad original."
if self.env.company.country_code == 'AR':
if self._context.get("put_in_pack", False):
return
invalid_lines = self.filtered(
lambda x: not x.location_id.should_bypass_reservation()
and x.picking_id.picking_type_id.block_manual_lines
and x._check_quantity_available() < 0
)
if not invalid_lines:
return
# Si lo ejecuta el superusuario (odoobot), revertir el cambio y loguear
if self.env.is_superuser():
for line in invalid_lines:
# Revertir el cambio de quantity
line.quantity = max(0, line._check_quantity_available() + line.quantity)
if line.picking_id:
line.picking_id.message_post(
body=_(
"Se intentó transferir una cantidad mayor al stock disponible en la línea %s durante la ejecución automática (odoobot/scheduler). El sistema ignoró el cambio y mantuvo la cantidad original."
)
% line.display_name
)
% line.display_name
)
return

raise ValidationError(_("You can't transfer more quantity than the quantity on stock!"))
return
raise ValidationError(_("You can't transfer more quantity than the quantity on stock!"))

def _check_quantity_available(self):
self.ensure_one()
Expand Down Expand Up @@ -111,11 +111,11 @@ def create(self, vals_list):
"""This is to solve a bug when create the sml (the value is not completed after creation)
and should be reported to odoo to solve."""
recs = super().create(vals_list)
# TODO: Odoo BTL - lock for AR
for rec in recs:
if rec.picking_id and not rec.description_picking:
product = rec.product_id.with_context(lang=rec.picking_id.partner_id.lang or rec.env.user.lang)
rec.description_picking = product._get_description(rec.picking_id.picking_type_id)
if self.env.company.country_code == 'AR':
for rec in recs:
if rec.picking_id and not rec.description_picking:
product = rec.product_id.with_context(lang=rec.picking_id.partner_id.lang or rec.env.user.lang)
rec.description_picking = product._get_description(rec.picking_id.picking_type_id)
return recs

def _get_aggregated_product_quantities(self, **kwargs):
Expand Down
Loading
Loading