예제 #1
0
파일: categories.py 프로젝트: louika/vivi
 def __set__(self, instance, value):
     recipe_categories = instance.xml.xpath('./head/recipe_categories')
     if len(recipe_categories) != 0:
         instance.xml.head.remove(recipe_categories[0])
     value = self._remove_duplicates(value)
     if len(value) > 0:
         el = E.recipe_categories()
         for item in value:
             el.append(E.category(code=item.code))
         instance.xml.head.append(el)
예제 #2
0
    def invoice_begin(self, **kwargs):

        defined_args = dict(invoice_type=('invoice', 'pharmacy'),
                            number=None,
                            nip=None,
                            description=('both', 'original'),
                            paymentname=None,
                            paymentdate=None,
                            recipient=None,
                            issuer=None,
                            copies=None,
                            margins=('yes', 'no'),
                            signarea=('yes', 'no'),
                            customernameoptions=('info', 'all', 'none'),
                            sellernameoptions=('info', 'all', 'none'),
                            paidlabel=None,
                            selldate=None,
                            buyerlabel=None,
                            additionalinfo=None)

        cmd = E.invoice()

        cmd.set('action', 'begin')

        # Prepare options
        options = set(kwargs.pop('options', []))
        if options:
            for op in options:
                if op in range(1, 20):
                    op_tag = cmd.append(E.option('', id=str(op)))

        # Prepare customer info
        customer = kwargs.pop('customer', [])
        for cust in customer:
            cust_tag = cmd.append(E.customer(cust))

        args = {}
        for name, value in kwargs.items():
            if name not in defined_args:
                raise TypeError('Unknown argument: {}'.format(name))

            allowed_values = defined_args.get(name)
            if allowed_values is not None and value not in allowed_values:
                raise TypeError(
                    'Argument {} has wrong value: {} (not in {})'.format(
                        name, value, allowed_values))

            if value is not None:
                cmd.set(name, str(value))

        self.send_command(cmd, check_for_errors=True)
예제 #3
0
    def non_fiscal_printout(self, lines, systemno='', nonfiscalheader='yes'):
        cmd = E.nonfiscalprintout('',
                                  systemno=systemno,
                                  nonfiscalheader=nonfiscalheader)

        for line in lines:
            if isinstance(line, collections.Mapping):
                text = line.pop('text', '')

                cmd.append(E.line(text, **line))

            else:
                # Just a text line
                cmd.append(E.line(line))

        self.send_command(cmd, check_for_errors=True)
예제 #4
0
    def receipt_begin(self, mode='online', pharmaceutical='no'):
        cmd = E.receipt('',
                        action='begin',
                        mode=mode,
                        pharmaceutical=pharmaceutical)

        self.send_command(cmd, check_for_errors=True)
예제 #5
0
    def markup(self, value, name, descid):
        cmd = E.discount('',
                         value=value,
                         name=name,
                         descid=str(descid),
                         action='markup')

        self.send_command(cmd, check_for_errors=True)
예제 #6
0
 def invoice_close(self, total, systemno, checkout, cashier, buyer):
     cmd = E.invoice('',
                     action='close',
                     total=str(total),
                     systemno=systemno,
                     checkout=checkout,
                     cashier=cashier,
                     buyer=buyer)
     self.send_command(cmd, check_for_errors=True)
예제 #7
0
    def payment_add(self, type_, value, rate=1, mode='payment', name=''):
        cmd = E.payment('',
                        action='add',
                        type=type_,
                        value=str(value),
                        rate=str(rate),
                        mode=mode,
                        name=name)

        self.send_command(cmd, check_for_errors=True)
예제 #8
0
 def ingredients(self, value):
     for node in self.xml.xpath('./ingredient'):
         node.getparent().remove(node)
     for item in value:
         self.xml.append(
             E.ingredient(
                 code=item.code,
                 amount=item.amount if hasattr(item, 'amount') else '',
                 unit=item.unit if hasattr(item, 'unit') else '',
                 details=item.details if hasattr(item, 'details') else ''))
예제 #9
0
    def info_checkout(self, type_='receipt'):

        cmd = E.info('',
                     action='checkout',
                     type=type_,
                     isfiscal='?',
                     lasterror='?')

        return self.send_command(
            cmd,
            read_reply=True,
        ).info
