unit_price_required in stock.move is False when shipment is external

#157448
This commit is contained in:
Raimon Esteve 2023-03-21 12:33:53 +01:00 committed by GitHub
parent afe6507cdb
commit 184274dc16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -125,6 +125,9 @@ class ShipmentExternal(Workflow, ModelSQL, ModelView):
('to_location', '=', Eval('to_location')),
('company', '=', Eval('company')),
],
context={
'stock_external': True,
},
depends=['state', 'from_location', 'to_location', 'planned_date',
'company'])
state = fields.Selection([
@ -402,3 +405,16 @@ class Move(metaclass=PoolMeta):
continue
moves_to_check.append(move)
super(Move, cls).check_origin(moves_to_check, types)
@fields.depends('from_location', 'to_location')
def on_change_with_unit_price_required(self, name=None):
External = Pool().get('stock.shipment.external')
unit_price_required = super(Move, self).on_change_with_unit_price_required(name)
if Transaction().context.get('stock_external', False) or (
hasattr(self, 'shipment') and self.shipment
and isinstance(self.shipment, External)):
return False
return unit_price_required

View file

@ -19,6 +19,10 @@ class StockExternalTestCase(CompanyTestMixin, ModuleTestCase):
Location = pool.get('stock.location')
Shipment = pool.get('stock.shipment.external')
Party = pool.get('party.party')
Move = pool.get('stock.move')
# moves has stock_external context
self.assertEqual(Shipment.moves.context.get('stock_external'), True)
# Create Company
party = Party(name='Party')
@ -31,12 +35,18 @@ class StockExternalTestCase(CompanyTestMixin, ModuleTestCase):
party, = Party.create([{
'name': 'Customer',
}])
Shipment.create([{
shipment, = Shipment.create([{
'company': company.id,
'party': party.id,
'from_location': supplier.id,
'to_location': storage.id,
}])
# unit_price_required is false when shipment is external
move = Move()
move.shipment = shipment
self.assertEqual(move.unit_price_required, False)
for from_, to in [
(supplier, supplier),
(supplier, customer),