Coverage for lino/modlib/contacts/models.py : 70%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: UTF-8 -*- # Copyright 2008-2015 Luc Saffre # License: BSD (see file COPYING for details)
- The :class:`Partner` model (and its two subclasses :class:`Person` and :class:`Company`)
- A :class:`CompanyType` model can be used to classify companies.
- The :class:`Role` and :class:`RoleType` models store "who is who" information.
TODO: rename :class:`Role` to "Contact", :class:`RoleType` to "Role" and field `Contact.type` to `role`. Move Partner, Person and Company into a separate plugin "partners".
.. autosummary::
"""
"""A Partner is any physical or moral person for which you want to keep contact data (address, phone numbers, ...).
A :class:`Partner` can act as the recipient of a sales invoice, as the sender of an incoming purchases invoice, ...
A Partner has at least a name and usually also an "official" address.
Predefined subclasses of Partners are :class:`Person` for physical persons and :class:`Company` for companies, organisations and any kind of non-formal Partners.
.. attribute:: name
The full name of this partner. Used for alphabetic sorting. Subclasses may hide this field and fill it automatically, e.g. saving a :class:`Person` will automatically set her `name` field to "last_name, first_name".
.. attribute:: email
The primary email address.
""" # preferred width for ForeignKey fields to a Partner
# print_labels = dd.PrintLabelsAction()
self.language = ar.get_user().language if not self.country: sc = settings.SITE.site_config if sc.site_company: self.country = sc.site_company.country super(Partner, self).on_create(ar)
if self.id is None: sc = settings.SITE.site_config if sc.next_partner_id is not None: try: self.__class__.objects.get(id=sc.next_partner_id) raise ValidationError( "Cannot create partner with id={0}. " "Check your next_partner_id in SiteConfig!".format( sc.next_partner_id)) except self.__class__.DoesNotExist: self.id = sc.next_partner_id sc.next_partner_id += 1 sc.save() #~ logger.info("20120327 Partner.save(%s,%s)",args,kw) super(Partner, self).save(*args, **kw)
#~ return self.name return self.get_full_name()
#~ yield self.name yield self.get_full_name()
"""\ Returns a one-line string representing this Partner. The default returns simply the `name` field, ignoring any parameters, but e.g. :class:`Human` overrides this. """ return self.name
def name_column(self, request): #~ return join_words(self.last_name.upper(),self.first_name) return str(self)
return self # compatibility with lino.modlib.partners
def overview(self, ar): return E.div(*self.get_overview_elems(ar))
elems = [] if ar is None: return elems buttons = self.get_mti_buttons(ar) # buttons = join_elems(buttons, ', ') elems.append(E.p(str(_("See as ")), *buttons, style="font-size:8px;text-align:right;padding:3pt;")) elems += self.get_name_elems(ar) elems.append(E.br()) elems += join_elems(list(self.address_location_lines()), sep=E.br) elems = [ E.div(*elems, style="font-size:18px;font-weigth:bold;" "vertical-align:bottom;text-align:middle")] return elems
return [E.b(self.name)]
return self.language
address_box:60 contact_box:30 overview bottom_box """
name_box country region city zip_code:10 addr1 street_prefix street:25 street_no street_box addr2 """, label=_("Address"))
info_box email:40 url phone gsm fax """, label=_("Contact"))
remarks """
name language email """
def get_queryset(self, ar): return self.model.objects.select_related('country', 'city')
#~ class AllPartners(Partners):
#~ @classmethod #~ def get_actor_label(self): #~ return _("All %s") % self.model._meta.verbose_name_plural
""" A physical person and an individual human being. See also :ref:`lino.tutorial.human`.
"""
"""Set the `name` field of this person. This field is visible in the Partner's detail but not in the Person's detail and serves for sorting when selecting a Partner. It also serves for quick search on Persons.
""" name = join_words(self.last_name, self.first_name) if name: self.name = name else: for k, v in list(name2kw(self.name).items()): setattr(self, k, v) # self.last_name = self.name super(Person, self).full_clean(*args, **kw)
"Deserves more documentation." # if self.title: # yield join_words(self.get_salutation(), self.title) # kw.update(salutation=False) yield self.get_full_name(*args, **kw)
elems = [self.get_salutation(nominative=True), ' ', self.title, E.br()] elems += [self.first_name, ' ', E.b(self.last_name)] return elems
""" List of all Persons. """ "name_column:20 address_column email " "phone:10 gsm:10 id language:10 *")
first_name last_name gender language """
"""A type of organization. Used by :attr:`Company.type` field.
"""
#~ label = _("Company types")
"""An organisation. The internal name is "Company" for historical reasons and because that's easier to type.
See also :srcref:`docs/tickets/14`.
.. attribute:: type
Pointer to the :class:`CompanyType`.
"""
_("Name prefix"), max_length=200, blank=True)
"""Deserves more documentation.""" #~ print '20120729 Company.get_full_name`' if self.type: return join_words(self.prefix, self.type.abbr, self.name) return join_words(self.prefix, self.name)
elems = [] if self.prefix: elems += [self.prefix, ' '] elems += [E.b(self.name)] return elems
remarks contacts.RolesByCompany """
"name_column:20 address_column email " "phone:10 gsm:10 id language:10 *") name language:20 email:40 type id """
#~ class List(Partner): #~ pass
#~ class Lists(Partners): #~ model = List #~ order_by = ["name"] #~ detail_layout = """ #~ id name #~ language email #~ MembersByList #~ """ #~ insert_layout = dd.FormLayout(""" #~ name #~ language email #~ """,window_size=(40,'auto'))
# class ContactType(mixins.BabelNamed):
"""A :class:`RoleType` is "what a given :class:`Person` can be for a given :class:`Company`".
TODO: rename "RoleType" to "Function" or "ContactType".
RoleType,name is used at "in seiner Eigenschaft als ..." in document templates for contracts.
"""
"""A Contact (historical model name :class:`Role`) is a :class:`Person` who has a given role (:class:`ContactType`) in a given :class:`Company`.
"""
'contacts.RoleType', blank=True, null=True, verbose_name=_("Contact Role")) "contacts.Person", related_name='rolesbyperson') "contacts.Company", related_name='rolesbycompany')
if self.person_id is None: return super(Role, self).__str__() if self.type is None: return str(self.person) return u"%s (%s)" % (self.person, self.type)
if self.company: for ln in self.company.address_person_lines(): yield ln for ln in self.person.address_person_lines(): yield ln
if self.company_id: return self.company.address_location_lines() if self.person_id: return self.person.address_location_lines() return super(Role, self).__str__()
if self.company_id: return self.company.language if self.person_id: return self.person.language return super(Role, self).get_print_language()
#~ required_user_level = None
#~ required_user_level = None
'system.SiteConfig', 'next_partner_id', models.IntegerField( default=PARTNER_NUMBERS_START_AT, blank=True, null=True, verbose_name=_("Next partner id"), help_text=_("The next automatic id for any new partner.")))
'system.SiteConfig', 'site_company', models.ForeignKey( "contacts.Company", blank=True, null=True, verbose_name=_("Site owner"), related_name='site_company_sites', help_text=_("""The organisation who runs this site. This is used e.g. as sender in documents. Or, newly created partners inherit the country of the site owner. """)))
name country type parent zip_code id PlacesByPlace contacts.PartnersByCity """)
def company_model_alias(sender, **kw): """ prepare ticket #72 which will rename Company to Organisation """
def company_tables_alias(sender, **kw): """ prepare ticket #72 which will rename Company to Organisation """
return models.ForeignKey(Partner, **kw) |