def set_auto_vote(self, user, state): # dd.logger.info("20170406 set_auto_vote %s %s", user, state) vote = self.get_favourite(user) if vote is None: create_row( rt.models.votes.Vote, user=user, votable=self, state=state)
def set_auto_vote(self, user, state): # dd.logger.info("20170406 set_auto_vote %s %s", user, state) vote = self.get_favourite(user) if vote is None: create_row(rt.models.votes.Vote, user=user, votable=self, state=state)
def before_execute(self, ar, obj): pv = ar.action_param_values # print(20170116, pv) obj.rating = pv.rating if pv.comment: create_row(rt.models.comments.Comment, owner=obj.votable, short_text=pv.comment, user=ar.get_user())
def test_makecopy(self): UserTypes = rt.models.users.UserTypes Partner = rt.models.contacts.Partner Account = rt.models.ledger.Account AnaAccountInvoice = rt.models.ana.AnaAccountInvoice jnl = rt.models.ledger.Journal.objects.get(ref="PRC") # acc = rt.models.ledger.Account.objects.get(ref="PRC") user = create_row(rt.models.users.User, username="******", user_type=UserTypes.admin) ses = rt.login('robin', renderer=TestRenderer()) partner = create_row(Partner, name="Foo") self.assertEqual(AnaAccountInvoice.objects.count(), 0) invoice = jnl.create_voucher(partner=partner, user=user) self.assertEqual(invoice.__class__, AnaAccountInvoice) invoice.full_clean() invoice.save() ga = Account.objects.filter( needs_ana=True, ana_account__isnull=False).order_by('ref')[0] for n in range(3): i = invoice.add_voucher_item( account=ga, seqno=3 - n, # enter them in reverse order to reproduce # #2470 total_incl=123 + n) i.full_clean() i.save() s = ses.show('ana.ItemsByInvoice', invoice, column_names="seqno account total_incl") # print(s) expected = """\ ==================== ============================= ================= No. Account Total incl. VAT -------------------- ----------------------------- ----------------- 1 (6010) Purchase of services 125,00 2 (6010) Purchase of services 124,00 3 (6010) Purchase of services 123,00 **Total (3 rows)** **372,00** ==================== ============================= ================= """ self.assertEqual(s, expected) self.assertEqual(AnaAccountInvoice.objects.count(), 1) self.assertEqual(invoice.number, 1) invoice.make_copy.run_from_session(ses) self.assertEqual(AnaAccountInvoice.objects.count(), 2) invoice = AnaAccountInvoice.objects.get(number=2) s = ses.show('ana.ItemsByInvoice', invoice, column_names="seqno account total_incl") # print(s) self.assertEqual(s, expected)
def test_makecopy(self): UserTypes = rt.models.users.UserTypes Partner = rt.models.contacts.Partner Account = rt.models.ledger.Account AnaAccountInvoice = rt.models.ana.AnaAccountInvoice jnl = rt.models.ledger.Journal.objects.get(ref="PRC") # acc = rt.models.ledger.Account.objects.get(ref="PRC") user = create_row(rt.models.users.User, username="******", user_type=UserTypes.admin) ses = rt.login('robin', renderer=TestRenderer()) partner = create_row(Partner, name="Foo") self.assertEqual(AnaAccountInvoice.objects.count(), 0) invoice = jnl.create_voucher(partner=partner, user=user) self.assertEqual( invoice.__class__, AnaAccountInvoice) invoice.full_clean() invoice.save() ga = Account.objects.filter( needs_ana=True, ana_account__isnull=False).order_by('ref')[0] for n in range(3): i = invoice.add_voucher_item( account=ga, seqno=3-n, # enter them in reverse order to reproduce # #2470 total_incl=123+n) i.full_clean() i.save() s = ses.show('ana.ItemsByInvoice', invoice, column_names="seqno account total_incl") # print(s) expected = """\ ==================== ============================= ================= No. Account Total incl. VAT -------------------- ----------------------------- ----------------- 1 (6010) Purchase of services 125,00 2 (6010) Purchase of services 124,00 3 (6010) Purchase of services 123,00 **Total (3 rows)** **372,00** ==================== ============================= ================= """ self.assertEqual(s, expected) self.assertEqual(AnaAccountInvoice.objects.count(), 1) self.assertEqual(invoice.number, 1) invoice.make_copy.run_from_session(ses) self.assertEqual(AnaAccountInvoice.objects.count(), 2) invoice = AnaAccountInvoice.objects.get(number=2) s = ses.show('ana.ItemsByInvoice', invoice, column_names="seqno account total_incl") # print(s) self.assertEqual(s, expected)
def full_clean(self): super(Deployment, self).full_clean() if self.deferred_to: if self.milestone == self.deferred_to: raise Warning(_("Cannot defer to myself")) qs = rt.models.deploy.Deployment.objects.filter( milestone=self.deferred_to, ticket=self.ticket) if qs.count() == 0: create_row( Deployment, milestone=self.deferred_to, ticket=self.ticket, wish_type=self.wish_type, remark=self.remark)
def set_value_in_object(self, request, obj, value): # dd.logger.info("20170508 set_value_in_object(%s, %s)", obj, value) # if value is None: # raise Exception("20170508") if value is not None: Interest = rt.models.topics.Interest if Interest.objects.filter(**gfk2lookup( Interest.owner, obj, topic=value)).count() == 0: try: create_row(Interest, topic=value, owner=obj) except Exception as e: dd.logger.warning("20170508 ignoring %s", e) return obj
def full_clean(self): super(Deployment, self).full_clean() if self.deferred_to: if self.milestone == self.deferred_to: raise Warning(_("Cannot defer to myself")) qs = rt.models.deploy.Deployment.objects.filter( milestone=self.deferred_to, ticket=self.ticket) if qs.count() == 0: create_row(Deployment, milestone=self.deferred_to, ticket=self.ticket, wish_type=self.wish_type, remark=self.remark)
def set_value_in_object(self, request, obj, value): # dd.logger.info("20170508 set_value_in_object(%s, %s)", obj, value) # if value is None: # raise Exception("20170508") if value is not None: Interest = rt.models.topics.Interest if Interest.objects.filter(**gfk2lookup( Interest.owner, obj, topic=value)).count() == 0: try: create_row(Interest, topic=value, owner=obj) except Exception as e: dd.logger.warning("20170508 ignoring %s", e) return obj
def test01(self): from lino.core import constants from lino.modlib.users.choicelists import UserTypes from lino.api.shell import countries, users Client = rt.models.avanti.Client u = users.User(username='******', user_type=UserTypes.admin, language="en") u.save() self.client.force_login(u) be = countries.Country(name="Belgium", isocode="BE") be.save() kw = dict() kw.update(national_id="680601 053-29") kw.update(first_name="Jean") kw.update(middle_name="Jacques") kw.update(last_name="Jeffin") jean = create_row(Client, **kw) kw.update(first_name="Jo") kw.update(national_id="680601 054-28") kw.update(last_name="Jeffin") jo = create_row(Client, **kw) def grid_put(username, url, **data): data[constants.URL_PARAM_ACTION_NAME] = 'grid_put' kwargs = dict(data=urlencode(data)) kwargs['REMOTE_USER'] = username response = self.client.put(url, **kwargs) # print(response) return self.check_json_result(response, 'rows success message') url = '/api/avanti/Clients/' + str(jean.pk) result = grid_put('robin', url, national_id="") self.assertEqual(result['success'], True) self.assertEqual(result['message'], 'Client "JEFFIN Jean (100)" has been updated.') jean = Client.objects.get(pk=jean.pk) self.assertEqual(jean.national_id, None) url = '/api/avanti/Clients/' + str(jo.pk) result = grid_put('robin', url, national_id="") self.assertEqual(result['success'], True) self.assertEqual(result['message'], 'Client "JEFFIN Jo (101)" has been updated.')
def objects(self): # yield Country(isocode='LU', **dd.str2kw('name', _("Luxemburg"))) # yield Country(isocode='PL', **dd.str2kw('name', _("Poland"))) # yield Country(isocode='AU', **dd.str2kw('name', _("Austria"))) # yield Country(isocode='US', short_code='USA', # **dd.str2kw('name', _("United States"))) # yield self.load_dbf('USR') # yield super(TimLoader, self).objects() # yield self.load_dbf('PLP') def bulkdel(*models): for m in models: m.objects.all()._raw_delete(DEFAULT_DB_ALIAS) bulkdel(rt.models.invoicing.Item) bulkdel(rt.models.invoicing.Plan) bulkdel(Guest, Event, SalesRule) bulkdel(Interest, Topic, Note) # bulkdel(Link) bulkdel(households_Member) bulkdel(ClientContact, Enrolment, Course) bulkdel(Line) with translation.override("de"): a = CourseAreas.therapies self.therapies = create_row(Line, name=a.text, course_area=a, ref="ET") a = CourseAreas.life_groups self.life_groups = create_row(Line, name=a.text, course_area=a, ref="LG") a = CourseAreas.default self.other_groups = create_row(Line, name=a.text, course_area=a, ref="TG") yield self.load_dbf('PAR') yield self.load_dbf('PLP') yield self.load_dbf('DLS') yield self.load_dbf('DLP') yield self.load_dbf('PRB') yield self.load_dbf('PPR') yield self.load_dbf('MSG')
def test01(self): from lino.modlib.users.choicelists import UserTypes User = rt.models.users.User Account = rt.models.accounts.Account AccountTypes = rt.models.accounts.AccountTypes Journal = rt.models.ledger.Journal Partner = rt.models.contacts.Partner Person = rt.models.contacts.Person Company = rt.models.contacts.Company Role = rt.models.contacts.Role # Account = rt.models.sepa.Account Invoice = rt.models.vat.VatAccountInvoice VoucherTypes = rt.models.ledger.VoucherTypes JournalGroups = rt.models.ledger.JournalGroups robin = create_row( User, username='******', user_type=UserTypes.admin, language="en") ar = rt.login('robin') a = create_row(Account, name="A", type=AccountTypes.expenses) b = create_row(Account, name="B", type=AccountTypes.expenses) c = create_row(Account, name="C", type=AccountTypes.expenses) d = create_row(Account, name="D", type=AccountTypes.expenses) lst = [i.seqno for i in Account.objects.order_by('name')] self.assertEqual(lst, [1, 2, 3, 4]) self.assertEqual(a.seqno, 1) self.assertEqual(b.seqno, 2) self.assertEqual(c.seqno, 3) self.assertEqual(d.seqno, 4) a.move_down(ar) self.assertEqual(ar.response, { 'message': 'Renumbered 1 of 3 siblings.', 'success': True, 'refresh_all': True}) # NOTE that a, b, c and d are invalid now a = b = c = d = None lst = [i.seqno for i in Account.objects.order_by('name')] self.assertEqual(lst, [2, 1, 3, 4]) lst = [i.name for i in Account.objects.order_by('seqno')] self.assertEqual(''.join(lst), "BACD")
def test01(self): from lino.modlib.users.choicelists import UserTypes User = rt.models.users.User Account = rt.models.ledger.Account Journal = rt.models.ledger.Journal Partner = rt.models.contacts.Partner Person = rt.models.contacts.Person Company = rt.models.contacts.Company Role = rt.models.contacts.Role # Account = rt.models.sepa.Account Invoice = rt.models.vat.VatAccountInvoice VoucherTypes = rt.models.ledger.VoucherTypes JournalGroups = rt.models.ledger.JournalGroups robin = create_row( User, username='******', user_type=UserTypes.admin, language="en") ar = rt.login('robin') a = create_row(Account, name="A") b = create_row(Account, name="B") c = create_row(Account, name="C") d = create_row(Account, name="D") lst = [i.seqno for i in Account.objects.order_by('name')] self.assertEqual(lst, [1, 2, 3, 4]) self.assertEqual(a.seqno, 1) self.assertEqual(b.seqno, 2) self.assertEqual(c.seqno, 3) self.assertEqual(d.seqno, 4) response = a.move_down() self.assertEqual(response, { 'message': 'Renumbered 1 of 3 siblings.', 'success': True, 'refresh_all': True}) # NOTE that a, b, c and d are invalid now a = b = c = d = None lst = [i.seqno for i in Account.objects.order_by('name')] self.assertEqual(lst, [2, 1, 3, 4]) lst = [i.name for i in Account.objects.order_by('seqno')] self.assertEqual(''.join(lst), "BACD")
def test01(self): from lino.core import constants from lino.modlib.users.choicelists import UserTypes from lino.api.shell import countries, users Client = rt.models.avanti.Client u = users.User(username='******', user_type=UserTypes.admin, language="en") u.save() self.client.force_login(u) be = countries.Country(name="Belgium", isocode="BE") be.save() kw = dict() kw.update(national_id="680601 053-29") kw.update(first_name="Jean") kw.update(middle_name="Jacques") kw.update(last_name="Jeffin") jean = create_row(Client, **kw) kw.update(first_name="Jo") kw.update(national_id="680601 054-28") kw.update(last_name="Jeffin") jo = create_row(Client, **kw) def grid_put(username, url, **data): data[constants.URL_PARAM_ACTION_NAME] = 'grid_put' kwargs = dict(data=urlencode(data)) kwargs['REMOTE_USER'] = username response = self.client.put(url, **kwargs) return self.check_json_result(response, 'rows success message') url = '/api/avanti/Clients/' + str(jean.pk) result = grid_put('robin', url, national_id="") self.assertEqual(result['success'], True) self.assertEqual(result['message'], 'Client "JEFFIN Jean (100)" has been updated.') jean = Client.objects.get(pk=jean.pk) self.assertEqual(jean.national_id, None) url = '/api/avanti/Clients/' + str(jo.pk) result = grid_put('robin', url, national_id="") self.assertEqual(result['success'], True) self.assertEqual(result['message'], 'Client "JEFFIN Jo (101)" has been updated.')
def objects(self): # yield Country(isocode='LU', **dd.str2kw('name', _("Luxemburg"))) # yield Country(isocode='PL', **dd.str2kw('name', _("Poland"))) # yield Country(isocode='AU', **dd.str2kw('name', _("Austria"))) # yield Country(isocode='US', short_code='USA', # **dd.str2kw('name', _("United States"))) # yield self.load_dbf('USR') # yield super(TimLoader, self).objects() # yield self.load_dbf('PLP') def bulkdel(*models): for m in models: m.objects.all()._raw_delete(DEFAULT_DB_ALIAS) bulkdel(rt.models.invoicing.Item) bulkdel(rt.models.invoicing.Plan) bulkdel(Guest, Event, SalesRule) bulkdel(Interest, Topic, Note) # bulkdel(Link) bulkdel(households_Member) bulkdel(ClientContact, Enrolment, Course) bulkdel(Line) with translation.override("de"): a = CourseAreas.therapies self.therapies = create_row( Line, name=a.text, course_area=a, ref="ET") a = CourseAreas.life_groups self.life_groups = create_row( Line, name=a.text, course_area=a, ref="LG") a = CourseAreas.default self.other_groups = create_row( Line, name=a.text, course_area=a, ref="TG") yield self.load_dbf('PAR') yield self.load_dbf('PLP') yield self.load_dbf('DLS') yield self.load_dbf('DLP') yield self.load_dbf('PRB') yield self.load_dbf('PPR') yield self.load_dbf('MSG')
def __init__(self, *args, **kwargs): super(TimLoader, self).__init__(*args, **kwargs) self.imported_sessions = set([]) self.obsolete_list = [] plptypes = dict() plptypes['01'] = LinkTypes.parent plptypes['01R'] = None plptypes['02'] = LinkTypes.uncle plptypes['02R'] = None plptypes['03'] = LinkTypes.stepparent plptypes['03R'] = None plptypes['04'] = LinkTypes.grandparent plptypes['04R'] = None plptypes['10'] = LinkTypes.spouse plptypes['11'] = LinkTypes.friend self.linktypes = plptypes a = CourseAreas.default self.other_groups = create_row(Line, name=a.text, course_area=a) a = CourseAreas.life_groups self.life_groups = create_row(Line, name=a.text, course_area=a) a = CourseAreas.therapies self.therapies = create_row(Line, name=a.text, course_area=a)
def objects(): Group = rt.models.groups.Group User = rt.models.users.User Membership = rt.models.groups.Membership Comment = rt.models.comments.Comment USERS = Cycler(User.objects.all()) for grp in Group.objects.all(): for i in range(2): u = USERS.pop() mbr = create_row(Membership, group=grp, user=u) yield mbr txt = _("Hi all, my name is {} and I am new here.").format(u) yield Comment(owner=grp, user=u, body=txt)
def run_from_ui(self, ar, **kw): me = ar.get_user() obj = ar.selected_rows[0] Vote = rt.models.votes.Vote options = dict(votable=obj, user=me) # pv = ar.action_param_values # options.update(state=pv.state) vote = create_row(Vote, **options) # if pv.comment: # create_row( # rt.models.comments.Comment, # owner=obj, # short_text=pv.comment, user=ar.get_user()) self.goto_vote(vote, ar)
def run_from_ui(self, ar, **kw): me = ar.get_user() obj = ar.selected_rows[0] Vote = rt.models.votes.Vote options = dict(votable=obj, user=me) # pv = ar.action_param_values # options.update(state=pv.state) vote = create_row(Vote, **options) # if pv.comment: # create_row( # rt.models.comments.Comment, # owner=obj, # short_text=pv.comment, user=ar.get_user()) self.goto_vote(vote, ar)
def objects(): Group = rt.models.groups.Group User = rt.models.users.User Membership = rt.models.groups.Membership Comment = rt.models.comments.Comment USERS = Cycler(User.objects.all()) for grp in Group.objects.all(): for i in range(2): u = USERS.pop() mbr = create_row(Membership, group=grp, user=u) yield mbr txt = _("Hi all, my name is {} and I am new here.").format( u) yield Comment(owner=grp, user=u, body=txt)
def test_cv_obstacle(self): """Test whether cv.Obstacle.user is correctly set to the requesting user. """ ContentType = rt.models.contenttypes.ContentType Obstacle = rt.models.cv.Obstacle ObstacleType = rt.models.cv.ObstacleType Client = rt.models.pcsw.Client User = settings.SITE.user_model robin = create_row(User, username='******', user_type=UserTypes.admin, language='en') self.assertTrue(robin.user_type.has_required_roles([IntegUser])) self.client.force_login(robin) ObstacleType(name='Alcohol').save() obj = Client(first_name="First", last_name="Last") obj.save() self.assertEqual(obj.first_name, "First") self.assertEqual(rt.models.cv.ObstaclesByPerson.column_names, "type user detected_date remark *") rh = rt.models.cv.ObstaclesByPerson.get_handle() colnames = [col.name for col in rh.get_columns()] colnames.sort() self.assertEqual( 'detected_date id mobile_item overview person remark type user workflow_buttons', ' '.join(colnames)) url = "/api/cv/ObstaclesByPerson" post_data = dict() post_data.update(type='1') post_data.update(typeHidden='1') post_data[constants.URL_PARAM_MASTER_PK] = obj.pk ct = ContentType.objects.get_for_model(Client) post_data[constants.URL_PARAM_MASTER_TYPE] = ct.id post_data[constants.URL_PARAM_ACTION_NAME] = 'grid_post' response = self.client.post(url, post_data, REMOTE_USER='******') result = self.check_json_result(response, 'rows success message navinfo') self.assertEqual(result['success'], True) if six.PY2: self.assertEqual( # result['message'], # """Freins "Obstacle object" a \xe9t\xe9 cr\xe9\xe9""") result['message'], """Obstacle "Obstacle object" has been created.""") self.assertEqual(result['rows'], [[ 'Alcohol', 1, 'robin', 1, '22.05.2014', '', 1, '<span />', '<div><em>Obstacle object</em></div>', u'<div><em>Obstacle object</em></div>', 'First LAST', 100, { 'id': True }, False ]]) else: self.assertEqual( # result['message'], # """Freins "Obstacle object" a \xe9t\xe9 cr\xe9\xe9""") result['message'], """Obstacle "Obstacle object (1)" has been created.""") # print(result['rows']) self.assertEqual(result['rows'], [[ 'Alcohol', 1, 'robin', 1, '22.05.2014', '', 1, '<div><em>Obstacle object (1)</em></div>', '<div><em>Obstacle object (1)</em></div>', '<span />', 'First LAST', 100, { 'id': True }, False ]]) self.assertEqual(Obstacle.objects.get(pk=1).user.username, 'robin')
def test01(self): from lino.modlib.users.choicelists import UserTypes User = rt.models.users.User Partner = rt.models.contacts.Partner Person = rt.models.contacts.Person Company = rt.models.contacts.Company Role = rt.models.contacts.Role Account = rt.models.sepa.Account Invoice = rt.models.vat.VatAccountInvoice Journal = rt.models.ledger.Journal VoucherTypes = rt.models.ledger.VoucherTypes JournalGroups = rt.models.ledger.JournalGroups u = User(username='******', user_type=UserTypes.admin, language="en") u.save() def createit(): obj = Person(first_name="John", last_name="Doe") obj.full_clean() obj.save() pk = obj.pk return (obj, Partner.objects.get(pk=pk)) # # If there are no vetos, user can ask to delete from any MTI form # pe, pa = createit() pe.delete() pe, pa = createit() pa.delete() # # Cascade-related objects (e.g. addresses) are deleted # independently of the polymorphic form which initiated # deletion. # def check_cascade(model): pe, pa = createit() obj = model.objects.get(pk=pa.pk) rel = Account(partner=pa, iban="AL32293653370340154130927280") rel.full_clean() rel.save() obj.delete() self.assertEqual(Account.objects.count(), 0) check_cascade(Partner) check_cascade(Person) # # Vetos of one form are deteced by all other forms. # def check_veto(obj, expected): try: obj.delete() self.fail("Failed to raise Warning({0})".format(expected)) except Warning as e: self.assertEqual(str(e), expected) VKR = create_row( Journal, ref="VKR", name="VKR", voucher_type=VoucherTypes.get_for_model(Invoice), journal_group=JournalGroups.sales) pe, pa = createit() def check_vetos(obj, msg): m = obj.__class__ obj.full_clean() obj.save() check_veto(pa, msg) check_veto(pe, msg) self.assertEqual(m.objects.count(), 1) obj.delete() self.assertEqual(m.objects.count(), 0) msg = "Cannot delete Partner Doe John because 1 Invoices refer to it." msg = "Kann Partner Doe John nicht löschen weil 1 Rechnungen darauf verweisen." check_vetos(Invoice(partner=pa, journal=VKR), msg) # # Having an invoice does not prevent from removing the Person # child of the partner. # invoice = create_row(Invoice, partner=pa, journal=VKR) self.assertEqual(Partner.objects.count(), 1) self.assertEqual(Person.objects.count(), 1) self.assertEqual(Invoice.objects.count(), 1) delete_child(pa, Person) # tidy up: self.assertEqual(Partner.objects.count(), 1) self.assertEqual(Person.objects.count(), 0) invoice.delete() pa.delete() self.assertEqual(Partner.objects.count(), 0) # But Lino refuses to remove the Person child if it has vetos. # For example if the person form is being used as a contact person. pe, pa = createit() co = create_row(Company, name="Test") create_row(Role, company=co, person=pe) msg = "[u'Cannot delete Partner Doe John because 1 Contact Persons refer to it.']" if six.PY2: msg = "[u'Kann Partner Doe John nicht l\\xf6schen weil 1 Kontaktpersonen darauf verweisen.']" else: msg = "['Kann Partner Doe John nicht löschen weil 1 Kontaktpersonen darauf verweisen.']" try: delete_child(pa, Person) self.fail("Expected ValidationError") except ValidationError as e: self.assertEqual(msg, str(e))
def test01(self): from lino.modlib.users.choicelists import UserTypes User = rt.models.users.User Partner = rt.models.contacts.Partner Person = rt.models.contacts.Person Company = rt.models.contacts.Company Role = rt.models.contacts.Role Account = rt.models.sepa.Account Invoice = rt.models.vat.VatAccountInvoice Journal = rt.models.ledger.Journal VoucherTypes = rt.models.ledger.VoucherTypes JournalGroups = rt.models.ledger.JournalGroups u = User(username='******', user_type=UserTypes.admin, language="en") u.save() def createit(): obj = Person(first_name="John", last_name="Doe") obj.full_clean() obj.save() pk = obj.pk return (obj, Partner.objects.get(pk=pk)) # # If there are no vetos, user can ask to delete from any MTI form # pe, pa = createit() pe.delete() pe, pa = createit() pa.delete() # # Cascade-related objects (e.g. addresses) are deleted # independently of the polymorphic form which initiated # deletion. # def check_cascade(model): pe, pa = createit() obj = model.objects.get(pk=pa.pk) rel = Account(partner=pa, iban="AL32293653370340154130927280") rel.full_clean() rel.save() obj.delete() self.assertEqual(Account.objects.count(), 0) check_cascade(Partner) check_cascade(Person) # # Vetos of one form are deteced by all other forms. # def check_veto(obj, expected): try: obj.delete() self.fail("Failed to raise Warning({0})".format(expected)) except Warning as e: self.assertEqual(str(e), expected) VKR = create_row( Journal, ref="VKR", name="VKR", voucher_type=VoucherTypes.get_for_model(Invoice), journal_group=JournalGroups.sales) pe, pa = createit() def check_vetos(obj, msg): m = obj.__class__ obj.full_clean() obj.save() check_veto(pa, msg) check_veto(pe, msg) self.assertEqual(m.objects.count(), 1) obj.delete() self.assertEqual(m.objects.count(), 0) msg = "Cannot delete Partner Doe John because 1 Invoices refer to it." msg = "Kann Partner Doe John nicht löschen weil 1 Rechnungen darauf verweisen." check_vetos(Invoice(partner=pa, journal=VKR), msg) # # Having an invoice does not prevent from removing the Person # child of the partner. # invoice = create_row(Invoice, partner=pa, journal=VKR) self.assertEqual(Partner.objects.count(), 1) self.assertEqual(Person.objects.count(), 1) self.assertEqual(Invoice.objects.count(), 1) delete_child(pa, Person) # tidy up: self.assertEqual(Partner.objects.count(), 1) self.assertEqual(Person.objects.count(), 0) invoice.delete() pa.delete() self.assertEqual(Partner.objects.count(), 0) # But Lino refuses to remove the Person child if it has vetos. # For example if the person form is being used as a contact person. pe, pa = createit() co = create_row(Company, name="Test") create_row(Role, company=co, person=pe) # msg = "['Cannot delete Partner Doe John because 1 Contact persons refer to it.']" msg = "['Kann Partner Doe John nicht löschen weil 1 Kontaktpersonen darauf verweisen.']" try: delete_child(pa, Person) self.fail("Expected ValidationError") except ValidationError as e: self.assertEqual(msg, str(e))
def get_event_type(self, pk): pk = int(pk) try: return EventType.objects.get(pk=pk) except EventType.DoesNotExist: return create_row(EventType, name=str(pk), pk=pk)
def get_event_type(self, pk): pk = int(pk) try: return EventType.objects.get(pk=pk) except EventType.DoesNotExist: return create_row(EventType, name=str(pk), pk=pk)