def _init_content(self): session = pos.database.session() ps = session.query(Product).filter(Product.in_stock).all() total = 0 def_c = currency.get_default() headers = ('Reference', 'Name', 'Price', 'Quantity', 'Total') data = [] marked = [] for p in ps: pc = p.currency p_total = p.quantity*p.price data.append([p.reference, p.name, pc.format(p.price), 'x%d' % (p.quantity,), pc.format(p_total)]) if p.quantity<=0: marked.append(len(data)) total += currency.convert(p_total, pc, def_c) table = self.doTable(data=data, header=headers, marked_rows=marked) total_para = Paragraph('Total: %s' % (def_c.format(total),), stylesheet['Heading3Right']) self.elements.append(Spacer(36,36)) self.elements.append(total_para)
def OnCurrencyChoice(self, event): event.Skip() t = self._doCheckCurrentTicket() if t: tc = t.currency currency_symbol = self.currencyChoice.GetStringSelection() session = pos.database.session() c = session.query(Currency).filter_by(symbol=currency_symbol).one() if len(t.ticketlines) == 0: t.update(currency=c) else: retCode = wx.MessageBox( 'Change sell prices accordingly?', 'Change Currency', wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION) if retCode == wx.NO: t.update(currency=c) elif retCode == wx.YES: for tl in t.ticketlines: tl.update( sell_price=currency.convert(tl.sell_price, tc, c)) t.update(currency=c) elif retCode == wx.CANCEL: self.currencyChoice.SetStringSelection(tc.symbol) self.updateTicketInfo() self.setCurrentTicket(t)
def _init_content(self): session = pos.database.session() ps = session.query(Product).filter(Product.in_stock).all() total = 0 def_c = currency.get_default() headers = ('Reference', 'Name', 'Price', 'Quantity', 'Total') data = [] marked = [] for p in ps: pc = p.currency p_total = p.quantity * p.price data.append([ p.reference, p.name, pc.format(p.price), 'x%d' % (p.quantity, ), pc.format(p_total) ]) if p.quantity <= 0: marked.append(len(data)) total += currency.convert(p_total, pc, def_c) table = self.doTable(data=data, header=headers, marked_rows=marked) total_para = Paragraph('Total: %s' % (def_c.format(total), ), stylesheet['Heading3Right']) self.elements.append(Spacer(36, 36)) self.elements.append(total_para)
def _init_content(self): period_total = 0 def_c = currency.get_default() headers = ('Description', 'Price', 'Amount', 'Total') for t in self.tickets: row = [Paragraph('Ticket #%.3d (%s)%s' % (t.id, t.payment_method, \ ' [not paid]' if not t.paid else ''), stylesheet['Heading3']), Paragraph(str(t.date_close), stylesheet['Heading3Right'])] info_table = self.doTable(data=[row]) #[doc.width/2.0]*2 data = [] tc = t.currency tls = t.ticketlines for tl in tls: # TODO add discount data.append([tl.description, tc.format(tl.sell_price), 'x%d' % (tl.amount,), tc.format(tl.amount*tl.sell_price)]) total = t.total footer = ['', '', 'Sub Total', tc.format(total)] period_total += currency.convert(total, tc, def_c) #colwidths = ['*']+['17%']*3 table = self.doTable(data=data, header=headers, footer=footer) total_para = Paragraph('Total: %s' % (def_c.format(period_total),), stylesheet['Heading3Right']) self.elements.append(Spacer(36,36)) self.elements.append(total_para)
def _init_content(self): period_total = 0 def_c = currency.get_default() headers = ('Description', 'Price', 'Amount', 'Total') for t in self.tickets: row = [Paragraph('Ticket #%.3d (%s)%s' % (t.id, t.payment_method, \ ' [not paid]' if not t.paid else ''), stylesheet['Heading3']), Paragraph(str(t.date_close), stylesheet['Heading3Right'])] info_table = self.doTable(data=[row]) #[doc.width/2.0]*2 data = [] tc = t.currency tls = t.ticketlines for tl in tls: # TODO add discount data.append([ tl.description, tc.format(tl.sell_price), 'x%d' % (tl.amount, ), tc.format(tl.amount * tl.sell_price) ]) total = t.total footer = ['', '', 'Sub Total', tc.format(total)] period_total += currency.convert(total, tc, def_c) #colwidths = ['*']+['17%']*3 table = self.doTable(data=data, header=headers, footer=footer) total_para = Paragraph('Total: %s' % (def_c.format(period_total), ), stylesheet['Heading3Right']) self.elements.append(Spacer(36, 36)) self.elements.append(total_para)
def addProductLine(self, p): sell_price = currency.convert(p.price, p.currency, self.ticket.currency) tl = TicketLine() tl.update(description=p.name, sell_price=sell_price, amount=1, discount=0, ticket=self.ticket, product=p, is_edited=False) self.updateList(self.ticket) index = self.findLine(tl) self.Select(index, True)
def debt(self): session = pos.database.session() qry = session.query(func.sum(TicketLine.total), Currency) \ .filter((TicketLine.ticket_id == Ticket.id) & \ (Ticket.customer == self) & \ (Ticket.currency_id == Currency.id) & \ (Ticket.payment_method == 'debt') & \ ~Ticket.paid) \ .group_by(Ticket.currency_id) total = sum(currency.convert(c_total, c, self.currency) for c_total, c in qry.all()) return total
def debt(self): session = pos.database.session() qry = ( session.query(func.sum(TicketLine.total), Currency) .filter( (TicketLine.ticket_id == Ticket.id) & (Ticket.customer == self) & (Ticket.currency_id == Currency.id) & (Ticket.payment_method == "debt") & ~Ticket.paid ) .group_by(Ticket.currency_id) ) total = sum(currency.convert(c_total, c, self.currency) for c_total, c in qry.all()) return total
def OnCurrencyChoice(self, event): event.Skip() t = self._doCheckCurrentTicket() if t: tc = t.currency currency_symbol = self.currencyChoice.GetStringSelection() session = pos.database.session() c = session.query(Currency).filter_by(symbol=currency_symbol).one() if len(t.ticketlines) == 0: t.update(currency=c) else: retCode = wx.MessageBox('Change sell prices accordingly?', 'Change Currency', wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION) if retCode == wx.NO: t.update(currency=c) elif retCode == wx.YES: for tl in t.ticketlines: tl.update(sell_price=currency.convert(tl.sell_price, tc, c)) t.update(currency=c) elif retCode == wx.CANCEL: self.currencyChoice.SetStringSelection(tc.symbol) self.updateTicketInfo() self.setCurrentTicket(t)