Skip to content

Conversation

tsk
Copy link

@tsk tsk commented Mar 14, 2014

1.- Installer: you can test it

$ virtualenv env --system-site-packages
$ source env/bin/activate
$ "clone my repository the devinstaller branch"
$ gtk-proxypos.py

This will create on your home

.proxypos/config/config.cfg
.proxypos/tmp

And a systray icon in star form.

To configure your printer right-click on the star icon --> Configure. Go to ESC/POS printer tab (the charSet still not working, I need to fix it), change values and save.

2.- I create the base for templating. Revise the templates in the path templates.

The basic structure of a Template is

template.tmp  <-- Template configurations and descriptio
template/         <-- html and css
$ cat default.tmp
{
  "name": "Template name",
  "type": "image",
  "description":"Description of this template",
  "path": "default",
  "files": {
      "css":"style.css",
      "template":"default.html"
  },
 "width":"420",
 "format":"html",
 "author" :{
     "name":"Author name",
    "email": "email",
    "web": "some_web"
  } 
}

$ cat default/default.html
<html>
<head>
    <link rel="stylesheet" href="style.css" type="text/css"/> <!--For test in our web browser-->
</head>
<body>
    <div id="pos-ticket">
        <div id="header">
            <t esc="order_name"  /><br/>
            <t esc="company_name"  /><br/>
            <t   esc="company_registry"/><br/>
        </div>
        <div id="products"></div>
        <div id="resume"></div>
        <div id="footer"></div>
    </div>
</body>
</html>

The names that you can use in your template are given in the mapping dict inside the init.py

mapping = {"order_name":lambda r: r['name'],
       "total_tax": lambda r: r['total_tax'],
       "shop_name": lambda r: r['shop']['name'],
       "company_name": lambda r: r['company']['name'],
       "company_website": lambda r: r['company']['website'],
       "company_phone": lambda r: r['company']['phone'],
       "company_email": lambda r: r['company']['email'],
       "company_address":lambda r: r['company']['contact_address'],
       "company_vat": lambda r: r['company']['vat'],
       "company_registry": lambda r: r['company']['company_registry'],
       "orderlines": lambda r: r['orderlines'],
       "cashier": lambda r: r['cashier'],
       "client": lambda r: r['client'],
       "currency": lambda r: r['currency'],
       "total_discount": lambda r: r['total_discount'],
       "invoice_id": lambda r: r['invoice_id'],
       "date": lambda r: r['date'],
       "total_paid": lambda r: r['total_paid'],
       "payment_amount": lambda r: r['paymentlines'][0]['amount'],
       "payment_journal": lambda r: r['paymentlines'][0]['journal'],
       "total_with_tax": lambda r: r["total_with_tax"],
       "subtotal": lambda r: r['subtotal'],
       "change": lambda r: r['change'],
      }

For a simple test

Install imagemagick, download from http://wkhtmltopdf.org/downloads.html the precompiled packages. Uncompress and copy wkhtmltoimage (wkhtmltox/bin) to /usr/local/bin, Then go to the templates directory (proxypos/templates)

$ python __init__.py

You will see the results inside of .proxypos/tmp/

pticket.png  ticket.html  ticket.png

What is missing?
1.- Get templates from .proxypos/templates/ (this is easy to do)
2.- Add the if stament in print_receipt (to allow printing from templates)

@tsk
Copy link
Author

tsk commented Mar 15, 2014

Now both kind of templates works,

a text template looks like:

