本文整理汇总了Python中c3smembership.data.model.base.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c3smembership.data.model.base.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def create(cls, membership_number, shares_quantity,
board_confirmation=None):
"""
Create a shares package.
Args:
membership_number: The membership number of the member for which
the shares package is created.
shares_quantity: The number of shares of the package to be created.
board_confirmation: Optional. The date on which the board of
directors confirmed the acquisition of the shares package.
Returns:
The technical primary key of the created shares package.
"""
shares = Shares(
number=shares_quantity,
date_of_acquisition=board_confirmation,
)
# pylint: disable=no-member
member = DBSession.query(C3sMember).filter(
C3sMember.membership_number == membership_number).first()
# pylint: disable=no-member
DBSession.add(shares)
member.shares.append(shares)
member.num_shares += shares_quantity
DBSession.flush()
return shares.id
示例2: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
my_settings = {"sqlalchemy.url": "sqlite:///:memory:", "api_auth_token": u"SECRETAUTHTOKEN"}
self.config = testing.setUp()
app = main({}, **my_settings)
# set up the database
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
member1 = C3sMember( # german
firstname=u"SomeFirstnäme",
lastname=u"SomeLastnäme",
email=u"[email protected]",
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u"ABCDEFGFOO",
password=u"arandompassword",
date_of_submission=date.today(),
membership_type=u"normal",
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u"23",
)
DBSession.add(member1)
member1.email_invite_token_bcgv16 = u"MEMBERS_TOKEN"
DBSession.flush()
self.testapp = TestApp(app)
示例3: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.close()
DBSession.remove()
# print("removed old DBSession ==============================")
except:
# print("no DBSession to remove =============================")
pass
# try:
# os.remove('test_webtest_functional.db')
# #print "deleted old test database"
# except:
# pass
# #print "never mind"
my_settings = {
# 'sqlalchemy.url': 'sqlite:///test_webtest_functional.db',
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.notification_sender': '[email protected]',
'testing.mail_to_console': 'false'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
self.session = DBSession # ()
Base.metadata.create_all(engine)
# dummy database entries for testing
with transaction.manager:
member1 = C3sMember( # german
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
DBSession.add(member1)
DBSession.flush()
from c3smembership import main
app = main({}, **my_settings)
app.registry.get_mailer = get_mailer
from webtest import TestApp
self.testapp = TestApp(app)
示例4: create_general_assembly
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def create_general_assembly(cls, number, name, date):
"""
Create a general assembly
Args:
number: Integer. The number of the general assembly as a unique
identifier.
name: String. The name of the general assembly.
date: `datetime.date`. The date at which the general assembly takes
place.
"""
assembly = GeneralAssembly(number, name, date)
# pylint: disable=no-member
DBSession.add(assembly)
DBSession.flush()
示例5: make_unconnected_shares
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def make_unconnected_shares(self):
with transaction.manager:
shares2 = Shares(
number=23,
date_of_acquisition=date.today(),
reference_code=u'IJKLMNO',
signature_received=True,
signature_received_date=date(2014, 1, 7),
payment_received=True,
payment_received_date=date(2014, 1, 8),
signature_confirmed=True,
signature_confirmed_date=date(2014, 1, 8),
payment_confirmed=True,
payment_confirmed_date=date(2014, 1, 9),
accountant_comment=u'not connected',
)
DBSession.add(shares2)
示例6: invite_member
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def invite_member(cls, membership_number, general_assembly_number, token):
"""
Store the member invitation for the general assembly
Args:
membership_number: Integer. The membership number of the member for
which the general assembly invitation is stored.
general_assembly_number: Integer. The number of the general
assembly for which the invitation is stored for the member.
token: String. The token set to verify the member for API access by
the ticketing application.
"""
# pylint: disable=no-member
member = MemberRepository.get_member(membership_number)
assembly = cls.get_general_assembly(general_assembly_number)
invitation = GeneralAssemblyInvitation(
assembly, member, cls.datetime.now(), token)
DBSession.add(invitation)
DBSession.flush()
示例7: make_member_with_shares2
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def make_member_with_shares2(self):
with transaction.manager:
member1 = C3sMember( # german
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
shares1 = Shares(
number=2,
date_of_acquisition=date.today(),
reference_code=u'ABCDEFGH',
signature_received=True,
signature_received_date=date(2014, 6, 7),
payment_received=True,
payment_received_date=date(2014, 6, 8),
signature_confirmed=True,
signature_confirmed_date=date(2014, 6, 8),
payment_confirmed=True,
payment_confirmed_date=date(2014, 6, 9),
accountant_comment=u'no comment',
)
member1.shares = [shares1]
DBSession.add(member1)
DBSession.add(shares1)
示例8: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
"""
Set up database and engine
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
DBSession().close()
DBSession.remove()
from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:')
DBSession.configure(bind=engine)
self.session = DBSession
Base.metadata.create_all(engine)
with transaction.manager:
# German member
member1 = C3sMember(
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u'addr one',
address2=u'addr two',
postcode=u'12345',
city=u'Footown Mäh',
country=u'Foocountry',
locale=u'DE',
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGBAR',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u'GEMA',
num_shares=u'23',
)
db_session = DBSession()
db_session.add(member1)
db_session.flush()
示例9: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:',
'api_auth_token': u"SECRETAUTHTOKEN",
'c3smembership.url': u'localhost',
'c3smembership.notification_sender': u'[email protected]',
'c3smembership.status_receiver': u'[email protected]',
'testing.mail_to_console': u'false',
}
self.config = testing.setUp()
app = main({}, **my_settings)
self.get_mailer = GetMailerDummy()
app.registry.get_mailer = self.get_mailer
app.registry.membership_application.datetime = DateTimeDummy(
datetime.datetime(2018, 4, 26, 12, 23, 34))
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
# a group for accountants/staff
accountants_group = Group(name=u"staff")
DBSession.add(accountants_group)
DBSession.flush()
# staff personnel
staffer1 = Staff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
DBSession.add(accountants_group)
DBSession.add(staffer1)
DBSession.flush()
self.testapp = TestApp(app)
示例10: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
"""
Setup test cases
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
DBSession.close()
DBSession.remove()
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.dashboard_number': '30'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
# self._insert_members()
with transaction.manager:
# a group for accountants/staff
accountants_group = Group(name=u"staff")
DBSession.add(accountants_group)
DBSession.flush()
# staff personnel
staffer1 = Staff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
DBSession.add(accountants_group)
DBSession.add(staffer1)
DBSession.flush()
app = main({}, **my_settings)
self.testapp = TestApp(app)
示例11: _initTestingDB
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def _initTestingDB():
"""
Set up a database for these tests: have some test data.
"""
my_settings = {'sqlalchemy.url': 'sqlite:///:memory:', }
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
normal_de = C3sMember( # german normal
firstname=u'Ada Musiziert',
lastname=u'Traumhaft ÄÖÜ',
email=u'[email protected]',
address1=u"ada addr one",
address2=u"ada addr two",
postcode=u"12345",
city=u"Foostadt Ada",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'NORMAL_DE1',
password=u'adasrandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
normal_en = C3sMember( # english normal
firstname=u'James',
lastname=u'Musician',
email=u'[email protected]',
address1=u"james addr 1",
address2=u"james appartment 2",
postcode=u"12345",
city=u"Jamestown",
country=u"Jamescountry",
locale=u"en",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'NORMAL_DE',
password=u'jamesrandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"",
num_shares=u'2',
)
investing_de = C3sMember( # german investing
firstname=u'Herman',
lastname=u'Investorius',
email=u'[email protected]',
address1=u"addr one4",
address2=u"addr two4",
postcode=u"12344",
city=u"Footown M44",
country=u"Foocountr4",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'INVESTING_DE',
password=u'arandompasswor4',
date_of_submission=date.today(),
membership_type=u'investing',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'60',
)
investing_en = C3sMember( # english investing
firstname=u'Britany',
lastname=u'Investing',
email=u'[email protected]',
address1=u"aone5",
address2=u"atwo5",
postcode=u"12355",
city=u"Footown M45",
country=u"Foocountr5",
locale=u"en",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'INVESTING_EN',
password=u'arandompasswor5',
date_of_submission=date.today(),
membership_type=u'investing',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'60',
)
legal_entity_de = C3sMember( # german investing legal entity
firstname=u'Deutscher',
lastname=u'Musikverlag',
email=u'[email protected]',
address1=u"foo bulevard",
address2=u"123-345",
postcode=u"98765",
city=u"Foo",
country=u"Bar",
locale=u"de",
date_of_birth=date.today(),
#.........这里部分代码省略.........
示例12: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
my_settings = {'sqlalchemy.url': 'sqlite:///:memory:', }
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
member1 = C3sMember( # german
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=35,
)
member2 = C3sMember( # german
firstname=u'AAASomeFirstnäme',
lastname=u'XXXSomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGBAR',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=45,
)
member3 = C3sMember(
firstname=u'Not Approved',
lastname=u'Member',
email=u'[email protected]',
address1=u'Some Street 123',
address2=u'',
postcode=u"12345",
city=u"Some City",
country=u"Some Country",
locale=u"DE",
date_of_birth=date(1980, 1, 2),
email_is_confirmed=False,
email_confirm_code=u'NOT_APPROVED_MEMBER',
password=u'not_approved_member',
date_of_submission=date(1970, 1, 1),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u'',
num_shares=7,
)
# pylint: disable=no-member
DBSession.add(member1)
# pylint: disable=no-member
DBSession.add(member2)
# pylint: disable=no-member
DBSession.add(member3)
member1.membership_number = u'member1'
member1.membership_date = date(2013, 1, 1)
member1.membership_accepted = True
member2.membership_number = u'member2'
member2.membership_date = date(2013, 1, 1)
member2.membership_accepted = True
member3.payment_received_date = date(2016, 10, 11)
share = Shares()
share.reference_code = u'share1'
share.date_of_acquisition = date(2013, 1, 2)
share.payment_received_date = date(2012, 11, 10)
share.number = 12
member1.shares.append(share)
share = Shares()
share.reference_code = u'share2'
share.date_of_acquisition = date(2014, 2, 3)
share.payment_received_date = date(2012, 12, 31)
share.number = 23
member1.shares.append(share)
share = Shares()
share.reference_code = u'share3'
share.date_of_acquisition = date(2014, 3, 4)
share.payment_received_date = date(2014, 3, 3)
share.number = 34
#.........这里部分代码省略.........
示例13: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def setUp(self):
"""
Set up tests
"""
datetime_mock = mock.Mock()
GeneralAssemblyRepository.datetime = datetime_mock
# pylint: disable=no-member
my_settings = {'sqlalchemy.url': 'sqlite:///:memory:', }
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2014,
u'1. ordentliche Generalversammlung',
date(2014, 8, 23)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2015,
u'2. ordentliche Generalversammlung',
date(2015, 6, 13)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2015_2,
u'Außerordentliche Generalversammlung',
date(2015, 7, 16)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2016,
u'3. ordentliche Generalversammlung',
date(2016, 4, 17)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2017,
u'4. ordentliche Generalversammlung',
date(2017, 4, 2)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2018,
u'5. ordentliche Generalversammlung',
date(2018, 6, 3)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2018_2,
u'Außerordentliche Generalversammlung',
date(2018, 12, 1)))
member1 = C3sMember(
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=35,
)
member2 = C3sMember(
firstname=u'AAASomeFirstnäme',
lastname=u'XXXSomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGBAR',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=45,
)
member3 = C3sMember(
firstname=u'Not invited',
lastname=u'at all',
email=u'[email protected]',
address1=u'Some',
address2=u'Address',
postcode=u'45678',
city=u'Hamburg',
country=u'Germany',
locale=u'DE',
date_of_birth=date(1980, 1, 2),
email_is_confirmed=False,
email_confirm_code=u'member3',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
#.........这里部分代码省略.........
示例14: send_dues18_invoice_email
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
def send_dues18_invoice_email(request, m_id=None):
"""
Send email to a member to prompt her to pay the membership dues.
- For normal members, also send link to invoice.
- For investing members that are legal entities,
ask for additional support depending on yearly turnover.
This view function works both if called via URL, e.g. /dues_invoice/123
and if called as a function with a member id as parameter.
The latter is useful for batch processing.
When this function is used for the first time for one member,
some database fields are filled:
- Invoice number
- Invoice amount (calculated from date of membership approval by the board)
- Invoice token
Also, the database table of invoices (and cancellations) is appended.
If this function gets called the second time for a member,
no new invoice is produced, but the same mail sent again.
"""
# either we are given a member id via url or function parameter
try: # view was called via http/s
member_id = request.matchdict['member_id']
batch = False
except KeyError: # ...or was called as function with parameter (see batch)
member_id = m_id
batch = True
try: # get member from DB
member = C3sMember.get_by_id(member_id)
assert(member is not None)
except AssertionError:
if not batch:
request.session.flash(
"member with id {} not found in DB!".format(member_id),
'warning')
return HTTPFound(request.route_url('dues'))
# sanity check:is this a member?
try:
assert(member.membership_accepted) # must be accepted member!
except AssertionError:
request.session.flash(
"member {} not accepted by the board!".format(member_id),
'warning')
return HTTPFound(request.route_url('dues'))
if 'normal' not in member.membership_type and \
'investing' not in member.membership_type:
request.session.flash(
'The membership type of member {0} is not specified! The '
'membership type must either be "normal" or "investing" in order '
'to be able to send an invoice email.'.format(member.id),
'warning')
return get_memberhip_listing_redirect(request)
if member.membership_date >= date(2019, 1, 1) or (
member.membership_loss_date is not None
and member.membership_loss_date < date(2018, 1, 1)
):
request.session.flash(
'Member {0} was not a member in 2018. Therefore, you cannot send '
'an invoice for 2018.'.format(member.id),
'warning')
return get_memberhip_listing_redirect(request)
# check if invoice no already exists.
# if yes: just send that email again!
# also: offer staffers to cancel this invoice
if member.dues18_invoice is True:
invoice = DuesInvoiceRepository.get_by_number(
member.dues18_invoice_no, 2018)
member.dues18_invoice_date = datetime.now()
else: # if no invoice already exists:
# make dues token and ...
randomstring = make_random_string()
# check if dues token is already used
while DuesInvoiceRepository.token_exists(randomstring, 2018):
# create a new one, if the new one already exists in the database
randomstring = make_random_string() # pragma: no cover
# prepare invoice number
try:
# either we already have an invoice number for that client...
invoice_no = member.dues18_invoice_no
assert invoice_no is not None
except AssertionError:
# ... or we create a new one and save it
# get max invoice no from db
max_invoice_no = DuesInvoiceRepository.get_max_invoice_number(2018)
# use the next free number, save it to db
new_invoice_no = int(max_invoice_no) + 1
DBSession.flush() # save dataset to DB
# calculate dues amount (maybe partial, depending on quarter)
dues_start, dues_amount = calculate_partial_dues18(member)
# now we have enough info to update the member info
#.........这里部分代码省略.........
示例15: dues18_reduction
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import add [as 别名]
#.........这里部分代码省略.........
max_invoice_no = DuesInvoiceRepository.get_max_invoice_number(2018)
# things to be done:
# * change dues amount for that member
# * cancel old invoice by issuing a reversal invoice
# * issue a new invoice with the new amount
member.set_dues18_reduced_amount(reduced_amount)
request.session.flash('reduction to {}'.format(reduced_amount),
'dues18_message_to_staff')
old_invoice = DuesInvoiceRepository.get_by_number(
member.dues18_invoice_no, 2018)
old_invoice.is_cancelled = True
reversal_invoice_amount = -D(old_invoice.invoice_amount)
# prepare reversal invoice number
new_invoice_no = max_invoice_no + 1
# create reversal invoice
reversal_invoice = Dues18Invoice(
invoice_no=new_invoice_no,
invoice_no_string=(
u'C3S-dues2018-' + str(new_invoice_no).zfill(4)) + '-S',
invoice_date=datetime.today(),
invoice_amount=reversal_invoice_amount.to_eng_string(),
member_id=member.id,
membership_no=member.membership_number,
email=member.email,
token=member.dues18_token,
)
reversal_invoice.preceding_invoice_no = old_invoice.invoice_no
reversal_invoice.is_reversal = True
DBSession.add(reversal_invoice)
DBSession.flush()
old_invoice.succeeding_invoice_no = new_invoice_no
# check if this is an exemption (reduction to zero)
is_exemption = False # sane default
# check if reduction to zero
if reduced_amount.is_zero():
is_exemption = True
if DEBUG:
print("this is an exemption: reduction to zero")
else:
if DEBUG:
print("this is a reduction to {}".format(reduced_amount))
if not is_exemption:
# create new invoice
new_invoice = Dues18Invoice(
invoice_no=new_invoice_no + 1,
invoice_no_string=(
u'C3S-dues2018-' + str(new_invoice_no + 1).zfill(4)),
invoice_date=datetime.today(),
invoice_amount=u'' + str(reduced_amount),
member_id=member.id,
membership_no=member.membership_number,
email=member.email,
token=member.dues18_token,
)
new_invoice.is_altered = True
new_invoice.preceding_invoice_no = reversal_invoice.invoice_no
reversal_invoice.succeeding_invoice_no = new_invoice_no + 1
DBSession.add(new_invoice)