Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] stock_request: Improve _check_qty constrain (moved to stock.request) #40

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions stock_request/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@
("name_uniq", "unique(name, company_id)", "Stock Request name must be unique")
]

@api.constrains("state", "product_qty")
def _check_qty(self):
for rec in self:
if rec.state == "draft" and rec.product_qty <= 0:
raise ValidationError(

Check warning on line 132 in stock_request/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request/models/stock_request.py#L132

Added line #L132 was not covered by tests
_("Stock Request product quantity has to be strictly positive.")
)
elif rec.state != "draft" and rec.product_qty < 0:
raise ValidationError(

Check warning on line 136 in stock_request/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request/models/stock_request.py#L136

Added line #L136 was not covered by tests
_("Stock Request product quantity cannot be negative.")
)

def _get_all_origin_moves(self, move):
all_moves = move
if move.move_orig_ids:
Expand Down
8 changes: 0 additions & 8 deletions stock_request/models/stock_request_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ def _check_product_uom(self):
)
)

@api.constrains("product_qty")
def _check_qty(self):
for rec in self:
if rec.product_qty <= 0:
raise ValidationError(
_("Stock Request product quantity has to be strictly positive.")
)

@api.onchange("warehouse_id")
def onchange_warehouse_id(self):
"""Finds location id for changed warehouse."""
Expand Down
9 changes: 5 additions & 4 deletions stock_request_purchase/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def _check_purchase_company_constrains(self):
def action_cancel(self):
"""Propagate the cancellation to the generated purchase orders."""
res = super().action_cancel()
self.sudo().purchase_ids.filtered(
lambda x: x.state not in ("purchase", "done", "cancel")
and x.stock_request_ids == self
).button_cancel()
if not self.env.context.get("skip_cancel_po_from_stock_request"):
self.sudo().purchase_ids.filtered(
lambda x: x.state not in ("purchase", "done", "cancel")
and x.stock_request_ids == self
).button_cancel()
return res

def action_view_purchase(self):
Expand Down
Loading