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 : 8.0
This commit is contained in:
Cédric Krier
2026-09-10 14:22:34 +02:00
parent b22a72940e
commit 0ae365085b
4 changed files with 12 additions and 25 deletions
+4 -8
View File
@@ -46,13 +46,11 @@ class ShipmentIn_Purchase(metaclass=PoolMeta):
def receive(cls, shipments):
pool = Pool()
Warning = pool.get('res.user.warning')
PurchaseLine = pool.get('purchase.line')
for shipment in shipments:
if shipment.incoterm:
incoterms = {
move.origin.purchase.incoterm for move in shipment.moves
if isinstance(move.origin, PurchaseLine)
and move.state != 'cancelled'}
move.purchase.incoterm for move in shipment.moves
if move.state != 'cancelled' and move.purchase}
if {shipment.incoterm} != incoterms:
incoterms.discard(shipment.incoterm)
origin_incoterms = ', '.join(
@@ -99,13 +97,11 @@ class ShipmentOut_Sale(metaclass=PoolMeta):
def wait(cls, shipments, moves=None):
pool = Pool()
Warning = pool.get('res.user.warning')
SaleLine = pool.get('sale.line')
for shipment in shipments:
if shipment.incoterm:
incoterms = {
move.origin.sale.incoterm for move in shipment.moves
if isinstance(move.origin, SaleLine)
and move.state != 'cancelled'}
move.sale.incoterm for move in shipment.moves
if move.state != 'cancelled' and move.sale}
if {shipment.incoterm} != incoterms:
incoterms.discard(shipment.incoterm)
origin_incoterms = ', '.join(
+2 -6
View File
@@ -54,11 +54,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))
@@ -93,11 +91,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
@@ -39,11 +39,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))
@@ -79,11 +77,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',