def customize_school(): dd.inject_field('courses.Pupil', 'school', models.ForeignKey(School, blank=True,null=True, help_text=_("""The regular school where this child goes.""") ))
def inject_vat_fields(sender, **kw): for tt in TradeTypes.items(): if tt.partner_account_field_name is not None: dd.inject_field( 'system.SiteConfig', tt.partner_account_field_name, dd.ForeignKey( 'accounts.Account', verbose_name=tt.partner_account_field_label, related_name='configs_by_' + tt.partner_account_field_name, blank=True, null=True)) if tt.vat_account_field_name is not None: dd.inject_field('system.SiteConfig', tt.vat_account_field_name, dd.ForeignKey('accounts.Account', verbose_name=tt.vat_account_field_label, related_name='configs_by_' + tt.vat_account_field_name, blank=True, null=True)) if tt.base_account_field_name is not None: dd.inject_field('system.SiteConfig', tt.base_account_field_name, dd.ForeignKey('accounts.Account', verbose_name=tt.base_account_field_label, related_name='configs_by_' + tt.base_account_field_name, blank=True, null=True)) dd.inject_field('products.Product', tt.base_account_field_name, dd.ForeignKey('accounts.Account', verbose_name=tt.base_account_field_label, related_name='products_by_' + tt.base_account_field_name, blank=True, null=True)) if tt.price_field_name is not None: dd.inject_field('products.Product', tt.price_field_name, dd.PriceField(verbose_name=tt.price_field_label, blank=True, null=True))
def customize_accounts(): for tt in vat.TradeTypes.objects(): dd.inject_field('accounts.Account', tt.name+'_allowed', models.BooleanField(verbose_name=tt.text,default=True)) dd.inject_field('accounts.Account', 'clearable',models.BooleanField(_("Clearable"),default=False))
def customize_siteconfig(): """ Injects application-specific fields to :class:`SiteConfig <lino.modlib.system.SiteConfig>`. """ dd.inject_field('system.SiteConfig', 'system_note_type', #~ models.ForeignKey(NoteType, models.ForeignKey(EventType, blank=True,null=True, verbose_name=_("Default system note type"), help_text=_("""\ Note Type used by system notes. If this is empty, then system notes won't create any entry to the Notes table.""")))
def customize_contacts(): dd.inject_field('contacts.Partner', 'national_id_et', models.CharField(max_length=200, blank=True,verbose_name=_("National ID") #~ ,validators=[niss_validator] ) ) dd.inject_field('contacts.Partner', 'bank_account1', models.CharField(max_length=100, blank=True,verbose_name=_("Bank account") #~ ,validators=[niss_validator] ) )
def customize_users(): """ Injects application-specific fields to users.User. """ dd.inject_field(settings.SITE.user_model, 'access_class', AccessClasses.field( default=AccessClasses.public, verbose_name=_("Default access class"), help_text=_( """The default access class for your calendar events and tasks.""") )) dd.inject_field(settings.SITE.user_model, 'event_type', models.ForeignKey('cal.EventType', blank=True, null=True, verbose_name=_("Default Event Type"), help_text=_("""The default event type for your calendar events.""") )) dd.inject_field('system.SiteConfig', 'default_event_type', models.ForeignKey('cal.EventType', blank=True, null=True, verbose_name=_("Default Event Type"), help_text=_("""The default type of events on this site.""") )) dd.inject_field( 'system.SiteConfig', 'site_calendar', models.ForeignKey( 'cal.Calendar', blank=True, null=True, related_name="%(app_label)s_%(class)s_set_by_site_calender", verbose_name=_("Site Calendar"), help_text=_("""The default calendar of this site."""))) dd.inject_field( 'system.SiteConfig', 'max_auto_events', models.IntegerField( _("Max automatic events"), default=72, blank=True, null=True, help_text=_( """Maximum number of automatic events to be generated.""") ))
def customize_partners(): #~ for ms in 'contacts.Partner', 'contacts.Person', 'contacts.Company': partner_model = settings.SITE.partners_app_label + '.Partner' dd.inject_field(partner_model, 'payment_term', models.ForeignKey(PaymentTerm, blank=True,null=True, help_text=_("The default payment term for sales invoices to this customer."))) dd.inject_field(partner_model, 'vat_regime', vat.VatRegimes.field( blank=True, help_text=_("The default VAT regime for sales to this customer."))) #~ dd.inject_field(partner_model, #~ 'item_vat', #~ models.BooleanField( #~ default=False, #~ help_text=_("The default item VAT setting for sales to this customer."))) #~ dd.inject_field(partner_model, 'imode', models.ForeignKey(InvoicingMode,blank=True,null=True))
auto_fit_column_widths = True hide_columns = "id" class MembersByRole(Members): required = dd.required() master_key = "role" column_names = "person household start_date end_date *" if settings.SITE.is_installed("households"): # ~ Don't inject fields if this is just being imported from some other module. dd.inject_field( "contacts.Partner", "is_household", mti.EnableChild("households.Household", verbose_name=_("is Household")), """Whether this Partner is a Household.""", ) from lino.modlib.households import App from lino.modlib.contacts import App as ContactsApp def setup_main_menu(site, ui, profile, m): m = m.add_menu("contacts", ContactsApp.verbose_name) m.add_action("households.Households") def setup_config_menu(site, ui, profile, m): m = m.add_menu("households", App.verbose_name)
vat.TradeTypes.sales.update( price_field_name='sales_price', price_field_label=_("Sales price"), base_account_field_name='sales_account', base_account_field_label=_("Sales Base account"), vat_account_field_name='sales_vat_account', vat_account_field_label=_("Sales VAT account"), partner_account_field_name='clients_account', partner_account_field_label=_("Clients account")) dd.inject_field('contacts.Partner', 'invoicing_address', dd.ForeignKey('contacts.Partner', verbose_name=_("Invoicing address"), blank=True, null=True)) #~ class Channel(ChoiceList): #~ label = _("Channel") #~ add = Channel.add_item #~ add('P',_("Paper")) #~ add('E',_("E-mail")) class InvoiceStates(dd.Workflow): """ This lists the possible values for the workflow of a :class:`Invoice` """ add = InvoiceStates.add_item
class Debts(dd.Table): model = Debt class DebtsByBudget(Debts): master_key = 'budget' column_names = 'partner amount remark' if settings.LINO.user_model: USER_MODEL = dd.resolve_model(settings.LINO.user_model) dd.inject_field(USER_MODEL, 'is_debts', models.BooleanField( verbose_name=_("is Debts user") ),"""Whether this user is responsible for Debts Mediation. """) def site_setup(site): pass def setup_main_menu(site,ui,user,m): pass def setup_master_menu(site,ui,user,m): pass def setup_my_menu(site,ui,user,m): m = m.add_menu("debts",_("Debts")) m.add_action(MyBudgets) def setup_config_menu(site,ui,user,m):
def customize_ledger(): dd.inject_field('ledger.Voucher', 'declared_in', models.ForeignKey(Declaration, blank=True, null=True))
#~ EventStates.add_item('30', _("Visit"), 'visit',fixed=False) add = GuestStates.add_item add('44', _("Waiting"), 'waiting') add('45', _("Busy"), 'busy') add('46', _("Gone"), 'gone') from lino.modlib.reception import Plugin #~ add = GuestStates.add_item #~ add('21', _("Waiting"),'waiting') dd.inject_field( 'cal.Guest', 'waiting_since', models.DateTimeField( _("Waiting since"), editable=False, blank=True, null=True, help_text=_("Time when the visitor arrived (checked in)."))) dd.inject_field( 'cal.Guest', 'busy_since', models.DateTimeField( _("Waiting until"), editable=False, blank=True, null=True, help_text=_("Time when the visitor was received by agent."))) dd.inject_field( 'cal.Guest', 'gone_since', models.DateTimeField( _("Present until"), editable=False, blank=True, null=True, help_text=_("Time when the visitor left (checked out).")))
# the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # Lino is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public License # along with Lino; if not, see <http://www.gnu.org/licenses/>. """ :xfile:`models.py` module for the :mod:`lino.modlib.sepa` app. Defines the :class:`EventType` and :class:`Event` models and their tables. """ from __future__ import unicode_literals from django.utils.translation import ugettext_lazy as _ from lino import dd from .fields import IBANField, BICField dd.inject_field( 'contacts.Partner', 'iban', IBANField(_("IBAN"), blank=True)) dd.inject_field( 'contacts.Partner', 'bic', BICField(_("BIC"), blank=True))
def set_excerpts_actions(sender, **kw): # logger.info("20140401 %s.set_attest_actions()", __name__) # in case ExcerptType is overridden ExcerptType = sender.modules.excerpts.ExcerptType Excerpt = sender.modules.excerpts.Excerpt try: etypes = [(obj, obj.content_type) for obj in ExcerptType.objects.all()] except Exception as e: etypes = [] logger.warning("Failed to set excerpts actions : %s", e) for atype, ct in etypes: if ct is not None: m = ct.model_class() an = atype.get_action_name() m.define_action(**{an: CreateExcerpt(atype, unicode(atype))}) if atype.primary: if atype.certifying: m.define_action( clear_printed=ClearPrinted()) # reved 20141006 because for pcsw.Client it was irritating: # else: # m.define_action( # show_excerpts=dd.ShowSlaveTable( # 'excerpts.ExcerptsByOwner' # )) # logger.info( # "20140618 %s.define_action('%s') from %s ", ct, an, atype) # An attestable model must also inherit # :class:`lino.mixins.printable.BasePrintable` or some subclass # thereof. for i in Shortcuts.items(): def f(obj, ar): if obj is None: return '' try: et = ExcerptType.objects.get(shortcut=i) except ExcerptType.DoesNotExist: return '' items = [] if True: sar = ar.spawn( ExcerptsByOwner, master_instance=obj, param_values=dict(pexcerpt_type=et)) n = sar.get_total_count() if n > 0: ex = sar.sliced_data_iterator[0] items.append(ar.obj2html(ex, _("Last"))) ba = sar.bound_action btn = sar.renderer.action_button( obj, sar, ba, "%s (%d)" % (_("All"), n), icon_name=None) items.append(btn) ia = getattr(obj, et.get_action_name()) btn = ar.instance_action_button( ia, _("Create"), icon_name=None) items.append(btn) else: ot = ContentType.objects.get_for_model(obj.__class__) qs = Excerpt.objects.filter( owner_id=obj.pk, owner_type=ot, excerpt_type=et) if qs.count() > 0: ex = qs[0] txt = ExcerptsByOwner.format_excerpt(ex) items.append(ar.obj2html(ex, txt)) return E.div(*join_elems(items, ', ')) vf = dd.VirtualField(dd.DisplayField(i.text), f) dd.inject_field(i.model_spec, i.name, vf)
def customize_users(): """ Injects application-specific fields to users.User. """ dd.inject_field(settings.SITE.user_model, 'access_class', AccessClasses.field( default=AccessClasses.public, verbose_name=_("Default access class"), help_text=_("""The default access class for your calendar events and tasks.""") )) dd.inject_field(settings.SITE.user_model, 'event_type', models.ForeignKey('cal.EventType', blank=True,null=True, verbose_name=_("Default Event Type"), help_text=_("""The default event type for your calendar events.""") )) dd.inject_field('system.SiteConfig', 'default_event_type', models.ForeignKey('cal.EventType', blank=True,null=True, verbose_name=_("Default Event Type"), help_text=_("""The default type of events on this site.""") )) #~ dd.inject_field('system.SiteConfig', #~ 'holiday_event_type', #~ models.ForeignKey('cal.EventType', #~ blank=True,null=True, #~ related_name="%(app_label)s_%(class)s_set_by_holiday_calender", #~ verbose_name=_("Holiday"), #~ help_text=_("""The default type for recurring calendar events.""") #~ )) #~ dd.inject_field('system.SiteConfig', 'site_calendar', models.ForeignKey('cal.Calendar', blank=True,null=True, related_name="%(app_label)s_%(class)s_set_by_site_calender", verbose_name=_("Site Calendar"), help_text=_("""The default calendar of this site.""") )) dd.inject_field('system.SiteConfig', 'max_auto_events', models.IntegerField(_("Max automatic events"),default=72, blank=True,null=True, help_text=_("""Maximum number of automatic events to be generated.""") )) dd.inject_field('system.SiteConfig', 'farest_future', models.DateField(_("Farest future"), default=datetime.date.today() + dateutil.relativedelta.relativedelta(years=5), help_text=_("""Don't generate automatic events past that date.""") ))
#~ def get_todo_tables(ar): #~ yield (PendingRequestedEnrolments, None) #~ yield (PendingConfirmedEnrolments, None) dd.inject_field('cal.Event', 'course', dd.ForeignKey('courses.Course', blank=True,null=True, related_name="events_by_course")) dd.inject_field(Person, 'is_teacher', mti.EnableChild('courses.Teacher', verbose_name=_("is a teacher"), help_text=_("Whether this Person is also a Teacher."))) dd.inject_field(Person, 'is_pupil', mti.EnableChild('courses.Pupil', verbose_name=_("is a pupil"), help_text=_("Whether this Person is also a Pupil.")))
def add_user_field(self, name, fld): if self.user_model: from lino import dd, rt #~ User = dd.resolve_model(self.user_model) dd.inject_field(self.user_model, name, fld)
elems.append(E.ul(*items)) elems += [ E.br(), ar.instance_action_button(obj.create_household)] return E.div(*elems) # class MembersByRole(Members): # required = dd.required() # master_key = 'role' # column_names = 'person household start_date end_date *' dd.inject_field( 'contacts.Partner', 'is_household', mti.EnableChild( 'households.Household', verbose_name=_("is Household"), help_text=("Whether this Partner is a Household."))) def setup_main_menu(site, ui, profile, m): m = m.add_menu(mnugrp.app_label, mnugrp.verbose_name) m.add_action('households.Households') def setup_config_menu(site, ui, profile, m): m = m.add_menu(mnugrp.app_label, mnugrp.verbose_name) # m.add_action(Roles) m.add_action(Types)
#~ order_by = ["creation_date"] #~ master_key = 'person' journals.register_doctype(Order,OrdersByJournal) journals.register_doctype(Invoice,InvoicesByJournal) if settings.SITE.is_installed('igen'): #~ from lino.modlib.contacts.models import Contact dd.inject_field(contacts.Partner, 'is_customer', mti.EnableChild('sales.Customer',verbose_name=_("is Customer")), """Whether this Partner is also a Customer.""" ) #~ dd.inject_field( #~ Contact,'payment_term', #~ models.ForeignKey(PaymentTerm, #~ blank=True,null=True, #~ verbose_name=_("payment term")), #~ """The default PaymentTerm for sales invoices to this Contact. #~ """) #~ dd.inject_field( #~ Contact, 'vat_exempt', #~ models.BooleanField(default=False,
column_names = "username person company is_superuser is_staff *" if settings.SITE.is_installed("contacts"): """ Don't inject fields if contacts is just being imported from some other module. """ from lino.models import SiteConfig dd.inject_field( SiteConfig, "site_company", models.ForeignKey( Company, blank=True, null=True, verbose_name=_("The company that runs this site"), related_name="site_company_sites", ), """The Company to be used as sender in documents.""", ) NAME = "contacts" LABEL = _("Contacts") def setup_main_menu(site, ui, profile, m): m.add_action(Companies) m.add_action(Persons) # ~ m.add_action(Contacts)
""" This just adds `inscode` fields to `countries.City` and `countries.Country`. """ from django.db import models from django.utils.translation import ugettext_lazy as _ from lino import dd dd.inject_field('countries.City', 'inscode', models.CharField( max_length=5, verbose_name=_("INS code"), blank=True, help_text=_("The official code for this place used by statbel.fgov.be") )) dd.inject_field('countries.Country', 'inscode', models.CharField( max_length=3, verbose_name=_("INS code"), blank=True, help_text=_("The official code for this country used by statbel.fgov.be") ))
def set_default_item_vat(sender, instance=None, **kwargs): instance.item_vat = settings.SITE.get_item_vat(instance) #~ print("20130902 set_default_item_vat", instance) @dd.receiver(dd.post_analyze) def on_post_analyze(sender, **kw): for m in dd.models_by_base(VatDocument): dd.post_init.connect(set_default_item_vat, sender=m) #~ print('20130902 on_post_analyze installed receiver for',m) dd.inject_field( 'contacts.Partner', 'vat_regime', VatRegimes.field( blank=True, help_text=_("The default VAT regime for \ sales and purchases of this partner."))) dd.inject_field( 'contacts.Company', 'vat_id', models.CharField(_("VAT id"), max_length=200, blank=True)) dd.inject_field( 'contacts.Partner', 'payment_term', models.ForeignKey( PaymentTerm, blank=True, null=True,
if qs.count() == 1: self.contact_person = qs[0] else: #~ print "20120227 clear contact!" self.contact_person = None contact = self.get_contact() if contact is not None: self.contact_role = contact.type #~ print '20120929b', contact.type super(ContactRelated, self).full_clean(*args, **kw) dd.inject_field( '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."))) dd.inject_field( '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.
#~ dd.inject_field(settings.SITE.user_model, #~ 'partner', #~ models.ForeignKey(Partner, #~ blank=True,null=True, #~ verbose_name=_("Partner"))) #~ if settings.SITE.is_installed('contacts'): #~ from lino.models import SiteConfig dd.inject_field('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."))) dd.inject_field('system.SiteConfig', 'site_company', models.ForeignKey("contacts.Company", blank=True,null=True, verbose_name=_("The company that runs this site"), related_name='site_company_sites', help_text=_("The Company to be used as sender in documents."))) #~ dd.inject_field(Partner, #~ 'is_person', #~ mti.EnableChild(
#~ @dd.virtualfield(dd.PriceField(_("Total excl. VAT"))) #~ def total_base(self,obj,ar=None): return obj.total_base #~ @dd.virtualfield(dd.PriceField(_("Total VAT"))) #~ def total_vat(self,obj,ar=None): return obj.total_vat #~ @dd.displayfield(_("Journal")) #~ def journal(self,obj,ar): return obj.journal.href_to(ar) #~ @dd.displayfield(_("Voucher")) #~ def voucher(self,obj,ar): return obj.href_to(ar) for fld in DeclarationFields.objects(): dd.inject_field(Declaration, fld.name, dd.PriceField(fld.text, default=Decimal)) class Declarations(dd.Table): model = Declaration column_names = 'year period workflow_buttons * state id' insert_layout = dd.FormLayout(""" date year period """, window_size=(40, 'auto')) detail_layout = dd.FormLayout(""" date year period user workflow_buttons fields VouchersByDeclaration """, fields=DeclarationFields.fields_layout)
system = m.add_menu("system", SYSTEM_USER_LABEL) if site.user_model: system.add_action(site.modules.users.Authorities) system.add_action(dd.UserGroups) system.add_action(dd.UserLevels) system.add_action(dd.UserProfiles) office.add_action(TextFieldTemplates) #~ if site.is_installed('contenttypes'): #~ system.add_action(Changes) dd.add_user_group('office', OFFICE_MODULE_LABEL) if settings.SITE.user_model == 'auth.User': dd.inject_field(settings.SITE.user_model, 'profile', dd.UserProfiles.field()) dd.inject_field(settings.SITE.user_model, 'language', dd.LanguageField()) @dd.receiver(dd.pre_ui_build) def my_pre_ui_build(sender, **kw): self = settings.SITE if self.is_installed('contenttypes'): from django.db.utils import DatabaseError from django.db.models import FieldDoesNotExist try: HelpText = dd.resolve_model('system.HelpText') for ht in HelpText.objects.filter(help_text__isnull=False): #~ logger.info("20120629 %s.help_text", ht)
#~ if ar.param_values.date: return qs.filter(date=ar.param_values.today) #~ return qs @classmethod def create_instance(self, ar, **kw): kw.update(date=ar.param_values.today) return super(MySessions, self).create_instance(ar, **kw) if blogs: dd.inject_field('blogs.Entry', 'ticket', models.ForeignKey("tickets.Ticket", blank=True, null=True, # verbose_name=_("Local job office"), # related_name='job_office_sites' help_text="""The Ticket attributed to this Entry.""")) class EntriesByTicket(blogs.Entries): master_key = 'ticket' class EntriesBySession(EntriesByTicket): """The Blog Entries linked to *the Ticket of* a Session. Blog Entries are not directly linked to a Session, but in the Detail of a Session we want to display a table of related blog entries.
CRL fields need to be sorted using pure ASCII sequence. Since this is not a database-transparent feature in Django, we store these strings as their hexadecimal representation. """ __metaclass__ = models.SubfieldBase # needed for to_python() to be called automatically. def __init__(self, *args, **kw): defaults = dict(verbose_name=_("Label"), max_length=100, blank=True) defaults.update(kw) models.CharField.__init__(self, *args, **defaults) def to_python(self, value): if not value: return value if isinstance(value, CRL): return value return CRL(hex2str(value)) def get_prep_value(self, value): if not value: return value assert isinstance(value, CRL) return str2hex(value) dd.inject_field(countries.City, "crl", CrlField()) dd.inject_field(contacts.Person, "crl", CrlField()) dd.inject_field(contacts.Person, "died_date", models.DateField(blank=True, null=True, verbose_name=_("Died date"))) dd.inject_field(contacts.Company, "crl", CrlField())
else: #~ print "20120227 clear contact!" self.contact = None contact = self.get_contact() if contact is not None: self.contact_role = contact.type #~ print '20120929b', contact.type super(ContactRelated, self).full_clean(*args, **kw) if settings.SITE.is_installed('partners'): dd.inject_field('system.SiteConfig', 'next_partner_id', models.IntegerField(default=100, # first 100 for users from demo fixtures. verbose_name=_( "The next automatic id for Person or Organisation") ), """The next automatic id for Person or Organisation. Deserves more documentation. """) dd.inject_field('system.SiteConfig', 'site_partner', models.ForeignKey("partners.Organisation", blank=True, null=True, verbose_name=_( "The partner that runs this site"), related_name='site_partner_sites', help_text=_("The partner to be used as sender in documents."))) def site_setup(site):
def __init__(self, *args, **kw): defaults = dict( verbose_name=_("Label"), max_length=100, blank=True, ) defaults.update(kw) models.CharField.__init__(self, *args, **defaults) def to_python(self, value): if not value: return value if isinstance(value, CRL): return value return CRL(hex2str(value)) def get_prep_value(self, value): if not value: return value assert isinstance(value, CRL) return str2hex(value) dd.inject_field(countries.Place, 'crl', CrlField()) dd.inject_field(contacts.Person, 'crl', CrlField()) dd.inject_field(contacts.Person, 'died_date', models.DateField( blank=True, null=True, verbose_name=_("Died date"))) dd.inject_field(contacts.Company, 'crl', CrlField())