Use usage from context for default contact mechanism on party
This commit is contained in:
@@ -74,12 +74,16 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
||||
_states['readonly']
|
||||
| Eval('party', True)
|
||||
| Eval('lines', [0])),
|
||||
},
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
})
|
||||
company_party = fields.Function(
|
||||
fields.Many2One(
|
||||
'party.party', "Company Party",
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
},
|
||||
depends={'company'}),
|
||||
'on_change_with_company_party')
|
||||
@@ -143,6 +147,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
||||
'party.party', 'Party', required=True, states=_states,
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
},
|
||||
depends={'company'})
|
||||
party_tax_identifier = fields.Many2One(
|
||||
@@ -2134,6 +2139,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
'party.party', "Party",
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
},
|
||||
depends=['company']),
|
||||
'on_change_with_invoice_party', searcher='search_invoice_party')
|
||||
@@ -2158,6 +2164,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
},
|
||||
depends={'company'})
|
||||
party_lang = fields.Function(fields.Char('Party Language'),
|
||||
@@ -2167,7 +2174,10 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
states=_states)
|
||||
company = fields.Many2One(
|
||||
'company.company', "Company", required=True,
|
||||
states=_states)
|
||||
states=_states,
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
})
|
||||
type = fields.Selection([
|
||||
('line', 'Line'),
|
||||
('subtotal', 'Subtotal'),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Use usage from context for default contact mechanism on party
|
||||
|
||||
Version 7.0.0 - 2023-10-30
|
||||
--------------------------
|
||||
|
||||
+18
-6
@@ -178,15 +178,15 @@ class Party(
|
||||
return self.name
|
||||
|
||||
def get_contact_mechanism(self, name):
|
||||
for mechanism in self.contact_mechanisms:
|
||||
if mechanism.type == name:
|
||||
return mechanism.value
|
||||
return ''
|
||||
usage = Transaction().context.get('party_contact_mechanism_usage')
|
||||
mechanism = self.contact_mechanism_get(name, usage)
|
||||
return mechanism.value if mechanism else ''
|
||||
|
||||
@classmethod
|
||||
def set_contact_mechanism(cls, parties, name, value):
|
||||
pool = Pool()
|
||||
ContactMechanism = pool.get('party.contact_mechanism')
|
||||
usage = Transaction().context.get('party_contact_mechanism_usage')
|
||||
contact_mechanisms = []
|
||||
for party in parties:
|
||||
if getattr(party, name):
|
||||
@@ -196,10 +196,22 @@ class Party(
|
||||
party=party.rec_name,
|
||||
field=type_string))
|
||||
if value:
|
||||
contact_mechanisms.append(ContactMechanism(
|
||||
contact_mechanism = None
|
||||
if usage:
|
||||
for contact_mechanism in party.contact_mechanisms:
|
||||
if (contact_mechanism.type == name
|
||||
and contact_mechanism.value == value):
|
||||
break
|
||||
else:
|
||||
contact_mechanism = None
|
||||
if not contact_mechanism:
|
||||
contact_mechanism = ContactMechanism(
|
||||
party=party,
|
||||
type=name,
|
||||
value=value))
|
||||
value=value)
|
||||
if usage:
|
||||
setattr(contact_mechanism, usage, True)
|
||||
contact_mechanisms.append(contact_mechanism)
|
||||
ContactMechanism.save(contact_mechanisms)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -123,6 +123,7 @@ class Purchase(
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
},
|
||||
search_context={
|
||||
'related_party': Eval('party'),
|
||||
|
||||
@@ -124,6 +124,7 @@ class Sale(
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'invoice',
|
||||
},
|
||||
search_context={
|
||||
'related_party': Eval('party'),
|
||||
@@ -145,6 +146,7 @@ class Sale(
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
search_context={
|
||||
'related_party': Eval('party'),
|
||||
|
||||
@@ -290,6 +290,9 @@ class ShipmentIn(
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
},
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
help="The company the shipment is associated with.")
|
||||
supplier = fields.Many2One('party.party', 'Supplier',
|
||||
states={
|
||||
@@ -299,6 +302,7 @@ class ShipmentIn(
|
||||
}, required=True,
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
depends={'company'},
|
||||
help="The party that supplied the stock.")
|
||||
@@ -755,6 +759,9 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
},
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
help="The company the shipment is associated with.")
|
||||
supplier = fields.Many2One('party.party', 'Supplier',
|
||||
states={
|
||||
@@ -764,6 +771,7 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
|
||||
}, required=True,
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
depends={'company'},
|
||||
help="The party that supplied the stock.")
|
||||
@@ -1123,6 +1131,9 @@ class ShipmentOut(
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
},
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
help="The company the shipment is associated with.")
|
||||
customer = fields.Many2One('party.party', 'Customer', required=True,
|
||||
states={
|
||||
@@ -1131,6 +1142,7 @@ class ShipmentOut(
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
depends={'company'},
|
||||
help="The party that purchased the stock.")
|
||||
@@ -1829,6 +1841,9 @@ class ShipmentOutReturn(
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
},
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
help="The company the shipment is associated with.")
|
||||
customer = fields.Many2One('party.party', 'Customer', required=True,
|
||||
states={
|
||||
@@ -1837,6 +1852,7 @@ class ShipmentOutReturn(
|
||||
},
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
depends={'company'},
|
||||
help="The party that purchased the stock.")
|
||||
@@ -2290,6 +2306,9 @@ class ShipmentInternal(
|
||||
states={
|
||||
'readonly': ~Eval('state').in_(['request', 'draft']),
|
||||
},
|
||||
context={
|
||||
'party_contact_mechanism_usage': 'delivery',
|
||||
},
|
||||
help="The company the shipment is associated with.")
|
||||
from_location = fields.Many2One('stock.location', "From Location",
|
||||
required=True, states={
|
||||
|
||||
Reference in New Issue
Block a user