예제 #10
0
    def taxrates_get(self):

        cmd = E.taxrates('', action='get')

        res = self.send_command(
            cmd,
            read_reply=True,
        )

        tax_rates = [(ptu.get('name'), ptu.text) for ptu in res.taxrates.ptu]

        return tax_rates
예제 #11
0
파일: html.py 프로젝트: sterling312/logtail
 def init(self, title=None, style=None, **body):
     self.html = E.html(E.head(), E.body(E.div(), **body))
     self.html.body.div.set('class', 'container')
     if title:
         self.html.head.append(E.title(title))
     if style:
         self.html.head.append(E.style(style, type='text/css'))
예제 #12
0
    def item(self,
             name,
             quantity,
             quantityunit,
             ptu,
             price,
             plu='',
             action='sale',
             recipe='',
             charge='',
             description='',
             discount_name='',
             discount_value=None,
             discount_descid=0):
        if discount_value is not None:
            dsc = E.discount('',
                             action='discount',
                             name=discount_name,
                             value=discount_value,
                             descid=str(discount_descid))
        else:
            dsc = ''

        cmd = E.item(dsc,
                     name=name,
                     quantity=str(quantity),
                     quantityunit=quantityunit,
                     ptu=ptu,
                     price=str(price),
                     plu=plu,
                     action=action,
                     recipe=recipe,
                     charge=charge,
                     description=description)

        self.send_command(cmd, check_for_errors=True)
예제 #13
0
    def receipt_close(self,
                      total,
                      systemno,
                      checkout,
                      cashier,
                      charge=None,
                      nip=None):
        cmd = E.receipt('',
                        action='close',
                        total=str(total),
                        systemno=systemno,
                        checkout=checkout,
                        cashier=cashier)

        if charge is not None:
            cmd.set('charge', str(charge))

        if nip is not None:
            cmd.set('nip', nip)

        self.send_command(cmd, check_for_errors=True)
예제 #14
0
def test_etree_to_bytes():
    assert etree_to_bytes(E.dle()) == b'<dle/>'
예제 #15
0
def test_send_existing_command(printer):
    pkt = printer.send_command(E.dle(), True)

    assert pkt.dle.get('online') in ('yes', 'no')
예제 #16
0
def test_send_not_existing_command(printer):
    printer.set_error('silent')

    with pytest.raises(ProtocolError):
        pkt = printer.send_command(E.not_existing(), False, True)
예제 #17
0
 def receipt_cancel(self):
     cmd = E.receipt('', action='cancel')
     self.send_command(cmd, check_for_errors=True)
예제 #18
0
    def get_error(self):
        cmd = E.error('', action='get', value='')

        return int(self.send_command(cmd, True).error.get('value'))
예제 #19
0
    def set_error(self, value):
        cmd = E.error('', action='set', value=value)

        self.send_command(cmd)
예제 #20
0
    def open_drawer(self):

        cmd = E.control('', action='drawer')

        self.send_command(cmd, check_for_errors=True)
예제 #21
0
def test_assemble_packet_crc():
    assert etree_to_bytes(assemble_packet(
        E.dle(), True)) == b'<packet crc="4259D34E"><dle/></packet>'
예제 #22
0
def test_assemble_packet_no_crc():
    assert etree_to_bytes(assemble_packet(
        E.dle())) == b'<packet><dle/></packet>'
예제 #23
0
 def dle(self):
     return self.send_command(E.dle(), True).dle.attrib
예제 #24
0
파일: html.py 프로젝트: sterling312/logtail
 def __init__(self, package_name='data_server', folder='templates'):
     self.env = Environment(loader=PackageLoader(package_name, folder))
     self.html = E.html()
예제 #25
0
 def enq(self):
     return self.send_command(E.enq(), True).enq.attrib
예제 #26
0
파일: html.py 프로젝트: sterling312/logtail
 def generate_table(self, col, **kwargs):
     table = E.table(**kwargs)
     for attr, value in col:
         table.append(E.tr(E.td(value, **attr))) 
     return table
예제 #27
0
 def invoice_cancel(self):
     cmd = E.invoice('', action='cancel')
     self.send_command(cmd, check_for_errors=True)