Create contract
This commit is contained in:
@@ -112,20 +112,33 @@ class ContractFactory:
|
||||
# Helpers
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
@classmethod
|
||||
def _apply_locations(cls, contract, base, type_):
|
||||
from_location, to_location = cls._get_mirror_locations(base, type_)
|
||||
if from_location:
|
||||
contract.from_location = from_location
|
||||
if to_location:
|
||||
contract.to_location = to_location
|
||||
|
||||
@staticmethod
|
||||
def _apply_locations(contract, base, type_):
|
||||
if not (base.from_location and base.to_location):
|
||||
return
|
||||
def _get_mirror_locations(base, type_):
|
||||
from_location = getattr(base, 'from_location', None)
|
||||
to_location = getattr(base, 'to_location', None)
|
||||
if not (from_location or to_location):
|
||||
return None, None
|
||||
|
||||
if (from_location and to_location
|
||||
and getattr(from_location, 'type', None) == 'supplier'
|
||||
and getattr(to_location, 'type', None) == 'customer'):
|
||||
return from_location, to_location
|
||||
|
||||
if type_ == 'Purchase':
|
||||
contract.to_location = base.from_location
|
||||
else:
|
||||
contract.from_location = base.to_location
|
||||
|
||||
if (base.from_location.type == 'supplier'
|
||||
and base.to_location.type == 'customer'):
|
||||
contract.from_location = base.from_location
|
||||
contract.to_location = base.to_location
|
||||
if getattr(from_location, 'type', None) == 'storage':
|
||||
return None, from_location
|
||||
elif type_ == 'Sale':
|
||||
if getattr(to_location, 'type', None) == 'storage':
|
||||
return to_location, None
|
||||
return None, None
|
||||
|
||||
@staticmethod
|
||||
def _apply_party_data(contract, party, type_):
|
||||
|
||||
Reference in New Issue
Block a user