{# Header Section #}
logo
{{bold(False)}}
{{font('a')}}
{{write("\n"+formatdate(date)+"\n",None,'left')}}
{{write(order_name+"\n",'','left')}}

{{write(company_name + '\n')}}
{{write('RFC: ' + str(company_registry) + '\n')}}
{{write('Telefono: ' + str(company_phone) + '\n')}}
{{write('Cajero: ' + cashier + '\n')}}
{{linefeed(1)}}
{# Order section #}
{% for line in orderlines %}
{% set left = ' '.join([str(line['quantity']),
                         line['unit_name'],
                         line['product_name']
                        ]).encode('utf-8')
%}
{% set right =  decimal(line['price_with_tax'])%}
{{write(left,right)}}
{{linefeed(1)}}
{% endfor %}
{{linefeed(2)}}
{{write('Subtotal:', decimal(total_without_tax) + '\n')}}
{{write('IVA:', decimal(total_tax) + '\n')}}
{{write('Descuento:', decimal(total_discount) + '\n')}}
{{bold(True)}}
{{write('TOTAL:', '$' + decimal(total_with_tax) + '\n')}}
{{linefeed(1)}}
{{font('a')}}
{{bold(False)}}

{% for payment in paymentlines %}
{{write(payment['journal'], decimal(payment['amount'])+'\n')}}
{% endfor %}}

{{bold(True)}}
{{write('Cambio:', '$ ' + decimal(change)+'\n')}}
{{bold(False)}}
{% if client %}
{{write('Cliente: ' + client['name'].encode('utf-8'))}}
{% endif %}

{# Footer #}

{{write('Recibo sin validez fiscal.\n', '', 'left')}}
{{write('Si requiere factura, solicitarla dentro de los proximos 5 dias','','left')}}
{{write('\n'+str(company_website)+'\n','','left')}}
{{write('\n'+str(company_email)+'\n','','left')}}
{{barcode(order_name[6:],'EAN13',64,2,'BELOW','A')}}

{{cut(1,True)}}

2014-03-15-061905

For html template

<html>
<head>
    <link rel="stylesheet" href="style.css" type="text/css"/> <!--For test in our web browser-->
</head>
<body>
    <div id="pos-ticket">
    <div id="header">
        {# logo #}
        {# <img src="{{ logo }}"/> #}
    <br/>
    {{ formatdate(date) }}<br/>
    {{order_name}}<br/>
    {{company_name}}<br/>
    RFC : {{str(company_registry)}}<br/>
    Telefono: {{str(company_phone)}}<br/>
    Cajero: {{cashier}}<br/>
    </div>
    <div id="orderlines">
    <table>
    {% for line in orderlines %}
    {% set left = ' '.join([str(line['quantity']),

2014-03-15-061930
This one still need a good css and a good html for the default template, but works!

Also you can add your own templates in ~/.proxypos/templates

@agb80
Copy link
Contributor

agb80 commented Mar 19, 2014

Hello, first of all let me said thank you for your contributions to ProxyPoS development.

Now let me ask you for keep separate branches for feature so we can better isolate changes and a historic view from merges give us better information on why there have been added some commits or changes into the code.

According to the description and the code you have pushed on your commits you are adding two main features, please let me know if I'm correct.

  1. GTK gui for proxypos
  2. Template system for print receipts

If possible please separate both features on two branches and two merge request. Anyway I'm going to start make some code review and we are going to move forward as you make the changes.

Thanks again for devote time to our project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think will be better if we add a command line option allowing people to launch ProxyPoS with or without a graphical interface on a central way, as far as I understand currently there are two ways to launch ProxyPoS and I guess that will be confusing for users.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.- An installer for the application.

For this reason we have in our bin path two commands more gtk-proxypos.py and proxypos-server. If one user want to load the gui is shorter write gtk-proxypos than proxypos-server --gtk or something like that. But if is needed give the option to load the gui as an option, it can be added, and also can be added the option to load the config file from another location "--conf=path-to-config-files"

Also I was thinking add some kind of plugin/addon manager, to avoid mess up with the main code and separate the pricipipal API from the customizations. In one hand the core API, and in the other the addons/plugins. This can help in make more easy add functionalities/hardware and keep the main code more clean, even if many people wan't to make their own customizations.

As example:
What happend if I add a custom route to the POS, I need to edit app.py to add it, but is a functionality that, in some cases, I'm the only one that is going to use it.
What happend with an addon system? The server automatically look up for addons and load them. Even can be added the posibility read the addons that you need to load from OpenERP.

The more obvious is the print receipt function. What happend if I made an improvement on some other part of the main code that I wan't to merge with the main code, but I change this function. Represent a little more work for the main code mantainer.

Or even, What if I don't need to use the ESC/POS printer. Just think in the case I develop some hardware that let you find the products in the warehouse. Enter or scan the receipt and bring the products to you, or turn on some ligths that guide you to the products. Then why load the printer or template system?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think is the most idiomatic python solution (http://mundogeek.net/traducciones/python-idiomatico/)

1.- Add an option to set from command line the option to turn on/off graphical interface
2.- Keep the way you design using two different launch scripts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log all the exceptions instead of screen printing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants