Refresh custom duplicate payment terms on party change
This commit is contained in:
@@ -115,6 +115,21 @@ class TradeCustomDuplicateStart(ModelView):
|
||||
'invisible': ~Bool(Eval('create_matched_mirror')),
|
||||
})
|
||||
|
||||
@fields.depends('party', 'source_model')
|
||||
def on_change_party(self):
|
||||
payment_term = TradeCustomDuplicate._party_payment_term(
|
||||
self.party, self.source_model)
|
||||
if payment_term:
|
||||
self.payment_term = payment_term
|
||||
|
||||
@fields.depends('mirror_party', 'source_model')
|
||||
def on_change_mirror_party(self):
|
||||
payment_term = TradeCustomDuplicate._party_payment_term(
|
||||
self.mirror_party,
|
||||
TradeCustomDuplicate._opposite_model(self.source_model))
|
||||
if payment_term:
|
||||
self.mirror_payment_term = payment_term
|
||||
|
||||
@fields.depends('source', 'mirror_mode')
|
||||
def on_change_mirror_mode(self):
|
||||
record = TradeCustomDuplicate._reference_record(self.source)
|
||||
@@ -164,6 +179,24 @@ class TradeCustomDuplicate(Wizard):
|
||||
def _opposite_type(source_model):
|
||||
return 'Sale' if source_model == 'purchase.purchase' else 'Purchase'
|
||||
|
||||
@staticmethod
|
||||
def _opposite_model(source_model):
|
||||
if source_model == 'purchase.purchase':
|
||||
return 'sale.sale'
|
||||
if source_model == 'sale.sale':
|
||||
return 'purchase.purchase'
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _party_payment_term(party, model_name):
|
||||
if not party:
|
||||
return None
|
||||
if model_name == 'purchase.purchase':
|
||||
return getattr(party, 'supplier_payment_term', None)
|
||||
if model_name == 'sale.sale':
|
||||
return getattr(party, 'customer_payment_term', None)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _record_from_lot_report(record):
|
||||
if getattr(record, '__name__', None) != 'lot.report':
|
||||
|
||||
@@ -8927,6 +8927,30 @@ description</t></is></c>
|
||||
self.assertIs(reloaded.shipment_address, shipment_address)
|
||||
reloaded.save.assert_called_once()
|
||||
|
||||
def test_custom_duplicate_party_change_uses_default_payment_term(self):
|
||||
'custom duplicate party change refreshes payment term'
|
||||
payment_term = SimpleNamespace(id=5)
|
||||
start = duplicate_module.TradeCustomDuplicateStart()
|
||||
start.source_model = 'sale.sale'
|
||||
start.party = SimpleNamespace(customer_payment_term=payment_term)
|
||||
start.payment_term = None
|
||||
|
||||
start.on_change_party()
|
||||
|
||||
self.assertIs(start.payment_term, payment_term)
|
||||
|
||||
def test_custom_duplicate_mirror_party_change_uses_default_payment_term(self):
|
||||
'custom duplicate mirror party change refreshes mirror payment term'
|
||||
payment_term = SimpleNamespace(id=7)
|
||||
start = duplicate_module.TradeCustomDuplicateStart()
|
||||
start.source_model = 'purchase.purchase'
|
||||
start.mirror_party = SimpleNamespace(customer_payment_term=payment_term)
|
||||
start.mirror_payment_term = None
|
||||
|
||||
start.on_change_mirror_party()
|
||||
|
||||
self.assertIs(start.mirror_payment_term, payment_term)
|
||||
|
||||
def test_custom_duplicate_creates_purchase_open_virtual_lot(self):
|
||||
'custom duplicate creates the purchase opening lot.qt explicitly'
|
||||
saved_lots = []
|
||||
|
||||
Reference in New Issue
Block a user