Replace typing of stock move origin by sale and purchase Function field

The origin may not always be a sale or purchase line like with product kit.
So such test must be extendable by other modules implicitly. This can be
achieved by using the Function fields.

Closes #15084
(grafted from 84761faccad43bc56a11a2e8bb8cf2977ba8e8db)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier
2026-09-10 14:22:34 +02:00
parent 3999c5e4c0
commit b0559bd5e2
3 changed files with 8 additions and 17 deletions
+2 -6
View File
@@ -52,11 +52,9 @@ class ShipmentIn(metaclass=PoolMeta):
@ModelView.button
@Workflow.transition('draft')
def draft(cls, shipments):
PurchaseLine = Pool().get('purchase.line')
for shipment in shipments:
for move in shipment.incoming_moves:
if (move.state == 'cancelled'
and isinstance(move.origin, PurchaseLine)):
if move.state == 'cancelled' and move.purchase:
raise AccessError(
gettext('purchase.msg_purchase_move_reset_draft',
move=move.rec_name))
@@ -91,11 +89,9 @@ class ShipmentInReturn(metaclass=PoolMeta):
@ModelView.button
@Workflow.transition('draft')
def draft(cls, shipments):
PurchaseLine = Pool().get('purchase.line')
for shipment in shipments:
for move in shipment.moves:
if (move.state == 'cancelled'
and isinstance(move.origin, PurchaseLine)):
if move.state == 'cancelled' and move.purchase:
raise AccessError(
gettext('purchase.msg_purchase_move_reset_draft',
move=move.rec_name))
+2 -6
View File
@@ -38,11 +38,9 @@ class ShipmentOut(metaclass=PoolMeta):
@ModelView.button
@Workflow.transition('draft')
def draft(cls, shipments):
SaleLine = Pool().get('sale.line')
for shipment in shipments:
for move in shipment.outgoing_moves:
if (move.state == 'cancelled'
and isinstance(move.origin, SaleLine)):
if move.state == 'cancelled' and move.sale:
raise AccessError(
gettext('sale.msg_sale_move_reset_draft',
move=move.rec_name))
@@ -71,11 +69,9 @@ class ShipmentOutReturn(metaclass=PoolMeta):
@ModelView.button
@Workflow.transition('draft')
def draft(cls, shipments):
SaleLine = Pool().get('sale.line')
for shipment in shipments:
for move in shipment.incoming_moves:
if (move.state == 'cancelled'
and isinstance(move.origin, SaleLine)):
if move.state == 'cancelled' and move.sale:
raise AccessError(
gettext('sale.msg_sale_move_reset_draft',
move=move.rec_name))
+4 -5
View File
@@ -17,12 +17,11 @@ class ShipmentOut(metaclass=PoolMeta):
def pack(cls, shipments):
pool = Pool()
Sale = pool.get('sale.sale')
SaleLine = pool.get('sale.line')
sales = {move.origin.sale
for shipment in shipments for move in shipment.moves
if isinstance(move.origin, SaleLine)}
for sale in Sale.browse([s.id for s in sales]):
sales = {
move.sale for shipment in shipments for move in shipment.moves
if move.sale}
for sale in Sale.browse(sales):
if sale.shipping_blocked:
raise ShippingBlocked(
gettext('sale_advance_payment.msg_shipping_blocked',