コード例 #1
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)