from lino.django.utils.validatingmodel import TomModel, ModelValidationError from lino.django.utils.reports import Report from lino.django.utils.render import ViewReportRenderer from django.db import models from django.forms.models import modelform_factory, formset_factory from django.conf import settings from lino.django.apps.journals import models as journals # Journal, Document, register_doctype, DocumentError class Document(journals.AbstractDocument): pass class Order(Document): pass journals.register_doctype(Order) class Invoice(Document): pass journals.register_doctype(Invoice) class JournalsTest(TestCase): def test01(self): # create two journals and some documents:: ORD = journals.create_journal("ORD",Order) INV = journals.create_journal("INV",Invoice,force_sequence=True)
self.value_date = self.creation_date return super(FinancialDocument,self).save(*args,**kw) def add_item(self,account=None,contact=None,**kw): pos = self.docitem_set.count() + 1 if account is not None: if not isinstance(account,Account): account = Account.objects.get(pk=account) if contact is not None: if not isinstance(contact,contacts.Contact): contact = contacts.Contact.objects.get(pk=contact) kw['account'] = account kw['contact'] = contact return self.docitem_set.create(**kw) journals.register_doctype(FinancialDocument) class Account(models.Model): name = models.CharField(max_length=200,blank=True) class DocItem(models.Model): document = models.ForeignKey(FinancialDocument) pos = models.IntegerField("Position") debit = fields.PriceField(blank=True,null=True) credit = fields.PriceField(blank=True,null=True) remark = models.CharField(max_length=200,blank=True) account = models.ForeignKey(Account) contact = models.ForeignKey(contacts.Contact,blank=True,null=True) def save(self,*args,**kw): if self.pos is None: