def CopyCustomers(session, session_new): attributes = ['Active', 'Discount', 'TaxIncluded', 'Credit', 'Notes'] # 'TaxTableOverride', 'Terms', 'TaxTable' # These attributes are not copied, and are lost. # you can include them to coppy and manually copy XML from the old XML # file to the new one ! # Tables to copy are: <gnc:GncBillTerm version="2.0.0"> # and <gnc:GncTaxTable version="2.0.0"> # The TaxTable needs to be edited afterwards, since the account reference changed. commodtable = session_new.book.get_table() for customer in Query.getCustomers(session.book): commod = commodtable.lookup('CURRENCY', customer.GetCurrency().get_mnemonic()) customer_new = Customer(session_new.book, customer.GetID(), commod, customer.GetName()) for attrib in attributes: getattr(customer_new, 'Set' + attrib)(getattr(customer, 'Get' + attrib)()) for job in customer.GetJoblist(True): job_old = Job(instance=job) if job_old.GetActive() == True: job_new = Job(book=session_new.book, id=job_old.GetID(), owner=customer_new, name=job_old.GetName()) _CopyAddress(customer.GetAddr(), customer_new.GetAddr()) _CopyAddress(customer.GetShipAddr(), customer_new.GetShipAddr())
def setUp(self): BookSession.setUp(self) self.today = datetime.today() self.bank = Account(self.book) self.bank.SetType(ACCT_TYPE_BANK) self.bank.SetCommodity(self.currency) self.income = Account(self.book) self.income.SetType(ACCT_TYPE_INCOME) self.income.SetCommodity(self.currency) self.receivable = Account(self.book) self.receivable.SetType(ACCT_TYPE_RECEIVABLE) self.receivable.SetCommodity(self.currency) self.customer = Customer(self.book,'CustomerID',self.currency) self.vendor = Vendor(self.book,'VendorID',self.currency) self.employee = Employee(self.book,'EmployeeID',self.currency) self.job = Job(self.book,'JobID',self.customer) self.invoice = Invoice(self.book,'InvoiceID',self.currency,self.customer) self.invoice.SetDateOpened(self.today) entry = Entry(self.book) entry.SetDate(self.today) entry.SetDescription("Some income") entry.SetQuantity(GncNumeric(1)) entry.SetInvAccount(self.income) entry.SetInvPrice(GncNumeric(100)) self.invoice.AddEntry(entry) self.invoice.PostToAccount(self.receivable, self.today, self.today, "", True, False)
a6.SetType(ACCT_TYPE_ASSET) a6.SetCommodity(CAD) # name isn't required, ID and currency are new_customer = Customer(book, "1", CAD, "Bill & Bob Industries") # not required, but a good idea because the GUI insists on basic address info address = new_customer.GetAddr() address.SetName("Bill & Bob") address.SetAddr1("201 Nowhere street") new_employee = Employee(book, "2", CAD, "Reliable employee") new_vendor = Vendor(book, "3", CAD, "Dependable vendor") new_job = Job(book, "4", new_vendor, "Good clean, fun") # 7% tax tax_table = TaxTable(book, "good tax", TaxTableEntry(a5, True, GncNumeric(700000, 100000))) invoice_customer = Invoice(book, "5", CAD, new_customer) customer_extract = invoice_customer.GetOwner() assert (isinstance(customer_extract, Customer)) assert (customer_extract.GetName() == new_customer.GetName()) invoice_employee = Invoice(book, "6", CAD, new_employee) employee_extract = invoice_employee.GetOwner() assert (isinstance(employee_extract, Employee)) assert (employee_extract.GetName() == new_employee.GetName())